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

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

ans = 0

R = []
for i ,Ai in enumerate(A,1):
  R.append(i+Ai)
R.sort()

L = []
for j ,Aj in enumerate(A,1):
  L.append(j-Aj)
L.sort()

for i in range(len(R)):
  r = bisect.bisect_right(L,R[i])
  l = bisect.bisect_left(L,R[i])
  ans+=r-l
 
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
cnt = [0 for i in range(int(2*1e5+1))]
ans = 0

for i, x in enumerate(A, 1):
    ans += cnt[max(0,i - x +1)]
    cnt[x + i + 1] += 1

print(ans)
Problem p02767 (python)

Fixed submission:
import numpy as np
N, *X = map(int,open(0).read().split())

X = np.array(X)
g0 = sum(X)//len(X)
g1 = sum(X)//len(X)+1

print(min(sum((X-g0)**2),sum((X-g1)**2)))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, *X = map(int,open(0).read().split())

X = np.array(X)
g0 = sum(X)//len(X)
g1 = sum(X)//len(X)+1

print(min(sum((X-g0)**2),sum((X-g1)**2)))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, *X = map(int,open(0).read().split())

X = np.array(X)
g0 = sum(X)//len(X)
g1 = sum(X)//len(X)+1

print(min(sum((X-g0)**2),sum((X-g1)**2)))
Problem p02823 (python)

Fixed submission:
N,a,b = map(int,input().split())

if (b-a)%2 ==0:
  ans = (b-a)//2
else:
  ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
N,a,b = map(int,input().split())

if (b-a)%2 ==0:
  ams = (b-a)//2
else:
  ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)
Problem p02923 (python)

Fixed submission:
N,*H = map(int,open(0).read().split())
maxLen = 0
tmpCnt = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    tmpCnt += 1
  else:
    tmpCnt = 0
  maxLen = max(maxLen,tmpCnt)

print(maxLen)

Buggy submission (verdict: Runtime Error):
N,*H = map(int,open(0).read().split())
maxLen = 0
tmpCnt = 0
for i in range(len(H)):
  if H[i] > H[1+1]:
    tmpCnt+=1
  else:
    maxLen = max(maxLen,tmpCnt)
    tmpCnt =0
print(maxLen)
Problem p02981 (python)

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

print(min(N*A,B))

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())
 
x = 2019**2
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break
print(x)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input()split())

x = 2019**2
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break

Buggy submission (verdict: Runtime Error):
L,R = map(int,input().split())
#divisor = [2019,673,3]
x = 2019
X = []
if L-R >= 2019:
    x=0
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            #x = min(x,(i%2019)*(j%2019))
            X.append((i*j)%2019)
x = min(X)
print(x)
Problem p02983 (python)

Fixed submission:
L,R = map(int,input().split())
 
x = 2019**2
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break
print(x)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input()split())
 
x = 2019**2
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break
print(x)

Buggy submission (verdict: Runtime Error):
L,R = map(int,input()split())
 
x = 2019**2
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break

Buggy submission (verdict: Runtime Error):
for i in range(L, R):
    for r in range(i+1, R+1):
        ans = (i*r) % 2019 
        if x > ans:
            x = ans
            if x == 0:
        	    break
    if x == 0:
      break
Problem p02993 (python)

Fixed submission:
S = input()
dif = False
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        dif=True
if dif:
    print("Bad")
else:
    print("Good")

Buggy submission (verdict: Runtime Error):
import fractions
  
A,B,C,D= map(int,input().split())
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
CD=lcm(C, D)
 
dc =  B//C -  (A-1)//C
dd = B//D - (A-1)//D
dcd = B//CD - (A-1)//CD
 
print(B-A+1-dc-dd+dcd)
Problem p02995 (python)

Fixed submission:
import fractions
  
A,B,C,D= map(int,input().split())
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
CD=lcm(C, D)
 
dc =  B//C -  (A-1)//C
dd = B//D - (A-1)//D
dcd = B//CD - (A-1)//CD
 
print(B-A+1-dc-dd+dcd)

Buggy submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D= map(int,input().split())
CD=lcm(C, D)

def xc(x,C=C,D=D,CD=CD):
    return(x//C+x//D-x//(CD))

print(B-A+1-xc(B+1)+xc(A))
Problem p03005 (python)

Fixed submission:
W = list(map(int,input().split()))
print(W[0]%W[1])

Buggy submission (verdict: Runtime Error):
N,K= map(int,input().split())
if k==1:
  print(1)
else:
  print(N-K)
Problem p03103 (python)

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

AB = []
for i in range(N):
  A, B = map(int,input().split())
  AB.append([A,B])
AB = sorted(AB,key = lambda x:x[0])
cost = 0

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())

