Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
L, R = list(map(int, input().split()))

_min = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        buf = i*j % 2019
        if buf < _min:
            _min = buf
print(_min)

Fixed submission:
L, R = list(map(int, input().split()))

if (R - L) >= 2019:
    print(0)
else:
    _min = 2019
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            buf = i*j % 2019
            if buf < _min:
                _min = buf
    print(_min)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

answer = [sys.maxsize for _ in range(N-1)]
distance = [sys.maxsize for _ in range(N)]
distance[0] = 0
q = deque([1])

while len(q) > 0:
  current = q.popleft()
  for A, B in AB:
    nextroom = 0
    if A == current:
        nextroom = B
    elif B == current:
        nextroom = A
    else:
        continue
    if distance[current-1] + 1 < distance[nextroom-1]:
        q.append(nextroom)
        distance[nextroom-1] = distance[current-1] + 1
        answer[nextroom-2] = current
    else:
        pass
if sys.maxsize in answer:
    print('No')
    exit()
print('Yes')
for a in answer:
    print(a)


Fixed submission:
import sys
from collections import deque

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

doors = [[] for _ in range(N)]

for A, B in AB:
    doors[A-1].append(B)
    doors[B-1].append(A)
#print(doors)
#exit()

answer = [sys.maxsize for _ in range(N-1)]
distance = [sys.maxsize for _ in range(N)]
distance[0] = 0
q = deque([1])

while len(q) > 0:
  current = q.popleft()
  for nextroom in doors[current-1]:
    if distance[current-1] + 1 < distance[nextroom-1]:
        q.append(nextroom)
        distance[nextroom-1] = distance[current-1] + 1
        answer[nextroom-2] = current
    else:
        pass
if sys.maxsize in answer:
    print('No')
    exit()
print('Yes')
for a in answer:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N, K = map(int, input().split())
A = list(map(int, input().split()))

# まずループを見つけてみる

loopstart = -1
loopend = -1
path = []
nextcity = 0
for i in range(N):
    currentcity = nextcity
    path.append(nextcity)
    nextcity = A[nextcity]-1
    if nextcity in path:
        loopstart = nextcity
        loopend = currentcity
        path.append(nextcity)
        break
#print(path)

# ループまでの距離
toloop = path.index(loopstart)

# ループ内の距離
looplength = path.index(loopend) - toloop + 1

#print(toloop)
#print(looplength)
if K < toloop + looplength + 1:
    print(path[K] + 1)
else:
    fromloopstart = (K - toloop) % looplength
    print(path[toloop + fromloopstart] + 1)

Fixed submission:
import itertools

N, K = map(int, input().split())
A = list(map(int, input().split()))

# まずループを見つけてみる

loopstart = -1
loopend = -1
path = []
nextcity = 0
FLAGS = [False for _ in range(N)]
for i in range(N):
    currentcity = nextcity
    path.append(nextcity)
    FLAGS[nextcity] = True
    nextcity = A[nextcity]-1
    if FLAGS[nextcity]:
        loopstart = nextcity
        loopend = currentcity
        path.append(nextcity)
        break
#print(path)

# ループまでの距離
toloop = path.index(loopstart)

# ループ内の距離
looplength = path.index(loopend) - toloop + 1

#print(toloop)
#print(looplength)
if K < toloop + looplength + 1:
    print(path[K] + 1)
