Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, a):
  if 0 in a:
    return 0
  else:
    p = 1
    x = 10**18
    for i in a:
      p*=i
    if p>x:
      p = -1
    return p

n = int(input())
a = [int(x) for x in input().split()]
print(solve(n, a))

Fixed submission:
def solve(n, a):
  if 0 in a:
    return 0
  else:
    p = 1
    x = 10**18
    for i in a:
      if p<=x:
      	p*=i
      else:
        break
    if p>x:
      p = -1
    return p

n = int(input())
a = [int(x) for x in input().split()]
print(solve(n, a))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if n==k or k==1:
  print(0)
else:
  ans=n
  res=[ans]
  while(1):
    ans=abs(ans-k)
    if ans in res or ans == k:
      break
    res.append(ans)
  print(min(res))

Fixed submission:
n, k = map(int, input().split())
print(min(n%k, k - n%k))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
if n==k or k==1:
  print(0)
else:
  ans=n
  res=[]
  while(1):
    ans=abs(ans-k)
    if ans in res:
      break
    res.append(ans)
  print(min(res))

Fixed submission:
n, k = map(int, input().split())
print(min(n%k, k - n%k))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
x=a*100//8
y=b*10
i=1
f=False
while(i<=1250):
  if i*8//100 == x and i//10 == y:
    print(i)
    f=True
    break
  i+=1
if not f:
  print(-1)

Fixed submission:
s=list(input())
if len(set(s))==1:
  print("No")
else:
  print("Yes")

Buggy python submission (verdict: Runtime Error):
n, a, b=map(int,input().split())
if n==a+b:
  print(a)