AB = {}
for i in range(N):
  A, B = map(int,input().split())
  AB[A]=B
AB = sorted(AB.items(),key = lambda x:x[0])

acost = 0

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)
Problem p03146 (python)

Fixed submission:
import collections

s = int(input())
A = [s]
for i in range(1000000+1):
  A.append(A[i]//2 if A[i]%2==0 else 3*A[i]+1)
  c = collections.Counter(A)
  if c.most_common()[0][1] == 2:
    print(len(A))
    break

Buggy submission (verdict: Runtime Error):
import collections

s = int(input())
A = [s]
for i in range(1000000+1):
  A.append(i//2 if i%2==0 else 3*n+1)
  c = collections.Counter(A)
  if c.most_common()[0][1] ==2:
    print(i)
    break
Problem p03455 (python)

Fixed submission:
A,B =map(int,input().split())
if (A*B)%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
A,B =map(int,input().split())
if (A*B)52==0:
  print("Even")
else:
  print("Odd")
Problem p03497 (python)

Fixed submission:
import collections as c
N,K,*A= map(int,open(0).read().split())
ans=0
C=c.Counter(A)
C=sorted(C.values())
#Aprint(C)
for i in range(len(C)-K):
  ans+=C[i]

print(ans)

Buggy submission (verdict: Runtime Error):
import collections as c
N,K,*A= map(int,open(0).read().split())
ans=0
C=c.Counter(A)
C=sorted(C.values())

for i in range(N):
  if len(C)<=K:
    break
  ans+=C[i]
print(ans)
Problem p03597 (python)

Fixed submission:
N,A = map(int,open(0).read().split())
print(N**2-A)

Buggy submission (verdict: Runtime Error):
N,A = open(0).read().split()
print(N**2-A)
Problem p03609 (python)

Fixed submission:
S=list(map(int,input().split()))
print(max(0,S[0]-S[1]))

Buggy submission (verdict: Runtime Error):
S=map(int,input().split())
print(max(0,S[0]-S[1]))
Problem p03611 (python)

Fixed submission:
N,*A  =map(int,open(0).read().split())

L = [0 for i in range(int(1e5)+1)]

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

ans = 0
for i in range(int(1e5)+1):
  S = sum(L[i:i+3])
  if ans < S:
    ans = S
  
print(ans)

Buggy submission (verdict: Runtime Error):
N,*A  =map(int,open(0).read().split())

L = [0 for i in range(N+3)]

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

ans = 0
for i in range(N+3):
  S = sum(L[i:i+3])
  if ans < S:
    ans = S
  
print(ans)

Buggy submission (verdict: Runtime Error):
N,*A  =map(int,open(0).read().split())

L = [0 for i in range(N+3)]

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

ans = 0
for i in range(N+2):
  S = sum(L[i:i+3])
  if ans < S:
    ans = S
  
print(ans)
Problem p03645 (python)

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

from1 = [False]*max(N,M)
toN = [False]*max(N,M)
for i in range(M):
  a,b = map(int,input().split())
  if a ==1 or b ==1:
    from1[a-1 if a!= 1 else b-1]=True
  if a == N or b == N:
    toN[a-1 if a!= N else b-1]=True
cnt =0 
for i in range(M):
  cnt+=from1[i]&toN[i]
print("POSSIBLE" if cnt else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())

from1 = [False]*N
toN = [False]*N
for i in range(M):
  a,b = map(int,input().split())
  if a ==1 or b ==1:
    from1[max(a,b)-1]=True
  if a == N or b == N:
    toN[a-1 if a!= N else b-1]=True
cnt =0 
for i in range(M):
  cnt+=from1[i]&toN[i]
print("POSSIBLE" if cnt else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())

from1 = [False]*N
toN = [False]*N
for i in range(M):
  a,b = map(int,input().split())
  if a ==1 or b ==1:
    from1[max(a,b)]=True
  if a == N or b == N:
    toN[a if a!= N else b]=True
cnt =0 
for i in range(M):
  cnt+=from1[i]&toN[i]
print("POSSIBLE" if cnt else "IMPOSSIBLE")
Problem p03695 (python)

Fixed submission:
N,*A=map(int,open(0).read().split())

colors = [0 for i in range(8)]
tyty = 0

for a in A:
  c = a//400
  if c>=8:
    tyty+=1
  else:
    colors[c]+=1

cNum = 8-colors.count(0)
    
minC = max(cNum,1)
maxC = cNum+tyty

print(minC,maxC)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,*A=map(int,open(0).read().split())
A=(np.array(A)//400).astype("int32")

color_num=0

colors=np.zeros(9)

for a in A:
    colors[min(a,9)]+=1
c=np.count_nonzero(colors[:-1])

min_color_num = 1 if (c==0 and colors[-1]>0) else c
max_color_num = min(8,c+max(int(colors[-1]),0))

print(min_color_num,max_color_num)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,*A=map(int,open(0).read().split())
A=(np.array(A)//400).astype("int32")

color_num=0

colors=np.zeros(9)

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

c=np.count_nonzero(colors[:-1])

min_color_num = 1 if (c==0 and colors[-1]>0) else c
max_color_num = min(8,c+max(int(colors[-1]),0))

print(min_color_num,max_color_num)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,*A=map(int,open(0).read().split())
A=(np.array(A)//400).astype("int32")

color_num=0

colors=np.zeros(9)

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

c=np.count_nonzero(colors[:8])

min_color_num = 1 if (c==0 and colors[-1]>0) else c
max_color_num = min(8,c+max(int(colors[-1]),0))

print(min_color_num,max_color_num)
Problem p03759 (python)

Fixed submission:
a,b,c = map(int,input().split())
print("YES" if b-a == c-b else "NO")

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

Fixed submission:
N=input()
S=input()
max_v =0
v =0
for i in S:
  if i=="I":
    v+=1
    if v>max_v:
      max_v=v
  else:
    v-=1
print(max_v)

Buggy submission (verdict: Runtime Error):
S=input()
max_v =0
v =0
for i in S:
  if i=="I":
    v+=1
    if v>max_v:
      max_v=v
  else:
    v-=
Problem p03962 (python)

Fixed submission:
import collections
print(len(collections.Counter(input().split())))

Buggy submission (verdict: Runtime Error):
v
Problem p02658 (python)

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
arr.sort();
x=int(1)
for i in arr:
  x=x*i
  if x>1e18:
    x=-1;
    break;
print(x)

Buggy submission (verdict: Runtime Error):
n=int(intput())
arr=list(input().slpit())
arr.sort();
x=int(1)
for i in arr:
  x=x*i
  if x>1e18:
    x=-1;
    break;
print(x)
Problem p02639 (python)

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

for i in range(5):
    if x[i]==0:
        print(i+1)
        break

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())

p=set(map(int,input().split()))

n=set(n for n in range(-100,101))

pd=list(n-p)

min1=1000

for i in range(len(pd)):
    if abs(pd[i]-x)<abs(min1-x):
        min1=pd[i]
    elif abs(pd[i]-x)==abs(min1-x):
        min1=min(pd[i],min1)
print(min1)

Buggy submission (verdict: Runtime Error):
x,n=map(int,input().split())

p=set(map(int,input().split()))

n=set(n for n in range(-100,101))

pd=list(n-p)

min1=1000

for i in range(len(pd)):
    if abs(pd[i]-x)<abs(min1-x):
        min1=pd[i]
    elif abs(pd[i]-x)==abs(min1-x):
        min1=min(pd[i],min1)
print(min1)
Problem p02640 (python)

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

for i in range(51):
    if 2*i+4*(x-i)==y:
        print("Yes")
        break
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int x,y;
    cin>>x>>y;
    int s=0;
    
    for (int i=0;i<100;++i)
    {
        for (int j=0;j<=x-i;++j)
        {
            if(y-2*i==j*4)
            {
                cout<<"Yes"<<endl;
                s++;
                break;
            }
        }
    }
    if(s==0){
        cout<<"No"<<endl;
    }
}
Problem p02713 (python)

Fixed submission:
import math
k=int(input())
ans=0

for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=math.gcd(math.gcd(a,b),c)
print(ans)

Buggy submission (verdict: Runtime Error):
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=math.gcd(math.gcd(a,b),c)
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n,q=map(int,input().split())
G=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

subtree_size=[0]*n
cnt=[0]*n

for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    cnt[p]+=x
ans=[0]*n

def dfs(G,v,p):
    ans[v]+=cnt[v]
    for nv in G[v]:
        if nv==p:
            continue
        cnt[nv]+=cnt[v]
        dfs(G,nv,v)
    
    subtree_size[v]=1
    for c in G[v]:
        if c==p:
            continue
        subtree_size[v]+=subtree_size[c]

root=0
dfs(G,root,-1)

for i in range(n):
    print(ans[i],end=' ')

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

subtree_size=[0]*n
cnt=[0]*n

for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    cnt[p]+=x
ans=[0]*n

def dfs(G,v,p):
    ans[v]+=cnt[v]
    for nv in G[v]:
        if nv==p:
            continue
        cnt[nv]+=cnt[v]
        dfs(G,nv,v)
    
    subtree_size[v]=1
    for c in G[v]:
        if c==p:
            continue
        subtree_size[v]+=subtree_size[c]

root=0
dfs(G,root,-1)

for i in range(n):
    print(ans[i],end=' ')
Problem p03000 (python)

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=[0]

for i in range(1,n+1):
    temp=d[i-1]+l[i-1]
    if temp>x:
        ans=i
        break
    d.append(temp)

else:
    ans=n+1

print(ans)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=[0]

for i in range(1,n+1):
    temp=d[i-1]+l[i-1]
    if temp>x:
        ans=i
        break
    d.append(temp)

print(ans)
Problem p03415 (python)

Fixed submission:
a=input()
b=input()
c=input()

print('{}{}{}'.format(a[0],b[1],c[2]))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())

if n>=2 and m>=2:
    print((n-2)*(m-2))

elif n==1 and m!=1:
    print(m-2)

elif m==1 and n!=1:
    print(n-2)
elif n==1 and m==1:
  print(1)
Problem p03424 (python)

Fixed submission:
n=int(input())

a=input().split()

if 'Y' in a:
    print('Four')

else:
    print('Three')

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

a=list(input.split())

if 'Y' in a:
    print('Four')

else:
    print('Three')
Problem p03447 (python)

Fixed submission:
X=int(input())
A=int(input())
B=int(input())

X=X-A

while True:
    X=X-B
    if X-B<0:
        break
    else:
        pass
print(X)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
X=int(input())

count=0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                count+=1
            else:
                pass
print(count)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int, input().split())
a=[]

for i in range(N+1):
    j=i
    n=0
    while True:
        n+=i%10
        if i//10==0:
            break
        else:
            i=i//10
    if A<=n<=B:
        a.append(j)
    else:
        pass
print(sum(a))

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                count+=1
            else:
                pass

print(count)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0

for i in range(A):
    for j in range(B):
        for k in range(C):
            if 500*i+100*j+50*k==X:
                count+=1
            else:
                pass

print(count)

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0

for i in range(A):
    for j in range(B):
        for k in range(C):
            if 500*i+100*j+50*k==X:
                count+=1
            else:
                pass

print(count)
Problem p03455 (python)

Fixed submission:
a,b=map(int, input().split())

if a*b%2==0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
N=int(input())
t=[0]*100001
x=[0]*100001
y=[0]*100001

for i in range(1,N+1):
    t[i],x[i],y[i]=map(int, input().split())
count=0

for i in range(1,N+1):
    dt=(t[i])-(t[i-1])
    dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    if dist>dt:
        break
    else:
        pass
    if dist%2==dt%2:
        pass
    else:
        break
    count+=1
if count==N:
    print('YES')
else:
    print('NO')
Problem p03471 (python)

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

for i in range(N+1):
    if count==0:
        pass
    else:
        break
    for j in range(N-i+1):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            print(i,j,N-i-j)
            count+=1
            break
        else:
            pass
if count==0:
    print(-1,-1,-1)
else:
    pass

Buggy submission (verdict: Runtime Error):
N,Y=map(int, input().split())
count=0

for i in range(N+1):
    if count==0:
        pass
    else:
        break
    for j in range(N-i+1):
        if count==0:
            pass
        else:
            break
        for k in range(N-i-j+1):
            if 10000*i+5000*j+1000*k==Y:
                print(f'{i}{j}{k}')
                count+=1
            else:
                pass
if count==0:
    print('{}{}{}'.format(-1,-1,-1))
else:
    pass
Problem p02602 (python)

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

ans = []
for i in range(n-k):
    if (a[i] < a[i+k]):
        ans.append("Yes")
    else:
        ans.append("No")

for i in range(len(ans)):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

shaku = []

for i in range(n-k+1):
    start = i
    end = start + k
    h = a[start] * a[start+1]
    now = start + 2
    while now < end:
        if (0 in a[now:end]):
            h = 0
            break

        h *= a[now]
        now += 1

    shaku.append(h)

for i in range(len(shaku)-1):
    if (shaku[i] < shaku[i+1]):
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

shaku = []

for i in range(n-k+1):
    start = i
    end = start + k
    h = a[start] * a[start+1]
    now = start + 2
    while now < end:
        h *= a[now]
        now += 1

    shaku.append(h)

for i in range(len(shaku)-1):
    if (shaku[i] < shaku[i+1]):
        print("Yes")
    else:
        print("No")
Problem p02641 (python)

Fixed submission:
import sys
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))

