up = list(itertools.takewhile(lambda x: x < down[-1], up))
if not up:
    return []
down = list(itertools.dropwhile(lambda x: x < up[0], down))
if not down:
    return []
for i in range(min(len(up), len(down))):
    if up[i] >= down[i]:
        up.insert(i, up[i - 1])
return tuple(itertools.zip_longest(up, down, fillvalue=(up, down)[len(up) >
    len(down)][-1]))
List of minimal pairs from a pair of lists