Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,d,dist):
    dist[v] = d
    for ve in edge[v]:
        if dist[ve] is None:
            dist = dfs(ve, d+1, dist)
    return dist
    
    
f_dist = dfs(0,0,[None]*n)
s_dist = dfs(n-1,0,[None]*n)

fget = sum(1 for f,s in zip(f_dist,s_dist) if f<=s)
print("Fennec" if fget*2>n else "Snuke")

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

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,d,dist):
    dist[v] = d
    for ve in edge[v]:
        if dist[ve] is None:
            dist = dfs(ve, d+1, dist)
    return dist
    
    
f_dist = dfs(0,0,[None]*n)
s_dist = dfs(n-1,0,[None]*n)

fget = sum(1 for f,s in zip(f_dist,s_dist) if f<=s)
print("Fennec" if fget*2>n else "Snuke")

Buggy submission (verdict: Runtime Error):
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dfs(v,d,dist):
    dist[v] = d
    for ve in edge[v]:
        if dist[ve] is None:
            dist = dfs(ve, d+1, dist)
    return dist
    
    
f_dist = dfs(0,0,[None]*n)
s_dist = dfs(n-1,0,[None]*n)

fget = sum(1 for f,s in zip(f_dist,s_dist) if f<=s)
print("Fennec" if fget*2>n else "Snuke")

Buggy submission (verdict: Runtime Error):
def dfs(v,d,dist,edge):
    dist[v] = d
    for ve in edge[v]:
        if dist[ve] is None:
            dist = dfs(ve, d+1, dist, edge)
    return dist

n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

    
f_dist = dfs(0,0,[None]*n,edge)
s_dist = dfs(n-1,0,[None]*n,edge)

fget = sum(1 for f,s in zip(f_dist,s_dist) if f<=s)
print("Fennec" if fget*2>n else "Snuke")
Problem p02585 (python)

Fixed submission:
N,K = map(int,input().rstrip().split(" "))
P = list(map(int,input().rstrip().split(" ")))
C = list(map(int,input().rstrip().split(" ")))

ans = -(10 ** 15)
for i in range(N):
    kans = 0
    score = [0]
    nex = P[i] -1
    while True:
        score.append(score[-1] + C[nex])
        nex = P[nex] - 1
        if nex == P[i] -1:
            break;

    if score[-1] > 0:
        if score[1:(K % (len(score) -1)) + 1] != []:
            kans = score[-1] * (K // (len(score) -1)) + max(score[1:(K % (len(score) -1)) + 1])
        else:
            kans = score[-1] * ((K // (len(score) -1)) - 1) + max(score)
    else:
        if score[1:min(len(score) - 1,K) + 1] != []:
            kans = max(score[1:min(len(score) - 1,K) + 1])
        else:
            kans = -(10 ** 15)
    ans = max(ans,kans)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().rstrip().split(" "))
P = list(map(int,input().rstrip().split(" ")))
C = list(map(int,input().rstrip().split(" ")))
check = [False for _ in range(N)]
ans = -(10 ** 15)
for i in range(N):
    kans = 0
    score = [0]
    nex = P[i] -1
    while True:
        score.append(score[-1] + C[nex])
        nex = P[nex] - 1
        if nex == P[i] -1:
            break;
    if score[-1] > 0:
        kans = score[-1] * (K // (len(score) -1)) + max(score[1:K % (len(score) -1) + 1])
    else:
        kans = max(score[1:min(len(score) - 1,K) + 1])
    ans = max(ans,kans)
print(ans)
Problem p02618 (python)

Fixed submission:
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
kankaku = [0 for i in range(27)]
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))

for i in range(D):
    p = 0
    t = 0
    for i2 in range(26):
        if p < s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2:
            p = s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2
            t = i2 + 1
    kankaku[t - 1] = -1
    print(t)
    for i in range(26):
        kankaku[i] += 1

Buggy submission (verdict: Runtime Error):
import time
import random

timestart = time.time() 
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
ta = []
ta_buf = []

man = 0
man_buf = 0
kankaku = [0 for i in range(27)]
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))

for i in range(D):
    p = 0
    t = 0
    for i2 in range(26):
        if p < s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2:
            p = s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2
            t = i2 + 1
    kankaku[t - 1] = -1
    ta.append(t)
    for i in range(26):
        kankaku[i] += 1

