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

Fixed submission:
from collections import Counter
from itertools import product

n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]

xlist = [[0 for j in range(n)] for i in range(n)]
sumlist = [[0 for j in range(n+1)] for i in range(n)]
for (l,r),i in Counter(rails).items():
    xlist[l-1][r-1]=i


for (i,j) in product(range(n),range(n)):
    sumlist[i][j+1]=sum(xlist[i][0:j+1])


for (p,q) in qs:
    ans = 0
    for i in range(p-1,q):
        ans = ans+sumlist[i][q]-sumlist[i][p-1]
    print(ans)

Buggy submission (verdict: Runtime Error):
n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]
enuq = list(enumerate(qs))
 
enuq.sort(key = lambda x:x[1][0])
ansli = [0 for i in range(q)]


for (i,(p,q)) in enuq:
    removelist=[]
    for (j,(l,r)) in enumerate(rails):
        if p<=l and r<=q:
            ansli[i]=ansli[i]+1
        elif l<p:
            removelist.append(j)
    for jj in removelist:
        rails.pop(jj)



for a in ansli:
    print(a)

Buggy submission (verdict: Runtime Error):
n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]
enuq = list(enumerate(qs))
 
enuq.sort(key = lambda x:x[1][0])
ansli = [0 for i in range(q)]


for (i,(p,q)) in enuq:
    removelist=[]
    for (j,(l,r)) in enumerate(rails):
        if p<=l and r<=q:
            ansli[i]=ansli[i]+1
        elif l<p:
            removelist.append(j)
    for jj in removelist:
        rails.pop(jj)



for a in ansli:
    print(a)
Problem p03297 (python)

Fixed submission:



t = int(input())
qs=[list(map(int,input().split())) for i in range(t)]

def computeGCD(x, y):
   while(y):
       x, y = y, x % y
   return x

def aprime(a,b,c,d):
    app = a%b
    return(c+d-b - (c-app)%(d-b))


def ans(a,b,c,d):
    if d < b or a<b or (a%b > c and c<b):
        return('No')
    elif b == d or c > b:
        return('Yes')
    elif aprime(a,b,c,d) < b:
        return('No')
    else: return (ans2(aprime(a,b,c,d),b,c,d))

