Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
jmax = 0
for i in range(n+1):
    for j in range(jmax, m+1):
        if b[m-j] > k-a[i]:
            pass
        else:
            jmax = m-j
            if jmax + i > x:
                x = jmax + i
print(x)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
jmax = m
for i in range(n+1):
    for j in range(jmax, -1, -1):
        if b[j] > k-a[i]:
            pass
        else:
            jmax = j
            if jmax + i > x:
                x = jmax + i
            break
print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
for i in range(n+1):
    for j in range(m+1):
        if b[m-j] > k-a[i]:
            pass
        else:
            jmax = m-j
            if jmax + i > x:
                x = jmax + i
print(x)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(n-1):
    a[i+1] = a[i] + a[i+1]
a.insert(0, 0)
for i in range(m-1):
    b[i+1] = b[i] + b[i+1]
b.insert(0, 0)

x = 0
jmax = m
for i in range(n+1):
    for j in range(jmax, -1, -1):
        if b[j] > k-a[i]:
            pass
        else:
            jmax = j
            if jmax + i > x:
                x = jmax + i
            break
print(x)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
q = [i for i in range(1, 101)]
if n != 0:
  p = list(map(int, input().split()))
  for i in p:
    q[i-1] = -100

if x in q:
  print(x)
  exit()

l = []

for i in range(100):
  if x+i in q:
    l.append(x+i)
    break
for j in range(100):
  if x-i in q:
    l.append(x-i)
    break

if len(l) == 1:
  print(l[0])
  exit()

if abs(l[0]-x) < abs(l[1]-x):
  print(l[0])
elif abs(l[0]-x) > abs(l[1]-x):
  print(l[1])
else:
  print(l[1])

Fixed submission:
x, n = map(int, input().split())
q = [i for i in range(-110, 210)]
if n != 0:
  p = list(map(int, input().split()))
  for i in p:
    q[i+110] = -500

if x in q:
  print(x)
  exit()

l = []

for i in range(100):
  if x+i in q:
    l.append(x+i)
    break
for j in range(100):
  if x-j in q:
    l.append(x-j)
    break

if abs(l[0]-x) < abs(l[1]-x):
  print(l[0])
elif abs(l[0]-x) > abs(l[1]-x):
  print(l[1])
else:
  print(l[1])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
l = []
for i in range(M):
  x = list(map(int, input().split()))
  l.append(x)
print(l)
m = []
n = [[1]]

for j in range(M):
  for i in range(M):
    for k in range(len(n[j])):
      if l[i][0] == n[j][k] or l[i][1] == n[j][k]:
        if l[i][0] == n[j][k]:
          m.append(l[i][1])
        else:
          m.append(l[i][0])
        l[i] = [0, 0]
  n.append(m)
  m = []
  print(n)

for i in range(M -1):
  

Fixed submission:
import queue

N, M = map(int, input().split())
parent = [-1] * N # -1なら未訪問
adj = [[] for _ in range(N)] # 隣接リスト作成
for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)
q = queue.Queue() # 自分の部屋、親の部屋
q.put([1, 0]) # 1の親は0
while not q.empty():
  x, y = q.get()
  if parent[x-1] != -1: # もし自分の部屋が訪問済みなら
    continue
  parent[x-1] = y # 自分の部屋の親yを指定
  for i in adj[x-1]:
    if parent[i-1] == -1:
      q.put([i, x])
print('Yes')
for j in parent[1:]:
  print(j)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
H = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(M)]
l = list()
m = list()
cnt = 0
for i in range(N):
  for j in range(M):
    if i+1 in C[j]:
      l = l + [H[C[j][0]-1], H[C[j][1]-1]]
    else:
      pass
  print(l)
  if len(l) == 0:
    cnt += 1
  elif H[i] == max(l):
    
  
  elif H[i] > max(l):
    cnt += 1
  else:
    pass
  l = list()
  m = list()
print(cnt)

Fixed submission:
N, M = map(int, input().split())
H = list(map(int, input().split()))
x = [1] * N

