Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans *= bset
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans *= aset
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)


Fixed submission:
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans = (ans * bset) % INF
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans = (ans * aset) % INF
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans *= bset
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans *= aset
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)


Fixed submission:
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans = (ans * bset) % INF
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans = (ans * aset) % INF
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = sorted([int(input()) for _ in range(n)])[::-1]
blist = sorted([int(input()) for _ in range(n)])[::-1]

a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans *= bset
      bset -= 1
    else:
      aset += 1
    if alist:
      a = alist.pop()
    else:
      a = pow(10, 9) + 7
  else:
    if aset > 0:
      ans *= aset
      aset -= 1
    else:
      bset += 1
    if blist:
      b = blist.pop()
    else:
      b = pow(10, 9) + 7
print(ans % (pow(10, 9) + 7))


Fixed submission:
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans = (ans * bset) % INF
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans = (ans * aset) % INF
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = sorted([int(input()) for _ in range(n)])[::-1]
blist = sorted([int(input()) for _ in range(n)])[::-1]

a = alist.pop()
b = blist.pop()
aset, bset = [], []
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset:
      ans *= len(bset)
      del bset[0]
    else:
      aset.append(a)
    if alist:
      a = alist.pop()
    else:
      a = pow(10, 9) + 7
  else:
    if aset:
      ans *= len(aset)
      del aset[0]
    else:
      bset.append(b)
    if blist:
      b = blist.pop()
    else:
      b = pow(10, 9) + 7
print(ans % (pow(10, 9) + 7))


Fixed submission:
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans = (ans * bset) % INF
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans = (ans * aset) % INF
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = sorted([int(input()) for _ in range(n)])[::-1]
blist = sorted([int(input()) for _ in range(n)])[::-1]

a = alist.pop()
b = blist.pop()
aset, bset = [], []
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset:
      ans *= len(bset)
      del bset[0]
    else:
      aset.append(a)
    if alist:
      a = alist.pop()
    else:
      a = pow(10, 9) + 7
  else:
    if aset:
      ans *= len(aset)
      del aset[0]
    else:
      bset.append(b)
    if blist:
      b = blist.pop()
    else:
      b = pow(10, 9) + 7
print(ans % (pow(10, 9) + 7))


Fixed submission:
n = int(input())
alist = list(reversed(sorted([int(input()) for _ in range(n)])))
blist = list(reversed(sorted([int(input()) for _ in range(n)])))
INF = pow(10, 9) + 7
a = alist.pop()
b = blist.pop()
aset, bset = 0, 0
ans = 1
while len(alist) > 0 or len(blist) > 0:
  if a < b:
    if bset > 0:
      ans = (ans * bset) % INF
      bset -= 1
    else:
      aset += 1
    a = INF
    if len(alist) > 0:
      a = alist.pop()
  else:
    if aset > 0:
      ans = (ans * aset) % INF
      aset -= 1
    else:
      bset += 1
    b = INF
    if len(blist) > 0:
      b = blist.pop()
print(ans % INF)