def ans2(a,b,c,d):
    b2 = b % (d-b)
    gcdbbd = abs(computeGCD(b2,b-d))
    aa = a - ((a-c)//gcdbbd)*gcdbbd
    if aa == c: aa = c+ gcdbbd
    if aa >= b: return('Yes')
    else: return('No')

for q in qs:
    print (ans(*q))

Buggy submission (verdict: Runtime Error):
import math

t = int(input())
qs=[list(map(int,input().split())) for i in range(t)]

def aprime(a,b,c,d):
    app = a%b
    return(c+d-b - (c-app)%(d-b))


def ans(a,b,c,d):
    if d < b or a<b or (a%b > c and c<b):
        return('No')
    elif b == d or c > b:
        return('Yes')
    elif aprime(a,b,c,d) < b:
        return('No')
    else: return (ans2(aprime(a,b,c,d),b,c,d))

def ans2(a,b,c,d):
    b2 = b % (d-b)
    gcdbbd = math.gcd(b2,b-d)
    aa = a - ((a-c)//gcdbbd)*gcdbbd
    if aa == c: aa = c+ gcdbbd
    if aa >= b: return('Yes')
    else: return('No')

for q in qs:
    print (ans(*q))
Problem p02606 (python)

Fixed submission:
l, r, d = map(int, input().split())
cnt = 0
a = l
while True:
    if a % d == 0:
        break
    else:
        a += 1
while True:
    if a > r:
        break
    cnt += 1
    a += d
print(cnt)

Buggy submission (verdict: Runtime Error):
def popcount(n):
    cnt = 0
    for i in range(n):
        if ((n >> i) & 1):
            cnt +=1
    return cnt

def f(n):
    cnt = 1
    while True:
        if n == 0:
            break
        n = n % popcount(n)
        cnt += 1
    return cnt

def pow_r(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2)
    else:
        return x * pow_r(x ** 2, (n - 1) // 2)

if __name__ == "__main__":
    n = int(input())
    x = input()
    xList = list(x)
    k = len(xList) - 1
    xNum = int("".join(xList), 2)
    numcnt = popcount(xNum)
    a = numcnt
    wk = 0
    for i in range(n):
        if xList[i] == '0':
            numcnt += 1
        else:
            numcnt -= 1
        xList[i] = str(int(xList[i]) ^ 1)
        xNum = int("".join(xList), 2)
        wk = xNum % numcnt
        if wk == 0:
            print(1)
        else:
            print(f(wk))
        xList[i] = str(int(xList[i]) ^ 1)
        numcnt = a
Problem p02576 (python)

Fixed submission:
n,x,t=map(int,input().split())
print(-n//x*-t)

Buggy submission (verdict: Runtime Error):
n,x,t=int(input().split())
print(n*x/t)
Problem p03645 (python)

Fixed submission:
n,m = map(int,input().split())
s=[False]*n
t=[False]*n
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    s[b-1]=True
  if b==n:
    t[a-1]=True
for i in range(n):
  if s[i]==True and t[i]==True:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab =  [list(map(int,input().split(" "))) for i in range(m)]
for i in range(m):
  if (ab[i][0] == 1):
    c = ab[i][1]
    for i in range(m):
      if (ab[i][0] == c and ab[i][1] == n):
        ans = 'POSSIBLE'
  else:
    ans = 'IMPOSSIBLE'
print(ans)
Problem p02556 (python)

Fixed submission:
def main():
    n, *xy = map(int, open(0).read().split())
    f = [(i - j, i + j) for i, j in zip(xy[::2], xy[1::2])]
 
    a = max(x[0] for x in f)
    b = min(x[0] for x in f)
 
    c = max(x[1] for x in f)
    d = min(x[1] for x in f)
 
    ans = max(a - b, c - d)
    print(ans)
 
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

def f(x,y):
    return x-y.x+y

def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    x = [0]*n
    y = [0]*n
    for i in range(n):
        x[i],y[i] = map(int,input().split())
    f0 = [0]*n
    f1 = [0]*n
    for i in range(n):
        f0[i],fi[i] = f(x[i],y[i])
    print(max(max(f0)-minf(0),max(f1)-minf(1)))

if __name__ = "__main__":
    main()
Problem p02579 (python)

Fixed submission:
from collections import deque
H, W= map(int, input().split())
CH, CW= map(int, input().split())
DH, DW= map(int, input().split())
S = [list(map(str, input())) for _ in range(H)]
q = deque([(CH-1, CW-1, 0)])
while q:
    h, w, c = q.popleft()
    if S[h][w] == '.':
        S[h][w] = c
        for i in range(-2, 3):
            for j in range(-2, 3):
                if 0<=h+i<H and 0<=w+j<W and S[h+i][w+j] == '.':
                    if abs(i)+abs(j) == 1:
                        q.appendleft((h+i, w+j, c))
                    elif abs(i)+abs(j) >= 2:
                        q.append((h+i, w+j, c+1))
if S[DH-1][DW-1] == '.':
    print(-1)
else:
    print(S[DH-1][DW-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w=map(int, input().split())
ch,cw=map(int, input().split())
dh,dw=map(int, input().split())
l = [list(input())for i in range(h)]
dist=[[-1 for _ in range(w)] for _ in range(h)]
d=[[1,0],[0,1],[-1,0],[0,-1]]
D=[[1,0],[0,1],[-1,0],[0,-1],[1,1],[-1,1],[-1,1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0],[1,2],[1,-2],[-1,2],[-1,-2],[2,1],[2,-1],[-2,1],[-2,-1],[2,2],[2,-2],[-2,2],[-2,-2]]
M = [-1]
ans = 0

q=deque([[ch-1,cw-1]])
dist[ch-1][cw-1]=0
while q:
    y,x=q.pop()
    for dy,dx in d:
        ny,nx=y+dy,x+dx
        if 0<=ny and ny<h and 0<=nx and nx<w and dist[ny][nx]==-1:
            if l[ny][nx]=='.':
                q.append([ny,nx])
            if l[nx][ny]=='#':
                for Dx,Dy in D:
                    Nx,Ny = y+Dx,y+Dy
                    if 0<=ny and ny<h and 0<=nx and nx<w and dist[ny][nx]==-1:
                        if l[ny][nx]=='.':
                            q.append([Ny,Nx])
                        if l[Ny][Nx]=='#':
                            q.appendleft([ny,nx])
            dist[ny][nx]=dist[y][x]+(l[ny][nx]=='#')
print(dist[dh-1][dw-1])
Problem p02601 (python)

Fixed submission:
a,b,c=map(int, input().split())
n=int(input()) 
 
k = n
 
if a < b < c:
    print('Yes')
 
if a < b and b >= c:
    while  b >= c and k >= 1:
        c = 2*c
        k -= 1
        if b >= c and k == 0:
            print('No')
        if b < c and k>=0:
            print('Yes')
 
if a >= b:
    while a >= b and k >= 1:
        b = 2*b
        k -= 1
        if a >= b and k == 0 :
            print('No')
        if a < b and b >= c and k == 0:
            print('No')
        if a < b < c:
            print('Yes')
            break
        if a < b and b >= c and k >= 1:
            while  b >= c and k >= 1:
                c = 2*c
                k -= 1
                if b >= c and k == 0:
                    print('No')
                if b < c and k>=0:
                    print('Yes')
                    break

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

k = n

if a < b < c:
    print('Yes')
    break

if a < b and b >= c:
    while  b >= c and k >= 1:
        c = 2*c
        k -= 1
        if b >= c and k == 0:
            print('No')
        if b < c and k>=0:
            print('Yes')

if a >= b:
    while a >= b and k >= 1:
        b = 2*b
        k -= 1
        if a >= b and k == 0 :
            print('No')
        if a < b and b >= c and k == 0:
            print('No')
        if a < b < c:
            print('Yes')
            break
        if a < b and b >= c and k >= 1:
            while  b >= c and k >= 1:
                c = 2*c
                k -= 1
                if b >= c and k == 0:
                    print('No')
                if b < c and k>=0:
                    print('Yes')
                    break
Problem p02608 (python)

Fixed submission:
N=int(input())
r=[0]*10000
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            v = i*i + j*j + k*k + i*j + i*k + k*j
            if v <= 10000:
                r[v-1] += 1
for i in range(N):
    print(r[i])

Buggy submission (verdict: Runtime Error):
N=int(input())
r=[0]*N
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            v = i*i + j*j + k*k + i*j + i*k + k*j
            if v <= 10000
            r[v-1] += 1
print(*r,sep='\n')
Problem p02612 (python)

Fixed submission:
n = int(input())
a = n%1000

if a == 0 :
  print(0)
if a != 0 :
  print(1000 - a)

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

s = sum(l[:2])
print(s)
Problem p02613 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)

for _ in range(N):
  s = input()
  if s == 'AC':
    d[s] += 1
  elif s == 'WA':
    d[s] += 1
  elif s == 'TLE':
    d[s] += 1
  else:
    d[s] += 1
    
    
for k in ['AC', 'WA', 'TLE', 'RE']:
  print('{} x {}'.format(k, d[k]))

Buggy submission (verdict: Runtime Error):
zn = int(input())
a = 0
b = 0
c = 0
d = 0
 
for i in range(n):
  S = str(input())
  if S == 'AC':
    a += 1
  elif S == 'WA':
    b += 1
  elif S == 'TLE':
    c += 1
  elif S == 'RE':
    d += 1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = 0
b = 0
c = 0
d = 0

for i in range(n):
  S = str(input())
  if S == 'AC':
    a += 1
  if S == 'WA':
    b += 1
  if S == 'TLE':
    c += 1
  if S == 'RE':
    d += 1
print('AC x '+str(a)
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Buggy submission (verdict: Runtime Error):
taka_h, taka_a, aoki_h, aoki_a = map(int, input().split())

while True:
    aoki_h -=taka_a
    taka_h -= aoki_a
    if(aoki_h <=0):
        print("Yes")
        break
    elif(taka_h <= 0):
        print("No")
        break
Problem p02621 (python)

Fixed submission:
a=int(input())
print(a+a*a+a**3)

Buggy submission (verdict: Runtime Error):
a=int(input()) 
print(a+a*a+a**3)

Buggy submission (verdict: Runtime Error):
a=int(input()) 
print(a+a*a+a**3)

Buggy submission (verdict: Runtime Error):
a=int(input()) #aを整数aの変数として扱う
print(a+a*a+a**3)　#a+a*a+a**3の値を表示する
Problem p02630 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N = int(readline())
    A = [0] *(10**5+1)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1
 
 
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0
 
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline

def main():
    N = int(readline())
    A = [0] *(10**5)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1
 
 
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0
 
 
if __name__ == '__main__':
    main()
Problem p02639 (python)

Fixed submission:
x=list(map(int,input().split()))
print(x.index(0)+1)

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())
P = list(map(int,input().split()))
 
for i in range(101):
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  elif xr not in P:
    print(xr)
    break
Problem p02660 (python)

Fixed submission:
import math
 
N = int(input())
Prime = []
ans = 0
 
def func(n):
    while n % 2 == 0:
        n = n // 2
        Prime.append(2)
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        while n % i == 0:
            n = n //i
            Prime.append(i)
    if n > 2:
        Prime.append(n)
 
func(N)
 
for i in set(Prime):
    c = i
    while N % c == 0:
        N = N // c
        ans += 1
        c = c * i
 
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
def main():
    N,M,*AB=map(int,open(0).read().split())
    g=[[] for _ in range(N+1)]
    for a,b in zip(*[iter(AB)]*2):
        g[a].append(b)
        g[b].append(a)
    q=deque([1])
    s=[0]*(N+1)
    s[1]=1
    while q:
        u=q.popleft()
        for v in g[u]:
            if not s[v]:
                s[v] = u
                q.append(v)
    print("Yes")
    print("\n".join(map(str, s[2:])))
if __name__ == "__main__":
    main()
Problem p02683 (python)

Fixed submission:
import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')

Buggy submission (verdict: Runtime Error):
a,b,import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')

Buggy submission (verdict: Runtime Error):
a,b,import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')
Problem p02732 (python)

Fixed submission:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(ans))

Buggy submission (verdict: Runtime Error):
rom collections import Counter
N=int(input())
A=list(map(int, input().split()))
 
count = Counter(A)
vals = count.values()
sum_ = 0
for v in vals:
  if v >= 2: sum_ += v*(v-1)
sum_ //= 2
 
for k in range(N):
  if count[A[k]] < 2: print(sum_)
  else:print(sum_ + 1 - count[A[k]])
Problem p02761 (python)

Fixed submission:
import sys
 
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for f in range(m)]
if n == 1:
    start = 0
    end = 10
else:
    start = 10**(n-1)
    end = 10**n
for i in range(start, end):
  x = False
  for j in sc:
    if str(i)[j[0]-1] != str(j[1]):
      x = True
      break
  if x:
    continue
  print(i)
  sys.exit()
print(-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())
s = [list(map(int, input().split())) for i in range(b)]
s = sum(s, [])
L = [-1]*[0]*(a-1)
ans = 0
ab = 10**(a-1)

for i in range(b):
    if L[s[i*2]-1] == 0:
        L[s[i*2]-1] = s[i*2+1]
    if L[s[i*2]-1] != 0 and L[s[i*2]-1] == s[i*2+1]:
        pass
    if L[s[i*2]-1] != 0 and L[s[i*2]-1] != s[i*2+1]:
        ans += 1

if ans == 0:
    if a == 1 and b == 0:
        print(0)
    if a != 1 and b == 0:
        print(ab)
    if b !=0 and L[0] == 0:
        print('-1')
    if b !=0 and L[0] == -1:
        T = ''.join(map(str,L[1:a]))
        ab = ab + int(T)
        print(ab)
    if b !=0 and L[0] != -1:
        T = ''.join(map(str,L))
        print(T)
if ans != 0:
    print('-1')

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())
s = [list(map(int, input().split())) for i in range(b)]
s = sum(s, [])
L =[0]*a
ans = 0
ab = 10**(a-1)

for i in range(b):
    if L[s[i*2]-1] == 0:
        L[s[i*2]-1] = s[i*2+1]
    if L[s[i*2]-1] != 0 and L[s[i*2]-1] == s[i*2+1]:
        pass
    if L[s[i*2]-1] != 0 and L[s[i*2]-1] != s[i*2+1]:
        ans += 1

if ans == 0:
    if a == 1 and b == 0:
        print(0)
    if a != 1 and b == 0:
        print(ab)
    if b !=0 and L[0] == 0:
        T = ''.join(map(str,L[1:a]))
        ab = ab + int(T)
        print(ab)
    if b !=0 and L[0] != 0:
        T = ''.join(map(str,L))
        print(T)
if ans != 0:
    print('-1')
Problem p02780 (python)

Fixed submission:
a,b=map(int, input().split())
c=list(map(int, input().split()))
l =[]
ans = 0

def abc(n):
    return (n+1)/2

cb = list(map(abc,c))

s = sum(cb[:b])
l.append(s)

for i in range(b,a):
    s = s - cb[i-b] + cb[i]
    l.append(s)

L = sorted(l)
print(L[-1])

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())
c=list(map(int, input().split()))
l =[]
ans = 0

def abc(n):
    return (n+1)/2

cb = list(map(abc,c))

s = sum(cb[:b])
l.append(s)

for i in range(b,a+1):
    s = s - cb[i-b] + cb[b]
    l.append(s)

L = sorted(l)
print(L[-1])
Problem p02838 (python)

Fixed submission:
import numpy as np
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)