for i in range(M):
  A, B = map(int, input().split())
  if H[A-1] <= H[B-1]:
    x[A-1] = 0
  if H[A-1] >= H[B-1]:
    x[B-1] = 0
print(x.count(1))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

B = [0] * N

for i in A:
  B[i-1] = int(B[i-1]) + 1
  
for j in B:
  print(j)

Fixed submission:
R = int(input())

l = 2 * R * 3.141592

print(l)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

for i in range(N):
  print(A.count(i+1))  


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

B = [0] * N

for i in A:
  B[i-1] = int(B[i-1]) + 1
  
for j in B:
  print(j)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

for i in range(N):
  print(A.count(i+1))  


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

B = [0] * N

for i in A:
  B[i-1] = int(B[i-1]) + 1
  
for j in B:
  print(j)
Buggy python submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N == 0:
  ans = combinations_count(M, 2)
elif M == 0:
  ans = combinations_count(N, 2)
elif N == 1 and M == 1:
  ans = 0
else:
  ans = combinations_count(N, 2) + combinations_count(M, 2)
print(ans)

Fixed submission:
import math

N, M = map(int, input().split())
def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N == 0:
  ans = combinations_count(M, 2)
elif M == 0:
  ans = combinations_count(N, 2)
elif N == 1 and M == 1:
  ans = 0
elif N == 1:
  ans = combinations_count(M, 2)
elif M == 1:
  ans = combinations_count(N, 2)
else:
  ans = combinations_count(N, 2) + combinations_count(M, 2)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
p = list(map(int, input().split()))

s = 0

for j in range(K):
  s += p[j]
  
x = s

for k in range(N - K):
  t = s - p[k] + p[K + k]
  if s <= t:
    x = t
  else:
    pass
  s = t

print((x + K) / 2)

Fixed submission:
S, T = map(str, input().split())
A, B = map(int, input().split())
U = str(input())

if S == U:
  print(A-1, B)
else:
  print(A, B-1)
Buggy python submission (verdict: Runtime Error):
C = str(input())
print chr(ord(C) + 1)

Fixed submission:
C = str(input())
print(chr(ord(C) + 1))
Buggy python submission (verdict: Runtime Error):
x, y, z = map(int, input().split())

def takahashi(A, B, K):
  if A <= K <= A + B:
    print(0, B - (K - A))
  elif K < A:
    print(A - K, B)
  else:
    print(0, 0)
    
takahashi(x, y, z)

Fixed submission:
import math

X = int(input())

cnt = 0

# 素数判定関数 素数:True, 素数じゃない:False
def prime(x):
  for i in range(2, math.floor(math.sqrt(x)) + 1):
    if x % i == 0:
      return False
  return True
      

for j in range(1000000000):
  if prime(X) == True:
    print(X)
    break
  else:
    X += 1
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
ans = A * B // math.gcd(A, B)
print(ans)

Fixed submission:
import fractions
A, B = map(int, input().split())
ans = A * B // fractions.gcd(A, B)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
ans = A * B / math.gcd(A, B)
print(int(ans))

Fixed submission:
import fractions
A, B = map(int, input().split())
ans = A * B // fractions.gcd(A, B)
print(ans)

Buggy python submission (verdict: Runtime Error):
123 456

Fixed submission:
import fractions
A, B = map(int, input().split())
ans = A * B // fractions.gcd(A, B)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

X1, Y1 = map(int, input().split())

if X1 >= Y1:
  X = X1
  Y = Y1
  pass
else:
  X = Y1
  Y = X1
if X > 2 * Y:
  print(0)
  exit()
else:
  pass

m = (2 * X - Y) // 3
n = (2 * Y - X) // 3 

if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
  print(0)
  exit()
else:
  ans = combinations_count((m + n), n) % (10 ** 9 + 7)
print(ans)

Fixed submission:
import math
def cmb(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, mod-2, mod)
    return x * y % mod
"""
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
"""
X1, Y1 = map(int, input().split())

if X1 >= Y1:
  X = X1
  Y = Y1
  pass
