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

Fixed submission:
n, k = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
l = l[::-1]
res = 0
for i in range(k):
    res += l[i]
print(res)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
l = list(map(int,input().split()))
l.sort()[::-1]
res = 0
for i in range(k):
    res+=l[i]
print(res)
Problem p03665 (python)

Fixed submission:
def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check(a):
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
def check(a):
    for i in a:
        if i%2:
            return True
    return False

n,p = map(int, input().split())
a = list(map(int,input().split()))
if check():
    print(2**(n-1))
elif p==0:
    print(2**n)
else:
    print(0)
Problem p03696 (python)

Fixed submission:
n = int(input())
s = input()
r = 0
l = 0
cnt = 0
for i in s:
    if i==')':
        cnt+=1
        if cnt>0:
            cnt-=1
            l+=1
    else:
        cnt-=1
print(l*'('+s+')'*(-cnt))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
t = s
r = 0
l = 0
id=n-1
while t[id]=='(':
    r+=1
    id-=1
t = t[:id+1]
id = 0
while id<len(t) and t[id]==')':
    l+=1
    id+=1
t = t[id:]
if t.count('(')>t.count(')'):
    r+=t.count('(')-t.count(')')
else:
    l+=t.count(')')-t.count('(')
print('('*l+s+')'*r)
Problem p03760 (python)

