import sys


def mergesort(A):
    if not A:
        return []

    if len(A) == 1:
        return A

    middle = int(len(A) / 2)
    left = A[:middle]
    right = A[middle:]

    left = mergesort(left)
    right = mergesort(right)

    return merge(left, right)


def merge(left, right):
    result = []
    i, j = 0, 0
    while i < len(left) and j < len(right):
        if left[i] <= right[j]:
            result.append(left[i])
            i += 1
        else:
            result.append(right[j])
            j += 1

    result += left[i:]
    result += right[j:]

    return result


def main():
    ls = [5, 4, 3, 2, 1, 0]
    print(ls)
    print(mergesort(ls))

if __name__ == '__main__':
    sys.exit(main())