else:
  X = Y1
  Y = X1
if X > 2 * Y:
  print(0)
  exit()
else:
  pass

m = (2 * X - Y) // 3
n = (2 * Y - X) // 3 

if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
  print(0)
  exit()
else:
  ans = cmb(m + n, n, 10 ** 9 + 7)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

X1, Y1 = map(int, input().split())

if X1 >= Y1:
  X = X1
  Y = Y1
  pass
else:
  X = Y1
  Y = X1
if X > 2 * Y:
  print(0)
  exit()
else:
  pass

cnt1 = 0

while X < 2 * Y:
  X = X - 1
  Y = Y - 2
  cnt1 += 1

if X != 2 *Y:
  print(0)
  exit()
else:
  pass

cnt2 = Y
ans = combinations_count((cnt1 + cnt2), cnt2) % (10 ** 9 + 7)
print(ans)

Fixed submission:
import math
def cmb(n, r, mod):
    r = min(r, n - r)
    x = 1
    y = 1
    for i in range(r):
        x = x * (n - i) % mod
        y = y * (i + 1) % mod
    y = pow(y, mod-2, mod)
    return x * y % mod
"""
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
"""
X1, Y1 = map(int, input().split())

if X1 >= Y1:
  X = X1
  Y = Y1
  pass
else:
  X = Y1
  Y = X1
if X > 2 * Y:
  print(0)
  exit()
else:
  pass

m = (2 * X - Y) // 3
n = (2 * Y - X) // 3 

if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
  print(0)
  exit()
else:
  ans = cmb(m + n, n, 10 ** 9 + 7)
print(ans)
Buggy python submission (verdict: Runtime Error):
def binary_search(x, li, value):
  l = []
  left = x+1
  y = x
  right = len(li) - 1
  while left <= right:
    mid = (left + right) // 2
    if li[mid] > value - 1:
      right = mid - 1
    elif li[mid] < value - 1:
      y = mid
      left = mid + 1
    else:
      for i in range(1, 1000):
        if li[mid] == li[mid + i]:
          y = mid + i
        else:
          y = mid
          break
  return y
  
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += binary_search(j, L, L[i]+L[j]) - j
print(cnt)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += bisect_left(L, L[i] + L[j]) - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
#L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
        cnt += 1
      else:
        pass
#      else:
#        break
print(cnt)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += bisect_left(L, L[i] + L[j]) - j - 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if L[i] + L[j] > L[k]:
        cnt += 1
      else:
        break
print(cnt)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += bisect_left(L, L[i] + L[j]) - j - 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
import re
s = str(input())
n = len(s)
z = [0] * n
lr = [m.start() for m in re.finditer('LR', s)]
rl = [m.start() for m in re.finditer('RL', s)]
t = []
if lr == []:
    t = s
else:
    t.append(s[:lr[0]+1])
    for i in range(len(lr)-1):
        t.append(s[lr[i]+1 : lr[i+1]+1])
    t.append(s[lr[-1]+1:])

for i in range(len(t)):
    r = t[i].count('R')
    l = len(t[i]) - r
    # x : RL界面左側の数。y : RL界面右側の数。
    x = (r+1) // 2 + l // 2
    y = r // 2 + (l+1) // 2
    z[rl[i]] = x
    z[rl[i]+1] = y

delta = [str(i) for i in z]
ans = ' '.join(delta)
print(ans)

Fixed submission:
import re
s = str(input())
n = len(s)
z = [0] * n
lr = [m.start() for m in re.finditer('LR', s)]
rl = [m.start() for m in re.finditer('RL', s)]
t = []
if lr == []:
    t.append(s)
else:
    t.append(s[:lr[0]+1])
    for i in range(len(lr)-1):
        t.append(s[lr[i]+1 : lr[i+1]+1])
    t.append(s[lr[-1]+1:])
for i in range(len(t)):
    r = t[i].count('R')
    l = len(t[i]) - r
    # x : RL界面左側の数。y : RL界面右側の数。
    x = (r+1) // 2 + l // 2
    y = r // 2 + (l+1) // 2
    z[rl[i]] = x
    z[rl[i]+1] = y

