Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
Alist = list(map(int, input().strip().split()))
r = [0]*N
r[0] = Alist[0]
for i in range(1,len(Alist)):
    r[i] = r[i-1] + Alist[i]
for i in range(len(r)):
    r[i] = r[i]%M
r.sort()
p = []
m = 0
for i in range(1,len(r)):
    m = m+1
    if r[i-1] != r[i]:
        p.append(m)
        m = 0
m = m+1
p.append(m)
def combi(n):
    if n == 0:
        return 0
    if n == 1:
        return 0
    else:
        return (n*(n-1))/2
s = 0
for i in range(len(p)):
    s = s + combi(p[i])
s = s + p[0]
print(int(s))

Fixed submission:
N, K = map(int,input().split())
if N % K == 0:
    print(0)
else:
    print(1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
p = []
if N > 0:
    for i in range(500):
        if (2**(2*i)-1)/3 < N <= (2**(2*(i+1))-1)/3:
            q = 2*i + 1
if N < 0:
    for i in range(1,500):
        if -(2**(2*i+1)-2)/3 <= N < -(2**(2*i-1)-2)/3:
            q = 2*i
if N == 0:
    q = 1
def cal(n,i):
    if i % 2 != 0:
        if (2**(i-1)-1)/3 < n <= (2**(i+1)-1)/3:
            p.append(1)
            n = n - (-2)**(i-1)
            i = i-1
            if i > 0:
                cal(n,i)
        else:
            p.append(0)
            i = i-1
            if i > 0:
                cal(n,i)
    elif n == 0:
        p.append(0)
        i = i-1
        if i > 0:
            cal(n,i)
    else:
        if -(2**(i+1)-2)/3 <= n < -(2**(i-1)-2)/3:
            p.append(1)
            n = n - (-2)**(i-1)
            i = i-1
            if i > 0:
                cal(n,i)
        else:
            p.append(0)
            i = i-1
            if i > 0:
                cal(n,i)
            
    return p
ans = cal(N,q)
for i in range(len(ans)):
    ans[i] = str(ans[i])
print(''.join(ans))

Fixed submission:
N, K = map(int,input().split())
if N % K == 0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
Alist = list(map(int, input().strip().split()))
p = 1
for i in range(len(Alist)-1):
    if Alist[i]*Alist[i+1] <= 0:
        q = i
        p = p*(-1)
length = 10**10
ans2 = 10**10
if p == 1:
    if Alist[0] > 0:
        ans = Alist[K-1]
    if Alist[0] < 0:
        ans = -Alist[0]
if p == -1:
    for i in range(len(Alist)):
        if i + K - 1 < len(Alist):
            if i + K - 1 == q:
                length = min(abs(Alist[i]),length)
            elif i == q + 1:
                length = min((Alist[i+K-1]),length)
            else:
                length = min(min(abs(Alist[i+K-1]-Alist[i])+abs(Alist[i]),abs(Alist[i+K-1]-Alist[i]),abs(Alist[i+K-1])),length)
    ans = length
for i in range(len(Alist)):
    ans2 = min(ans2,abs(Alist[i]))
if K == 1:
    print(ans2)
else:
    if len(Alist) > 1:
        print(ans)
    if len(Alist) ==1:
        print(Alist[0])

Fixed submission:
N = int(input())
p = []
if N > 0:
    for i in range(500):
        if (2**(2*i)-1)/3 < N <= (2**(2*(i+1))-1)/3:
            q = 2*i + 1
if N < 0:
    for i in range(1,500):
        if -(2**(2*i+1)-2)/3 <= N < -(2**(2*i-1)-2)/3:
            q = 2*i
if N == 0:
    q = 1
def cal(n,i):
    if i % 2 != 0:
        if (2**(i-1)-1)/3 < n <= (2**(i+1)-1)/3:
            p.append(1)
            n = n - (-2)**(i-1)
            i = i-1
            if i > 0:
                cal(n,i)
        else:
            p.append(0)
            i = i-1
            if i > 0:
                cal(n,i)
    elif n == 0:
        p.append(0)
        i = i-1
        if i > 0:
            cal(n,i)
    else:
        if -(2**(i+1)-2)/3 <= n < -(2**(i-1)-2)/3:
            p.append(1)
            n = n - (-2)**(i-1)
            i = i-1
            if i > 0:
                cal(n,i)
        else:
            p.append(0)
            i = i-1
            if i > 0:
                cal(n,i)
            
    return p
ans = cal(N,q)
for i in range(len(ans)):
    ans[i] = str(ans[i])
print(int(''.join(ans)))
Buggy python submission (verdict: Runtime Error):
S = str(input())
s = list(S)
p = 0
for i in range(2,len(s)-1):
        if s[i] == 'C':
            p = p + 1
            del s[i]
if s[0] == 'A':
    del s[0]
    if p == 1:
        q = ''.join(s)
        if q.islower() == True:
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')

Fixed submission:
S = str(input())
s = list(S)
u = s
p = 0
for i in range(2,len(s)-1):
        if s[i] == 'C':
            p = p + 1
for i in range(2,len(s)-p):
    if s[i] == 'C':
        if i != len(s) - 1:
            del s[i]
if s[0] == 'A':
    del s[0]
    if p == 1:
        q = ''.join(s)
        if q.islower() == True:
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
print(-(-N-1//k-1))

Fixed submission:
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
print(-(-(N-1)//(K-1)))

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
n = 0
l = 0
r = o
for i in range(N):
    if Alist[i] == 1:
        p = i
n = n -(-p//(K-1))
n = n -(-(N-p-1)//(K-1))
print(-(-N-1//k-1))

Fixed submission:
N, K = map(int,input().split())
Alist = list(map(int,input().split()))
print(-(-(N-1)//(K-1)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
Tlist = [int(N) for N in input().split()]
M = int(input())
PXlist = [[int(i) for i in input().split()]for j in range(M)]
def time_sum():
    s = 0
    for i in range(0,N):
        s = s+Tlist[i]
    return s
def time_cal():
    empty = []
    for i in range(0,M):
        empty.append(time_sum() - Tlist[i] + PXlist[i][1])
    return empty
for i in time_cal():
    print(i)

Fixed submission:
N = int(input())
Tlist = [int(N) for N in input().split()]
M = int(input())
PXlist = [[int(i) for i in input().split()]for j in range(M)]
def time_sum():
    s = 0
    for i in range(0,N):
        s = s+Tlist[i]
    return s
def time_cal():
    empty = []
    for i in range(0,M):
        empty.append(time_sum() - Tlist[PXlist[i][0]-1] + PXlist[i][1])
    return empty
for i in time_cal():
    print(i)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Tlist = [int(N) for N in input().split()]
M = int(input())
PXlist = [[int(i) for i in input().split()]for j in range(M)]
def time_sum():
    s = 0
    for i in range(0,N):
        s = s+Tlist[i]
    return s
def time_cal():
    ans = ita.array.make1d(M)
    for i in range(0,M):
        ans[i] = time_sum() - Tlist[i] + PXlist[i][1]
    return ans
print(Tlist,PXlist)
time_cal()

Fixed submission:
N = int(input())
Tlist = [int(N) for N in input().split()]
M = int(input())
PXlist = [[int(i) for i in input().split()]for j in range(M)]
def time_sum():
    s = 0
    for i in range(0,N):
        s = s+Tlist[i]
    return s
def time_cal():
    empty = []
    for i in range(0,M):
        empty.append(time_sum() - Tlist[PXlist[i][0]-1] + PXlist[i][1])
    return empty
for i in time_cal():
    print(i)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import math

n = int(input())

result = [0] * (n + 1)
border = int(math.sqrt(n - 2))
for x in range(1, border):
    for y in range(1, border):
        for z in range(1, border):
            r = ((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2) // 2
            if r > n:
                break
            else:
                result[r] += 1

for num in result[1::]:
    print(num)

Fixed submission:
#!/usr/bin/env python3

import math

n = int(input())

result = [0] * (n + 1)
border = 0
if n>=3:
    border = int(math.sqrt(n - 2))
for x in range(1, border):
    for y in range(1, border):
        for z in range(1, border):
            r = ((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2) // 2
            if r > n:
                break
            else:
                result[r] += 1

for num in result[1::]:
    print(num)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import math

def is_natural(x):
    if x % 1 == 0 and x >= 1:
        return True
    else:
        return False



n = int(input())


for i in range(1, n + 1):
    result = 0
    if i >= 6:
        for j in range(2, int(math.sqrt(2 * i - 8)) + 1):
            for k in range(2, int(math.sqrt(2 * i - 8)) + 1 ):
                if 2 * i - j ** 2 - k ** 2 < 2:
                    break
                else:
                    r = math.sqrt(2 * i - j ** 2 - k ** 2)

                    if r >= 2 and r % 1 == 0:
                        a = j
                        b = k
                        c = r
                        x = (c + a - b) / 2
                        y = (a + b - c) / 2
                        z = (b + c - a) / 2
                        if is_natural(x) and is_natural(y) and is_natural(z):
                            result += 1

    print(result)







Fixed submission:
#!/usr/bin/env python3

import math

n = int(input())

result = [0] * (n + 1)
border = 0
if n>=3:
    border = int(math.sqrt(n - 2))
for x in range(1, border):
    for y in range(1, border):
        for z in range(1, border):
            r = ((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2) // 2
            if r > n:
                break
            else:
                result[r] += 1

for num in result[1::]:
    print(num)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

n = int(input())
numbers = input().split(" ")
a = [int(x) for x in numbers]
q = int(input())

r = []


for i in range(q):

  numbers = input().split(" ")
  b = int(numbers[0])
  c = int(numbers[1])
  s = 0

  # a.sort()
  for i in range(n):
    if a[i] == b:
      a[i] = c
    s += a[i]
  r.append(s)

for x in r:
  print(x)





Fixed submission:
#!/usr/bin/env python3

def exist_or_not(list, value):
  for i in range(len(list)):
    if list[i] < value:
      continue
    elif list[i] == value:
      return i
    else:
      break
  return -1

n = int(input())
a = [0] * 100001
numbers = input().split(" ")
sum = 0
for x in numbers:
  int_x = int(x)
  a[int_x] += 1
  sum += int_x

q = int(input())

r = []
b = []
c = []



for i in range(q):
  numbers = input().split(" ")
  b.append(int(numbers[0]))
  c.append(int(numbers[1]))

for i in range(q):
  b_count = a[b[i]]
  a[c[i]] += b_count
  a[b[i]] = 0
  sum += (c[i] - b[i]) * b_count
  print(sum)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import numpy as np
nmx = input().split(" ")
n = int(nmx[0])
m = int(nmx[1])
x = int(nmx[2])
a = []
c = []
tanka = []
noryoku = [0] * m

r = 0

for i in range(n):
  text = input().split(" ")
  price = int(text[0])
  c.append(price)
  a.append([int(text[i]) for i in range(1, m + 1)])
  tanka.append([price / int(text[i]) for i in range(1, m + 1)])

a = np.array(a)
# price = np.array(price)

while len(tanka) > 0:
  min_i = np.argmin(tanka, axis=0)
  min_v = np.min(tanka, axis=0)
  index = min_i[np.argmax(min_v)]
  # print(min_i)

  # for j in range(m):
  #   noryoku[j] += a[min_i][j]

  noryoku = [noryoku[j] +  a[index][j] for j in range(m)]
  r += c[index]

  if all(v >= x for v in noryoku):
    print(r)
    break

  tanka = np.delete(tanka, index, 0)
  a = np.delete(a, index, 0)
  c.pop(index)

else:
  print(-1)

Fixed submission:
#!/usr/bin/env python3

import numpy as np
nmx = input().split(" ")
n = int(nmx[0])
m = int(nmx[1])
x = int(nmx[2])
a = []
c = []
total = []
pattern = [[0] * n]

for i in range(pow(2, n) - 1):
  pattern.append([pattern[i][j] for j in range(n)])
  for j in range(n):
    if pattern[i+1][j] == 0:
      pattern[i+1][j] = 1
      break
    else:
      pattern[i+1][j] = 0

r = 0

for i in range(n):
  text = input().split(" ")
  c.append(int(text[0]))
  a.append([int(text[i]) for i in range(1, m + 1)])

a = np.array(a)

for i in range(pow(2, n) - 1, -1,  -1):
  array = a.T @ pattern[i]
  if not(all(v >= x for v in array)):
    pattern = np.delete(pattern, i, 0)


total = [np.dot(np.array(c), p) for p in pattern]
# print(pattern)
# print(total)

if len(total) > 0:
  print(min(total))
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, m = map(int, input().split())

cnt = [x]

for i in range(m+1):
    x = x*x % m
    if x in cnt:
        break
    cnt.append(x)

start = cnt.index(x)


ans = sum(cnt[:start])
roop = len(cnt) - start
#print(roop)
n = n-start
ans = ans + (n//roop)*sum(cnt[start:]) + sum(list(cnt)[start:(start+n%roop)])

print(ans)

Fixed submission:
n, x, m = map(int, input().split())

cnt = [x]
c = set()
c.add(x)

for i in range(m+1):
    x = x*x % m
    if x in c:
        break
    cnt.append(x)
    c.add(x)

start = cnt.index(x)

ans = sum(cnt[:start])
roop = len(cnt) - start

n = n-start
ans = ans + (n//roop)*sum(cnt[start:]) + sum(list(cnt)[start:(start+n%roop)])

print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
s = int(input())
x = s//3

MAX = s
fac = [0] * MAX 
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD


COMinit()
ans = 0

for i in range(x):
    ans = (ans + COM(s-2*(i+1)-1, i)) % MOD
    #print(COM(s-2*(i+1)-1, i))
print(ans)

Fixed submission:
MOD = 10**9+7

MAX = 1000010
fac = [0] * MAX 
finv = [0] * MAX
inv = [0] * MAX
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD//i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n, k):
    res = 1
    for i in range(k):
        res = res * (n-i) % MOD
    return res * finv[k] % MOD


s = int(input())
x = s//3

COMinit()
ans = 0

for i in range(x):
    ans = (ans + COM(s-2*(i+1)-1, i)) % MOD
    #print(COM(s-2*(i+1)-1, i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
n = int(input())
a = [int(x) for x in input().split()]

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans = (ans + a[i]*a[j]%MOD) % MOD

print(ans)

Fixed submission:
MOD = 10**9+7
n = int(input())
a = [int(x) for x in input().split()]

s = sum(a)
ans = 0

for i in range(n):
    s -= a[i]
    ans = (ans + a[i]*s%MOD) % MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]


ai = 0
bi = 0

dp = [0 for i in range(M+N+1)]

for i in range(1, N+M+1):
    if ai == N:
        res = b[bi]
        bi += 1
    elif bi == M:
        res = a[ai]
        ai += 1
    elif a[ai] == b[bi]:
        ra = ai; rb = bi
        while a[ra] == b[rb]:
            ra += 1
            rb += 1
            if a[ra] < b[rb]:
                res = a[ai]
                ai += 1
                break
            elif a[ra] > b[rb]:
                res = b[bi]
                bi += 1
                break
    elif a[ai] < b[bi]:
        res = a[ai]
        ai += 1
    else:
        res = b[bi]
        bi += 1
    dp[i] = dp[i-1] + res

#print(dp)

import bisect
print(bisect.bisect_right(dp, K)-1)

Fixed submission:
import bisect

N, M, K = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0
for i in range(N+1):
    if da[i] > K:
        break
    ans = max(ans, i + bisect.bisect_right(db, K-da[i]) - 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from collections import deque

N = int(input())
a = [int(y) for y in input().split()]
a.sort()

q = deque()
for i in range(N):
    q.append(a[i])

cnt = 0

while N > 0:
    flag = True
    res = q.popleft()

    for i in range(N-1):
        now = q.popleft()
        if now == res and flag:
            cnt -= 1
            flag = False
        if now % res != 0:
            q.append(now)
    
    N = len(q)
    cnt += 1

print(cnt)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

max_a = max(a)
flag = [True for i in range(max_a+1)]

dup = set()
for i in range(n):
    if a[i] in dup:
        flag[a[i]] = False
    else:
        dup.add(a[i])
    for j in range(2*a[i], max_a+1, a[i]):
        flag[j] = False

ans = 0
for i in a:
    ans += flag[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(y) for y in input().split()]
a.sort()

cnt = 0

while N > 0:
    flag = True
    b = []
    res = a[0]

    for i in range(1, N):
        if a[i] == res and flag:
            cnt -= 1
            flag = False
        if a[i] % res != 0:
            b.append(a[i])
    
    a = b
    N = len(a)
    cnt += 1

print(cnt)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]

max_a = max(a)
flag = [True for i in range(max_a+1)]

dup = set()
for i in range(n):
    if a[i] in dup:
        flag[a[i]] = False
    else:
        dup.add(a[i])
    for j in range(2*a[i], max_a+1, a[i]):
        flag[j] = False

ans = 0
for i in a:
    ans += flag[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
INF = 10**18
ans = 1
A.sort()
for i in range(N):
    ans *= A[i]
    if ans > INF:
        ans = -1
print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
INF = 10**18
ans = 1
A.sort()
for i in range(N):
    ans *= A[i]
    if ans > INF:
        ans = -1
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]
INF = 10**18
ans = 1
for i in range(N):
    ans *= A[i]
if ans > INF:
    ans = -1
print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
INF = 10**18
ans = 1
A.sort()
for i in range(N):
    ans *= A[i]
    if ans > INF:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
i = 0
his = []

if K >= N:
  for j in range(N):
    i = A[i]-1
    his.append(i)
    K -= 1

    for k in range(1, j):
      if his[j] == his[j-k]:
        K = K % k
        break

while K > 0:
  i = A[i]-1
  K -= 1

print(i+1)

Fixed submission:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

when = [-1 for _ in range(N+1)]
new = 1
i = 0

while when[new] == -1:
    when[new] = i
    new = A[new - 1]
    i += 1

line = when[new]
roop = i - when[new]

if K > line:
    K = (K - line) % roop
    for j in range(N+1):
        when[j] -= line
    
for j in range(N+1):
    if when[j] == K:
        print(j)
        break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        if j-i == A[j]+A[i]:
            cnt += 1
print(cnt)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

L = dict(); R = dict()
for i in range(N):
    l = i + A[i]
    if l in L:
        L[l] += 1
    else:
        L[l] = 1
    r = i - A[i]
    if r in R:
        R[r] += 1
    else:
        R[r] = 1

ans = 0
for x in R:
    if x in L:
        ans += L[x] * R[x]

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

if B <= N:
    x = B - 1
    ans = (A*x)//B-A*(x//B)
if B > N:
    ans = 0
    for x in range(1, N+1):
        ans = max(ans, (A*x)//B-A*(x//B))
print(ans)

Fixed submission:
A, B, N = map(int, input().split())
if N >= B:
    x = B - 1
else:
    x = N
print( (A*x//B) - A*(x//B) )
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
cnt = []
for i in range(N):
    S = input().rstrip()
    if S not in cnt:
        cnt.append(S)
print(len(cnt))

Fixed submission:
N = int(input())
l = []
for i in range(N):
    l.append(input().rstrip())
print(len(list(set(l))))
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 k in range(1, K+1):
            ans += math.gcd(math.gcd(i,j),k)
print(ans)

Fixed submission:
import math
K = int(input())
b = []
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        b.append(math.gcd(i, j))
n = len(b)
for i in range(n):
    for k in range(1, K+1):
        ans += math.gcd(b[i], k)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def bfs(v):
    todo = deque()
    todo.append(v)
    seen[v] = 0
    while len(todo) > 0:
        v = todo.popleft()
        d = seen[v]
        for w in graph[v]:
            if seen[w] != -1:
                continue
            seen[w] = d + 1
            todo.append(w)


N, X, Y = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i].append(i+1)
    graph[i+1].append(i)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0 for _ in range(N)]
for i in range(N-1):
    seen = [-1 for _ in range(N)]
    bfs(i)
    for j in range(i+1, N):
        cnt[seen[j]] += 1

for i in range(1, N):
    print(cnt[i])

Fixed submission:
from collections import deque
def bfs(v):
    todo = deque()
    todo.append(v)
    seen[v] = 0
    while len(todo) > 0:
        v = todo.popleft()
        d = seen[v]
        for w in graph[v]:
            if seen[w] != -1:
                continue
            seen[w] = d + 1
            todo.append(w)


N, X, Y = map(int, input().split())
graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i].append(i+1)
    graph[i+1].append(i)
graph[X-1].append(Y-1)
graph[Y-1].append(X-1)

cnt = [0 for _ in range(N)]
for i in range(N-1):
    seen = [-1 for _ in range(N)]
    bfs(i)
    for j in range(i+1, N):
        cnt[seen[j]] += 1

for i in range(1, N):
    print(cnt[i])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for i in range(Q):
    q = input()
    if q == "1":
        S = S[::-1]
    else:
        if q[2] == "1":
            S = q[-1] + S
        if q[2] == "2":
            S = S + q[-1]

print(S)

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

left = ""
right = ""
cnt = 0

for i in range(Q):
    q = input()
    if q == "1":
        cnt += 1
    elif (cnt%2 == 0 and q[2] == "1") or (cnt%2 == 1 and q[2] == "2"):
        left += q[4]
    else:
        right += q[4]

if cnt%2 == 0:
    ans = left[::-1] + S + right
else:
    ans = right[::-1] + S[::-1] + left

print(ans)
Buggy python submission (verdict: Runtime Error):
N, a, b = map(int, input().split())
num = b - a
if num%2 == 0:
    half = num//2
    print(half)
else:
    edge = min(N-a, b-1)
    print(min((b-a-1)//2), edge)

Fixed submission:
N, a, b = map(int, input().split())
num = b - a
if num%2 == 0:
    half = num//2
    print(half)
else:
    edge = min(N-a, b-1)
    edge2 = min((b-a-1)//2+a, (b-a-1)//2+N-b+1)
    print(min(edge2, edge))
Buggy python submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b = map(int, input().split())
lcm(a, b)

print(lcm(a, b))

Fixed submission:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a, b = map(int, input().split())
lcm(a, b)

print(lcm(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(x) for x in input().split()]

if 1 in a:
    ans = 1
    while ans in a:
        a = a[a.index(ans):]
        ans += 1
    print(N - ans + 1)
else:
    print(-1)

Fixed submission:
N = int(input())
a = [int(x) for x in input().split()]

if 1 in a:
    ans = 1
    for i in range(N):
        if a[i] == ans:
            ans += 1
    print(N - ans + 1)
else:
    print(-1)