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

Fixed submission:
n,m=map(int,input().split())
if n==1:
    A=[i for i in range(10)]
    for i in range(m):
        _,c=map(int,input().split())
        if not c in A:
            print(-1)
            exit()
        else:A=[c]
    print(min(A))

if n==2:
    A=[[i+1 for i in range(9)] , [i for i in range(10)]]
    for i in range(m):
        t,c=map(int,input().split())
        t=t-1
        if not c in A[t]:
            print(-1)
            exit()
        else: 
            A[t]=[c]
    print(10*min(A[0]) + min(A[1]))

if n==3:
    A=[[i+1 for i in range(9)] ,[i for i in range(10)] ,[i for i in range(10)]]
    for i in range(m):
        t,c=map(int,input().split())
        t=t-1
        if not c in A[t]:
            print(-1)
            exit()
        else: 
            A[t]=[c]
    print(100*min(A[0]) + 10*min(A[1]) + min(A[2]))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
if n==1:
  if m==0:
    print(0)
    exit()
  Q=[]
  for i in range(m):
    _,q=map(int,input().split())
    Q.append(q)
  if len(set(Q)) in [2,3,4,5,6,7]:
    print(-1)
    exit()
  print(min(Q))
  exit()

A=[[1,2,3,4,5,6,7,8,9]]+ [[0,1,2,3,4,5,6,7,8,9]]*(n-1)
for i in range(m):
  k,q=map(int,input().split())
  if k==1 and q==0:
    print(-1)
    exit()
  if not q in A[k-1]:
    print(-1)
    exit()
          
  A[k-1]=[q]
for i in range(n):
  A[i]=min(A[i])
ans=""
for i in range(n):
  ans+=str(A[i])
print(ans)
n,m=map(int,input().split())
if n==1:
  Q=[]
  for i in range(m):
    _,q=map(int,input().split())
    Q.append(q)
  if len(set(Q))!=1:
    print(-1)
    exit()
  print(min(Q))
  exit()

A=[[1,2,3,4,5,6,7,8,9]]+ [[0,1,2,3,4,5,6,7,8,9]]*(n-1)
for i in range(m):
  k,q=map(int,input().split())
  if k==1 and q==0:
    print(-1)
    exit()
  if not q in A[k-1]:
    print(-1)
    exit()
          
  A[k-1]=[q]
for i in range(n):
  A[i]=min(A[i])
ans=""
for i in range(n):
  ans+=str(A[i])
print(ans)
Problem p02780 (python)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n):
  A[i]=(1+A[i])/2
S=[0 for i in range(n+1)]
for i in range(n):
  S[i+1]=S[i]+A[i]
ans=0
for i in range(n-k+1):
  ans=max(ans,S[i+k]-S[i])
  
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
for i in range(A):
  A[i]=(1+A[i])/2
sum=0
for i in range(0,n-k+1):
  sum=max(sum,sum(A[i:i+k+1]))
print(sum)
Problem p02791 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=1
qq=A[0]
for i in range(n-1):
  if qq<A[i+1]:
    continue
  if qq>=A[i+1]:
    qq=A[i+1]
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
ans=1
qq=A[0]
for i in range(n):
  if qq<A[i+1]:
    qq=A[i+1]
    continue
  else:
    ans+=1
print(ans)
Problem p02802 (python)

Fixed submission:
n,m=map(int,input().split())
A=[[0,0] for i in range(n)] #ACしたか、WA数
AC=0
pen=0
for i in range(m):
    a,b=map(str,input().split())
    a=int(a)
    if b=="AC":
        A[a-1][0]=1
    elif b=="WA" and A[a-1][0]==0:
        A[a-1][1]+=1
for i in range(n):
    if A[i][0]==1:
        AC+=1
        pen+=A[i][1]
print(AC,pen)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
A=[[0,0] for i in range(m)] #ACしたか、WA数
AC=0
pen=0
for i in range(m):
    a,b=map(str,input().split())
    a=int(a)
    if b=="AC":
        A[a-1][0]=1
    elif b=="WA" and A[a-1]==0:
        A[a-1][1]+=1
for i in range(n):
    if A[i][0]==1:
        AC+=1
        pen+=A[i][1]
print(AC,pen)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
pen=0
A=[0 for i in range(n)]
for i in range(m):
  a,b=map(str,input().split())
  a=int(a)
  if b=="AC":
    A[a-1]=1