Buggy submission (verdict: Runtime Error):
N, *A = map(int, open(0).read().split())
A = np.array(A, dtype=np.int64)
mod = 10**9 + 7
 
ans = 0
for i in range(60):
    mask = 1 << i
    cnt = np.count_nonzero(A&mask)
    x = cnt * (N-cnt)
    x *= mask % mod
    ans += x
    ans %= mod
 
print(ans)
Problem p02888 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
a.sort()
count = 0
for i in range(n-1, 0, -1):
    l = 0
    r = i-1
    while(l<r):
        if a[l] + a[r] > a[i]:
            count += r-l
            r -= 1
 
        else:
            l += 1
 
print(count)

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
 
a.sort()
count = 0
for i in range(n-1,0,-1):
    l = 0
    r = i-1
    while(l<r):
        if a[l] + a[r] > a[i]:
            count += r-l
            r -= 1
 
        else:
            l += 1
 
print(count)

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
 
a.sort()
count = 0
for i in range(0, n-1):
    l = 0
    r = i-1
    while(l<r):
        if a[l] + a[r] > a[i]:
            count += r-l
            r -= 1
 
        else:
            l += 1
 
print(count)
Problem p02936 (python)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
 
 
def main():
    n, q = map(int, input().split())
    node = [[]for _ in range(n)]
    looked = [1] * n
    for i in range(n - 1):
        a, b = map(int, input().split())
        node[b - 1].append(a - 1)
        node[a - 1].append(b - 1)
    counter = [0] * n
    for i in range(q):
        p, x = map(int, input().split())
        counter[p - 1] += x
    queue = deque([0])
    looked[0] = 0
    while queue:
        now = queue.pop()
        for i in node[now]:
            if looked[i]:
                queue.append(i)
                counter[i] += counter[now]
                looked[i] = 0
    print(*counter)
 
