Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
number = [0 for i in range(N+1)]
for i in range(N):
  a, b = map(int, input().split())
  number[a] += b
for i in range(N):
  if K - number[i+1] <= 0:
    print(i+1)
    break
  else:
    K -= number[i+1]
   


Fixed submission:
N, K = map(int, input().split())
a = []
b = []
hairetu = []
for i in range(N):
    A, B = map(int, input().split())
    hairetu.append([A, B])

hairetu.sort()
for i in range(N):
    K -= hairetu[i][1]
    if K <= 0:
        print(hairetu[i][0])
        break

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
number = [0 for i in range(N+1)]
for i in range(N):
  a, b = map(int, input().split())
  number[a] += b
for i in range(N):
  if K - number[i+1] <= 0:
    print(i+1)
  else:
    K -= number[i+1]
   


Fixed submission:
N, K = map(int, input().split())
a = []
b = []
hairetu = []
for i in range(N):
    A, B = map(int, input().split())
    hairetu.append([A, B])

hairetu.sort()
for i in range(N):
    K -= hairetu[i][1]
    if K <= 0:
        print(hairetu[i][0])
        break

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = []
b = []
hairetu = []
for i in range(N):
    A, B = map(int, input().split())
    h = [A for i in range(B)]
    hairetu.extend(h)

hairetu.sort()
print(hairetu[K-1])


Fixed submission:
N, K = map(int, input().split())
a = []
b = []
hairetu = []
for i in range(N):
    A, B = map(int, input().split())
    hairetu.append([A, B])

hairetu.sort()
for i in range(N):
    K -= hairetu[i][1]
    if K <= 0:
        print(hairetu[i][0])
        break
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
num = [0] * (N+1)
for i in range(M):
    a, b = map(int, input().split())
    num[a] += 1
    num[b] += 1

flag = 1
for i in num:
    if i % 2 != 0:
        flag = 0

if flag = 1:
    print("YES")
else:
    print("NO")


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

flag = 1
for i in num:
    if i % 2 != 0:
        flag = 0

if flag == 1:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
num = [0] * (N+1)
for i in range(M):
    a, b = map(int, input().split())
    num[a] += 1
    num[b] += 1

flag = 1
for i in num:
    if num % 2 != 0:
        flag = 0

if flag = 1:
    print("YES")
else:
    print("NO")


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

flag = 1
for i in num:
    if i % 2 != 0:
        flag = 0

if flag == 1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if b-a = c-b:
    print("YES")
else:
    print("NO")


Fixed submission:
a, b, c = map(int, input().split())
if b-a == c-b:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
ans = []

def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
        
    else:
        return 100000000

for i in range(1, 50000):
    ans.append(move(X, i))

print(min(ans))


Fixed submission:
X = int(input())
ans = []
def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
    else:
        return 50000

for i in range(1, 45000):
    ans.append(move(X, i))

print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
ans = 100000000
def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
    else:
        return 100000000

for i in range(1, 50000):
    ans = min(ans, move(X, i))

print(ans)


Fixed submission:
X = int(input())
ans = []
def move(x, T):
    for i in range(T, 0, -1):
        if x >= i:
            x -= i
    if x == 0:
        return T
    else:
        return 50000

for i in range(1, 45000):
    ans.append(move(X, i))

print(min(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N):
    b.append([a[i], i+1])
b.sort(reverse = True)
ans = [0]*(N+1)
mini = N+1

for i in range(N-1):
    mini = min(mini, b[i][1])
    if b[i+1][0] - b[i][0] < 0:
        ans[mini] += (b[i][0] - b[i+1][0])*(i+1)

ans[1] += N*min(b)
for i in range(N):
    print(ans[i+1])


Fixed submission:
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N):
    b.append([a[i], i+1])
b.sort(reverse = True)
ans = [0]*(N+1)
mini = N+1

for i in range(N-1):
    mini = min(mini, b[i][1])
    if b[i+1][0] - b[i][0] < 0:
        ans[mini] += (b[i][0] - b[i+1][0])*(i+1)

ans[1] += N*b[-1][0]
for i in range(N):
    print(ans[i+1])