for i in range(m):
  a,b=map(int,input().split())
  a=int(a)
  if b=="WA" and A[a-1]==1:
    pen+=1
print(sum(A),pen)
Problem p02803 (python)

Fixed submission:
import sys
import math
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)

h,w=map(int,input().split())
miti=[]
for i in range(h):
    miti.append(input())
    

def bfs(x,y):
    for i,j in [[x+1,y],[x,y+1],[x-1,y],[x,y-1]]:
        if i<0 or h<=i or j<0 or w<=j :continue
        if dist[i][j] != -1:continue
        if miti[i][j]=="#":continue
        dist[i][j]=dist[x][y]+1
        queue.append([i,j])
    while queue:
        t,r=queue.popleft()
        bfs(t,r)
ans=0
for i in range(h):
    for j in range(w):
        if miti[i][j]=="#":continue
        dist=[[-1 for i in range(w)] for j in range(h)]
        dist[i][j]=0
        queue=deque([])
        bfs(i,j)
        
        
        for s in range(h):
            for t in range(w):
                ans=max(ans,dist[s][t])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)

h,w=map(int,input().split())
miti=[]
for i in range(h):
    miti.append(input())

queue=deque([])
def bfs(x,y):
    for i,j in [[x+1,y],[x,y+1],[x-1,y],[x,y-1]]:
        if i<0 or h<=i or j<0 or w<=j :continue
        if dist[i][j] != -1:continue
        if miti[i][j]=="#":continue
        dist[i][j]=dist[x][y]+1
        queue.append([i,j])
    while queue:
        t,r=queue.popleft()
        bfs(t,r)

for i in range(h):
  for j in range(w):
    if miti[i][j]==".":
      s=i;t=j
      break
  break
dist=[[-1 for i in range(w)] for j in range(h)]
dist[s][t]=0
bfs(s,t)


dis0=0
ty=[0,0]
for i in range(h):
    for j in range(w):
        if dis0<dist[i][j]:
            dis0=dist[i][j]
            ty=[i,j]
q,e=ty
dist=[[-1 for i in range(w)] for j in range(h)]
dist[q][e]=0
queue=deque([])
bfs(q,e)

ans=0

for i in range(h):
    for j in range(w):
        if ans<dist[i][j]:
            ans=dist[i][j]

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)

h,w=map(int,input().split())
miti=[]
for i in range(h):
    miti.append(input())
    
dist=[[-1 for i in range(w)] for j in range(h)]
dist[0][0]=0
queue=deque([])
def bfs(x,y):
    for i,j in [[x+1,y],[x,y+1],[x-1,y],[x,y-1]]:
        if i<0 or h<=i or j<0 or w<=j :continue
        if dist[i][j] != -1:continue
        if miti[i][j]=="#":continue
        dist[i][j]=dist[x][y]+1
        queue.append([i,j])
    while queue:
        t,r=queue.popleft()
        bfs(t,r)

for i in range(h):
  for j in range(w):
    if miti[i][j]==".":
      s=i;t=j
      break
  break
bfs(s,t)
dis0=0
ty=[0,0]
for i in range(h):
    for j in range(w):
        if dis0<dist[i][j]:
            dis0=dist[i][j]
            ty=[i,j]
i,j=ty
dist=[[-1 for i in range(w)] for j in range(h)]
dist[i][j]=0
queue=deque([])
bfs(i,j)

ans=0


for i in range(h):
    for j in range(w):
        if ans<dist[i][j]:
            ans=dist[i][j]

print(ans)
Problem p02814 (python)

Fixed submission:
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
import fractions as math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def qq(numbers):
    return reduce(lcm_base, numbers, 1)

n,m=map(int,input().split())
A=list(map(int,input().split()))

