import itertools


def _repeat_elements(arr, n):
    """
    Repeats the elements int the input array, e.g.
    [1, 2, 3] -> [1, 1, 1, 2, 2, 2, 3, 3, 3]
    """
    ret = list(itertools.chain(*[list(itertools.repeat(elem, n)) for elem in arr]))
    return ret