t.append(-1)
for i in range(D):
    man += s[i][ta[i]]
    last[ta[i]] = i + 1
    for i2 in range(26):
        man -= (i + 1 - last[i2]) * c[i2]

while timestart + 1.900 > time.time():
    for i in range(D):
        ta_buf[i] = ta[i]
    a = randint(0,360)
    b = a + randint(1,4)
    ta_buf[a], ta_buf[b] = ta_buf[b],ta_buf[a]

    for i in range(D):
        man_buf += s[i][ta_buf[i]]
        last[ta_buf[i]] = i + 1
        for i2 in range(26):
            man_buf -= (i + 1 - last[i2]) * c[i2]

    if man_buf > man:
        man = man_buf
        for i in range(D):
            ta[i] = ta_buf[i]

for i in range(D):
    print(ta[i] + 1)

Buggy submission (verdict: Runtime Error):
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
for i in range(D):
    a.append(list(map(int,input().rstrip().split(" "))))

p = 0
t = 0
for i in range(D):
    for i2 in range(26):
        if p < S[i][i2]:
            p = s[i][i2]
            t = i2
    print(t)
Problem p02642 (python)

Fixed submission:
N = int(input())
ans = 0
A = list(map(int,input().rstrip().split(" ")))
A.sort()
A2 = [True for i in range(A[-1] + 1)]
for i in range(len(A)):
    k = A[i] * 2
    if A2[A[i]]:
        if i != 0 and A[i-1] == A[i]:
            A2[A[i]] = False
        while(k < len(A2)):
            A2[k] = False
            k += A[i]
for i in A:
    if A2[i]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
nokori = N
kaburi = set()
ans = 0
A = list(map(int,input().rstrip().split(" ")))
A2 = set()
rem = set()
for i in A:
    if i in A2:
        kaburi.add(i)
    else:
        A2.add(i)
for i in kaburi:
    A2.remove(i)
for i in kaburi:
    k = i
    for i2 in A2:
        if i2 % k == 0:
            rem.add(i2)
    for i2 in rem:
        A2.remove(rem)
    rem.clear()
while len(A2) != 0:
    i = min(A2)
    ans += 1
    for i2 in A2:
        if i2 % i == 0:
            rem.add(i2)
    for i2 in rem:
        A2.remove(i2)
    rem.clear()
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
nokori = N
kaburi = set()
ans = 0
A = list(map(int,input().rstrip().split(" ")))
A2 = set()
for i in A:
    if i in A2:
        kaburi.add(i)
    else:
        A2.add(i)
for i in kaburi:
    A2.remove(i)
for i in kaburi:
    k = i
    for i2 in A2:
        if i2 % K == 0:
            A2.remove(i2)
while len(A2) != 0:
    i = min(A2)
    ans += 1
    k = i
    for i2 in A2:
        if i2 % K == 0:
            A2.remove(i2)
print(ans)
Problem p02646 (python)

Fixed submission:
A,V = map(int,input().rstrip().split(" "))
B,W = map(int,input().rstrip().split(" "))
T = int(input())
if(abs(A - B) <= (V - W) * T):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A,V = map(int,input().rstrip().split(" "))
B,W = map(int,input().rstrip().split(" "))
T = int(input())
if(V <= W):
    print("NO")
else:
    if(abs(A - B) <= (V - W) * T):
        print("YES")
    else:
        Print("NO")
Problem p02691 (python)

Fixed submission:
N =int(input())
A = list(map(int,input().rstrip().split(" ")))
Aq = []
DP = [0 for i in range(5 * 10 ** 5)]
DPP = []
ans = 0
for i in range(N):
    if i >= A[i]:
        ans += DP[i - A[i]]
    if A[i] <= N:
        DP[A[i] + i] += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N =int(input())
A = list(map(int,input().rstrip().split(" ")))
Aq = []
DP = [0 for i in range(2 * 10 ** 5)]
DPP = []
ans = 0
for i in range(N):
    if i >= A[i]:
        ans += DP[i - A[i]]
    if A[i] <= N:
        DP[A[i] + i] += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N =int(input())