B=[i//2 for i in A]
p=qq(B)
for i in A:
    i//=2
    if (p//i)%2==0:
        print(0)
        exit()
print(m//p - m//(p*2))

Buggy submission (verdict: Runtime Error):
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
from math import ceil
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
@lru_cache(maxsize=10**10)
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
@lru_cache(maxsize=10**10)        
def lcm(a,b):
    return a*b//gcd(a,b)

n,m=map(int,input().split())
A=list(map(int,input().split()))

def llcm(A):
    n=len(A)
    if n==1 : return A[0]
    elif n%2==1 : 
        A[1]=lcm(A[0],A[1])
        if max(A)>m :
            print(0)
            exit()
        return llcm(A[1:])
    else: 
        B=[lcm(A[i],A[i+1]) for i in range(0,n,2)]
        if max(B)>m:
            print(0)
            exit()
        return llcm(B)

B=[i//2 for i in A]
p=llcm(B)
print(m//p - m///(p*2))
Problem p02838 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7

B=[[] for i in range(n)]
for i in range(n):
    B[i]= [((A[i]>>(59-j))) & 1 for j in range(60)]
    B[i] = [0]*(60-len(B[i]))+B[i]

TB=[[0]*n for i in range(60)]
for i in range(60):
    TB[i] = [B[j][i] for j in range(n)]
        
# import numpy as np
#print(TB)
ans=0
for i in range(60):
    now=TB[i]
    q=sum(now)
    
    ans+= ((pow(2,59-i,mod)* (q*(n-q)))%mod)%mod
    ans%=mod


print((ans)%mod)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7

B=[[] for i in range(n)]
for i in range(n):
    B[i]= [int(i) for i in bin(A[i])[2:]]
    B[i] = [0]*(60-len(B[i]))+B[i]

TB=[[0]*n for i in range(60)]
for i in range(60):
    for j in range(n):
        TB[i][j] = B[j][i]
        
# import numpy as np
#print(TB)
ans=0
for i in range(60):
    now=TB[i]
    q=now.count(1)
    ans+= ((pow(2,59-i,mod)* (q*(q-1))%mod)%mod *pow(2,-1,mod))%mod
    ans%=mod
ans*=2
ans%=mod


last=0
for i in A:
    last+=i%mod
    last%=mod
last*=(n-1)
last%=mod
print((last-ans)%mod)
Problem p02850 (python)

Fixed submission:
import copy ; import sys ; sys.setrecursionlimit(11451419)
n=int(input())
HEN=[list(map(int,input().split())) for _ in range(n-1)]
G=[[] for _ in range(n)]
for i,[a,b] in enumerate(HEN):
    a=a-1;b=b-1
    G[a].append([b,i])
    G[b].append([a,i])  #Gに、道番号も記録

visited=[0 for i in range(n)]
ans=[-1 for i in range(n-1)]

def search(v,c=-1):  #search(a)ならaと-1  search(a,b)ならaとb
    nc=1
    for to,i in G[v]:
        if visited[to]==1: continue
        visited[v]=1
        if c==nc:
            nc+=1
        ans[i]=nc
        search(to,nc)
        nc+=1
search(0)
print(max(ans))
print(*ans,sep="\n")

Buggy submission (verdict: Runtime Error):
n=int(input())
hen_count=[0 for i in range(n+1)]
HEN=[]
for i in range(n-1):
  a,b=map(int,input().split())
  hen_count[a]+=1
  hen_count[b]+=1
  HEN.append([a,b])
print(max(hen_count))

qwe=max(hen_count)
color=[0]+[[i+1 for i in range(qwe)] for i in range(n)]

for q in HEN:
  p=max(min(color[q[0]]),min(color[q[1]]))
  color[q[0]].remove(p)
  color[q[1]].remove(p)
  print(p)
Problem p02861 (python)

Fixed submission:
#n個の都市を好きな都市から出発してすべての都市を１度だけ訪れる最短時間
#全ての都市の組i,jについてi,jを結ぶ道がある

import itertools
n=int(input())
A=[]
for i in range(n):
  A.append(list(map(int,input().split())))
  
def kaijo(x):
  if x==1:
    return x
  return x*kaijo(x-1)

def dist(x,y):
  return ((A[x][0]-A[y][0])**2+(A[x][1]-A[y][1])**2)**(1/2)

DIST=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    DIST[i][j]=dist(i,j)
    
ans=[]   
for Q in itertools.permutations([i for i in range(n)]):
  t=0
  for i in range(n-1):
    t+=DIST[Q[i]][Q[i+1]]
  ans.append(t)
  
print(sum(ans)/kaijo(n))

Buggy submission (verdict: Runtime Error):
import itertools
n=int(input())
A=[]
for i in range(n):
  A.append(list(map(int,input().split())))
  
def kaijo(x):
  if x==1:
    return x
  return x*kaijo(x-1)

def dist(x,y):
  return ((A[x][0]-A[y][0])**2+(A[x][1]-A[y][1])**2)**(1/2)

DIST=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
  for j in range(n):
    DIST[i][j]=dist(i,j)
    
ans=[]   
for Q in itertools.permutations(n):
  t=0
  for i in range(n-1):
    t+=DIST[i][i+1]
  ans.append(t)
print(sum(ans)/kaijo(n))
Problem p02882 (python)

Fixed submission:
import math
a,b,x=map(int,input().split())
if a*a*b<2*x:
  print(math.degrees(math.atan(2*(a*a*b-x)/(a**3))))
else:
  print(math.degrees(math.atan(a*b*b/2/x)))

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
if a*a*b<2*x:
  print(math.degrees(math.atan((2*x/(a*a)-b)/(a*a))))
else:
  print(90-math.degrees(math.atan(2*x/(b*b))))
Problem p02900 (python)

Fixed submission:
import fractions
a,b=map(int,input().split())
n=fractions.gcd(a,b)

if n==1:
  print(1)
  exit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

print(len(factorization(n))+1)

Buggy submission (verdict: Runtime Error):
import fraction
a,b=map(int,input().split())
n=fraction.gcd(a,b)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

print(len(factorization(n))+1)
Problem p02917 (python)

Fixed submission:
n=int(input())
B=list(map(int,input().split()))
ans=B[0]+B[-1]
for i in range(n-2):
  ans+=min(B[i],B[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
B=list(map(int,input().split()))
ans=B[0]+B[-1]
for i in range(n-1):
  ans+=min(B[i],B[i+1])
print(ans)
Problem p02923 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
seq=0
B=[]
for i in range(n-1):
  if A[i]>=A[i+1]:
    seq+=1
  else:
    B.append(seq)
    seq=0
B.append(seq)
print(max(B))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
seq=0
B=[]
for i in range(n-1):
  if A[i]>=A[i+1]:
    seq+=1
  else:
    B.append(seq)
    seq=0
print(max(B))
Problem p02934 (python)

Fixed submission:
n=int(input())
ans=0
A=list(map(int,input().split()))
for i in range(n):
  ans+=A[i]**(-1)
  
print(ans**(-1))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=sorted(map(int,input().split()))
ans=A[0]
for i in range(1,n):
  ans=(ans+A[i])/2
print(ans^(-1))
Problem p02946 (python)

Fixed submission:
a,b=map(int,input().split());q=max(-1000000,b-a+1);w=min(1000000,b+a-1);A=[i for i in range(q,w+1)]
for i in range(len(A)):
  print(A[i])

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split());q=max(-1000000,b-a+1);w=min(1000000,b+a-1);A=[i for i in range(q,w+1)];print([A][0]*)
Problem p02947 (python)

Fixed submission:
n=int(input())
from collections import Counter 
A=[]
for i in range(n):
  a=sorted(input())
  a="".join(a)
  A.append(a)
ans=0
for j in Counter(A).values():
  ans+=j*(j-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
from collections import Counter 
A=[]
for i in range(n):
  A.append(sorted(list(input())))
  
q=Counter(A);ans=0
for j in q.values():
  ans+= j*(j-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
from collections import Counter as C
A=input()
for i in range(n):
  A.append(sorted(list(input())))
  
q=C(A);ans=0
for j in q.values():
  ans+= j*(j-1)//2
print(ans)
Problem p02958 (python)

Fixed submission:
n=int(input())
sp=0
A=list(map(int,input().split()))
for i in range(n):
  if i+1!=A[i]:
    sp+=1
if sp==0 or sp==2:
  print("YES")
  exit()
print("NO")

Buggy submission (verdict: Runtime Error):
n=int(input())
sp=0
A=list(map(int,input.split()))
for i in range(n):
  if i+1!=A[i]:
    sp+=1
if sp==0 or sp==2:
  print("YES")
  exit()
print("NO")

Buggy submission (verdict: Runtime Error):
n=int(input())
sp=0
A=list(map(int,input.split()))
for i in range(n):
  if i+1!=A[i]:
    sp+=1
if sp==0 or 2:
  print("YES")
  exit()
print("NO")
Problem p02969 (python)

Fixed submission:
k=int(input())

print(3*k*k)

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

for i in range(10**6):
  if int((S+i**2)**(1/2))==(S+i**2)**(1/2):
    y=i
    x=int((S+i**2)**(1/2))
    
print("{} {} {} {} {} {}".format(0,0,x,y,y,x))
Problem p03001 (python)

Fixed submission:
w,h,x,y=map(int,input().split())
cx,cy=w/2,h/2
# x,y=map(int,input().split())
if x==cx and y==cy:
    print(w*h/2,1);exit()
else:
    print(w*h/2,0)
    exit()

Buggy submission (verdict: Runtime Error):
w,h=map(int,input().split())
cx,cy=w/2,h/2
x,y=map(int,input().split())
if x==cx and y==cy:
    print(w*h/2,1);exit()
else:
    print(w*h/2,0)
    exit()
Problem p03007 (python)

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

if n==2:
    print(abs(A[0]-A[1]))
    print(*A)
    exit()
A.sort()
menos=[] ; plus=[]
for i in range(len(A)):
    if A[i]<0:
        menos.append(A[i])
    else:
        plus.append(A[i])
if menos==[]:
    print(sum(plus)-plus[0]*2)
    res=plus[0]
    for i in range(n-2):
        print(res, A[i+1])
        res=res-A[i+1]
    print(A[n-1], res);exit()
        
elif plus==[]:
    print(-sum(menos)+ menos[-1]*2)
    res=menos[-1]
    for i in range(n-1):
        print(res,menos[i])
        res=res-menos[i]
    exit()
    

print(sum(plus)-sum(menos))
m=len(menos); p=len(plus)
if p==1:
    res=plus[-1]
    for i in range(n-1):
        print(res,menos[i])
        res=res-menos[i]
    exit()
if m==1:
    res=menos[0]
    for i in range(n-2):
        print(res, plus[i])
        res=res-plus[i]
    print(plus[-1], res);exit()

Q= plus[1:]+ [menos[0]]
W= menos[1:]+[plus[0]] ;#print(Q,W)

res=W[-1]
for i in range(len(W)-1):
    print(res,W[i])
    res=res-W[i]
rec=Q[-1]
for i in range(len(Q)-1):
    print(rec, Q[i])
    rec=rec-Q[i]
print(res,rec)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[n//2:])-sum(A[:n//2]))

i=0
while len(A)>3:  
  a=min(A)
  b=max(A)
  if i%2==0:
    print("{} {}".format(b,a))
    A.append(b-a)
  else:
    print("{} {}".format(a,b))
    A.append(a-b)
  i+=1
  A.remove(a)
  A.remove(b)
  
  
A.sort()
print("{} {}".format(A[0],A[1]))
print("{} {}".format(A[2],A[0]-A[1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[n//2:])-sum(A[:n//2]))

i=0
while len(A)>3:  
  a=min(A)
  b=max(A)
  if i%2==0:
    print("{} {}".format(b,a))
    A.append(b-a)
  else:
    print("{} {}".format(a,b))
    A.append(a-b)
  i+=1
  A.remove(a)
  A.remove(b)
  
  
A.sort()
print("{} {}".format(A[0],A[1]))
print("{} {}".format(A[2],A[0]-A[1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[n//2:])-sum(A[:n//2]))

  
while len(A)>3:  
  a=min(A)
  b=max(A)
  print("{} {}".format(b,a))
  A.remove(a)
  A.remove(b)
  
  A.append(b-a)
A.sort()
print("{} {}".format(A[0],A[1]))
print("{} {}".format(A[2],A[0]-A[1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[n//2:])-sum(A[:n//2]))

  
while len(A)>3:  
  a=min(A)
  b=max(A)
  print("{} {}".format(b,a))
  A.remove(a)
  A.remove(b)
  
  A.append(b-a)
  A.sort()
print("{} {}".format(A[0],A[1]))
print("{} {}".format(A[2],A[0]-A[1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
A=sorted(list(map(int,input().split())))
print(sum(A[n//2:])-sum(A[:n//2]))

  
while len(A)!=3:  
  a=A[0]
  b=A[len(A)-1]
  print("{} {}".format(b,a))
  del A[0]
  del A[len(A)-1]
  A.append(b-a)
print("{} {}".format(A[0],A[1]))
print("{} {}".format(A[2],A[0]-A[1]))
Problem p03044 (python)

Fixed submission:
import copy ; import sys ; sys.setrecursionlimit(11451419)
n=int(input())
color=[-1 for i in range(n)]
color[0]=1
G=[[] for i in range(n)]
for i in range(n-1):
  a,b,d=map(int,input().split())
  G[a-1].append([b-1,d])
  G[b-1].append([a-1,d])
  
def dfs(x):
  
  for i,dis in G[x]:
    
    if color[i] != -1: continue
    if dis %2==1:
      color[i]=1-color[x]
    else:
      color[i]=color[x]
    dfs(i)
dfs(0)
for i in range(n):
  print(color[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,w=map(int,input().split())
    a-=1;b-=1
    G[a].append((b,w))
    G[b].append((a,w))
C=[-1]*n 
C[0]=0
def dfs(x):
    for v,w in G[x]:
        if C[v]==-1:
            C[v]=1-C[x] if w%2==1 else C[x]
            dfs(v)

dfs(0)
#print(G)
for i in range(n):
    print(C[i])

Buggy submission (verdict: Runtime Error):
n=int(input())
color=[-1 for i in range(n)]
color[0]=1
G=[[] for i in range(n)]
for i in range(n-1):
  a,b,d=map(int,input().split())
  G[a-1].append([b-1,d])
  G[b-1].append([a-1,d])
  
def dfs(x):
  
  for i,dis in G[x]:
    
    if color[i] != -1: continue
    if dis %2==1:
      color[i]=1-color[x]
    else:
      color[i]=color[x]
    dfs(i)
dfs(0)
for i in range(n):
  print(color[i])

Buggy submission (verdict: Runtime Error):
n=map(int,input().split())
color=[-1 for i in range(n)]
color[0]=0
G=[[] for i in range(n)]
for i in range(n-1):
  a,b,d=map(int,input().split())
  G[a-1].append([b-1,d])
  G[b-1].append([a-1,d])
  
def dfs(x):
  for i in G[x]:
    if color[i] != -1: return
    color[i]=1-color[x]
    dfs(i)
dfs(0)
print(*color)

Buggy submission (verdict: Runtime Error):
n=int(input())
kyori=sorted([list(map(int,input().split())) for i in range(n)])
ans=[0]*n

for i in range(n):
  C=kyori[i-1][0]
  if kyori[i-1][2]%2==0:
    ans[kyori[i-1][1]-1]=C
  else:
    ans[kyori[i-1][1]-1]=1-C
    
for i in range(n):
  print(ans[i])
Problem p03059 (python)

Fixed submission:
a,b,c=map(int,input().split());print(c//a*b)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input(),split());print(c//a*b)
Problem p03061 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[0]*(n+5)
C=[0]*(n+5)

for i in range(n):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,gcd(B[i],C[n-1-i]))
print(po)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
  if a*b==0:
    return a if b==0 else b
  else:
    while b:
      a,b=b,a%b
  return a

B=[]
B[0]=0
C=[]
C[0]=0
for i in range(n-1):
  B[i+1]=gcd(B[i],A[i])
  C[i+1]=gcd(C[i],A[n-i-1])
po=0
for i in range(n):
  po=max(po,B[i]*C[n-1-i])
print(po)
Problem p03076 (python)

Fixed submission:
A=[int(input()) for i in range(5)]
B=[10 if A[i]%10==0 else A[i]%10 for i in range(5)]
k=B.index(min(B))
C=[(A[i]-0.001)//10*10+10 for i in range(5)]
print(int(sum(C)-C[k]+A[k]))

Buggy submission (verdict: Runtime Error):
A=[int(input()) for  i in range(5)]
B=[int(str(A[i])[-1]) for i in range(5)]
if B==[0]*5:
	print(sum(A))
else:
	for i in range(5):
		if B[i]==0:
			B[i]=10
	ans=min(B)
	o=B.index(ans)
print((sum(A)-A[o])+10-(sum(A)-A[o])%10+A[o])
Problem p03087 (python)

Fixed submission:
n,m=map(int,input().split())
s=input()
ACsuu=[0 for i in range(n)]
for i in range(1,n):
  ACsuu[i]=ACsuu[i-1]+(1 if s[i-1:i+1]=="AC" else 0)
for i in range(m):
  a,b=map(int,input().split())
  print(ACsuu[b-1]-ACsuu[a-1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,iput().split())
s=input()
ACsuu=[0 for i in range(n)]
for i in range(1,n):
  Acsuu[i]=ACsuu[i-1]+(1 if s[i-1:i+1]=="AC" else 0)
for i in range(m):
  a,b=map(int,input().split())
  print(ACsuu[b-1]-ACsuu[a-1])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
s=input()
for i in m:
  a,b=map(int,input().split())
  lan=s[a-1:b]
  print(lan.count("AC"))