if (n == 0):
    print(x)
    sys.exit()

i = 0
while True:
    if (not (x-i) in p):
        print(x-i)
        break
    if (not (x+i) in p):
        print(x+i)
        break
    i += 1

Buggy submission (verdict: Runtime Error):
import sys
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))

if (n == 0):
    print(x)
    sys.exit()

a = [i for i in range(-110,210)]

for j in p:
    d = a.index(j)
    a.pop(d)

a.append(x)
a = set(a.sort())

idx_x = a.index(x)

if (idx_x == 0):
    print(a[idx_x+1])
    sys.exit()
if (idx_x == len(a)-1):
    print(a[-2])
    sys.exit()

lesser = a[idx_x-1]
greater = a[idx_x+1]

dl = abs(x - lesser)
dg = abs(greater - x)

if (dl <= dg):
    print(lesser)
else:
    print(greater)
Problem p02687 (python)

Fixed submission:
t = input()

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

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input().split()))

height = [int(i) for i in input().split()]

tele = {}
for num, h in enumerate(height, 1):
    tele[num] = [h, "G"]

for roads in range(m):
    a, b = list(map(int, input().split()))
    if (tele[a][0] > tele[b][0]):
        tele[b][1] = "N"
    elif (tele[a][0] < tele[b][0]):
        tele[a][1] = "N"
    elif (tele[a][0] == tele[b][0]):
        tele[a][1] = "N"
        tele[b][1] = "N"