delta = [str(i) for i in z]
ans = ' '.join(delta)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

A, B, K = map(int, input().split())
gcd = math.gcd(A, B)
l = []

for i in range(1, gcd+1):
  if gcd % i == 0:
    l.append(i)
  else:
    pass
l.reverse()
print(l[K-1])

Fixed submission:
from fractions import gcd

A, B, K = map(int, input().split())
gcd = gcd(A, B)
l = []

for i in range(1, gcd+1):
  if gcd % i == 0:
    l.append(i)
  else:
    pass
l.reverse()
print(l[K-1])

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

A, B, K = map(int, input().split())
gcd = math.gcd(A, B)
l = []

for i in range(1, gcd+1):
  if gcd % i == 0:
    l.append(i)
  else:
    pass
l.reverse()
print(l[K-1])

Fixed submission:
from fractions import gcd

A, B, K = map(int, input().split())
gcd = gcd(A, B)
l = []

for i in range(1, gcd+1):
  if gcd % i == 0:
    l.append(i)
  else:
    pass
l.reverse()
print(l[K-1])

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

A, B, K = map(int, input().split())
gcd = math.gcd(A, B)
l = []

for i in range(1, gcd+1):
  if gcd % i == 0:
    l.append(i)
  else:
    pass
l.reverse()
print(l[K-1])

Fixed submission:
from fractions import gcd

A, B, K = map(int, input().split())
gcd = gcd(A, B)
l = []

for i in range(1, gcd+1):
  if gcd % i == 0:
    l.append(i)
  else:
    pass
l.reverse()
print(l[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
  x = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2, K+1):
    if i-j < 0:
      continue
    x = min(dp[i-j] + abs(h[i]-h[i-j]), x)
  dp[i] = x
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
  x = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2, K+1):
    if i-j >= 0:
      x = min(dp[i-j] + abs(h[i]-h[i-j]), x)
    else:
      pass
  dp[i] = x
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
  x = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2, K+1):
    if i-j >= 0:
      x = min(dp[i-j] + abs(h[i]-h[i-j]), x)
    else:
      pass
  dp[i] = x
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9 for _ in range(N)]
dp[0] = 0
for i in range(1, N):
  x = dp[i-1] + abs(h[i]-h[i-1])
  for j in range(2, K+1):
    if i-j >= 0:
      x = min(dp[i-j] + abs(h[i]-h[i-j]), x)
    else:
      pass
  dp[i] = x
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
a = list()
a.append([0, 0])
inf = float('inf')
for _ in range(N):
  x = list(map(int, input().split()))
  a.append(x)
dp = [[-inf for _ in range(W+1)]for _ in range(N+1)]
# dp[i][w] : i-1番目までで、wを超えないように選んだ時の価値の最大値
for w in range(W+1):
  dp[0][w] = 0
for i in range(N):
  for w in range(W+1):
    # i番目を選ぶかもしれないとき
    if w - a[i+1][0] >= 0:
      dp[i+1][w] = max(dp[i][w], dp[i][w-a[i+1][0]] + a[i+1][1])
    # i番目を選ばないとき
    else:
      dp[i+1][w] = dp[i][w]
print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
a = list()
a.append([0, 0])
inf = float('inf')
for _ in range(N):
  x = list(map(int, input().split()))
  a.append(x)
dp = [[-inf for _ in range(W+1)]for _ in range(N+1)]
# dp[i][w] : i番目までで、wを超えないように選んだ時の価値の最大値
for w in range(W+1):
  dp[0][w] = 0
for i in range(N):
  for w in range(W+1):
    # i+1番目を選ぶかもしれないとき
    if w - a[i+1][0] >= 0:
      dp[i+1][w] = max(dp[i][w], dp[i][w-a[i+1][0]] + a[i+1][1])
    # i+1番目を選ばないとき
    else:
      dp[i+1][w] = dp[i][w]
print(dp[N][W])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000000)