Buggy python submission (verdict: Runtime Error):
def lensetlist(A):
    B = []
    for i in A:
        if i not in B:
            B.append(i)
    return len(B)

N, M = map(int, input().split())
A = []
B = []

for i in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

used = [0 for i in range(N)]
result = []
stack = []
ans = 0
def path(start, visited):
    if len(visited) == N:
        result.append(visited[:])
        exit
    stack.append(start)
    while len(stack) > 0:
        nextpoint = stack.pop()
        if nextpoint in visited:
            continue
        visited.append(nextpoint)
        for i in range(M):
            if A[i] == start:
                path(B[i], visited)
            if B[i] == start:
                path(A[i], visited)
        visited.pop()

path(1, [])
print(lensetlist(result))


Fixed submission:
A, B = map(int, input().split())
if A == 1:
    A = 14
if B == 1:
    B = 14
if A > B:
    print("Alice")
elif A < B:
    print("Bob")
else:
    print("Draw")

Buggy python submission (verdict: Runtime Error):
A, B = map(int, input(),split())
if A == 1:
    A = 14
elif B == 1:
    B = 14
if A > B:
    print("Alice")
elif A < B:
    print("Bob")
else:
    print("Draw")

Fixed submission:
A, B = map(int, input().split())
if A == 1:
    A = 14
if B == 1:
    B = 14
if A > B:
    print("Alice")
elif A < B:
    print("Bob")
else:
    print("Draw")
Buggy python submission (verdict: Runtime Error):
A, op, B = map(int,input().split())
if op == '+':
    print(A+B)
else:
    print(A-B)


Fixed submission:
A, op, B = input().split()
if op == '+':
    print(int(A)+int(B))
else:
    print(int(A)-int(B))
