from collections import deque


def merge_reduce(f, data):
    """
    Apply f cumulatively to the items of data,
    from left to right in binary tree structure, so as to
    reduce the data to a single value.

    :param f: function to apply to reduce data
    :param data: List of items to be reduced
    :return: result of reduce the data to a single value
    """

    q = deque(range(len(data)))
    new_data = data[:]
    while len(q):
        x = q.popleft()
        if len(q):
            y = q.popleft()
            new_data[x] = f(new_data[x], new_data[y])
            q.append(x)
        else:
            return new_data[x]