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

Fixed submission:

import queue
h,w = map(int,input().split())

maze=[]

count_white=0

for i in range(h):
    maze_row = input()
    maze.append(maze_row)
    
    count_white+=maze_row.count(".")
    
dist = [ [-1]*w for i in range(h)]
goal = [w-1,h-1]
q=queue.Queue()
q.put((0,0,0))

moves = [[0,1], [1,0], [0,-1], [-1,0]]
dmax=-1
while not q.empty():
    
    x,y,d = q.get()
    
    if x==goal[0] and y==goal[1]:
        time=d
        dist[y][x]=d
        dmax=d
        break
    
    if dist[y][x] >= 0:
        continue
    
    else:
        
        dist[y][x]=d
        
        for dx,dy in moves:
            
            if 0<=x+dx<w and 0<=y+dy<h:
                if dist[y+dy][x+dx] == -1 and maze[y+dy][x+dx]!="#":
                
                    q.put((x+dx,y+dy,d+1))
if dmax!=-1:
    print(count_white-dmax-1)
    
else:
    print(-1)

Buggy submission (verdict: Runtime Error):

import queue
h,w = map(int,input().split())

maze=[]

count_white=0

for i in range(h):
    maze_row = input()
    maze.append(maze_row)
    
    count_white+=maze_row.count(".")
    
dist = [ [-1]*w for i in range(h)]
goal = [w-1,h-1]
q=queue.Queue()
q.put((0,0,0))

moves = [[0,1], [1,0], [0,-1], [-1,0]]
dmax=-1
while not q.empty():
    
    x,y,d = q.get()
    
    if x==goal[0] and y==goal[1]:
        time=d
        dist[x][y]=d
        dmax=d
        break
    
    if dist[y][x] >= 0:
        continue
    
    else:
        
        dist[y][x]=d
        
        for dx,dy in moves:
            
            if 0<=x+dx<w and 0<=y+dy<h:
                if dist[y+dy][x+dx] == -1 and maze[y+dy][x+dx]!="#":
                
                    q.put((x+dx,y+dy,d+1))
if dmax!=-1:
    print(count_white-dmax-1)
    
else:
    print(-1)
Problem p03280 (python)

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

print(listA[0]*listA[1]-(listA[0]+listA[1]-1))

Buggy submission (verdict: Runtime Error):
A=int(input())
B=int(input())
print(A*B-(A+B-1))
Problem p03337 (python)

Fixed submission:
listA=list(map(int,input().split()))
A=listA[0]
B=listA[1]
listB=[A*B,A+B,A-B]
print(max(listB))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
s=input()
west=[]
east=[]
for i in range(N):
    west.append(0)
    east.append(0)
    if(s[i]=='W'):
        west[i]=1
    else:
        east[i]=1
eastsum=np.zeros(N)
westsum=np.zeros(N)
westsum[0]=west[0]
eastsum[0]=east[N-1]
for i in range(1,N):
    eastsum[N-1-i]=eastsum[N-i]+east[N-1-i]
    westsum[i]=westsum[i-1]+west[i]
print(eastsum+westsum)
Problem p02706 (python)

Fixed submission:
tot , n = list( map ( int ,input().split()))
a = list( map( int , input().split()))
if tot >= sum(a):
	print(tot -sum(a))
else:
	print(-1)

Buggy submission (verdict: Runtime Error):
tot , n = list( map ( int ,input().split()))
a = list( map( int , input().split()))
if tot >= a.sum():
	print(tot -a.sum())
else:
	print(-1)
Problem p02885 (python)

Fixed submission:
n, k = list(map( int , input().split()))
print( max( 0 , n - 2*k))

Buggy submission (verdict: Runtime Error):
 n, k = list(map( int , input().split()))
 print( max( 0 , n - 2*k))
Problem p02918 (python)

Fixed submission:
n , k = [ int(i) for i in input().split()]
s =input()
a =0
for i , ch in enumerate(s[1:] , 1):
  if ch == s[i-1]:
   	a+=1
print( min( n -1, a +2*k))

Buggy submission (verdict: Runtime Error):
n , k = [ (int) i for i in input().split()]
s =input()
a =0
for i , ch in enumerate(s[1:] , 1):
  if ch == s[i-1]:
   	a+=1
print( min( n -1, a +2*k))

