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

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

for i in range(1,10001):
    if (i*0.08)//1==a and (i*0.1)//1==b:
        print(i)
        exit()
print(-1)

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

p1 = int(a // 0.08 + 1)
p2 = int(b // 0.1 + 1)

p1_list = [i for i in range(p1,p1+13)]
p2_list = [i for i in range(p2,p2+10)]

p_list = set(p1_list) & set(p2_list)

p_list = list(p_list)
p_list = sorted(p_list)

print(p_list[0])
Problem p02995 (python)

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

#c,d,lcm(c,d)の倍数がa~bの区間にいくつあるか調べる関数
def check(p):
    if a%p==0:
        e = a//p
    else:
        e = (a//p) +1

    if b%p==0:
        f = b//p
    else:
        f = (b//p)
        
    return(f-e+1)
        

lcm = (c*d)//gcd(c,d)
    
ans = b-a+1 -(check(c)+check(d)) +check(lcm)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b, c, d = map(int, input().split())

#c,d,lcm(c,d)の倍数がa~bの区間にいくつあるか調べる関数
def check(p):
    if a%p==0:
        e = a//p
    else:
        e = (a//p) +1

    if b%p==0:
        f = b//p
    else:
        f = (b//p)
        
    return(f-e+1)
        

lcm = (c*d)//gcd(c,d)
    
ans = b-a+1 -(check(c)+check(d)) +check(lcm)
print(ans)
Problem p03061 (python)

Fixed submission:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n=int(input())
lst=sorted(map(int,input().split()))

p=make_divisors(lst[0])
q=make_divisors(lst[1])
pq=set(p+q)
pq=sorted(pq)
for i in range(len(pq)-1,-1,-1):
    out=0
    for j in lst:
        if j%pq[i]!=0:
            out+=1
    if out<=1:
        print(pq[i])
        exit()

Buggy submission (verdict: Runtime Error):
from sympy import divisors

n=int(input())
lst=sorted(map(int,input().split()))

p=divisors(lst[0])
q=divisors(lst[1])
pq=set(p+q)
pq=sorted(pq)
for i in range(len(pq)-1,-1,-1):
    out=0
    for j in lst:
        if j%pq[i]!=0:
            out+=1
    if out<=1:
        print(pq[i])
        exit()
Problem p03076 (python)

Fixed submission:
a=[]
for i in range(5):
    a.append(int(input()))

zako=9
switch=0
for i in range(5):
    b=a[i]%10
    if b<=zako and b!=0:
        zako=b
        memory=i
        switch=1

if switch==0:
    memory=1
x=a.pop(memory)

lst=[]

for i in range(4):
    c=a[i]//10
    c=c*10
    if a[i]%10!=0:
        c+=10
    lst.append(c)

print(x+sum(lst))

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(5):
    a.append(int(input()))

zako=9
switch=0
for i in range(5):
    b=a[i]%10
    if b<=zako and b!=0:
        zako=b
        memory=i
        switch=1

if switch=0:
    memory=1
x=a.pop(memory)

lst=[]

for i in range(4):
    c=a[i]//10
    c=c*10
    if a[i]%10!=0:
        c+=10
    lst.append(c)

print(x+sum(lst))

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(5):
    a.append(int(input()))

zako=9
for i in range(5):
    b=a[i]%10
    if b<=zako and b!=0:
        zako=b
        memory=i
x=a.pop(memory)

lst=[]

for i in range(4):
    c=a[i]//10
    c=c*10
    if a[i]%10!=0:
        c+=10
    lst.append(c)

print(x+sum(lst))

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(5):
    a.append(int(input()))

zako=9
for i in range(5):
    b=a[i]%10
    if b<zako and b!=0:
        zako=b
        memory=i
x=a.pop(memory)

lst=[]

for i in range(4):
    c=a[i]//10
    c=c*10
    if a[i]%10!=0:
        c+=10
    lst.append(c)

print(x+sum(lst))
Problem p03240 (python)

Fixed submission:
n=int(input())
lst=[None]*n
for i in range(n):
    a,b,c=map(int,input().split())
    lst[i]=[a,b,c]
lst=sorted(lst,key=lambda x:x[2],reverse=True)
for i in range(101):
    for j in range(101):
        switch=0
        x,y,z=lst[0]
        height=z+abs(i-x)+abs(j-y)
        for k in range(1,n):
            x,y,z=lst[k]
            if z==0:
                if abs(i-x)+abs(j-y)<height:
                    switch=1
                    break
            elif abs(i-x)+abs(j-y)+z!=height:
                switch=1
                break
        if switch==0:
            print(i,j,height)

Buggy submission (verdict: Runtime Error):
n=int(input())
if n==2:
  a=3/0
lst=[None]*n
for i in range(n):
    a,b,c=map(int,input().split())
    lst[i]=[a,b,c]
for i in range(101):
    for j in range(101):
        switch=0
        x,y,z=lst[0]
        height=z+abs(i-x)+abs(j-y)
        for k in range(1,n):
            x,y,z=lst[k]
            if abs(i-x)+abs(j-y)+z!=height:
                switch=1
                break
        if switch==0:
            print(i,j,height)
Problem p03282 (python)

Fixed submission:
s=list(input())
k=int(input())
for i in range(len(s)):
    if s[i]!="1":
        p=i+1
        pnum=int(s[i])
        break
    p=101

if k<p:
    print(1)
else:
    print(pnum)

Buggy submission (verdict: Runtime Error):
s=list(input())
k=int(input())
for i in range(100):
    if s[i]!="1":
        p=i+1
        pnum=int(s[i])
        break

if k<p:
    print(1)
else:
    print(pnum)
Problem p03659 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
left_ruiseki=[a[0]]
for i in range(1,n):
    left_ruiseki.append(left_ruiseki[i-1]+a[i])
a.reverse()
right_ruiseki=[a[0]]
for i in range(1,n):
    right_ruiseki.append(right_ruiseki[i-1]+a[i])

ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_ruiseki[i]-right_ruiseki[-i-2]))
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
from numpy import cumsum
left_cumsum=cumsum(a)
a.reverse()
right_cumsum=cumsum(a)
ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_cumsum[i]-right_cumsum[-i-2]))
print(ans)
Problem p03720 (python)

Fixed submission:
n,m=map(int,input().split())
lst=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    lst[a-1]+=1
    lst[b-1]+=1

for i in lst:
    print(i)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
lst=[0]*m

for i in range(m):
    a,b=map(int,input().split())
    lst[a-1]+=1
    lst[b-1]+=1

for i in lst:
    print(i)
Problem p03732 (python)

Fixed submission:
N,W=map(int,input().split())
w1,v=map(int,input().split())
if w1>W:
    print(0)
    exit()
lst=[[-1]*(3*N-2) for _ in range(N)]
lst[0][0]=v
for i in range(N-1):
    w,v=map(int,input().split())
    for j in range(N-1,-1,-1):
        for k in range(3*N-2):
            if lst[j][k]!=-1:
                if (j+1)*w1+k+w<=W:
                    lst[j+1][k+w-w1]=max(lst[j][k]+v,lst[j+1][k+w-w1])
    lst[0][w-w1]=max(v,lst[0][w-w1])

lst=[i for j in lst for i in j]
print(max(lst))

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
a,v=map(int,input().split())
w0=[v]
w1=[]
w2=[]
w3=[]
for i in range(N-1):
    w,v=map(int,input().split())
    if w-a==0:
        w0.append(v)
    elif w-a==1:
        w1.append(v)
    elif w-a==2:
        w2.append(v)
    else:
        w3.appned(v)
w0=sorted(w0,reverse=True)
w1=sorted(w1,reverse=True)
w2=sorted(w2,reverse=True)
w3=sorted(w3,reverse=True)
ans=0
for i in range(max(len(w0)+1,1)):
    for j in range(max(len(w1)+1,1)):
        for k in range(max(len(w2)+1,1)):
            for l in range(max(len(w3)+1,1)):
                if a*i+(a+1)*j+(a+2)*k+(a+3)*l<=W:
                    lst=w0[:i]+w1[:j]+w2[:k]+w3[:l]
                    ans=max(sum(lst),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
lst=[-1]*(W+1)
lst[0]=0

for i in range(N):
    w,v=map(int,input().split())
    for j in range(W-w,-1,-1):
        if lst[j]!=-1:
            Value=lst[j]+v
            if Value>lst[j+w]:
                lst[j+w]=Value

print(max(lst))

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
lst=[-1]*(W+1)
lst[0]=0

for i in range(N):
    w,v=map(int,input().split())
    for i in range(W-w,-1,-1):
        if lst[i]!=-1:
            Value=lst[i]+v
            if Value>lst[i+w]:
                lst[i+w]=Value

print(max(lst))
Problem p03814 (python)

Fixed submission:
s=input()
ans=False
for i,v in enumerate(s):
    if ans==False:
        if v=="A":
            a=i
            ans=True
    else:
        if v=="Z":
            z=i
print(z-a+1)

Buggy submission (verdict: Runtime Error):
s=input()
a=False
for i,v in enumerate(s):
    if a==False:
        if v=="A":
            a=i
    else:
        if v=="Z":
            z=i
print(z-a+1)
Problem p02684 (python)

Fixed submission:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

sys.setrecursionlimit(10 ** 7)

n, k = na()
a = na()

proc = [0] * n
def rec(i, cnt):
    if proc[i]:
        return (cnt, i)
    proc[i] = 1
    return rec(a[i] - 1, cnt + 1)

def rec2(i, arr):
    if proc[i] >= 2:
        return arr
    proc[i] += 1
    arr.append(i)
    return rec2(a[i] - 1, arr)

cnt, i = rec(0, 0)
arr = rec2(i, [])

nk = k
nk -= cnt - len(arr)
if nk < 0:
    ans = 0
    for i in range(k):
        ans = a[ans] - 1
    print(ans + 1)
else:
    print(arr[nk % len(arr)] + 1)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, k = na()
a = na()

proc = [0] * n
def rec(i, cnt):
    if proc[i]:
        return (cnt, i)
    proc[i] = 1
    return rec(a[i] - 1, cnt + 1)

def rec2(i, arr):
    if proc[i] >= 2:
        return arr
    proc[i] += 1
    arr.append(i)
    return rec2(a[i] - 1, arr)

cnt, i = rec(0, 0)
arr = rec2(i, [])

k -= cnt - len(arr)
print(arr[k % len(arr)] + 1)
Problem p02747 (python)

Fixed submission:
# Author: cr4zjh0bp
# Created: Sun Mar  8 12:16:38 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

s = ns()
n = len(s)
if n % 2 == 1:
    print("No")
else:
    i = 0
    cnt = 0
    while i < n - 1:
        if s[i] == 'h' and s[i + 1] == 'i':
            cnt += 2
        i += 2
    if cnt == n:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):

# Author: cr4zjh0bp
# Created: Sun Mar  8 11:28:28 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

s = ns()
n = len(s)
cnt = True
i = 0
flag = True
if n == 1:
    print("No")
else:
    while i < n:
        if s[i] != 'h' or s[i + 1] != 'i':
            flag = False
            break
        i += 2

    if flag:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
# Author: cr4zjh0bp
# Created: Sun Mar  8 11:28:28 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

s = ns()
n = len(s)
cnt = True
i = 0
flag = True
while i < n:
    if s[i] != 'h' or s[i + 1] != 'i':
        flag = False
        break
    i += 2

if flag:
    print("Yes")
else:
    print("No")
Problem p02780 (python)

Fixed submission:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n, k = na()
p = na()
d = [0] * (n + 1)
for i in range(n):
    a = (p[i] * (p[i] + 1) // 2) * (1 / p[i])
    d[i + 1] = d[i] + a

ans = 0.0
for i in range(n - k + 1):
    a = d[i + k] - d[i]
    ans = max(ans, a)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

import numpy as np

n, k = na()
p = na()
d = [0] * (n + 1)
for i in range(n):
    a = (p[i] * (p[i] + 1) // 2) * (1 / p[i])
    d[i + 1] = d[i] + a

ans = 0.0
for i in range(n - k + 1):
    a = d[i + k] - d[i]
    ans = max(ans, a)

print(ans)
Problem p02789 (python)

Fixed submission:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, m = na()
if n <= m:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, m = na()
if n <= m_:
    print("Yes")
else:
    print("No")
Problem p02841 (python)

Fixed submission:
# Author: cr4zjh0bp
# Created: Sat Mar 28 15:38:17 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

m, d = na()
m2, d2 = na()

if d + 1 != d2:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
# Author: cr4zjh0bp
# Created: Sun Mar 29 05:26:08 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
s = ns()

def ok(p):
    k = 0
    for i in range(n):
        if s[i] == p[k]:
            k += 1
        if k == 3:
            return True
    return False

ans = 0
for i in range(1000):
    p = "{:0>3}".format(i)
    if ok(p):
        ans += 1

print(ans)
Problem p02861 (python)

Fixed submission:
from itertools import permutations
from math import sqrt, pow

n = int(input())
x = []
y = []
for i in range(n):
    m = input().split()
    x.append(int(m[0]))
    y.append(int(m[1]))

l = []
for i in range(n):
    l.append(i)

p = list(permutations(l))
ave = 0
cnt = 0
for i in p:
    j = 0
    while (j < n - 1):
        ave += sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
        j += 1
    cnt += 1

res = ave / cnt
print(res)

Buggy submission (verdict: Runtime Error):
from itertools import permutations
from math import sqrt, pow

n = int(input())
x = []
y = []
for i in range(n):
    m = raw_input().split()
    x.append(int(m[0]))
    y.append(int(m[1]))

l = []
for i in range(n):
    l.append(i)

p = list(permutations(l))
ave = 0
cnt = 0
for i in p:
    j = 0
    while (j < n - 1):
        ave += sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
        j += 1
    cnt += 1

res = ave / cnt
print(res)
Problem p02936 (python)

Fixed submission:
# Author: cr4zjh0bp
# Created: Tue Mar 17 19:50:06 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

sys.setrecursionlimit(10 ** 6)

n, q = na()
ab = nan(n - 1)
px = nan(q)

tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = ab[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

cnt = [0 for _ in range(n)]
for i in range(q):
    p, x = px[i]
    p -= 1
    cnt[p] += x

def dfs(i, p, s):
    x = s + cnt[i]
    cnt[i] = x
    for j in tree[i]:
        if j == p:
            continue
        dfs(j, i, x)

def bfs():
    q = deque()
    q.append((0, -1, 0))
    while len(q):
        p, b, s = q.popleft()
        x = s + cnt[p]
        cnt[p] = x
        for i in tree[p]:
            if i == b:
                continue
            q.append((i, p, x))

bfs()
print(*cnt)

Buggy submission (verdict: Runtime Error):
# Author: cr4zjh0bp
# Created: Tue Mar 17 19:50:06 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, q = na()
ab = nan(n - 1)
px = nan(q)

tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = ab[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

cnt = [0 for _ in range(n)]
for i in range(q):
    p, x = px[i]
    p -= 1
    cnt[p] += x

def dfs(i, p, s):
    x = s + cnt[i]
    cnt[i] = x
    for j in tree[i]:
        if j == p:
            continue
        dfs(j, i, x)

dfs(0, -1, 0)
print(*cnt)
Problem p03166 (python)

Fixed submission:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

sys.setrecursionlimit(10 ** 6)

n, m = na()
xy = nan(m)

g = [[] for _ in range(n)]
for i in range(m):
    x, y = xy[i]
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * (n + 1)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return dp[v]

ans = 0
for v in range(n):
    ans = max(ans, dfs(v))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
xy = nan(m)

g = [[] for _ in range(n)]
for i in range(m):
    x, y = xy[i]
    x -= 1
    y -= 1
    g[x].append(y)

dp = [-1] * (n + 1)

def dfs(v):
    if dp[v] != -1:
        return dp[v]
    res = 0
    for nv in g[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return dp[v]

ans = 0
for v in range(n):
    ans = max(ans, dfs(v))

print(ans)
Problem p03244 (python)

Fixed submission:
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import Counter
from itertools import product

n = ni()
a = na()

even = Counter(a[::2])
odd = Counter(a[1::2])

even[-1] = 0
odd[-2] = 0

e = even.most_common(2)
o = odd.most_common(2)

ans = n
for (k1, v1), (k2, v2) in product(e, o):
    if k1 == k2:
        continue
    x = (n - v1 - v2)
    if ans > x:
        ans = x

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()

d = defaultdict(int)
b = defaultdict(int)

for i in range(1, n + 1):
	if i % 2 == 0:
		d[a[i - 1]] += 1
	else:
		b[a[i - 1]] += 1

d_mkey, d_mval = [0] * 2
b_mkey, b_mval = [0] * 2

for k, v in d.items():
	if d_mval < v:
		d_mkey = k
		d_mval = v

for k, v in b.items():
	if b_mval < v:
		b_mkey = k
		b_mval = v

if d_mkey != b_mkey:
	print(n - d_mval - b_mval)
else:
	p = list(d.values())
	q = list(b.values())
	p.sort()
	q.sort()
	pv = p[len(p) - 2]
	qv = p[len(q) - 2]
	if pv <= qv:
		print((n - d_mval) + (n // 2 - qv))
	else:
		print((n - b_mval) + (n // 2 - pv))