from typing import List


def merge(A: List[int], B: List[int]) -> List[int]:
    """merge two sorted lists"""
    combined: List[int] = []
    while A and B:
        # merge backward, from big to small
        a = A.pop()
        b = B.pop()
        if a >= b:
            combined.append(a)
            B.append(b)
        else:
            combined.append(b)
            A.append(a)
    # either A or B is empty, put leftover in A
    A += B
    while A:
        combined.append(A.pop())
    # reverse to small to big
    combined.reverse()
    return combined