A = list(map(int,input().rstrip().split(" ")))
Aq = []
DP = [0 for i in range(10 ** 5)]
DPP = []
ans = 0
for i in range(N):
    if i >= A[i]:
        ans += DP[i - A[i]] 
    DP[A[i] + i] += 1
    
print(ans)
Problem p02697 (python)

Fixed submission:
N,M = map(int,input().rstrip().split(" "))
ans = []
K = (N - 1) // 2
if K % 2 == 0:
    for i in range(K // 2):
        ans.append([K // 2 - i,K // 2 + i + 1])
    for i in range(K // 2):
        ans.append([N - K // 2 -1  - i,N - K // 2 + i + 1])
else:
    for i in range(K // 2 + 1):
        ans.append([K // 2 + 1 - i,K // 2 + i + 2])
    for i in range(K // 2):
        ans.append([N - K // 2 - 1  - i,N - K // 2 + i + 1])
for i in range(M):
    print(str(ans[i][0]) + " " + str(ans[i][1]))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().rstrip().split(" "))
ans = [[False for _ in range(N)] for _ in range(N)]

if N % 2 == 1:
    for i in range(1,M + 1):
        print(str(i) + " " + str(N - i))
else:
    for i in range(1,min(M + 1,(N - 1) / 2)):
        print(str(i) + " " + str(N - i))
    if (N - 1) // 2 == M:
        print(str(N / 2) + " " + str(N / 2 + 1))
Problem p02713 (python)

Fixed submission:
import math
ans = 0
n = int(input())
K = [0 for _ in range(n + 1)]
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    K[math.gcd(i,i2)] += 1
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    ans += K[i] * math.gcd(i,i2)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
ans = 0
K = [0 for _ in range(200)]
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    K[math.gcd(i,i2)] += 1
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    ans += K[i] * math.gcd(i,i2)
print(ans)
Problem p02721 (python)

Fixed submission:
N,K,C =map(int,input().rstrip().split(" "))
S = input()
kinmu = 0
niti = 0
f = []
b = []
kinmu = 0
niti = 0
while kinmu < K and niti < N:
  if S[niti] == "o":
    f.append(niti)
    kinmu += 1
    niti += C
  niti += 1
kinmu = 0
niti = N -1
while kinmu < K and niti >= 0:
  if S[niti] == "o":
    b.append(niti)
    kinmu += 1
    niti -= C
  niti -= 1
b.reverse()
for i in range(K):
  if f[i] == b[i]:
    print(f[i] + 1)

Buggy submission (verdict: Runtime Error):
N,K,C =map(int,input().rstrip().split(" "))
S = input()
kinmu = 0
niti = 0
f = []
b = []
for i in range(N):
  kinmu = 0
  niti = 0
  while kinmu < K and niti < N:
    if S[niti] == "o":
      f.append(niti)
      kinmu += 1
      niti += C
    niti += 1
  kinmu = 0
  niti = N -1
  while kinmu < K and niti > 0:
    if S[niti] == "o":
      b.append(niti)
      kinmu -= 1
      niti -= C
    niti -= 1
b.reverse()
for i in range(K):
  if f[i] == b[i]:
    print(f[i] + 1)

Buggy submission (verdict: Runtime Error):
kinmu = 0
niti = 0
p = 0
for i in range(N):
  if S[i] == "o" and tyousa[i] == p:
    kinmu = 0
    niti = 0
    route.clear()
    while kinmu < K and niti < N:
      if S[niti] == "o" and niti != i:
        route.append(niti)
        kinmu += 1
        niti += C
      niti += 1
    if niti >= N and kinmu < K:
      print(i + 1)
    if kinmu >= K:
      for i2 in route:
        tyousa[i2] += 1
      p += 1
Problem p02727 (python)

Fixed submission:
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  n= 1
  while RA[eatRA - n] == GA[eatGA -n] and n != min(eatRA,eatGA):
    n += 1
  if RA[eatRA - n] > GA[eatGA - n]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C or eatRA == 0 or eatGA == 0:
    break
if eatRA == 0 and eatGA != 0 and eatWA != C:
  while GA[eatGA -1] < WA[eatWA]:
    eatGA -= 1
    eatWA += 1
    if eatWA == C or eatGA == 0:
      break
elif eatRA != 0 and eatGA == 0 and eatWA != C:
  while RA[eatRA -1] < WA[eatWA]:
    eatRA -= 1
    eatWA += 1
    if eatWA == C or eatRA == 0:
      break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[i]
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
RAeatList = RA[:X]
GAeatList = GA[:Y]
while RAeatList[-1] < WA[0] or GAeatList[-1] < WA[0]:
  n= 1
  while RAeatList[-1 * n] == GAeatList[-1 * n] or n == min(X,Y) :
    n -= 1
  if RAeatList[-1 * n] < GAeatList[-1 * n]:
    RAeatList.pop(len(RAeatList) -1)
    RAeatList.insert(0,WA[0])
  else:
    GAeatList.pop(len(RAeatList) -1)
    GAeatList.insert(0,WA[0])
  if len(WA) == 1:
    break
  WA.pop(0)
  if eatWA == C:
    break

for i in range(X):
  ans += RAeatList[i]
for i in range(Y):
  ans += GAeatList[i]
print(ans)
Problem p02743 (python)

Fixed submission:
A,B,C = map(int,input().split())
N = C- A- B
if  N > 0:
  if A * B * 4 < N ** 2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
print(int((A * B + 1) / 2))
Problem p02744 (python)

Fixed submission:
d = ['','a','b','c','d','e','f','g','h','i','j']
N = int(input())
if N == 1:
  print("a")
elif N == 2:
  print("aa")
  print("ab")
else:
  ans = [[[]]for _ in range(N - 1)]
  ans[0][0] = [1]
  ans[1][0] = [1,1]
  ans[1].append([1,2])
  ansstr = []
  for i in range(N -2):
    for i2 in range(len(ans[i + 1])):
      for i3 in range(max(ans[i + 1][i2]) + 1):
        if i == N - 3:
          ansstr.clear()
          for i4 in range(N - 1):
            ansstr.append(d[ans[i + 1][i2][i4]])
          ansstr.append(d[i3 + 1])
          print("".join(ansstr))
        else:
          ans[i + 2].append(ans[i + 1][i2] + [i3 + 1])
    if i < N - 3:
      ans[i + 2].pop(0)

Buggy submission (verdict: Runtime Error):
d = ['','a','b','c','d','e','f','g','h','i','j']
N = int(input())
if N == 1:
  print("a")
elif N == 2:
  print("aa")
  print("ab")
else:
  ans = [[[]]for _ in range(N - 1)]
  ans[0][0] = [1]
  ans[1][0] = [1,1]
  ans[1].append([1,2])
  ansstr = []
  for i in range(N -2):
    for i2 in range(len(ans[i + 1])):
      for i3 in range(max(ans[i + 1][i2]) + 1):
        if i == N - 3:
          ansstr.clear()
          for i4 in range(N - 1):
            ansstr.append(d[ans[i + 1][i2][i4]])
          ansstr.append(d[i3 + 1])
          print("".join(ansstr))
        else:
          ans[i + 2].append(ans[i + 1][i2] + [i3 + 1])
    if i < N - 3:
      ans[i + 2].pop(0)
Problem p02756 (python)

Fixed submission:
S = list(input())
mae = []
ato = []
rev = False
Q = int(input())
for i in range(Q):
    A = list(input().rstrip().split(" "))
    if int(A[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if (rev and int(A[1]) == 2 or not rev and int(A[1]) == 1):
            mae.append(A[2])
        else:
            ato.append(A[2])
if rev:
    ato.reverse()
    S.reverse()
    print("".join(ato) + "".join(S) + "".join(mae))
else:
    mae.reverse()
    print("".join(mae) + "".join(S) + "".join(ato))

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())
 = 0
ans = []
T = []

for i in range(Q):
  TS = input()
  if TS == "1":
    revcount += 1
  else:
    T.append(TS.rstrip().split(" "))
    T[len()-1][1] = str((int(T[len(T)-1][1]) + revcount % 2 + 1) % 2 + 1)
if revcount % 2 == 1:
  ans.append(S[::-1])
else:
  ans.append(S)
for i in range(len(T)):
  if (int(T[iinput()
Q = int(input())
revcount = 0
ans = []
T = []

for i in range(Q):
  TS = input()
  if TS == "1":
    revcount += 1
  else:
    T.append(TS.rstrip().split(" "))
    T[len(T)-1][1] = str((int(T[len(T)-1][1]) + revcount % 2 + 1) % 2 + 1)
if revcount % 2 == 1:
  ans.append(S[::-1])
else:
  ans.append(S)
            
for i in range(len(T)):
  if (int(T[i][1]) == 1 and revcount % 2 == 0) or (int(T[i][1]) == 2 and revcount % 2 == 1):
    ans.insert(0,T[i][2])
  else:
    ans.append(T[i][2])
ans2 = "".join(ans2  1]) == 1 and revcount % 2 == 0) or (int(T[i][1]) == 2 and revcount % 2 == 1)
    ans.insert(0,T[i][2])
  else:
    ans.append(T[i][2])
ans2 = "".join(ans)
print(ans2)
Problem p02760 (python)

Fixed submission:
A = [[0 for i in range(3)]for i2 in range(3)]
c = [[False for i in range(3)]for i2 in range(3)]
A[0] = list(map(int,input().rstrip().split(" ")))
A[1] = list(map(int,input().rstrip().split(" ")))
A[2] = list(map(int,input().rstrip().split(" ")))
int_inp = int(input())
s = 0
for i in range(int_inp):
  s = int(input())
  for i2 in range(9):
    if A[int(i2 / 3)][i2 % 3] == s:
      c[int(i2 / 3)][i2 % 3] = True
ans = False
for i in range(3):
  if c[i][0] and c[i][1] and c[i][2]:ans = True
for i in range(3):
  if c[0][i] and c[1][i] and c[2][i]:ans = True
if c[0][0] and c[1][1] and c[2][2]:ans = True
if c[2][0] and c[1][1] and c[0][2]:ans = True
if ans:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
A = [[0 for i in range(3)]for i2 in range(3)]
c = [[False for i in range(3)]for i2 in range(3)]
A[0] = list(map(int,input().rstrip().split(" ")))
A[1] = list(map(int,input().rstrip().split(" ")))
A[2] = list(map(int,input().rstrip().split(" ")))
int_inp = int(input())
s = 0
for i in range(int_inp):
  s = int(input())
  for i2 in range(9):
    for A[int(i2 / 3)][i2 % 3] == s:
      c[int(i2 / 3)][i2 % 3] == True
ans = False
for i in range(3):
  if c[i][0] and c[i][1] and c[i][2]:ans = True
for i in range(3):
  if c[0][i] and c[1][i] and c[2][i]:ans = True
if c[0][0] and c[1][1] and c[2][2]:ans = True
if c[2][0] and c[1][1] and c[0][2]:ans = True
if ans:
  print('Yes')
else:
  print('No')
Problem p02765 (python)

Fixed submission:
N,R = map(int,input().rstrip().split(" "))
if N >= 10:
  print(R)
else:
  print(R + (10-N)*100)

Buggy submission (verdict: Runtime Error):
import math

N,K = map(int,input().rstrip().split(" "))
if N > 0:
  print(math.ceil(math.log(N+1,K)))
else:
  print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().rstrip().split(" ")))
ans = 0
ansb = 0
for i in range(100):
  ansb = 0
  for i2 in range(N):
    ansb += (X[i2] - i)**2
  if i == 0 or ans > ansb:
    ans = ansb
print(ans)
Problem p02789 (python)

Fixed submission:
a = input().rstrip().split()
if a[0] == a[1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a = input().rstrip().split()
if a[0] = a[1]:
  print('Yes')
else:
  print('No')
Problem p03049 (python)

Fixed submission:
N = int(input())
ans = 0
f = False
xx = 0
xA = 0
Bx = 0
BA = 0
A = 0
B = 0
for i in range(N):
  S = input()
  for i in range(len(S) - 1):
    if S[i] == "A" and S[i + 1] == "B":
      ans += 1
  if S[0] == "B":
    if S[-1] == "A":BA += 1
    else:Bx += 1
  else:
    if S[-1] == "A":xA += 1
if xA != 0 and Bx != 0:
  ans += BA + 1
  xA -= 1
  Bx -= 1
elif xA != 0:
  ans += BA
  xA -= 1
elif Bx != 0:
  ans += BA
  Bx -= 1
else:
  if BA >= 2:
    ans += BA - 1
ans += min(Bx,xA)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
f = False
xx = 0
xA = 0
Bx = 0
BA = 0
A = 0
B = 0
for i in range(N):
  S = input()
  for i in range(len(S) - 1):
    if S[i] == "A" and S[i + 1] == "B":
      ans += 1
  if S[0] == "B":
    if S[-1] == "A":BA += 1
    else:Bx += 1
  else:
    if S[-1] == "A":xA += 1
if xA != 0 and Bx != 0:
  ans += BA + 1
  xA -= 1
  Bx -= 1
elif xA != 0:
  ans += BA
  xA -= 1
elif Bx != 0:
  ans += AB
  Bx -= 1
else:
  if BA >= 2:
    ans += BA - 1
ans += min(Bx,xA)
print(ans)
Problem p03612 (python)

Fixed submission:
N = int(input())
p = list(map(int,input().rstrip().split(" ")))
ans = 0
swap = 0
for i in range(N):
    if p[i] == i + 1:
        if i != N - 1:
            swap = p[i]
            p[i] = p[i + 1]
            p[i + 1] = swap
            ans += 1
        else:
            swap = p[i]
            p[i] = p[i - 1]
            p[i - 1] = swap
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int,input().rstrip().split(" ")))
ans = 0
swap = 0
for i in range(N):
    if p[i] == i + 1:
        if i != N:
            swap = p[i]
            p[i] = p[i + 1]
            p[i + 1] = swap
            ans += 1
        else:
            swap = p[i]
            p[i] = p[i - 1]
            p[i - 1] = swap
            ans += 1
print(ans)
Problem p03637 (python)

Fixed submission:
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1])

if counter[2] + 1 >= counter[0]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1])

if counter[2] += 1 >= counter[0]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1
counter[0] += min(1,counter[1] += 1)

if counter[2] += 1 >= counter[0]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().rstrip().split(" ")))
counter = [0,0,0]
for i in a:
    if i % 4 == 0:
        counter[2] += 1
    elif i % 2 == 0:
        counter[1] += 1
    else:
        counter[0] += 1

if counter[1] == 1:
    counter[1] = 0
    counter[0] += 1
    if(counter[2] != 0):
        p += 1
p = (max(counter[1] - 1,0)) + counter[2] * 2

if p >= counter[0]:
    print("Yes")
else:
    print("No")
Problem p03720 (python)

Fixed submission:
N,M = map(int,input().split())
ans = [0 for _ in range(N)]
for _ in range(M):
  a,b = map(int,input().split())
  ans[a-1] += 1
  ans[b-1] += 1
for i in range(N):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
M,N = map(int,input().split())
ans = [0 for _ in range(N)]
for _ in range(M):
  a,b = map(int,input().split())
  ans[a-1] += 1
  ans[b-1] += 1
for i in range(N):
  print(ans[i])
Problem p03238 (python)

Fixed submission:
age = int(input());
if age == 1:
  print("Hello World");
else:
  b = int(input());
  c = int(input());
  print(b + c);

Buggy submission (verdict: Runtime Error):
age = int(input());
if age == 1:
  print(1);
else:
  b, c = map(int, input().split());
  print(b + c);
Problem p03469 (python)

Fixed submission:
s = list(input());
s[3] = '8';
s = "".join(s); #区切り文字なし
print(s);

Buggy submission (verdict: Runtime Error):
#include<iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
}

Buggy submission (verdict: Runtime Error):
s = input();
s[3] = '8';
print(s);
Problem p04043 (python)

Fixed submission:
a, b, c = map(int, input().split())
five = 0
seven =0
if a == 5:
  five = five + 1;
elif a == 7:
  seven = seven + 1;
if b == 5:
  five = five + 1;
elif b == 7:
  seven = seven + 1;
if c == 5:
  five = five + 1;
elif c == 7:
  seven = seven + 1;
if five == 2 and seven == 1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
five = 0;
if a == 5:
  five = five + 1;
elif a == 7:
  seven = seven + 1;
if b == 5:
  five = five + 1;
elif b == 7:
  seven = seven + 1;
if c == 5:
  five = five + 1;
elif c == 7:
  seven = seven + 1;
if five == 2 and seven == 1:
  print("YES")
else:
  print("NO")