main()

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

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [[] for _ in range(N)]

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

X = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [0]*N

def dfs(u, parent=None):
    ans[u] = ans[parent] + X[u]
    for v in tree[u]:
        if v != parent:
            dfs(v, u)

dfs(0, 0)
print(' '.join([str(i) for i in ans]))

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
tree = [[] for _ in range(N)]

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

X = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    X[p-1] += x

ans = [0]*N

def dfs(u, parent=None):
    """
    u: 子ノード
    parent: 親ノード
    """
    ans[u] = ans[parent] + X[u]
    for v in tree[u]:
        if v != parent:
            dfs(v, u)

dfs(0, 0)
print(' '.join([str(i) for i in ans]))
Problem p02993 (python)

Fixed submission:
s = input()
l = len(s)
ans = 0

for i in range(l-1):
    if s[i] == s[i+1]:
        ans +=1

if ans == 0:
    print('Good')
if ans !=0:
    print('Bad')

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
ans = 0

for i in range(l):
    for k in range(i,k) :
        if s[i] == s[k]:
            ans += 1

if ans == 0:
    print('Good')
if ans !=0:
    print('Bad')
Problem p02996 (python)

Fixed submission:
N=int(input())
ba=[list(map(int,input().split()))[::-1]for _ in range(N)]
ba.sort()
 