Buggy python submission (verdict: Runtime Error):
N = int(input())
x, y = 0
for i in range(N):
  a, b = map(int, input().split())
  mul = max((x-1)//a+1, (y-1)//b+1)
  x = mul*a
  y = mul*b
print(x+y)

Fixed submission:
N = int(input())
x, y = 1, 1
for i in range(N):
  a, b = map(int, input().split())
  mul = max((x+a-1)//a, (y+b-1)//b)
  x = mul*a
  y = mul*b
print(x+y)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
S = input()
a = 0
b = 0
for i in range(S):
  if S[i] == 'a' and a+b < A+B:
    a += 1
    print('Yes')
  elif S[i] == 'b' and a+b < A+B and b < B:
    print('Yes')
  else:
    print('No')

Fixed submission:
N, A, B = map(int, input().split())
S = input()
a = 0
b = 0
for i in range(N):
  if S[i] == 'a' and a+b < A+B:
    a += 1
    print('Yes')
  elif S[i] == 'b' and a+b < A+B and b < B:
    b += 1
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from bisect import *
h, w, n = map(int, input().split())

d = defaultdict(list)
q = [list(map(int, input().split())) for i in range(n)]
q.sort()
ans = [0]*10
for i in range(n):
    a, b = q[i]
    d[a].append(b)

for a, b in q:
    for i in range(max(1, a-2), min(h-2, a)+1):
        for j in range(max(1, b-2), min(w-2, b)+1):
            count = 0
            for k in range(3):
                count += bisect_right(d[i+k], j+2) - bisect_left(d[i+k], j)
            ans[count] += 1


for i in range(1, 10):
    ans[i] //= i

ans[0] = (w-2)*(h-2) - sum(ans[1:])
for i in range(10):
    print(ans[i])


Fixed submission:
from collections import defaultdict
from bisect import *
h, w, n = map(int, input().split())

d = defaultdict(list)
q = [list(map(int, input().split())) for i in range(n)]
q.sort()
ans = [0]*10
for i in range(n):
    a, b = q[i]
    d[a].append(b)

for a, b in q:
    for i in range(max(1, a-2), min(h-2, a)+1):
        for j in range(max(1, b-2), min(w-2, b)+1):
            count = 0
            for k in range(3):
                count += bisect_right(d[i+k], j+2) - bisect_left(d[i+k], j)
            ans[count] += 1


for i in range(1, 10):
    ans[i] //= i

ans[0] = (w-2)*(h-2) - sum(ans[1:])
for i in range(10):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
x = list(map(int, input().split()))
dp = [[[0 for i in range(N*A+1)] for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1


for i in range(N):
    for j in range(N*A+1):
        for k in range(N):
 #i個の整数のうちk個使ってjにする場合の数
            if x[i] > j:
                dp[k][i+1][j] = dp[k][i][j]
            else:
                dp[k+1][i+1][j] = dp[k][i][j - x[i]] + dp[k+1][i][j]

ans = 0
for i in range(1, N + 1):
    ans += dp[i][N][A * i]
print(ans)


Fixed submission:
N, A = map(int, input().split())
x = list(map(int, input().split()))
dp = [[[0 for i in range(N*A+1)] for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1


for i in range(N):
    for j in range(N*A+1):
        for k in range(N):
 #i個の整数のうちk個使ってjにする場合の数
            if x[i] > j:
                dp[k][i+1][j] = dp[k][i][j]
            else:
                dp[k+1][i+1][j] = dp[k][i][j - x[i]] + dp[k+1][i][j]

ans = 0
for i in range(1, N + 1):
    ans += dp[i][N][A * i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())

dp_plus = [[0]*(n+1) for i in range(30)]
dp_minus = [[0]*(n+1) for i in range(30)]

for i in range(n):
    now = x[i]
    reach = now + l
    dp_plus[0][i+1] = bisect_right(x, reach)

for i in range(n):
    now = x[i]
    reach = now - l
    dp_minus[0][i+1] = bisect_left(x, reach) + 1



for i in range(29):
    for j in range(1, n+1):
        dp_plus[i+1][j] = dp_plus[i][dp_plus[i][j]]
        dp_minus[i+1][j] = dp_minus[i][dp_minus[i][j]]


for _ in range(q):
    a, b = map(int, input().split())
    ans = 1
    if a < b:
        for i in range(29, -1, -1):
            if dp_plus[i][a] < b:
                a = dp_plus[i][a]
                ans += pow(2, i)

    else:
        for i in range(29, -1, -1):
            if dp_minus[i][a] > b:
                a = dp_minus[i][a]
                ans += pow(2, i)

    print(ans)


Fixed submission:
from bisect import *
n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())

dp_plus = [[0]*(n+1) for i in range(30)]
dp_minus = [[0]*(n+1) for i in range(30)]

for i in range(n):
    now = x[i]
    reach = now + l
    dp_plus[0][i+1] = bisect_right(x, reach)

for i in range(n):
    now = x[i]
    reach = now - l
    dp_minus[0][i+1] = bisect_left(x, reach) + 1



for i in range(29):
    for j in range(1, n+1):
        dp_plus[i+1][j] = dp_plus[i][dp_plus[i][j]]
        dp_minus[i+1][j] = dp_minus[i][dp_minus[i][j]]


for _ in range(q):
    a, b = map(int, input().split())
    ans = 1
    if a < b:
        for i in range(29, -1, -1):
            if dp_plus[i][a] < b:
                a = dp_plus[i][a]
                ans += pow(2, i)

    else:
        for i in range(29, -1, -1):
            if dp_minus[i][a] > b:
                a = dp_minus[i][a]
                ans += pow(2, i)

    print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
red = [False for i in range(N+1)]
red[1] = True
box = [1 for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[i] == 0:
        red[x] = False

ans = 0
for i in range(1, N+1):
    if red[i] and box[i] > 0:
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
red = [False for i in range(N+1)]
red[1] = True
box = [1 for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        red[x] = False

ans = 0
for i in range(1, N+1):
    if red[i] and box[i] > 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
red = [False for i in range(N+1)]
red[1] = True
box = [1 for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[i] == 0:
        red[i] = False

ans = 0
for i in range(1, N+1):
    if red[i] and box[i] > 0:
        ans += 1
print(ans)


Fixed submission:
N, M = map(int, input().split())
red = [False for i in range(N+1)]
red[1] = True
box = [1 for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    if red[x]:
        red[y] = True
    box[x] -= 1
    box[y] += 1
    if box[x] == 0:
        red[x] = False

ans = 0
for i in range(1, N+1):
    if red[i] and box[i] > 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
lx=[]
ly=[]
for i in range(n):
  x,y=map(int,input().split())
  lx.append(x+y)
  ly.append(x-y)
ax,bx,ay,by=max(lx),min(lx),max(ly),min(ly)
print(max(ax-bx,ay-by))

Fixed submission:

n=int(input())
lx=[]
ly=[]
for i in range(n):
  x,y=map(int,input().split())
  lx.append(x+y)
  ly.append(x-y)
ax,bx,ay,by=max(lx),min(lx),max(ly),min(ly)
print(max(ax-bx,ay-by))
Buggy python submission (verdict: Runtime Error):
d,t,s=map(int,input().split())
if d<=t*s:
  print(Yes)
else:print(No)

Fixed submission:
d,t,s=map(int,input().split())
if d<=t*s:
  print('Yes')
else:print('No')
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=[(i,1)for i in range(n)]
def find(i):
  if p[i][0]==i:return i
  else:
    c=find(p[i])
    p[i]=(c,0)
    return c
def union(i,j):
  pi=find(i)
  pj=find(j)
  if not pi==pj:
    if p[pi][1]>p[pj][1]:
      p[pj]=(pi,p[pi][1]+p[pj][1])
    else:
      p[pi]=(pj,p[pi][1]+p[pj][1])

for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if p[i][0]==i:ans=max(ans,p[i][1])
print(ans)

Fixed submission:
n,m=map(int,input().split())
p=[(i,1)for i in range(n)]
def find(i):
  if p[i][0]==i:return i
  else:
    c=find(p[i][0])
    p[i]=(c,0)
    return c
def union(i,j):
  pi=find(i)
  pj=find(j)
  if not pi==pj:
    if p[pi][1]>p[pj][1]:
      p[pi]=(pi,p[pi][1]+p[pj][1])
      p[pj]=(pi,0)
    else:
      p[pj]=(pj,p[pi][1]+p[pj][1])
      p[pi]=(pj,0)
      

for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if p[i][0]==i:ans=max(ans,p[i][1])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
p=[(i,1)for i in range(n)]
def find(i):
  if p[i][0]==i:return i
  else:
    c=find(p[i][0])
    p[i]=(c,0)
    return c
def union(i,j):
  pi=find(i)
  pj=find(j)
  if not pi==pj:
    if p[pi][1]>p[pj][1]:
      p[pi]=(pi,p[pi][1]+p[pj][1])
      p[pj]=(pi,0)
    else:
      p[pj]=(pj,p[pi][1]+p[pj][1])
      p[pi]=(pj,0)
      

for i in range(m):
  a,b=map(int,input().split())
  union(a,b)
ans=0
for i in range(n):
  if p[i][0]==i:ans=max(ans,p[i][1])
print(ans)

Fixed submission:
n,m=map(int,input().split())
p=[(i,1)for i in range(n)]
def find(i):
  if p[i][0]==i:return i
  else:
    c=find(p[i][0])
    p[i]=(c,0)
    return c
def union(i,j):
  pi=find(i)
  pj=find(j)
  if not pi==pj:
    if p[pi][1]>p[pj][1]:
      p[pi]=(pi,p[pi][1]+p[pj][1])
      p[pj]=(pi,0)
    else:
      p[pj]=(pj,p[pi][1]+p[pj][1])
      p[pi]=(pj,0)
      

for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if p[i][0]==i:ans=max(ans,p[i][1])
print(ans)
Buggy python submission (verdict: Runtime Error):
x,k,d=map(int,input().split())
xa=abs(x)
pm=x//xa
kz=xa//d
xz=xa-kz*d
if xz*2>d:
  xzz=d-xz
  kz+=1
else:
  xzz=xz
rest=k-kz
if rest%2==0:
  print(xzz)
else:
  print(d-xzz)
  

Fixed submission:
x,k,d=map(int,input().split())
xa=abs(x)
kz=xa//d
xz=xa-kz*d

if xz*2>d:
  xzz=d-xz
  kz+=1
else:
  xzz=xz
rest=k-kz
if rest<0:
  print(xa-k*d)
elif rest%2==0:
  print(xzz)
else:
  print(d-xzz)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
l=[i for i in range(n+1)]
for i in range(2,int(math.sqrt(n))+1):
  if l[i]==i:
    for j in range(2,int(n/i)+1):
      if l[i*j]==i*j:
        l[i*j]=i

def time(n,r,c,ans):
  lc=l[c]
  if lc==1:
    return ans*(n+1)
  elif r==lc:
    return time(n+1,r,c//r,ans)
  else:
    return time(1,lc,c//lc,ans*(n+1))
ans=0
for i in range(1,n+1):
  t=time(0,0,i,1)
  ans+=i*t
print(ans)

Fixed submission:
import math
n=int(input())
ans=0
for i in range(1,n+1):
  ans+=(i+(n//i)*i)*(n//i)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,K=map(int,input().split())
C=998244353
fac=[0]*a #階乗 fac[i]=i!
finv=[0]*a# i!の逆元
inv=[0]*a
N=a-1
def com_init():
	fac[0],fac[1],finv[0],finv[1]=1,1,1,1
	inv[1]=1
	for i in range(2,N+1):
		fac[i]=fac[i-1]*i%C
		inv[i]=C-inv[C%i]*(C//i)%C#ある数の逆元
		finv[i]=finv[i-1]*inv[i]%C
def com(m,k):
	if m<k: return 0
	elif m<0 or k<0:return 0
	else:
		return fac[m]*(finv[k]*finv[m-k]%C)%C
com_init()
bfac=[0]*a
bfac[0]=1
for i in range(1,a):
  bfac[i]=bfac[i-1]*(b-1) %C
ans=0

for i in range(K+1):
  ans+= com(a-1,i)*bfac[a-1-i]%C
print(ans*b%C)

Fixed submission:
a,b,K=map(int,input().split())
C=998244353
fac=[0]*a #階乗 fac[i]=i!
finv=[0]*a# i!の逆元
inv=[0]*a
N=a-1
def com_init():
	fac[0],finv[0]=1,1
	if a<2:return
	fac[1],finv[1]=1,1
	inv[1]=1
	for i in range(2,N+1):
		fac[i]=fac[i-1]*i%C
		inv[i]=C-inv[C%i]*(C//i)%C#ある数の逆元
		finv[i]=finv[i-1]*inv[i]%C
def com(m,k):
	if m<k: return 0
	elif m<0 or k<0:return 0
	else:
		return fac[m]*(finv[k]*finv[m-k]%C)%C
com_init()
bfac=[0]*a
bfac[0]=1
for i in range(1,a):
  bfac[i]=bfac[i-1]*(b-1) %C
ans=0

for i in range(K+1):
  ans+= com(a-1,i)*bfac[a-1-i]%C
print(ans*b%C)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
    a=i-l[i]
    if a in dic.keys():
       dic[a].add(i)
    else:
       dic[a]={i}
for i in range(n):
  a=i+l[i]
  if a in dic.keys():
    s=dic[a]
  else:
    continue
  k=0
  for j in s:
    if i<j:
      break
    k+=1
  ans+=len(s)-k
print(ans)

Fixed submission:
import bisect
n=int(input())
l=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
    a=i-l[i]
    if a in dic.keys():
       dic[a].append(i)
    else:
       dic[a]=[i]
for i in range(n):
  a=i+l[i]
  if a in dic.keys():
    s=dic[a]
  else:
    continue
  k=bisect.bisect_right(s,i)
  ans+=(len(s)-k)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()
print((n/3)**3)

Fixed submission:
n=int(input())
print((n/3)**3)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=list(map(int,input().split()))
dic={}
for i in range(n):
  if x[i] in dic.keys():
    dic[x[i]]+=1
  else:
    dic[x[i]]=1
s=0
for i in dic.keys():
  s+=dic[i]*(dic[i]-1)//2
for i in range(n):
  print(s-dic[x[i]]+1)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
dic={}
for i in range(n):
  if x[i] in dic.keys():
    dic[x[i]]+=1
  else:
    dic[x[i]]=1
s=0
for i in dic.keys():
  s+=dic[i]*(dic[i]-1)//2
for i in range(n):
  print(s-dic[x[i]]+1)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
ans=0
for i in range(N):
    if S[i]=='A':
        if S[i+1]=='B':
            if S[i+2]=='C':
                ans+=1
print(ans)

Fixed submission:
N=int(input())
S=input()
ans=0
for i in range(N):
    if S[i]=='A':
        if i+1<N and S[i+1]=='B':
            if i+2<N and S[i+2]=='C':
                ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import copy
N,K=map(int,input().split())
R,S,P=map(int,input().split())
point=score={'r':R,'s':S,'p':P}
T=input()
l=[[]for i in range(K)]
for i in range(N):
  l[i%K].append(T[i])
def get_point(s1,s2):
    num={'r':0,'s':1,'p':2}
    if num[s1]==(num[s2]+1)%3:
        return point[s2]
    else:return 0
def rest(hand):
    if hand=='r':return['s','p']
    elif hand=='s':return['r','p']
    elif hand=='p':return['r','s']
def cal(mini_l):
    size=len(mini_l)
    kind=['r','s','p']
    order={'r':[],'s':[],'p':[]}
    score={'r':[],'s':[],'p':[]}
    for hand in kind:
        order[hand].append(hand)
        score[hand].append(get_point(mini_l[0],hand))
    for i in range(1,size):
        new_order={'r':0,'s':0,'p':0}
        for hand in kind:
            choice=''
            tmp_score=-1
            for pre_hand in rest(hand):
                if score[pre_hand][i-1]+get_point(mini_l[i],hand)>tmp_score:
                    choice=pre_hand
                    tmp_score=score[pre_hand][i-1]+get_point(mini_l[i],hand)
            new_order[hand]=copy.copy(order[choice])
            new_order[hand].append(hand)
            score[hand].append(tmp_score)
        order=new_order
    tmp_score=-1
    for hand in kind:
        if score[hand][-1]>tmp_score:
            ans=hand
            tmp_score=score[hand][-1]
    return tmp_score
ans=0
for ll in l:
    ans+=cal(ll)
print(ans)        

Fixed submission:
# coding: utf-8
# Your code here!
import copy
N,K=map(int,input().split())
R,S,P=map(int,input().split())
point=score={'r':R,'s':S,'p':P}
T=input()
l=[[]for i in range(K)]
for i in range(N):
  l[i%K].append(T[i])
def get_point(s1,s2):
    num={'r':0,'s':1,'p':2}
    if num[s1]==(num[s2]+1)%3:
        return point[s2]
    else:return 0
def rest(hand):
    if hand=='r':return['s','p']
    elif hand=='s':return['r','p']
    elif hand=='p':return['r','s']
def cal(mini_l):
    size=len(mini_l)
    kind=['r','s','p']
    score={'r':[],'s':[],'p':[]}
    for hand in kind:
        score[hand].append(get_point(mini_l[0],hand))
    for i in range(1,size):
        for hand in kind:
            choice=''
            tmp_score=-1
            for pre_hand in rest(hand):
                if score[pre_hand][i-1]+get_point(mini_l[i],hand)>tmp_score:
                    choice=pre_hand
                    tmp_score=score[pre_hand][i-1]+get_point(mini_l[i],hand)
            score[hand].append(tmp_score)
    tmp_score=-1
    for hand in kind:
        if score[hand][-1]>tmp_score:
            ans=hand
            tmp_score=score[hand][-1]
    return tmp_score
ans=0
for ll in l:
    ans+=cal(ll)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input())
if a+b+c<=21:
  print('win')
else:
  print('bust')

Fixed submission:
a,b,c=map(int,input().split())
if a+b+c<=21:
  print('win')
else:
  print('bust')
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
l=-1
r=2*10**12+1
while l+1<r:
  c=(l+r)//2
  s=0
  for i in range(n):
    m=max(0,math.ceil((a[i]*f[i]-c)/f[i]))
    s=s+m
  if s>k:
  	l=c
  else:
    r=c
print(r)

Fixed submission:
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a=sorted(a)
f=sorted(f,reverse=True)
l=-1
r=2*10**12+1
while l+1<r:
  c=(l+r)//2
  s=0
  for i in range(n):
    m=max(0,math.ceil((a[i]*f[i]-c)/f[i]))
    s=s+m
  if s>k:
  	l=c
  else:
    r=c
print(r)