def merge_n_reduce(f, arity, data):
    """ Apply f cumulatively to the items of data,
    from left to right in n-tree structure, so as to
    reduce the data.

    :param f: function to apply to reduce data
    :param arity: Number of elements in group
    :param data: List of items to be reduced
    :return: List of results
    """
    while len(data) > 1:
        data_chunk = data[:arity]
        data = data[arity:]
        data.append(f(*data_chunk))
    return data[0]