ans_list = tele.values()
ans = 0
for a in ans_list:
    if (a[1] == "G"):
        ans += 1

print(ans)
Problem p02705 (python)

Fixed submission:
import math
r = int(input())
r = 2*r*math.pi
print(r)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = input().split()
c = [int(n) for n in c]

for i in range(1, n+1):
    print(c.count(i))
Problem p02924 (python)

Fixed submission:
N = int(input())

print(round(((N-1)*N)//2))

Buggy submission (verdict: Runtime Error):
N = int(input()
print(int(((N-1)*N)/2))
Problem p02574 (python)

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

c=[0]*(10**6+5)

isPairwise=True
isSetwise=True
for i in range(N):
    c[A[i]]+=1

for i in range(2,1000005):
    cnt=0
    for j in range(i,1000005,i):
        cnt+=c[j]
    
    if cnt>1:
        isPairwise=False

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

g=0
for i in range(N):
    g=gcd(g,A[i])
if g>1:
    isSetwise=False

if isPairwise:
    print('pairwise coprime')
elif isSetwise:
    print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

c=[0]*10**6

isPairwise=True
isSetwise=True
for i in range(N):
    c[A[i]]+=1

for i in range(2,1000000):
    cnt=0
    for j in range(2,1000000,i):
        cnt+=c[j]
    
    if cnt>1:
        isPairwise=False

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

g=0
for i in range(N):
    g=gcd(g,A[i])
if g>1:
    isSetwise=False

if isPairwise:
    print('pairwise coprime')
elif isSetwise:
    print('setwise coprime')
else:
    print('not coprime')
Problem p02585 (python)

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

for i in range(N):
    P[i]-=1

ans=-float('inf')

for start in range(N):
    loop_len=1
    pos=P[start]
    score=C[pos]
    scores=[score]

    while pos!=start:
        loop_len+=1
        pos=P[pos]
        score+=C[pos]
        scores.append(score)
    
    loops=(K-1)//loop_len

    if score>0:
        cand=score*loops + max(scores[:(K-loop_len*loops)])
    else:
        cand=max(scores[:min(K,loop_len)])
    ans=max(ans,cand)
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))

for i in range(N):
    P[i]-=1

ans=-float('inf')

for start in range(N):
    loop_len=1
    pos=P[start]
    score=C[pos]
    scores=[score]

    while pos!=start:
        loop_len+=1
        pos=P[pos]
        score+=C[pos]
        scores.append(score)
    
    loops=(K-1)//loop_len

    if score>0:
        cand=score*loops + max(scores[:(K%loop_len)])
    else:
        cand=max(scores[:min(K,loop_len)])
    ans=max(ans,cand)
print(ans)