def merge_sort(seq):
    """Sort sequence by merge sort."""
    if isinstance(seq, list):
        mid = len(seq) // 2
        left, right = seq[:mid], seq[mid:]
        if len(left) > 1:
            left = merge_sort(left)
        if len(right) > 1:
            right = merge_sort(right)
        sorted_seq = []
        while left and right:
            if left[-1] >= right[-1]:
                sorted_seq.insert(0, left.pop())
            else:
                sorted_seq.insert(0, right.pop())
        return list(left or right) + sorted_seq
    else:
        raise TypeError('Input type must be a list.')