def missing2(list1, list2): 
    list1 = sorted(list1)
    list2 = sorted(list2)
    missing = []
    while list1 and list2:
        if list1[0] <= list2[0]:
            x = list1.pop(0)
            if x < list2[0]:
                missing.append(x)
        else:
            list2.pop(0)
    return missing + list1

def missing3(a, b):
    setb = set(b)
    return [ai for ai in a if ai not in setb]

def missing2S(list1, list2):
  list1 = sorted(list1)
  list2 = sorted(list2)
  missing = []
  y=0
  for x in list1:
    while list2 and y < x:
      y = list2.pop(0)
    if y > x:
      missing.append(x)
  return missing
    

from random import randrange
for n in range(20):
    b = [randrange(1, 100) for i in range(5)]
    a = b + [randrange(1, 100)]
    m1, m2 = missing3(a, b), missing2S(a, b)
    if m1 != m2:
        print(n, m1, m2, sorted(a), sorted(b))


        