N, M = map(int, input().split())
adj = [[] for _ in range(M)]
visited = [0] * N

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
print(sum(ans))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
adj = [[] for _ in range(N)]
visited = [0] * N

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
if ans == []:
  print(0)
else:
  print(sum(ans))

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
adj = [[] for _ in range(M)]
visited = [0] * N

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
print(sum(ans))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
adj = [[] for _ in range(N)]
visited = [0] * N

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
if ans == []:
  print(0)
else:
  print(sum(ans))

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

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
print(sum(ans))

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N, M = map(int, input().split())
adj = [[] for _ in range(N)]
visited = [0] * N

for i in range(M):
  a, b = map(int, input().split())
  adj[a-1].append(b)
  adj[b-1].append(a)

ans = []

def dfs(x):
  visited[x-1] = 1
  if visited == [1] * N:
    ans.append(1)
  for i in range(len(adj[x-1])):
    if visited[adj[x-1][i] - 1] == 0:
      dfs(adj[x-1][i])
  visited[x-1] = 0
      
dfs(1)
if ans == []:
  print(0)
else:
  print(sum(ans))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
numlist = []
for i in range(len(s)-len(t)):
    a = s[i:i+len(t)]
    count = 0
    for j in range(len(t)):
        if a[j] != t[j]:
            count += 1
    numlist.append(count)
print(min(numlist))

Fixed submission:
s = input()
t = input()
numlist = []
for i in range(len(s)-len(t)+1):
    a = s[i:i+len(t)]
    count = 0
    for j in range(len(t)):
        if a[j] != t[j]:
            count += 1
    numlist.append(count)
print(min(numlist))
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
sumlist = []
ans = 0
for i in range(1, len(alist)+1):
    sumlist.append(sum(alist[0:i]))
for i in range(len(alist)):
    ans += alist[i]*(sumlist[-1]-sumlist[i])
print(ans%mod)

Fixed submission:
a = int(input())
alist = list(map(int, input().split()))
mod = 10**9+7
total = sum(alist)
sumlist = []
ans = 0
for i in range(len(alist)-1):
    total -= alist[i]
    ans += alist[i]*(total)
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    seisulist = list(map(int, input().split()))
    if max(seisulist) > x:
        size = max(seisulist) + 1
    else:
        size = x + 1
    numlist = [i for i in range(1,size) if i not in seisulist]
    xretu = [x]*len(numlist)
    hikizan = [abs(s-t) for (s, t) in zip(numlist, xretu)]
    sa = min(hikizan)
    if x-sa not in seisulist:
        print(x-sa)
    else:
        print(x+sa)

Fixed submission:
#ABC170 C 通せず
x, n = map(int, input().split())
seisulist = list(map(int, input().split()))
numlist = [i for i in range(0,102) if i not in seisulist]
xretu = [x]*len(numlist)
hikizan = [abs(s-t) for (s, t) in zip(numlist, xretu)]
sa = min(hikizan)
if x-sa not in seisulist:
    print(x-sa)
else:
    print(x+sa)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator

pi = functools.partial(functools.reduce, operator.mul)
n = int(input())
a = list(map(int, input().split()))
ans = pi(a)
if ans > 10**18:
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if a[-1] == 0:
    print(0)
else:
    for i in range(1, n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans *= a[i]

if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if a[-1] == 0:
    print(0)
else:
    for i in range(1, n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = a.pop(0)
for i in range(n-1):
    ans *= a.pop(0)

if ans <= 10**18:
    print(ans)
else:
    print(-1)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if a[-1] == 0:
    print(0)
else:
    for i in range(1, n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if 7 in n:
  print("Yes")
else:
  print("No")

Fixed submission:
n = input()
if "7" in n:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())
ans = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    for l in range(1, k+1):
      ans += math.gcd(l, math.gcd(i, j))
print(ans)

Fixed submission:
import math
k = int(input())
ans = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    a = math.gcd(i, j)
    for l in range(1, k+1):
      ans += math.gcd(l, a)
print(ans)