else:
    fromloopstart = (K - toloop) % looplength
    print(path[toloop + fromloopstart] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

count = 0

for diff in range(1, N):
    for i in range(N-diff):
#        print(diff, i, i+diff)
        if i+diff < N and A[i] + A[i+diff] == diff:
            count += 1

print(count)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L = {}

count = 0

for i in range(N):
    l = i + A[i]
    r = i - A[i]
    if r in L.keys():
        count += L[r]
    if l in L.keys():
        L[l] += 1
    else:
        L[l] = 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

count = 0

for i in range(N):
    for j in range(i+A[i], N):
        if A[i] + A[j] == abs(i-j):
            count += 1

print(count)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L = {}

count = 0

for i in range(N):
    l = i + A[i]
    r = i - A[i]
    if r in L.keys():
        count += L[r]
    if l in L.keys():
        L[l] += 1
    else:
        L[l] = 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
A = list(map(int, input().split()))

# total = N * (N-1) // 2

combi = list(itertools.combinations(range(N), 2))

count = 0
for i, j in combi:
    if A[i] + A[j] == abs(i-j):
        count += 1
print(count)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L = {}

count = 0

for i in range(N):
    l = i + A[i]
    r = i - A[i]
    if r in L.keys():
        count += L[r]
    if l in L.keys():
        L[l] += 1
    else:
        L[l] = 1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
total = 0
for a in range(K):
  for b in range(K):
    for c in range(K):
      total += math.gcd(a, b)
print(total)

Fixed submission:
import math

K = int(input())
total = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    ab = math.gcd(a, b)
    for c in range(1, K+1):
      total += math.gcd(ab, c)
print(total)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

A = [-1 for _ in range(N)]

for s, c in SC:
  if A[s-1] == -1:
    A[s-1] = c
  else:
    if A[s-1] == c:
      pass
    else:
      print(-1)
      exit()

for i in range(M):
  if A[i] == -1:
    A[i] = 0

if A[0] == 0 and N != 1:
  print(-1)
  exit()

print(''.join(map(str, A)))

Fixed submission:
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

A = [-1 for _ in range(N)]

for s, c in SC:
  if s == 1 and c == 0 and N != 1:
    print(-1)
    exit()
  if A[s-1] == -1:
    A[s-1] = c
  else:
    if A[s-1] == c:
      pass
    else:
      print(-1)
      exit()

for i in range(N):
  if A[i] == -1:
    A[i] = 0

if A[0] == 0:
  if N == 1:
    pass
  else:
    A[0] = 1

print(''.join(map(str, A)))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

A = [-1 for _ in range(N)]

for s, c in SC:
  if A[s-1] == -1:
    A[s-1] = c
  else:
    if A[s-1] == c:
      pass
    else:
      print(-1)
      exit()

for i in range(M):
  if A[i] == -1:
    A[i] = 0

if A[0] == 0:
  print(-1)
  exit()

print(''.join(map(str, A)))

Fixed submission:
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

A = [-1 for _ in range(N)]

for s, c in SC:
  if s == 1 and c == 0 and N != 1:
    print(-1)
    exit()
  if A[s-1] == -1:
    A[s-1] = c
  else:
    if A[s-1] == c:
      pass
    else:
      print(-1)
      exit()

for i in range(N):
  if A[i] == -1:
    A[i] = 0

if A[0] == 0:
  if N == 1:
    pass
  else:
    A[0] = 1

print(''.join(map(str, A)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

def compare(item):
  return item[1]

newXL = sorted([[x-l, x+l] for x, l in XL], key=compare)

memo = [0]

for i in range(N):
  flag = True
  for j in memo:
    if newXL[i][0] < newXL[j][1]:
      flag = False
  if flag:
    memo.append(i)

print(len(memo))

Fixed submission:
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

newXL = sorted([[x-l, x+l] for x, l in XL], key=lambda x:x[1])

previous = 0
total = 1

for i in range(1, N):
  if newXL[i][0] < newXL[previous][1]:
    pass
  else:
    previous = i
    total += 1
    
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

def compare(item):
  return item[3]

newXL = sorted([[x, l, x-l, x+l] for x, l in XL], key=compare)

memo = [0]

for i in range(N):
  flag = True
  for j in memo:
    if newXL[i][2] < newXL[j][3]:
      flag = False
  if flag:
    memo.append(i)

print(len(memo))

Fixed submission:
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

newXL = sorted([[x-l, x+l] for x, l in XL], key=lambda x:x[1])

previous = 0
total = 1

for i in range(1, N):
  if newXL[i][0] < newXL[previous][1]:
    pass
  else:
    previous = i
    total += 1
    
print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

def compare(item):
  return item[3]

newXL = sorted([[x, l, x-l, x+l] for x, l in XL], key=compare)

memo = [0]*N
memo[0] = 1

for i in range(N):
  flag = True
  for j in range(N):
    if memo[j] == 1:
      if newXL[i][2] < newXL[j][3]:
        flag = False
  if flag:
    memo[i] = 1

print(sum(memo))

Fixed submission:
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

newXL = sorted([[x-l, x+l] for x, l in XL], key=lambda x:x[1])

previous = 0
total = 1

for i in range(1, N):
  if newXL[i][0] < newXL[previous][1]:
    pass
  else:
    previous = i
    total += 1
    
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def countComb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

bignum = 10 ** 9 + 7

totalMaxA = 0
totalMinA = 0
for i in range(K-1, N):
  totalMaxA += A[i] * countComb(i, K-1) % bignum
for i in range(N-K+1):
  totalMinA += A[i] * countComb(N-i-1, K-1) % bignum

print((totalMaxA - totalMinA)%bignum)


Fixed submission:
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def countComb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
NN = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, NN + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(cmb(n, r, p))

totalMaxA = 0
totalMinA = 0
for i in range(K-1, N):
  totalMaxA += A[i] * countComb(i, K-1, p)
for i in range(N-K+1):
  totalMinA += A[i] * countComb(N-i-1, K-1, p)

print((totalMaxA - totalMinA) % p)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N, K = map(int, input().split())
A = list(map(int, input().split()))

c = list(combinations(A, K))

mod = 10**9 + 7

total = 0

for S in c:
  fx = max(S) - min(S)
  total += fx
  total = total % mod

print(total)

Fixed submission:
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def countComb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
NN = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, NN + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(cmb(n, r, p))

totalMaxA = 0
totalMinA = 0
for i in range(K-1, N):
  totalMaxA += A[i] * countComb(i, K-1, p)
for i in range(N-K+1):
  totalMinA += A[i] * countComb(N-i-1, K-1, p)

print((totalMaxA - totalMinA) % p)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections

N = int(input())
S = input()

c = collections.Counter(itertools.combinations(S, 3))
#print(len(set(itertools.combinations(S, 3))))
print(len(c))

Fixed submission:
N = int(input())
S = input()

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import collections

N = int(input())
S = input()

c = collections.Counter(itertools.combinations(S, 3))
print(len(c))

Fixed submission:
N = int(input())
S = input()

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
S = input()

passwords = list(itertools.combinations(S, 3))

print(len(set(passwords)))

Fixed submission:
N = int(input())
S = input()

count = 0
for h in range(10):
  pos_h = S.find(str(h))
  if pos_h < 0:
    continue
  for i in range(10):
    pos_i = S.find(str(i), pos_h+1)
    if pos_i < 0:
      continue
    for j in range(10):
      pos_j = S.find(str(j), pos_i+1)
      if pos_j < 0:
        continue
      count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
costs = [0 for x in range(N-1)]

mem = [0 for x in range(N-1)]
def calcsum(i):
  if mem[i] == 0:
    mem[i] == calcsum(i - 1) + A[i-1]
  return mem[i]

for i in range(1, N):
  costs[i-1] = abs(total - 2 * sum(A[:i]))
  
print(min(costs))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
costs = [0 for x in range(N-1)]
mem = [0 for x in range(N-1)]

for i in range(1, N):
  if i == 1:
    mem[i-1] = A[i-1] * 2
  else:
    mem[i-1] = mem[i-2] + A[i-1] * 2
  costs[i-1] = abs(total - mem[i-1])
  
print(min(costs))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

costs = [0 for x in range(N-1)]
for i in range(1, N):
  costs[i-1] = abs(sum(A[:i]) - sum(A[i:]))
  
print(min(costs))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
costs = [0 for x in range(N-1)]
mem = [0 for x in range(N-1)]

for i in range(1, N):
  if i == 1:
    mem[i-1] = A[i-1] * 2
  else:
    mem[i-1] = mem[i-2] + A[i-1] * 2
  costs[i-1] = abs(total - mem[i-1])
  
print(min(costs))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

total = sum(A)

barlen = total/2

costs = [0 for x in range(N-1)]
for i in range(1, N):
#  print(abs(sum(A[:i]) - sum(A[i:])))
  costs[i-1] = abs(sum(A[:i]) - sum(A[i:]))
  
print(min(costs))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
total = sum(A)
costs = [0 for x in range(N-1)]
mem = [0 for x in range(N-1)]

for i in range(1, N):
  if i == 1:
    mem[i-1] = A[i-1] * 2
  else:
    mem[i-1] = mem[i-2] + A[i-1] * 2
  costs[i-1] = abs(total - mem[i-1])
  
print(min(costs))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = d.count(y)
  return mem[y]

if d[0] != 0:
  print(0)
  exit()

for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()

count = 1
for i in range(n-1):
  count = count * countd(i) ** countd(i+1)
  count = count % 998244353

print(count)


Fixed submission:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))

mem = Counter(d)

if d[0] != 0 or mem[0] != 1:
  print(0)
  exit()

count = 1
for i in range(max(d)):
  count = count * mem[i] ** mem[i+1]
  count = count % 998244353

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = d.count(y)
  return mem[y]

if d[0] != 0:
  print(0)
  exit()

count = 1
for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()
  if x == 1:
    continue
  count = count * countd(x-1)
  count = count % 998244353

print(count)


Fixed submission:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))