Buggy submission (verdict: Runtime Error):
n , k = [ (int) i for i in input().split()]
s =input()
a =0
for i , ch in enumerate(s[1:] , 1):
  if ch == s[i-1]:
   	a+=1
print( min( n -1, a +2*k)
Problem p02999 (python)

Fixed submission:
n , k = [int(i) for i in input().split()]
if n < k:
	print('0')
else:
	print('10')

Buggy submission (verdict: Runtime Error):
x ,y = int(i) for i in input().split()
if x < y:
  print(0)
else:
  print(10)
Problem p03059 (python)

Fixed submission:
a,b,t=map(int,input().split())
print(max(t//a*b,0))

Buggy submission (verdict: Runtime Error):
a,b,t=map(int,input().split())
print(max(t//a*b),0)

Buggy submission (verdict: Runtime Error):
a,b,t=map(int,input().split())
print(max(t//a*b),0)
Problem p03067 (python)

Fixed submission:
a,b,c=map(int,input().split())
if a<c<b:
    print("Yes")
elif b<c<a:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
sharp=[]
dot=[]
c=s[0]
if s[0]!=".":
    dot.append(0)
cnt=1
i=0
while i<n-1:
    while True:
        if s[i+1]==s[i]:
            cnt+=1
            i+=1
            if i>=n-1:
                if s[i-1]==".":
                    dot.append(cnt)
                else:
                    sharp.append(cnt)
                break
        else:
            if s[i]==".":
                dot.append(cnt)
            else:
                sharp.append(cnt)
            i+=1
            cnt=1
            break
if s[-2]!=s[-1]:
    if s[-1]==".":
        dot.append(1)
    else:
        sharp.append(1)
if len(dot)>len(sharp):
    sharp.append(0)
ans=sum(dot[1:])
tmp=0
for i in range(len(dot)-1):
    tmp=ans-dot[i+1]+sharp[i]
    ans=min(tmp,ans)
print(ans)
Problem p03069 (python)

Fixed submission:
n=int(input())
s=list(input())
sharp=[0]*n
dot=[0]*n
if s[0]=="#":
    sharp[0]+=1
else:
    dot[0]+=1
for i in range(1,n):
    if s[i]=="#":
        sharp[i]=sharp[i-1]+1
        dot[i]=dot[i-1]
    else:
        sharp[i]=sharp[i-1]
        dot[i]=dot[i-1]+1
MIN=3*10**6
for i in range(n):
    if s[i]=="#":
        MIN=min(MIN,(sharp[i]-1)+(dot[-1]-dot[i]))
    else:
        MIN=min(MIN,sharp[i]+(dot[-1]-dot[i]))
print(MIN)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
sharp=[]
dot=[]
c=s[0]
if s[0]!=".":
    dot.append(0)
cnt=1
i=0
while i<n-1:
    while True:
        if s[i+1]==s[i]:
            cnt+=1
            i+=1
            if i>=n-1:
                if s[i-1]==".":
                    dot.append(cnt)
                else:
                    sharp.append(cnt)
                break
        else:
            if s[i]==".":
                dot.append(cnt)
            else:
                sharp.append(cnt)
            i+=1
            cnt=1
            break
if s[-2]!=s[-1]:
    if s[-1]==".":
        dot.append(1)
    else:
        sharp.append(1)
if len(dot)>len(sharp):
    sharp.append(0)
ans=sum(dot[1:])
tmp=0
for i in range(len(dot)-1):
    tmp=ans-dot[i+1]+sharp[i]
    ans=min(tmp,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=list(input())
sharp=[]
dot=[]
c=s[0]
if s[0]!=".":
    dot.append(0)
cnt=1
i=0
while i<n-1:
    while True:
        if s[i+1]==s[i]:
            cnt+=1
            i+=1
            if i>=n-1:
                if s[i-1]==".":
                    dot.append(cnt)
                else:
                    sharp.append(cnt)
                break
        else:
            if s[i]==".":
                dot.append(cnt)
            else:
                sharp.append(cnt)
            i+=1
            cnt=1
            break
if s[-2]!=s[-1]:
    if s[-1]==".":
        dot.append(1)
    else:
        sharp.append(1)
if len(dot)>len(sharp):
    sharp.append(0)
ans=sum(dot[1:])
tmp=0
for i in range(len(dot)-1):
    tmp=ans-dot[i+1]+sharp[i]
    ans=min(tmp,ans)
print(ans)
Problem p03095 (python)

Fixed submission:
n=int(input())
s=list(input())
s.sort()
cnt=1
cnt_list=[]
if len(s)==1:
    print(1)
    exit()
for i in range(n-1):
    if s[i]==s[i+1]:
        cnt+=1
        if i==n-2:
            cnt_list.append(cnt)
    else:
        cnt_list.append(cnt)
        cnt=1
        if i==n-2:
            cnt_list.append(1)
ans=1
for i in range(len(cnt_list)):
    ans=ans*(cnt_list[i]+1)%(10**9+7)
print(ans-1)

Buggy submission (verdict: Runtime Error):
input();s=input();a=set(s)
a=1
for i in a:ans=ans*(s.count(i)+1)%(10**9+7)
print(a-1)
Problem p03112 (python)

Fixed submission:
from bisect import bisect_left
a,b,q=map(int,input().split())
s=[]
t=[]
x=[]
s.append(-10**12)
t.append(-10**12)
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
s.append(10**12)
t.append(10**12)
for i in range(q):
    x=int(input())
    tmp_s=bisect_left(s,x)-1
    tmp_s_1=s[tmp_s]
    tmp_s_2=s[tmp_s+1]
    tmp_t=bisect_left(t,x)-1
    tmp_t_1=t[tmp_t]
    tmp_t_2=t[tmp_t+1]
    print(min(abs(x-tmp_s_1)+abs(tmp_s_1-tmp_t_1),
    abs(x-tmp_s_1)+abs(tmp_s_1-tmp_t_2),
    abs(x-tmp_s_2)+abs(tmp_s_2-tmp_t_1),
    abs(x-tmp_s_2)+abs(tmp_s_2-tmp_t_2),
    abs(x-tmp_t_1)+abs(tmp_t_1-tmp_s_1),
    abs(x-tmp_t_1)+abs(tmp_t_1-tmp_s_2),
    abs(x-tmp_t_2)+abs(tmp_t_2-tmp_s_1),
    abs(x-tmp_t_2)+abs(tmp_t_2-tmp_s_2)))

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
a,b,q=map(int,input().split())
s=[]
t=[]
x=[]
s.append(-float("inf"))
t.append(-float("inf"))
for i in range(a):
    s.append(int(input()))
for i in range(b):
    t.append(int(input()))
s.append(float("inf"))
t.append(float("inf"))
s.sort()
t.sort()
for i in range(q):
    x=int(input())
    ans=float("inf")
    tmp_s_1=bisect.bisect_left(s,x)-1
    tmp_s_2=tmp_s_1+1
    tmp_s_1_t=bisect.bisect_left(t,s[tmp_s_1])
    tmp_s_2_t=bisect.bisect_left(t,s[tmp_s_2])
    ans=min(abs(x-s[tmp_s_1])+abs(s[tmp_s_1]-t[tmp_s_1_t-1]), abs(x-s[tmp_s_1])+abs(s[tmp_s_1]-t[tmp_s_1_t]), abs(x-s[tmp_s_2])+abs(s[tmp_s_2]-t[tmp_s_2_t-1]), abs(x-s[tmp_s_2])+abs(s[tmp_s_2]-t[tmp_s_2_t]))
    tmp_t_1=bisect.bisect_left(t,x)-1
    tmp_t_2=tmp_t_1+1
    tmp_t_1_s=bisect.bisect_left(s,t[tmp_t_1])
    tmp_t_2_s=bisect.bisect_left(s,t[tmp_t_2])
    ans=min(ans, abs(x-t[tmp_t_1])+abs(t[tmp_t_1]-s[tmp_t_1_s-1]), abs(x-t[tmp_t_1])+abs(t[tmp_t_1]-s[tmp_t_1_s]), abs(x-t[tmp_t_2])+abs(t[tmp_t_2]-s[tmp_t_2_s-1]), abs(x-t[tmp_t_2])+abs(t[tmp_t_2]-s[tmp_t_2_s]))
    print(ans)
Problem p03260 (python)

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

if a % 2 == 1 and b % 2 == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = arr[-1]**5
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)
 
print(a)
Problem p03262 (python)

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

N, X = map(int, input().split())
x = [int(_) for _ in input().split(' ')]

dist = [abs(i - X) for i in x]

ans = dist[0]

for i in range(N-1):
    ans = gcd(ans, dist[i+1])

print(ans)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())
arr = [int(_) for _ in input().split(' ')]

a = 1000000000000000

for i in range(N):
    for j in range(N):
        if math.gcd(abs(arr[i] - X), abs(arr[j] - X)) < a:
            a = math.gcd(abs(arr[i] - X), abs(arr[j] - X))

print(a)

Buggy submission (verdict: Runtime Error):
import math

N, X = map(int, input().split())
arr = [int(_) for _ in input().split(' ')]

a = 1000000000000000

for i in range(N):
    for j in range(N):
        if math.gcd(abs(arr[i] - X), abs(arr[i] - X)) < a:
            a = math.gcd(abs(arr[i] - X), abs(arr[i] - X))

print(a)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
 
arr = [int(_) for _ in input().split(' ')]
arr.sort()
 
a = 1000000000000
 
 
for i in range(N-1):
    if abs(arr[i+1]-arr[i]) < a:
        a = abs(arr[i+1]-arr[i])
 
for j in range(N):
    if abs(arr[j] - X) < a:
        a = abs(arr[j] - X)

if X > arr[N] or X < arr[0]:
    a = 1
 
print(a)
Problem p03284 (python)

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

if N % K == 0:
    print(0)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
 
if N in [1, 2, 3, 5, 6, 7, 9, 10, 13, 17]:
   print("Yes")
else:
   print("No")

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

if N in [1, 2, 3, 5, 6, 7, 9, 10, 13, 17]:
   print("Yes")
else:
   print("No")

Buggy submission (verdict: Runtime Error):
N = input()
K = input()

if N % K == 0:
    print(0)
else:
    print(1)
Problem p03624 (python)

Fixed submission:
s=list(input())
s=set(s)
s=list(s)
s.sort()
k=0
for i in range(26):
    if ord(s[i])-97!=i:
        if i==0:
            print("a")
            k=1
            break
        print(chr(ord(s[i-1])+1))
        break
    if i==25:
        print("None")
        k=1
        break
    if i==len(s)-1:
        print(chr(ord(s[-1])+1))
        break

Buggy submission (verdict: Runtime Error):
s=list(input())
s=set(s)
s=list(s)
s.sort()
for i in range(26):
    if ord(s[i])-97!=i:
        if i==0:
            print("a")
            break
        print(chr(ord(s[i-1])+1))
        break
    if i==25:
        print("None")
        break
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().split())
print("YES" if b-a==c-b else "NO)
Problem p03844 (python)

Fixed submission:
print(eval(input()))

Buggy submission (verdict: Runtime Error):
N = int(input())
 
t = [input() for i in range(N)]
 
M = int(input())
 
a = []
for i in range(M):
    a.append(map(int, raw_input().split()))       
 
cal = sum(t)
 
for j in range(M):
    print(cal - t[a[j][0] - 1] + a[j][1])

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

op = input()

if op ==  "+":
    print(A + B)
else :
    print(A - B)

Buggy submission (verdict: Runtime Error):
a =  input().split()

if a[1] ==  "+":
    print(int(a[0]) + int(a[2]))
else a[1] == "-":
    print(int(a[0]) - int(a[2]))

Buggy submission (verdict: Runtime Error):
a =  input().split()

if a[1] = "+":
    print(int(a[0]) + int(a[2]))
    
if a[1] = "-":
    print(int(a[0]) - int(a[2]))
Problem p03943 (python)

Fixed submission:
a = list(map(int, input().split()))
a.sort()
if a[2] == a[0] + a[1]:
    print("Yes")
else:
    print("No")

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

s = [a, b, c]
ld = sorted(s, reverse=True)

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

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

s = [a, b, c]
ld = sorted(s, reverse=True)

if ld[0] = ld[1] + ld[2]:
    print(Yes)
else:
    print(No)
Problem p03962 (python)

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

if a == b == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)

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

if a == b == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)
Problem p02713 (python)

Fixed submission:
import math
 
k = int(input()) + 1
ans = 0
 
for a in range(1, k):
    for b in range(1, k):
        d = math.gcd(a, b)
        for c in range(1, k):
            ans += math.gcd(d, c)
 
print(ans)

Buggy submission (verdict: Runtime Error):
K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if j < k:
                j,k = k,j
            temp = gcd(j,k)
            if i < temp:
                i,temp = temp,i
            ans += gcd(i,temp)
print(ans)
Problem p02716 (python)

Fixed submission:
n = int(input())
nums = list(map(int,input().split()))
if n == 2:
    print(max(nums[0],nums[1]))
else:
    temp =[0]
    for i in range(n):
        if i%2 == 0:
            temp += [temp[-1]+nums[i]]
    dp = [[0,0,0] for _ in range(n)]
    dp[0][0] = nums[0]
    dp[1][0],dp[1][1],dp[1][2] = nums[1],nums[0],-float("inf")
    dp[2][0],dp[2][1],dp[2][2] = nums[2],nums[1],nums[0]
    for i in range(3,n):
        if i%2 == 0:
            dp[i][0] = max(dp[i-2]) + nums[i]
            dp[i][1] = max(dp[i-3]) + nums[i-1]
            dp[i][2] = temp[i//2]
        else:
            dp[i][0] = max(dp[i-2]) + nums[i]
            dp[i][1] = temp[(i-1)//2] + nums[i-1]
            dp[i][2] = -float("inf")
    print(max(dp[n-1]))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int,input().split()))
dp = [[0,0,0] for _ in range(n)]
dp[0][0] = nums[0]
dp[1][0],dp[1][1],dp[1][2] = nums[1],nums[0],-float("inf")
dp[2][0],dp[2][1],dp[2][2] = nums[2],nums[1],nums[0]
for i in range(3,n):
    if i%2 == 0:
        dp[i][0] = max(dp[i-2]) + nums[i]
        dp[i][1] = max(dp[i-3]) + nums[i-1]
        dp[i][2] = sum(nums[0:i-1:2])
    else:
        dp[i][0] = max(dp[i-2]) + nums[i]
        dp[i][1] = sum(nums[0:i-2:2]) + nums[i-1]
        dp[i][2] = -float("inf")
print(max(dp[n-1]))

Buggy submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int,input().split()))
dp = [[0,0,0] for _ in range(n)]
dp[0][0] = nums[0]
dp[1][0],dp[1][1],dp[1][2] = nums[1],nums[0],-float("inf")
dp[2][0],dp[2][1],dp[2][2] = nums[2],nums[1],nums[0]
for i in range(3,n):
    if i%2 == 0:
        dp[i][0] = max(dp[i-2]) + nums[i]
        dp[i][1] = max(dp[i-3]) + nums[i-1]
        dp[i][2] = sum(nums[0:i-1:2])
    else:
        dp[i][0] = max(dp[i-2]) + nums[i]
        dp[i][1] = sum(nums[0:i-2:2]) + nums[i-1]
        dp[i][2] = -float("inf")
print(max(dp[n-1]))
print(dp)
Problem p02732 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
d = {}
ans = 0
for i in a:
    d[i] = d.get(i,0) + 1
for key in d:
    ans += d[key]*(d[key]-1)//2
for i in a:
    print(ans + 1 - d[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
d = {}
ans = 0
for _ in range(n):
    a.append(int(input()))
for i in a:
    d[i] = d.get(i,0) + 1
for key in d:
    ans += d[key]*(d[key]-1)//2
for i in a:
    print(ans + 1 - d[i])
Problem p02888 (python)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input()))
import bisect
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        x = bisect.bisect_left(l[j+1:],l[i]+l[j])
        ans += x
print(ans)
Problem p02899 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
res = []
for i,e in enumerate(a):
    res.append((e,i))
res.sort()
ans = []
for i in res:
    ans.append(i[1]+1)
print(" ".join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
res = []
for i,e in enumerate(a):
    res.append((e,i))
res.sort()
ans = []
for i in res:
    ans.append(i[1]+1)
print(" ".join(ans))
Problem p02909 (python)

Fixed submission:
S = input()
if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")

Buggy submission (verdict: Runtime Error):
s = input()
if s == "Sunny":
    print("Cloudy")
elif:
    print("Rainy")
else:
    print("Sunny")
Problem p02934 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    A[i] = 1/A[i]
a = sum(A)
print(1/a)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())
for i in range(N):
    A[i] = 1/A[i]
a = sum(A)
print(1/a)
Problem p02936 (python)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
 
n,q = map(int, input().split())
#長さn個のリストを入れ子にしたリストの作成：adj
adj = [[] for i in range(n)]
 
#adjに繋がっている要素を上流下流関わらず全て加える。
for j in range(n-1):
    a,b=map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1) 
 
#加算する値を合計したリストの作成
queries = [0 for i in range(n)]
for j in range(q):
    p, x = map(int, input().split())
    queries[p-1] += x
 
ans = [0 for i in range(n)]
 
#aの値，直前の値，直前のaの値
st = [(0, 0, -1)] 
 
#つながってる奴の一番後ろから処理していく。
#０スタート→1,2繋がってるなら2にいく。2に3が繋がってるなら次は3。
#3に繋がってるのがなければ1に戻る。
#この際，aの直前の値をタプルで保持したままリストに挿入して保管しておく。
while st:
    #stの先頭を取り出す。初期値は末尾のため-1
    l = st.pop()  
    ans[l[0]] = l[1] + queries[l[0]]
    for v in adj[l[0]]:
        if v != l[2]:
            st.append((v, ans[l[0]], l[0]))
 
print(*ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
tree = [[0] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    if tree[a] == [0]:
        tree[a] = [b]
    else:
        tree[a].append(b)
counter = [0 for i in range(N+1)]
def dfs(p,x):
    counter[p] += x
    for i in tree[p]:
        if i != 0:
            dfs(i,x)
               
    
for i in range(Q):
    p,x = map(int,input().split())
    dfs(p,x)
counter = [str(i) for i in counter]
ans = ' '.join(counter[1:])
print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
tree = [[0] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    if tree[a] == [0]:
        tree[a] = [b]
    else:
        tree[a].append(b)
counter = [0 for i in range(N+1)]
def dfs(p,x):
    if p == 0:
        return
    counter[p] += x
    for i in tree[p]:
        dfs(i,x)   
    
for i in range(Q):
    p,x = map(int,input().split())
    dfs(p,x)
counter = [str(i) for i in counter]
ans = ' '.join(counter[1:])
print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
tree = [[0] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    if tree[a] == [0]:
        tree[a] = [b]
    else:
        tree[a].append(b)
counter = [0 for i in range(N+1)]
def dfs(p,x):
    if p == 0:
        return
    counter[p] += x
    for i in tree[p]:
        dfs(i,x)   
    
for i in range(Q):
    p,x = map(int,inupt().split())
    dfs(p,x)
counter = [str(i) for i in counter]
ans = ' '.join(counter[1:])
print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int,input().split())
tree = [[0] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    if tree[a] == [0]:
        tree[a] = [b]
    else:
        tree[a].append(b)
counter = [0 for i in range(N+1)]
def dfs(p,x):
    if p == 0:
        return
    counter[p] += x
    for i in tree[p]:
        dfs(i,x)   
    
for i in range(Q):
    p,x = map(int,inupt().split())
    dfs(p,x)
print(counter[1:])
Problem p02953 (python)

Fixed submission:
N = int(input())
H = list(map(int, input().split()))
H.append(1000000001)

max = H[0]
for i in range(N):
    if max >= H[i+1] + 2:
        print('No')
        break
    if max < H[i+1]:
        max = H[i+1]
        
else:
    print('Yes')

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

max = H[0]
for i in range(N):
    if max >= H[i+1] + 2:
        print('No')
        break
    if max < H[i+1]:
        max = H[i+1]
        
else:
    print('Yes')
Problem p02957 (python)

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

if ((a%2 == 1)and(b%2==1)):
    c = (a+b)/2
    print(int(c))

elif ((a%2==0)and(b%2==0)):
    c =(a+b)/2
    print(int(c))

else:
    print("IMPOSSIBLE")

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

if ((a%2 == 1)and(b%2==1)):
    c = (a+b)/2
    print(int(c))

if ((a%2==0)and(b%2==0)):
    c =(a+b)/2
    print(int(c))

if ((a%2==0)and(b%2==1)) or ((a%2==1)and(b%==0)):
    print("IMPOSSIBLE")
Problem p02971 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

B = A[:]

a1 = max(A)
A.remove(a1)
a2 = max(A)

for i in range(N):
    if B[i] != a1:
        print(a1)
    else:
        print(a2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]

a1 = max(A)
B = [i for i in A if i!= a1]
a2 = max(B)

for i in range(N):
    if A[i] != a1:
        print(a1)
    else:
        print(a2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]

a1 = max(A)
B = A.remove(a1)
a2 = max(B)

for i in range(N):
    if A[i] != a1:
        print(a1)
    else:
        print(a2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]

B = sorted(A)
for i in range(N):
    if A[i] != B[N-1]:
        print(B[N-1])
    else:
        for j in range(N):
            if A[i] != B[(N-1)-j]
            print(B[N-1-j])
            break