time=0
ans='Yes'
for b,a in ba:
    time+=a
    if time>b:
        ans='No'
print(ans)

Buggy submission (verdict: Runtime Error):
5
2 4
1 9
1 8
4 9
3 12
Problem p03469 (python)

Fixed submission:
S = input()
print("2018"+S[4::])

Buggy submission (verdict: Runtime Error):
n = int(input())
d = [int(input()) for i in range(n)]
ans = []
 
for i in range(n):
    if d[i] not in ans:
        ans.append(d[i])
 
print(len(ans))
Problem p03611 (python)

Fixed submission:
import collections
n = int(input())
l = sorted(list(map(int, input().split())) )
c = collections.Counter(l)
L = [0]*(10**5+1)
M = [0]*(10**5+1)
 
for x,y in c.items():
    L[x] += y
 
M[0] = L[0]
M[10**5] = L[10**5]
for i in range(1,10**5):
    M[i] = L[i-1] + L[i] + L[i+1]
print(max(M))

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())
l = sorted(list(map(int, input().split())) )
c = collections.Counter(l)
L = [0]*10**5
M = [0]*10**5

for x,y in c.items():
    L[x-1] += y

M[0] = L[0]
M[n] = L[n]
for i in range(1,10**5-1):
    M[i] = L[i-1] + L[i] + L[i+1]
print(max(M))