user
Write a python script that implements the Merge Sort algorithm for sorting a list of integers. The program should take a list of integers as input and return the sorted list as output.
assistant
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    left_half = arr[:mid]
    right_half = arr[mid:]

    left_sorted = merge_sort(left_half)
    right_sorted = merge_sort(right_half)

    return merge(left_sorted, right_sorted)


def merge(left, right):
    result = []
    i = j = 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.extend(left[i:])
    result.extend(right[j:])

    return result


if __name__ == "__main__":
    arr = [int(x) for x in input("Enter a list of integers separated by space: ").split()]
    sorted_arr = merge_sort(arr)
    print("Sorted array:", sorted_arr)