Fixed submission:
a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        if i//2>=len(b):
            continue
        print(b[i//2],end='')
    else:
        if i//2 >= len(a):
            continue
        print(a[i//2],end='')
print()

Buggy submission (verdict: Runtime Error):
a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        print(a[i//2],end='')
    else:
        print(b[i//2],end='')
print()

Buggy submission (verdict: Runtime Error):
a= input()
b = input()
for i in range(len(a)*2):
    if i%2:
        print(a[i/2],end='')
    else:
        print(b[i/2],end='')
print()
Problem p02641 (python)

Fixed submission:
x , n = map(int , input().split())
b = []
if n!=0:
    b = list(map(int,input().split()))
t = 0
ans = 0
while 1:
    if x-t not in b:
        ans = x - t
        break
    if x+t not in b:
        ans = x + t
        break
    t += 1
print(ans)

Buggy submission (verdict: Runtime Error):
x , n = map(int , input().split())
b = list(map(int,input().split()))
for i in b:
    a[i] = 1
t = 1
ans = 0
while 1:
    if x-t not in b:
        ans = x - t
        break
    if x+t not in b:
        ans = x + t
        break
    t += 1
print(ans)

Buggy submission (verdict: Runtime Error):
x , n = map(int , input().split())
a = [0] * 101
b = list(map(int,input().split()))
for i in b:
    a[i] = 1
t = 1
ans = 0
while 1:
    if a[x-t] == 0:
        ans = x - t
        break
    if a[x+t] == 0:
        ans = x + t
        break
    t += 1
print(ans)
Problem p02555 (python)

Fixed submission:
import numpy as np
from functools import reduce


mod = 10**9+7
def cmb(R,B):
    numerator = reduce(lambda x,y: x * y % mod, [R+B-k for k in range(B)])
    denominator = reduce(lambda x, y: x * y % mod, [B-k for k in range(B)])
    return numerator * pow(denominator, mod - 2, mod) % mod


S = int(input())
p = S // 3
A = 0

for b in range(p):

    r = S-3*(b+1)

    if b == 0:
        A+=1
    else:
        A+=cmb(r,b)

print(A%mod)

Buggy submission (verdict: Runtime Error):
S = int(input())
p = S // 3
A = 0

for b in range(p):

    r = S-3*(b+1)

    if b == 0:
        A+=1
    else:

        x = 1
        y = 1
        z = 1
        for k in range(r+b):
            x *= k+1
        for k in range(r):
            y *= k+1
        for k in range(b):
            z *= k+1

        A += int(x/(y*z))


print(int(A%(10**9+7)))
Problem p03161 (python)

Fixed submission:
import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

N,K=map(int,input().split())
height_list=list(map(int,input().split()))
score_list=[ 0, abs(height_list[0]-height_list[1]) ]



for i in range(2,N):
    tmp_list = []
    for k in range(K):
        tmp_list.append(abs(height_list[i]-height_list[i-k-1])+score_list[i-k-1])
    score_list.append(min(tmp_list))

print(score_list[N-1])

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
height_list=list(map(int,input().split()))
score_list=[ 0, abs(height_list[0]-height_list[1]) ]



for i in range(2,N):
    tmp_list = []
    for k in range(K):
        tmp_list.append(abs(height_list[i]-height_list[i-k-1])+score_list[i-k-1])
    score_list.append(min(tmp_list))

print(score_list[N-1])
Problem p02574 (python)

Fixed submission:
import numpy as np
n=int(input())
a=list(map(int, input().split()))

if np.gcd.reduce(a) != 1:
    print('not coprime')
    exit()

m=max(a)
cnt=[0]*(m+1)

for i in range(len(a)):
    cnt[a[i]]+=1
#print(cnt)
for i in range(2, m + 1):
    #print(cnt[i::i])
    if sum(cnt[i::i]) > 1:
        print('setwise coprime')
        exit()

print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=list(map(int, input().split()))

if np.gcd.reduce(a) != 1:
    print('not coprime')
    exit()

N=max(a)+1
A=list(range(2,N))
p=list()

while A[0]**2<=N:
	tmp=A[0]
	p.append(tmp)
	A=[e for e in A if e%tmp!=0]
l=p+A

#print(l)
for i in range(len(a)):
    count=0
    for j in range(len(l)):
        if a[i]%l[j]==0:
            count+=1
            if count > 1:
                print('setwise coprime')
                exit() 
    #print(count) 

print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=list(map(int, input().split()))

if np.gcd.reduce(a) != 1:
    print('not coprime')
    exit()

N=max(a)+1
A=list(range(2,N))
p=list()

while A[0]**2<=N:
	tmp=A[0]
	p.append(tmp)
	A=[e for e in A if e%tmp!=0]
l=p+A

print(l)
for i in range(len(a)):
    count=0
    for j in range(len(l)):
        if a[i]%l[j]==0:
            count+=1
            if count > 1:
                print('setwise coprime')
                exit() 
    #print(count) 

print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=list(map(int, input().split()))

N=max(a)+1
A=list(range(2,N))
p=list()
c=[0]*max(a)

while A[0]**2<=N:
	tmp=A[0]
	p.append(tmp)
	A=[e for e in A if e%tmp!=0]
l=p+A

for i in range(len(a)):
    for j in range(len(l)):
        if a[i]%l[j]==0:
            c[l[j]-1]+=1

#print(c)
maxcount=max(c)
if np.gcd.reduce(a) != 1:
    print('not coprime')
elif maxcount <= 1:
    print('pairwise coprime')
else:
    print('setwise coprime')
Problem p02642 (python)

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

a.sort()
dp = [True] * a[-1]
ans = 0

for i,num in enumerate(a):
    if dp[num-1]:
        j= 2 * num
        while j <= a[-1]:
            dp[j-1] = False
            j += num
        if not i+1==len(a):
            if a[i]==a[i+1]:
                dp[num-1] = False

for k in a:
    if dp[k-1]:
        ans += 1

#print(dp)
print(ans)

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

l = sorted(a)
tmp = l
ans = []
ans.append(tmp[0])

#print(l)

for i in range(n):
    tmp = [s for s in tmp if s % ans[0] != 0]
    #print(tmp)
    if tmp != []:
        if tmp[0] not in ans:
            ans.insert(0,tmp[0])

if len(ans) == 1 and l[0] == l[1]:
    print(0)
else:
    print(len(ans))
Problem p02684 (python)

Fixed submission:
a,b=map(int, input().split())
c=list(map(int, input().split())) 
 
l = [1]
f = [0]*a
f[0] += 1
tmp = 1
s = 0
for i in range(b):
    l.append(c[tmp-1])
    tmp = c[tmp-1]
    if f[tmp-1] != 0:
        s = c[tmp-1]
        t = len(l)+1
        break
    f[tmp-1] += 1

#print(l)
if a > b:
    print(l[b])
    exit()

h = l.index(s) + 1

#print(s,h,t)
l2 = l[h-1:t-1]
#print(l2)
if s == 1:
    id = b % (t - 1)
    print(l2[id])
else:
    id = (b - h + 1) % (t - h)
    print(l2[id])

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())
c=list(map(int, input().split())) 
 
l = [1]
tmp = 1
s = 0
for i in range(b):
    l.append(c[tmp-1])
    tmp = c[tmp-1]
    d = l.count(l[i])
    if d > 1:
        s = l[i]
        t = i + 1
        break

#print(l)
if a > b:
    print(l[b])
    exit()

h = l.index(s) + 1

#print(s,h,t)
l2 = l[h-1:t-1]
#print(l2)
if s == 1:
    id = b % (t - 1)
    print(l2[id])
else:
    id = (b - h + 1) % (t - h)
    print(l2[id])

Buggy submission (verdict: Runtime Error):
a,b=map(int, input().split())
c=list(map(int, input().split())) 
 
l = [1]
tmp = 1
s = 0
for i in range(b):
    l.append(c[tmp-1])
    tmp = c[tmp-1]
    d = l.count(l[i])
    if d > 1:
        s = l[i]
        break

tmp2 = [i for i, x in enumerate(l) if x == s]
h = tmp2[0]+1
t = tmp2[1]+1
 
#print(s,h,t)
l2 = l[h-1:t-1]
#print(l2)
if s == 1:
    id = b % (t - 1)
    print(l2[id])
else:
    id = (b - h + 1) % (t - h)
    print(l2[id])
Problem p02690 (python)

Fixed submission:
x=int(input())
a = 0
b = 0

for i in range(1000):
    for j in range(1,1000):
        tmp = (i*i*i*i*i) + (j*j*j*j*j)
        if x == tmp:
            a = i
            b = -j
            break

for i in range(1000):
    for j in range(1,1000):
        tmp = (i*i*i*i*i) - (j*j*j*j*j)
        if x == tmp:
            a = i
            b = j
            break

print(a,b)

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

b = -1
for i in range(100000):
    tmp = i*i*i*i*i + 1
    if x == tmp:
        a = i
        break

print(a,b)
Problem p02761 (python)

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

for i in range(n):
    r.append(str(0))

if n == 1 and m == 0:
    print('0')
    exit()
if n == 2 and m == 0:
    print('10')
    exit()
if n == 3 and m == 0:
    print('100')
    exit()

for i in range(m):
    s,c = map(int, input().split())
    if n == 1 and s == 1 and c == 0:
        print('0')
        exit()
    elif n > 1 and s == 1 and c == 0:
        print('-1')
        exit()

    if int(r[s-1]) == 0:
        r[s-1] = str(c)
    elif int(r[s-1]) == c:
        r[s-1] = str(c)
    else:
        print('-1')
        exit()

if n > 1 and r[0] == '0':
    r[0] = '1'
    print(''.join(r))
else:
    print(''.join(r))

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

for i in range(n):
    r.append(str(0))

if n != 1 and m == 0:
    print('-1')
    exit()

for i in range(m):
    s,c = map(int, input().split())
    if n == 1 and r[0] == '0':
        print('0')
        exit()
    elif n > 1 and s == 1 and c == 0:
        print('-1')
        exit()

    if int(r[s-1]) == 0:
        r[s-1] = str(c)
    elif int(r[s-1]) == c:
        r[s-1] = str(c)
    else:
        print('-1')
        exit()

if n > 1 and r[0] == '0':
    r[0] = 1
    print(''.join(r))
else:
    print(''.join(r))

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

for i in range(n):
    r.append(str(0))

for i in range(m):
    s,c = map(int, input().split())
    if n > 1 and s ==1 and c == 0:
        print('-1')
        exit()

    if int(r[s-1]) == 0:
        r[s-1] = str(c)
    elif int(r[s-1]) == c:
        r[s-1] = str(c)
    else:
        print('-1')
        exit()
         
if n == 1 and r[0] == '0':
    print('0')
elif n > 1 and r[0] == '0':
    r[0] = 1
    print(''.join(r))
else:
    print(''.join(r))

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

for i in range(m):
    r.append(str(0))

for i in range(m):
    s,c = map(int, input().split())
    if r[s-1] != '0' and int(r[s-1]) < c:
        r[s-1] = r[s-1]
    else:
        r[s-1] = str(c)
    
if m == 1 and r[0] == '0':
    print(0)
elif r[0] == '0':
    print('-1')
else:
    print(''.join(r))

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

for i in range(m):
    r.append(str(0))

for i in range(m):
    s,c = map(int, input().split())
    r[s-1] = str(c)

if r[0] == '0':
    print('-1')
else:
    print(''.join(r))
Problem p02772 (python)

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

for i in range(n):
    if a[i] % 2 == 0 and (a[i] % 3 != 0 and a[i] % 5 != 0):
        print('DENIED')
        tmp = 1
        break

if tmp == 0:
    print('APPROVED')

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

for i in range(n):
    if a[i] % 2 == 0 and (a[i] % 3 != 0 and a[i] % 5 != 0):
        print('DENIED')
        tmp = 1
        break

if tmp == 0:
    rint('APPROVED')
Problem p02553 (python)

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

print(max(a*c, a*d, b*c, b*d))

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

print(max(a*c, a*d, b*c, b*d))
Problem p02802 (python)

Fixed submission:
n,m = map(int,input().split())
lis = [list(input().split()) for _ in range(m)]

dp = [[0 for _ in range(2)] for _ in range(n)] # AC_flg, WA数

for i in range(m):
    if dp[int(lis[i][0])-1][0]==1:
        continue
    else:
        if lis[i][1]=='WA':
            dp[int(lis[i][0])-1][1] += 1
        if lis[i][1]=='AC':
            dp[int(lis[i][0])-1][0] = 1

ac = 0
wa = 0

for i in range(n):
    if dp[i][0]==1:
        ac += 1
        wa += dp[i][1]

print(ac,wa)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
lis = [list(input().split()) for _ in range(m)]

dp = [[0 for _ in range(2)] for _ in range(n)] # AC_flg, WA数

for i in range(m):
    if dp[i][0]==1:
        continue
    else:
        if lis[i][1]=='WA':
            dp[int(lis[i][0])][1] += 1
        if lis[i][1]=='AC':
            dp[int(lis[i][0])][0] = 1

ac = 0
wa = 0

for i in range(n):
    if dp[i][0]==1:
        ac += 1
        wa += dp[i][1]

print(ac,wa)
Problem p02918 (python)

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

ans  = 0
tran = 0

for i in range(n-1):
    chk = s[i] + s[i+1]

    if chk == 'LR' or chk == 'RL':
        tran += 1
    else:
        ans += 1

if k*2 >= tran:
    print(n-1)
else:
    print(ans+(k*2))

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

ans  = 0
tran = 0

for i in range(n):
    chk = s[i] + s[i+1]

    if chk == 'LR' or chk == 'RL':
        tran += 1
    else:
        ans += 1

if k*2 >= tran:
    print(n-1)
else:
    print(tran+(k*2))
Problem p02936 (python)

Fixed submission:
from collections import deque
# from collections import Counter
# from itertools import accumulate
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n,q = map(int,input().split())

road = [[] for _ in range(n)]
cnt  = [0 for _ in range(n)]

for i in range(n-1):
    a,b = map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)

for i in range(q):
    idx,v = map(int,input().split())
    cnt[idx-1] += v

dist = [-1]*n
que  = deque()
dist[0] = 0
que.append(0)

while(len(que)!=0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r]!=-1:
            continue
        dist[r] = dist[v] + 1
        cnt[r] += cnt[v]
        que.append(r)

print(*cnt)

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

road = [[] for _ in range(n)]
cnt  = [0 for _ in range(n)]

for i in range(n-1):
    a,b = map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)

for i in range(q):
    idx,v = map(int,input().split())
    cnt[idx-1] = v

dist = [-1]*n
que  = deque()
dist[0] = 0
que.append(0)

while(len(que)!=0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r]!=-1:
            continue
        dist[r] = dist[v] + 1
        cnt[r] += cnt[v]
        que.append(r)

print(*cnt)
Problem p02945 (python)

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

print(max(a+b,a-b,a*b))

Buggy submission (verdict: Runtime Error):

a,b=int(input().split())

print(max(a*b,a-b,a+b))
Problem p02947 (python)

Fixed submission:
from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n = int(input())

clist = [''.join(sorted(input())) for _ in range(n)]

c = Counter(clist)

print(sum([v*(v-1)//2 for v in c.values()]))

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

clist = [None for _ in range(n)]
cnt   = 0

for i in range(n):
    clist[i] = Counter(input())

for i in range(n):
    if i < n:
        for j in range(i+1,n):
            if clist[i] == clist[j]:
                cnt += 1

print(cnt)
Problem p02973 (python)

Fixed submission:
import bisect
# from collections import deque
# from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt
 
n = int(input())
li = [int(input()) for i in range(n)]
li = [-x for x in li]

X = []
X.append(li[0])

for i in range(1,n):
    idx = bisect.bisect_right(X,li[i])
    if idx==len(X):
        X.append(li[i])
    else:
        X[idx] = li[i]

print(len(X))

Buggy submission (verdict: Runtime Error):
def bisect_left_reverse(a, x):
    '''
    reverseにソートされたlist aに対してxを挿入できるidxを返す。
    xが存在する場合には一番左側のidxとなる。
    '''
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok
 
n = int(input())
li = [int(input()) for i in range(n)]
 
tmp = [li[0]]
minli = li[0]
 
for i in range(1,n):
    if li[i] <= minli:
        minli = li[i]
        tmp.append(li[i])
    else:
        idx = bisect_left_reverse(tmp,li[i])
        tmp[idx] = li[i]
 
print(len(tmp))
Problem p03014 (python)

Fixed submission:
# import itertools
# import pprint
# import copy
# from collections import deque

h,w   = map(int,input().split())
mp    = list(list(input()) for i in range(h))
scx   = [[0 for _ in range(w)] for _ in range(h)]
scy   = [[0 for _ in range(w)] for _ in range(h)]
donex = [[0 for _ in range(w)] for _ in range(h)]
doney = [[0 for _ in range(w)] for _ in range(h)]
sc    = 0
ans   = 0

for y in range(h):
  for x in range(w):
    if mp[y][x]=='#':
      scx[y][x]==0
    elif donex[y][x]==1:
      continue
    else:
      l = 1
      while(x+l<w):
        if mp[y][x+l]=='#':
          break
        l += 1
      for i in range(l):
        scx[y][x+i] = l
        donex[y][x+i] = 1

for y in range(h):
  for x in range(w):
    if mp[y][x]=='#':
      scy[y][x]==0
    elif doney[y][x]==1:
      continue
    else:
      l = 1
      while(y+l<h):
        if mp[y+l][x]=='#':
          break
        l += 1
      for i in range(l):
        scy[y+i][x] = l
        doney[y+i][x] = 1

for y in range(h):
  for x in range(w):
    ans = max(ans, (scy[y][x] + scx[y][x] - 1))

print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
li  = list(list(input()) for i in range(h))
sc  = [[0]*w for j in range(h)]
ans = 0

def chk_l(y,x,score):
  if x==0:
    return score
  
  if li[y][x-1]=='.':
    score += 1
    return chk_l(y,x-1,score)
  else:
    return score

def chk_r(y,x,w,score):
  if x==w-1:
    return score

  if li[y][x+1]=='.':
    score += 1
    return chk_r(y,x+1,w,score)
  else:
    return score

def chk_t(y,x,score):
  if y==0:
    return score
  
  if li[y-1][x]=='.':
    score += 1
    return chk_t(y-1,x,score)
  else:
    return score

def chk_b(y,x,h,score):
  if y==h-1:
    return score
  
  if li[y+1][x]=='.':
    score += 1
    return chk_b(y+1,x,h,score)
  else:
    return score

for y in range(h):
  for x in range(w):
    if li[y][x]=='#':
      continue
    score = 1
    score = chk_l(y,x,score)
    score = chk_r(y,x,w,score)
    score = chk_t(y,x,score)
    score = chk_b(y,x,h,score)
    sc[y][x] = score

for y in range(h):
  for x in range(w):
    ans = max(ans,sc[y][x])

print(ans)
Problem p03044 (python)

Fixed submission:
from collections import deque
# from fractions import gcd # >=Python3.5
# from math import gcd # <Python3.5

n  = int(input())
li = [list(map(int,input().split())) for i in range(n-1)]

road = [[] for i in range(n)]
cost = [[] for i in range(n)]

for i in li:
  i[0]-=1
  i[1]-=1
  road[i[0]].append(i[1])
  road[i[1]].append(i[0])
  cost[i[0]].append(i[2]%2)
  cost[i[1]].append(i[2]%2)

dist = [-1]*n
que  = deque()
dist[0] = 0
que.append(0)

while(len(que)!=0):
  # BFS/DFS
  v = que.popleft()
  for i,r in enumerate(road[v]):
    if dist[r]!=-1:
      continue
    dist[r] = (dist[v]+cost[v][i])%2
    que.append(r)

print(*dist,sep='\n')

Buggy submission (verdict: Runtime Error):
n    = int(input())
li   = [list(map(int,input().split())) for i in range(n-1)]
clr  = [0]*n
done = [0]*n
tmp  = 0

print(li)

for i in li:
  if i[0]>i[1]:
    tmp  = i[0]
    i[0] = i[1]
    i[1] = tmp
  i[2] %= 2

li.sort()

for i in li:
  if done[i[0]-1]==0 and done[i[1]-1]==0:
    if i[2]==1:
      i[1] = i[0]^1
    done[i[0]-1] = 1
    done[i[1]-1] = 1
  elif done[i[0]-1]==1 and done[i[1]-1]==0:
    if i[2]==1:
      i[1] = i[0]^1
    done[i[1]-1] = 1
  elif done[i[0]-1]==0 and done[i[1]-1]==1:
    if i[2]==1:
      i[0] = i[1]^1
    done[i[0]-1] = 1
  else:
    continue

for i in clr:
  print(i)
Problem p02768 (python)

Fixed submission:
from math import factorial
N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

def calc(n):
    ret = 1
    for i in range(n):
        ret = ret * (N - i) % MOD
    return ret * pow(factorial(n), MOD - 2, MOD) % MOD

print(max(0, (pow(2, N, MOD) - ((calc(A) + calc(B)) % MOD) - 1) % MOD))

Buggy submission (verdict: Runtime Error):
import math

MOD = 10 ** 9 + 7


def cmb(n, r):
    total = 1
    for i in range(r):
        total *= (n - i) % MOD
    return total * pow(math.factorial(r), MOD - 2, MOD) % MOD


def calc(n, r):
    ret = 1
    for i in range(r):
        ret = ret * (n - i) % MOD
    return ret * pow(factorial(r), MOD - 2, MOD) % MOD


if __name__ == '__main__':
    n, a, b = list(map(int, input().split(" ")))

    total = pow(2, n, MOD)
    a_total = calc(n, a)
    b_total = calc(n, b)
    print((total - a_total - b_total - 1) % MOD)
Problem p02780 (python)

Fixed submission:
from collections import deque

if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    d = deque([0])
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        max_sum = max(max_sum, d[i + k] - d[i])
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum / 2) + (k * 0.5))

Buggy submission (verdict: Runtime Error):
if __name__ == '__main__':
    n, k = list(map(int, input().split(" ")))
    p = list(map(int, input().split(" ")))

    d = deque([0])
    for i in range(n):
        d.append(d[i] + p[i])

    # print(d)

    max_sum = 0
    rangeN = n - k + 1

    for i in range(rangeN):
        max_sum = max(max_sum, d[i + k] - d[i])
    # print(max_sum)

    # r_array = [sum(p[i:i + k]) for i in range(rangeN)]
    print((max_sum / 2) + (k * 0.5))