mem = Counter(d)

if d[0] != 0 or mem[0] != 1:
  print(0)
  exit()

count = 1
for i in range(max(d)):
  count = count * mem[i] ** mem[i+1]
  count = count % 998244353

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = d.count(y)
  return mem[y]

if d[0] != 0:
  print(0)
  exit()

count = 1
for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()
  if x == 1:
    continue
  count = count * countd(x-1)

print(count % 998244353)


Fixed submission:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))

mem = Counter(d)

if d[0] != 0 or mem[0] != 1:
  print(0)
  exit()

count = 1
for i in range(max(d)):
  count = count * mem[i] ** mem[i+1]
  count = count % 998244353

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = list(map(int, input().split()))

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = len([a for a in d if a == y])
  return mem[y]

if d[0] != 0:
  print(0)
  exit()

count = 1
for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()
  if x == 1:
    continue
  count = count * countd(x-1)

print(count % 998244353)

Fixed submission:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))

mem = Counter(d)

if d[0] != 0 or mem[0] != 1:
  print(0)
  exit()

count = 1
for i in range(max(d)):
  count = count * mem[i] ** mem[i+1]
  count = count % 998244353

print(count)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

n = int(math.sqrt(N))
lens = []
for a in range(1, n):
  if N % a == 0:
    lens.append(a+N//a-2)

print(min(lens))


Fixed submission:
import math

N = int(input())

n = int(math.sqrt(N)) + 1
lens = [N-1]
for a in range(2, n):
  if N % a == 0:
    lens.append(a+N//a-2)

print(min(lens))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

H, W = map(int, input().split())
c = [input() for a in range(H)]

d = [[ sys.maxsize for b in range(W)] for a in range(H)]

dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

q = deque()

for y in range(H):
  for x in range(W):
    if c[y][x] == '#':
      q.append([y, x])
      d[y][x] = 0
ans = 0
while len(q) > 0:
  y, x = q.popleft()
  for i in range(4):
    ny = y + dy[i]
    nx = x + dx[i]
    if 0 <= nx and nx <= W-1 and 0 <= ny and ny <= H-1 and c[ny][nx] == '.' and d[ny][nx] == sys.maxsize:
      q.append([ny, nx])
      d[ny][nx] = d[y][x]+1
      ans = max(ans, d[ny][nx])

      
print(ans)


Fixed submission:
import sys
from collections import deque

H, W = map(int, input().split())
c = [input() for a in range(H)]

d = [[ sys.maxsize for b in range(W)] for a in range(H)]

dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

q = deque()

for y in range(H):
  for x in range(W):
    if c[y][x] == '#':
      q.append([y, x])
      d[y][x] = 0
ans = 0
while len(q) > 0:
  y, x = q.popleft()
  for i in range(4):
    ny = y + dy[i]
    nx = x + dx[i]
    if 0 <= nx and nx <= W-1 and 0 <= ny and ny <= H-1 and c[ny][nx] == '.' and d[ny][nx] == sys.maxsize:
      q.append([ny, nx])
      d[ny][nx] = d[y][x]+1
      ans = max(ans, d[ny][nx])

      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

count = 0
lenB = len(B)
lenC = len(C)
for a in A:
  startB = bisect.bisect_right(B, a)
  for i in range(startB, lenB):
    count += lenC - bisect.bisect_right(C, B[i])
print(count)


Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
lenA = len(A)
lenB = len(B)
lenC = len(C)
for b in B:
  count += (bisect.bisect_left(A, b))*(lenC-bisect.bisect_right(C, b))
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

count = 0
lenB = len(B)
lenC = len(C)
for a in A:
  for i in range(bisect.bisect_right(B, a), lenB):
    count += lenC - bisect.bisect_right(C, B[i])
print(count)


Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
lenA = len(A)
lenB = len(B)
lenC = len(C)
for b in B:
  count += (bisect.bisect_left(A, b))*(lenC-bisect.bisect_right(C, b))
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

count = 0
for a in A:
  for i in range(bisect.bisect_right(B, a), len(B)):
    count += len(C) - bisect.bisect_right(C, B[i])
print(count)


Fixed submission:
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
count = 0
lenA = len(A)
lenB = len(B)
lenC = len(C)
for b in B:
  count += (bisect.bisect_left(A, b))*(lenC-bisect.bisect_right(C, b))
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())

power = 1

for i in range(n):
  power = power * (i+1)
  
print(power%(10**9+7))


Fixed submission:
N = int(input())

power = 1
bigint = 10 ** 9 + 7
for n in range(1, N+1):
  power = power * n % bigint
print(power)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

P = N-1
count = 0
for path in itertools.permutations(ab, P):
  flag = True
  prev = 1
  memo = [0]*N
  for i in range(P):
    memo[prev-1] += 1
    if flag == True:
      if path[i][0] == prev:
        prev = path[i][1]
      elif path[i][1] == prev:
        prev = path[i][0]
      else:
        flag = False
        continue
      if 0 < memo[prev-1]:
        flag = False
        continue
      if i == P-1:
        count += 1
        
print(count)


Fixed submission:
import itertools

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

count = 0
for path in itertools.permutations([i for i in range(2, N+1)], N-1):
  flag = True
  if [1, path[0]] in ab or [path[0], 1] in ab:
    pass
  else:
    flag = False
    continue
  for i in range(1, N):
    if flag:
      if i == N-1:
        count += 1
        continue
      if [path[i-1], path[i]] in ab or [path[i], path[i-1]] in ab:
        continue
      else:
        flag = False
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

sum_ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum_ans += gcd(i, j, k)

print(sum_ans)

Fixed submission:
import math

K = int(input())

sum_ans = 0
gcd_list = []
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = math.gcd(i, j)
        gcd_list.append(tmp)

for k in range(1, K+1):
    for g in gcd_list:
            tmp = math.gcd(k, g)
            sum_ans += tmp

print(sum_ans)