else:
  if a==0:
    print(0)
  else:
    print((n//(a+b))*a + min(n%(a+b), a))

Fixed submission:
s=list(input())
if len(set(s))==1:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=deque(input())
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    s.reverse()
  else:
    if t[1]=='1':
      s.appendleft(t[2])
    else:
      s.append(t[2])
print(''.join(s))

Fixed submission:
from collections import deque
s=deque(input())
f=False
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    if f is False:
      f = True
    else:
      f = False
  else:
    if t[1]=='1':
      if f is False:
      	s.appendleft(t[2])
      else:
        s.append(t[2])
    else:
      if f is False:
      	s.append(t[2])
      else:
        s.appendleft(t[2])
x=''.join(map(str,s))
if f is False:
	print(x)
else:
  print(x[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
for _ in range(int(input())):
  t=list(input().split())
  if int(t[0])==1:
    s=s[::-1]
  else:
    if int(t[1])==1:
      s=s[::-1]
      s.append(t[2])
      s=s[::-1]
    else:
      s.append(t[2])
print(''.join(s))

Fixed submission:
from collections import deque
s=deque(input())
f=False
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    if f is False:
      f = True
    else:
      f = False
  else:
    if t[1]=='1':
      if f is False:
      	s.appendleft(t[2])
      else:
        s.append(t[2])
    else:
      if f is False:
      	s.append(t[2])
      else:
        s.appendleft(t[2])
x=''.join(map(str,s))
if f is False:
	print(x)
else:
  print(x[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
for _ in range(int(input())):
  t=list(input().split())
  if int(t[0])==1:
    s.reverse()
  else:
    if int(t[1])==1:
      s.insert(0, t[2])
    else:
      s.append(t[2])
print(''.join(s))

Fixed submission:
from collections import deque
s=deque(input())
f=False
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    if f is False:
      f = True
    else:
      f = False
  else:
    if t[1]=='1':
      if f is False:
      	s.appendleft(t[2])
      else:
        s.append(t[2])
    else:
      if f is False:
      	s.append(t[2])
      else:
        s.appendleft(t[2])
x=''.join(map(str,s))
if f is False:
	print(x)
else:
  print(x[::-1])
Buggy python submission (verdict: Runtime Error):
print(int(input()//2)

Fixed submission:
n=int(input())
if n%2==0:
  print(n//2)
else:
  print(n//2 +1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(x) for x in input().split()]
flag=True
for i in a:
  if i%2==0:
    if i%3==0 or i%5==0:
      f=True
    else:
      f=False
      break
if f:
  print("APPROVED")
else:
  print("DENIED")

Fixed submission:
n=int(input())
a=[int(x) for x in input().split()]
f=True
for i in a:
  if i%2==0:
    if i%3==0 or i%5==0:
      f=True
    else:
      f=False
      break
if f:
  print("APPROVED")
else:
  print("DENIED")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum(range(1,n)))

Fixed submission:
n = int(input())
print((n)*(n-1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import itertools

n = int(input())
S = [''.join(sorted(input())) for _ in range(n)]
d = [len(list(itertools.combinations(range(v),2))) for v in collections.Counter(S).values()]
print(sum(d))

Fixed submission:
N = int(input())
S = [list(input()) for _ in range(N)]
cnt = 0
dic = {}
for s in S:
    s.sort()
    s_ = "".join(s)
    if s_ in dic.keys():
        cnt += dic[s_]
        dic[s_] += 1
    else:
        dic[s_] = 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = [input() for _ in range(n)]
cnt = 0
for i in range(len(S)):
    for j in range(i+1, len(S)):
        if ''.join(sorted(S[i])) == ''.join(sorted(S[j])):
            cnt += 1
print(cnt)

Fixed submission:
N = int(input())
S = [list(input()) for _ in range(N)]
cnt = 0
dic = {}
for s in S:
    s.sort()
    s_ = "".join(s)
    if s_ in dic.keys():
        cnt += dic[s_]
        dic[s_] += 1
    else:
        dic[s_] = 1
print(cnt)

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

n = int(input())
s = [collections.Counter(input()) for _ in range(n)]
cnt = 0
for i in range(n):
    a = s[i]
    for b in s[i+1:]:
        if a == b:
            cnt += 1
print(cnt)

Fixed submission:
N = int(input())
S = [list(input()) for _ in range(N)]
cnt = 0
dic = {}
for s in S:
    s.sort()
    s_ = "".join(s)
    if s_ in dic.keys():
        cnt += dic[s_]
        dic[s_] += 1
    else:
        dic[s_] = 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())
nums = list(range(a,b+1))
ans = nums[:k] + nums[len(nums)-k:]
for a in sorted(set(ans)):
    print(a)


Fixed submission:
a,b,k = map(int, input().split())
tmp = []
for i in range(k):
    if a + i <= b:
        tmp.append(a+i)
    if b - i >= a:
        tmp.append(b-i)

for i in sorted(set(tmp)):
    print(i)

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())
nums = list(range(a,b+1))
ans = nums[:k] + nums[len(nums)-k:]
for a in sorted(list(set(ans))):
    print(a)


Fixed submission:
a,b,k = map(int, input().split())
tmp = []
for i in range(k):
    if a + i <= b:
        tmp.append(a+i)
    if b - i >= a:
        tmp.append(b-i)

for i in sorted(set(tmp)):
    print(i)

Buggy python submission (verdict: Runtime Error):
a,b,k = map(int, input().split())
nums = list(range(a,b+1))
ans = nums[:k] + list(reversed(nums))[:k]
print(ans)
for a in set(sorted(ans)):
    print(a)


Fixed submission:
a,b,k = map(int, input().split())
tmp = []
for i in range(k):
    if a + i <= b:
        tmp.append(a+i)
    if b - i >= a:
        tmp.append(b-i)

for i in sorted(set(tmp)):
    print(i)
Buggy python submission (verdict: Runtime Error):
n = int(input())
tmp1 = 2
tmp2 = 1
for i in range(n-1):
    luc = tmp1 + tmp2
    tmp1,tmp2 = tmp2,luc

print(luc)



Fixed submission:
n = int(input())
a,b = 2,1
for _ in range(n):
    a,b = b,a+b

print(a)
Buggy python submission (verdict: Runtime Error):
S = input()

if S == ABC :
  print("ARC")
else :
  print("ABC")

Fixed submission:
S = input()

if S == "ABC" :
  print("ARC")
else :
  print("ABC")

Buggy python submission (verdict: Runtime Error):
S = input()

if S == ABC :
  print(ARC)
else :
  print(ABC)

Fixed submission:
S = input()

if S == "ABC" :
  print("ARC")
else :
  print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

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

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

c = collections.Counter(A)
for i in range(1, N + 1):
    print(c[i])
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
S = sum(A)
if A[M-1] >= S / (4*M):
print("Yes")
else:
print("No")

Fixed submission:
N, M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
S = sum(A)
if A[M-1] >= S / (4*M):
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
L = int(input())
s = []
for i in range(1,L+1):
    for j in range(1,L - i + 1):
        for k in range(1, L - i - j + 1):
            s.append(i * j * k)
print(max(s))





Fixed submission:
L = int(input())

c = float(L) / 3
print(c * c * c)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

aa = list(reversed(A))

cnt = 0
for i in range(0,N):
    if aa[i] == min(aa[i:]):
        cnt += 1
print(cnt)



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

m = A[0]
cnt = 1
for i in range(1,N):
    m = min(m, A[i])
    if A[i] <= m:
        cnt += 1
print(cnt)

Buggy python submission (verdict: Runtime Error):
from typing import List

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

aa = list(reversed(A))

cnt = 0
for i in range(0,N):
    if aa[i] == min(aa[i:]):
        cnt += 1
print(cnt)



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

m = A[0]
cnt = 1
for i in range(1,N):
    m = min(m, A[i])
    if A[i] <= m:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N, K, M =map(int, input().split())
A = list(map(int, input().split()))


if K >= N * M - sum(A) >= 0:
    print(N * M -sum(A))
elif sum(A) >= N * M - M:
    print("0")
else:
    print("-1")

#達成できる
#もう達成している
#無理

Fixed submission:
alphabet = input()
print(chr(ord(alphabet) + 1))
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

if A + B + C >= 22:
    print("bust")
else:
    print(win)
    

Fixed submission:
A, B, C = map(int, input().split())

if A + B + C >= 22:
    print("bust")
else:
    print("win")

Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

if A + B + C >= 22
    print("bust")
else:
    print(win)

Fixed submission:
A, B, C = map(int, input().split())

if A + B + C >= 22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

import math

for i in range(int(math.sqrt(N)), N):
    if N % i == 0:
        print(i-1 + int(N / i) -1)
        break


Fixed submission:
N = int(input())

def divisors(n, sort=False):
    """
    nの約数をO(√n)で列挙する
    """
    d = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            d.append((i, n//i))  #タプル括弧の中に数字が二つはいる
    if sort:
        d.sort()
    return d
l = []
for d1, d2 in divisors(N):
    m = d1 + d2
    l.append(m)
print(min(l) - 2)
Buggy python submission (verdict: Runtime Error):
import sys

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

zero_search = 0 in a_list
ans = 1

if zero_search:
    ans = 0
else:
    for i in a_list:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
            
print(ans)


Fixed submission:
import sys

a,b = list(map(int,input().split()))
print(a*b)
Buggy python submission (verdict: Runtime Error):
import sys

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

zero_search = 0 in a_list
ans = 1

if zero_search:
    ans = 0
else:
    for i in a_list:
        ans *= i
        if ans > 10**18;
            ans = -1
            break
            
print(-1)

Fixed submission:
import sys

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

zero_search = 0 in a_list
ans = 1

if zero_search:
    ans = 0
else:
    for i in a_list:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
            
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())

a = list(int(i) for i in input().split(" "))

prod = 1

for i in a:
  prod *= i
  if prod > (10 ** 18):
  	prod = -1
    break


print(prod)


Fixed submission:
n = int(input())

a = list(int(i) for i in input().split(" "))

prod = 1

if 0 in a:
  prod = 0
else:
  for i in a:
    prod *= i
    if prod > (10 ** 18):
      prod = -1
      break


print(prod)

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

a = list(int(i) for i in input().split(" "))

prod = 1

for i in a:
  prod *= i

if prod > (10 ** 18):
  prod = -1

print(prod)

Fixed submission:
n = int(input())

a = list(int(i) for i in input().split(" "))

prod = 1

if 0 in a:
  prod = 0
else:
  for i in a:
    prod *= i
    if prod > (10 ** 18):
      prod = -1
      break


print(prod)

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
s = 1
for i  in input().split():
  s = s * int(i)

if s > 1e+18:
  print(-1)  
else:
  print(s)

Fixed submission:
n = input()
s = 1

int_list = [int(s) for s in input().split()]
if 0 in int_list:
  print(0)
else:
  for i in int_list:
    s = s * int(i)
    if s > 1e+18:
      s = -1
      break
  print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import collections as c

S = input()
N = len(S)
MOD = 2019
dp = [0] * (len(S))
dp[0] = int(S[-1])
for i in range(1,N):
    tmp = (int(S[-(i+1)]) * (10 ** i)) % 2019
    dp[i] = dp[i-1] + tmp
    dp[i] %= 2019 

D = c.Counter(dp)
ans = 0
for k,v in zip(D.keys(),D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Fixed submission:
from collections import defaultdict

S = input()
S = S[::-1]
N = len(S)
MOD = 2019
D = defaultdict(int)
res = 0
p = 1
for i in range(N):
    tmp = res + int(S[i]) * p
    tmp %= MOD
    D[tmp] += 1

    res = tmp
    p *= 10
    p %= 2019 

ans = 0
for k,v in zip(D.keys(), D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

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

S = input()
N = len(S)
MOD = 2019
dp = [0] * (len(S))
for i in range(N):
    dp[i] = int(S[-(i+1):]) % 2019

D = c.Counter(dp)
ans = 0
for k,v in zip(D.keys(),D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Fixed submission:
from collections import defaultdict

S = input()
S = S[::-1]
N = len(S)
MOD = 2019
D = defaultdict(int)
res = 0
p = 1
for i in range(N):
    tmp = res + int(S[i]) * p
    tmp %= MOD
    D[tmp] += 1

    res = tmp
    p *= 10
    p %= 2019 

ans = 0
for k,v in zip(D.keys(), D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

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

S = input()
N = len(S)
MOD = 2019
dp = [0] * (len(S))
for i in range(N):
    dp[i] = int(S[-(i+1):]) % 2019

D = c.Counter(dp)
ans = 0
for k,v in zip(D.keys(),D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Fixed submission:
from collections import defaultdict

S = input()
S = S[::-1]
N = len(S)
MOD = 2019
D = defaultdict(int)
res = 0
p = 1
for i in range(N):
    tmp = res + int(S[i]) * p
    tmp %= MOD
    D[tmp] += 1

    res = tmp
    p *= 10
    p %= 2019 

ans = 0
for k,v in zip(D.keys(), D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))
tot = np.sum(A)

if tot > N:
	print(-1)
else:
	print(N-tot)

Fixed submission:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))

tot = np.sum(A)
if N < tot:
	print(-1)
else:
	print(N-tot)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))
tot = np.sum(A)

if tot > N:
	print(-1)
else:
	print(N-tot)

Fixed submission:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(input())
A = np.array(list(map(int, input().split())), dtype=np.int64)
cnt = np.zeros(N+1, dtype=np.int64)

for a in A:
	cnt[a] += 1

for c in cnt[1:]:
	print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(input())
S = input()
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = N - (r_cnt + g_cnt)

ans = r_cnt * g_cnt * b_cnt

for i in range(1,(N//2)+1):
	for j in range(N):
		if j + 2*i >= N:
			break
		tmp = [S[j],S[j+i],S[j+2*i]]
		tmp = list(set(tmp))
		if len(tmp) == 3:
			ans -= 1

print(ans)


Fixed submission:
N = int(input())
S = input()
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = N - (r_cnt + g_cnt)

ans = r_cnt * g_cnt * b_cnt

for i in range(1,(N//2)+1):
	for j in range(N):
		if j + 2*i >= N:
			break
		tmp = [S[j],S[j+i],S[j+2*i]]
		tmp = list(set(tmp))
		if len(tmp) == 3:
			ans -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(input())
A = [0] + list(map(int, input().split()))
if N <= 3:
	print(max(A))
	sys.exit()

dp = np.zeros([N//2+1, N+1], np.int64)
for i in range(1,4):
	dp[1,i] = max(A[1:i+1])

for j in range(2,(N//2)+1):
	for i in range(j*2-1, min(N+1, j*2+2)):
		dp[j,i] = max(dp[j,i-1],dp[j-1,i-2] + A[i])

print(max(dp[-1,-4:]))

Fixed submission:
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import defaultdict

N, *A = map(int, read().split())

INF = 10**18
dp_not = defaultdict(lambda : -INF)
dp_take = defaultdict(lambda: -INF)
dp_not[(0,0)] = 0

for i,x in enumerate(A,1):
	j = (i-1)//2
	for n in (j,j+1):
		dp_not[(i,n)] = max(dp_not[(i-1,n)], dp_take[(i-1,n)])
		dp_take[(i,n)] = dp_not[(i-1,n-1)] + x

print(max(dp_not[(N, N//2)], dp_take[(N, N//2)]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
def BFS(s):
	cnt = [0] * (N+1)
	flg = [-1] * (N+1)
	flg[s] = 0
	q = deque([s])
	while q:
		cp = q.popleft()
		for d in [-1,1]:
			tmp = cp + d
			if (0 <= tmp < N) and (flg[tmp] == -1):
				flg[tmp] = flg[cp] + 1
				ans[flg[tmp]] += 1
				q.append(tmp)
		if cp == X:
			if flg[Y] == -1:
				flg[Y] = flg[cp] + 1
				ans[flg[Y]] += 1
				q.append(Y)
		if cp == Y:
			if flg[X] == -1:
				flg[X] = flg[cp] + 1
				ans[flg[X]] += 1
				q.append(X)
	return cnt

for i in range(N):
	C = BFS(i)

for a in ans[1:]:
	print(a//2)

Fixed submission:
N, X, Y = map(int, input().split())

ans = [0] * N

for i in range(1,N+1):
	q = [i]
	flg = [-1] * (N+1)
	flg[i] = 0
	while q:
		cp = q.pop(0)
		for d in [-1,1]:
			if 1 <= cp+d <= N:
				if flg[cp+d] == -1:
					flg[cp+d] = flg[cp]+1
					ans[flg[cp+d]] += 1
					q.append(cp+d)
		if cp == X:
			if flg[Y] == -1:
				flg[Y] = flg[cp]+1
				ans[flg[Y]] += 1
				q.append(Y)
		if cp == Y:
			if flg[X] == -1:
				flg[X] = flg[cp]+1
				ans[flg[X]] += 1
				q.append(X)

for i in range(1,N):
	print(ans[i]//2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
def BFS(s):
	cnt = [0] * (N+1)
	flg = [-1] * (N+1)
	flg[s] = 0
	q = deque([s])
	while q:
		cp = q.popleft()
		for d in [-1,1]:
			if (0 <= cp + d < N) and (flg[cp + d] == -1):
				flg[cp + d] = flg[cp] + 1
				cnt[flg[cp+d]] += 1
				q.append(cp + d)
		if cp == X:
			if flg[Y] == -1:
				flg[Y] = flg[cp] + 1
				cnt[flg[Y]] += 1
				q.append(Y)
		if cp == Y:
			if flg[X] == -1:
				flg[X] = flg[cp] + 1
				cnt[flg[X]] += 1
				q.append(X)
	return cnt
ans = [0] * (N)
for i in range(N):
	C = BFS(i)
	for j in range(1,N):
		ans[j] += C[j]

for a in ans[1:]:
	print(a//2)

Fixed submission:
N, X, Y = map(int, input().split())

ans = [0] * N

for i in range(1,N+1):
	q = [i]
	flg = [-1] * (N+1)
	flg[i] = 0
	while q:
		cp = q.pop(0)
		for d in [-1,1]:
			if 1 <= cp+d <= N:
				if flg[cp+d] == -1:
					flg[cp+d] = flg[cp]+1
					ans[flg[cp+d]] += 1
					q.append(cp+d)
		if cp == X:
			if flg[Y] == -1:
				flg[Y] = flg[cp]+1
				ans[flg[Y]] += 1
				q.append(Y)
		if cp == Y:
			if flg[X] == -1:
				flg[X] = flg[cp]+1
				ans[flg[X]] += 1
				q.append(X)

for i in range(1,N):
	print(ans[i]//2)
Buggy python submission (verdict: Runtime Error):
import sys
s=input()
s_pre = s[:(n-1)//2]
s_epi = s[(n+1)//2:]
n = len(s)
if s != s[::-1]:
    print('No')
    sys.exit()
if s_pre != s_pre[::-1]:
    print('No')
    sys.exit()
if s_epi != s_epi[::-1]:
    print('No')
    sys.exit()
print('Yes')

Fixed submission:
import sys
s=input()
n=len(s)
s_pre = s[:(n-1)//2]
s_epi = s[(n+1)//2:]
if s != s[::-1]:
    print('No')
    sys.exit()
if s_pre != s_pre[::-1]:
    print('No')
    sys.exit()
if s_epi != s_epi[::-1]:
    print('No')
    sys.exit()
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H,W,K = map(int, input().split())
C = np.array([list(map(int, input())) for _ in range(H)])
C = np.hstack([np.zeros([H,1]),C])
np.cumsum(C, axis=1, out=C)
ans = 10**5
for s in range(1<<(H-1)):
	ind = 0
	A = np.zeros([1,W+1])
	for i in range(H):
		if s >> i & 1 == 1:
			A = np.vstack([A,C[ind:i+1,:].sum(axis=0)])
			ind = i+1
	A = np.vstack([A,C[ind:].sum(axis=0)])

	ind = 0
	cnt = 0
	while True:
		cut = 10**3+2
		for a in A:
			cut = min(cut, np.searchsorted(a,a[ind]+K,side='right'))
		if cut == W+1:
			break
		ind = cut-1
		cnt += 1

	h_cnt = 0
	for i in range(H):
		if s >> i & 1 == 1:
			h_cnt += 1

	ans = min(ans, cnt+h_cnt)

print(ans)

Fixed submission:
import numpy as np
H,W,K = map(int, input().split())
C = np.array([list(map(int, input())) for _ in range(H)])
C = np.hstack([np.zeros([H,1]),C])
np.cumsum(C, axis=1, out=C)
ans = 10**5
for s in range(1<<(H-1)):
	ind = 0
	A = np.zeros([1,W+1])
	for i in range(H):
		if s >> i & 1 == 1:
			A = np.vstack([A,C[ind:i+1,:].sum(axis=0)])
			ind = i+1
	A = np.vstack([A,C[ind:].sum(axis=0)])

	ind = 0
	cnt = 0
	while True:
		cut = 10**3+2
		for a in A:
			cut = min(cut, np.searchsorted(a,a[ind]+K,side='right'))
		if cut == W+1:
			break
		if ind == cut-1:
			cnt = 10**4+2
			break
		else:
			ind = cut-1
		cnt += 1

	h_cnt = 0
	for i in range(H):
		if s >> i & 1 == 1:
			h_cnt += 1

	ans = min(ans, cnt+h_cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
cond = 1
for i in range(Q):
	q = list(map(str, input().split()))
	if q[0] == "1":
		cond *= -1
	else:
		if q[1] == "1":
			if cond == 1:
				S = q[2] + S
			else:
				S += q[2]
		else:
			if cond == 1:
				S += q[2]
			else:
				S = q[2] + S

if cond == 1:
	print(S)
else:
	print(S[::-1])

Fixed submission:
S = input()
Q = int(input())
cond = 1
pre = ''
epi = ''
for i in range(Q):
	q = list(map(str, input().split()))
	if q[0] == "1":
		cond *= -1
	else:
		if q[1] == "1":
			if cond == 1:
				pre += q[2]
			else:
				epi += q[2]
		else:
			if cond == 1:
				epi += q[2]
			else:
				pre += q[2]

if cond == 1:
	print(pre[::-1]+S+epi)
else:
	print(epi[::-1]+S[::-1]+pre)