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

Fixed submission:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



ss = input()
n = len(ss)
s=[]
for i in range(n):
    s.append(int(ss[i]))

ans = 0
for i in range(2**(n-1)):
    d=[[]]
    bit = ValueToBits(i,n-1)
    for j in range(n-1):
        d[-1].append(s[j])
        if(bit[j]==1):
            d.append([])
    d[-1].append(s[n-1])
    #print(d)
    
    for j in d:
        for k in range(len(j)):
            ans += 10**(len(j)-1-k) * j[k]

            



print(ans)

Buggy submission (verdict: Runtime Error):

ss = input()
n = len(ss)
s=[]
for i in range(n):
    s.append(int(ss[i]))

ans = 0
for i in range(2**(n-1)):
    d=[[]]
    bit = ValueToBits(i,n-1)
    for j in range(n-1):
        d[-1].append(s[j])
        if(bit[j]==1):
            d.append([])
    d[-1].append(s[n-1])
    #print(d)
    
    for j in d:
        for k in range(len(j)):
            ans += 10**(len(j)-1-k) * j[k]

            



print(ans)
Problem p04015 (python)

Fixed submission:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a):
    return [0 for i in range(a)]

def Zeros(a,b):
    if(b<=0):
        return Zeros(a)
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



n,ave = list(map(int, input().split()))
a = list(map(int, input().split()))

dp = [Zeros(3000,n+1) for k in range(n+1)]

dp[0][0][0] = 1
for i in range(n):
    for j in range(2900):
        for k in range(n):
            dp[i+1][j+a[i]][k+1] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]

            
ans = 0
for k in range(n):
    ans+= dp[-1][ave*(k+1)][k+1]
print(ans)

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

dp = [Zeros(3000,n+1) for k in range(n+1)]

dp[0][0][0] = 1
for i in range(n):
    for j in range(2900):
        for k in range(n):
            dp[i+1][j+a[i]][k+1] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]

            
ans = 0
for k in range(n):
    ans+= dp[-1][ave*(k+1)][k+1]
print(ans)
Problem p04045 (python)

Fixed submission:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


n,k = list(map(int, input().split()))

a = list(map(int, input().split()))

for ii in range(n*10):
    i = ii+1
    ar = ValueToArray10(i, int(1+(math.log(i)+0.00001)/math.log(10)))
    ok=1
    for j in ar:
        for k in a:
            if(j==k):
                ok=0
    if(ok==1 and i>=n):
        print(i)
        exit()

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

a = list(map(int, input().split()))

for ii in range(n*10):
    i = ii+1
    ar = ValueToArray10(i, int(1+(math.log(i)+0.00001)/math.log(10)))
    ok=1
    for j in ar:
        for k in a:
            if(j==k):
                ok=0
    if(ok==1 and i>=n):
        print(i)
        exit()
Problem p02713 (python)

Fixed submission:
k=int(input())
z=range(1,k+1)
import math
from functools import reduce
sum=0
for i in z:
	for j in z:
		for jj in z:
			sum=sum+reduce(math.gcd,[i,j,jj])
print(sum)

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> product(z,z)
k=int(input())
z=range(1,k+1)
print(sum(gcd(i,gcd(j,k)) product(z,z,z)))

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
from itertools import product ##for i in z for j in z -> product(z,z)
k=int(input())
z=range(1,k+1)
print(sum(gcd(i,gcd(j,k)) product(z,z,z,z)))
Problem p02716 (python)

Fixed submission:
from math import gcd
from functools import reduce
 
n=int(input())
ar=list(map(int,input().split(' ')))
 
dp=[[-(10**20)]*6 for i in range(n+5)]+[[0]+[-(10**20)]*8 for i in range(3)]
 
 
#1> 2 3> 4  6> 7 8> 9 10 11> 12> 14
def cn(z,j):
	return (z-j+1)//2
ans=-(10**20)
for i in range(n):
	idx=int(i)
	dp[idx]=dp[idx-2].copy()
	for j in range(0,5):
			for k in range(j+1):
					dp[idx][j]=max(dp[idx][j],dp[idx-k-2][j-k])
	for j in range(5):
		dp[i][j]+=ar[i]
		if cn(i+1,j)==n//2:
			ans=max(ans,dp[i][j])
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
 
n=int(input())
ar=list(map(int,input().split(' ')))
 
if n%2==0:
	print(max(sum(ar[i] for i in range(0,n,2)),sum(ar[i] for i in range(1,n,2))))
	exit(0)
exit(1)	
dp=[[-(10**20)]*6 for i in range(n+5)]+[[0]+[-(10**20)]*8 for i in range(3)]
 
 
#1> 2 3> 4  6> 7 8> 9 10 11> 12> 14
def cn(z,j):
	return (z-j+1)//2
ans=-(10**20)
for i in range(n):
	idx=int(i)
	dp[idx]=dp[idx-2].copy()
	for j in range(0,5):
			for k in range(j+1):
					dp[idx][j]=max(dp[idx][j],dp[idx-k-2][j-k])
	for j in range(5):
		dp[i][j]+=ar[i]
		if cn(i+1,j)==n//2:
			ans=max(ans,dp[i][j])
print(ans)
Problem p03281 (python)

Fixed submission:
n=int(input())
ans=0
for i in range(1,n+1):
  if i % 2==0:
    continue
  cnt=0
  for j in range(1,n+1):
    if i%j==0:
      cnt=cnt+1
  if cnt==8:
    ans+=1
print(int(ans))

Buggy submission (verdict: Runtime Error):
n=input()
ans=0
for i in range(1,n):
  cnt=0
  for j in range(1,n):
    if i%j==0:
      cnt=cnt+1
  if cnt==8:
    ans+=1
print(int(ans))
Problem p03288 (python)

Fixed submission:
a=int(input())
if a<1200:
	print("ABC")
elif a<2800:
	print("ARC")
else:
	print("AGC")

Buggy submission (verdict: Runtime Error):
a=input()
if a<1200:
	print("ABC")
elif a<2800:
	print("ARC")
else:
  print("AGC")

Buggy submission (verdict: Runtime Error):
a=int(input())
if a<1200:
	print("ABC")
else if a<2800:
	print("ARC")
else:
  print("AGC")

Buggy submission (verdict: Runtime Error):
a=int(input())
if a<1500:
	print("ABC")
else if a<2800:
	print("ARC")
else:
  print("AGC")

Buggy submission (verdict: Runtime Error):
#a,b=map(int,input().split())
a=map(int,input())
if a<2800:
	print("ABC")
else:
	print("ARC")

Buggy submission (verdict: Runtime Error):
#a,b=map(int,input().split())
a=input()
if a<2800:
	print("ABC")
else:
	print("ARC")

Buggy submission (verdict: Runtime Error):
#a,b=map(int,input().split())
a=input()
if(a<2800):
	print("ABC")
else:
	print("ARC")
Problem p03292 (python)

Fixed submission:
a,b,c=map(int,input().split())
print(max(a,b,c)-min(a,b,c))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
mx =[0 for i in range(0,n)]
for z in range(0,m):
  a,b=map(int,input().split())
  mx[b-1]=max(mx[b-1],a-1)
cut=0
cn=0
for z in range(0,n):
  if cut<mx[z]:
   	cut=z
    cn=cn+1
print(cn)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
for i in range(0,len(a)):
  if a==b[i:]+b[:i] : 
    print("Yes")
    exit(0)
print("No")

Buggy submission (verdict: Runtime Error):
lis=map(int,input().split())
print(max(lis)-min(lis))
Problem p03293 (python)

Fixed submission:
a=input()
b=input()
z=len(a)
for i in range(0,z):
  if a==b[i:]+b[:i] : 
    print("Yes")
    exit(0)
print("No")

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
z=len(a)
for i in range(0,z):
  if a==b[i:]+b[:i] : 
    print("Yes")
    Exit(0)
print("No")
Problem p03294 (python)

Fixed submission:
n=int(input())
print(sum([int(j) for j in input().split()])-n)

Buggy submission (verdict: Runtime Error):
n=input()
print(sum([int(j) for j in input().split()])-n)
Problem p03359 (python)

Fixed submission:
# n objects m seller 
# Write your code here
import math
a,b=map(int,input().split());
ans=a;
if a>b : 
    ans=ans-1;
print(ans);

Buggy submission (verdict: Runtime Error):
# n objects m seller 
# Write your code here
import math
a,b=map(int,input().split());
ans=a;
if a>b : 
    ans--;
print(ans);
Problem p02621 (python)

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

Buggy submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.append(10**9+1)
B.append(10**9+1)

Ac = 0
Bc = 0
Time = 0
for _ in range(N+M):
    if A[Ac] > B[Bc]:
        Time += B[Bc]
        Bc += 1
        if Time > K:
            Bc -= 1
            Time -= B[Bc]
            break
    else:
        Time += A[Ac]
        Ac += 1
        if Time > K:
            Ac -= 1
            Time -= A[Ac]
            break
            
print(Ac+Bc)
Problem p03106 (python)

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


C = gcd(A,B)

y = []
for i in range(C):
    if C % (i+1) == 0:
        y.append(i+1)


print(y[::-1][K-1])

Buggy submission (verdict: Runtime Error):
import sympy

A,B,K = map(int, input().split())


C = sympy.gcd(A,B)

y = []
for i in range(C):
    if C % (i+1) == 0:
        y.append(i+1)


print(y[::-1][K-1])

Buggy submission (verdict: Runtime Error):
import math

A,B,K = map(int, input().split())


C = math.gcd(A,B)

y = []
for i in range(C):
    if C % (i+1) == 0:
        y.append(i+1)


print(y[::-1][K-1])
Problem p03138 (python)

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

binK = bin(K)[2:]
maC = 0

B = [0 for _ in [0]*40]

for i in range(N):
    C = bin(A[i])[2:][::-1]
    maC = max(maC,len(C))
    for j in range(len(C)):
        B[j] = B[j] + int(C[j])
        
an = 0

PPP = max(len(binK),maC)
KK = [int(t < N/2) for t in B[:len(binK)][::-1]]

for k in range(PPP):
    if k < len(binK):
        an = an + max(B[k], N-B[k])*(2**k)
    else:
        an = an + B[k]*(2**k)

#t = PPP-1 
#an1 = an + (N-B[t])*(2**t)
#an0 = an + (B[t])*(2**t)


#flag = 0
#if an0 >= an1:
#    print(an0)
#    flag = 1
#else:
for l in range(len(binK)):
    if int(binK[l]) > KK[l]:
        break
    if int(binK[l]) < KK[l]:
        ll = len(KK) - l -1
        an = an - max(B[ll], N-B[ll])*(2**ll) + min(B[ll], N-B[ll])*(2**ll)
            
#if flag < 1:
print(an)

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

binK = bin(K)[2:]
maC = 0

B = [0 for _ in [0]*40]

for i in range(N):
    C = bin(A[i])[2:][::-1]
    maC = max(maC,len(C))
    for j in range(len(C)):
        B[j] = B[j] + int(C[j])
        
an = 0

PPP = max(len(binK),maC)

KK = [int(t < N/2) for t in B[:len(binK)][::-1]]
for k in range(PPP-1):
    if k < len(binK):
        an = an + max(B[k], N-B[k])*(2**k)
    else:
        an = an + B[k]*(2**k)

t = PPP-1 
an1 = an + (N-B[t])*(2**t)
an0 = an + (B[t])*(2**t)


flag = 0
if an0 >= an1:
    print(an0)
    flag = 1
else:
    for l in range(t+1):
        if int(binK[l]) > KK[l]:
            break
        if int(binK[l]) < KK[l]:
            ll = len(KK) - l -1
            an1 = an1 - max(B[ll], N-B[ll])*(2**ll) + min(B[ll], N-B[ll])*(2**ll)
            
if flag < 1:
    print(max(an0,an1))
Problem p03331 (python)

Fixed submission:
N = int(input())
A = sum(list(map(int, list(str(N)))))
if A == 1:
    print(10)
else:
    print(A)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
if A == 1:
    print(5)
else:
    print(A)
Problem p02608 (python)

Fixed submission:
n = int(input())

f = [0] * (n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if s < n + 1:
                f[s] += 1

for i in range(n):
    print(f[i+1])

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

f = [0] * 1001

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if s <= 1000:
                f[s] += 1

for i in range(n):
    print(f[i+1])
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(min(X+Y, C)):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)

Buggy submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(C):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)
Problem p02782 (python)

Fixed submission:
u, l, d, r = map(int, input().split())
mod = 10 ** 9 + 7

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

f = [0] * (2 * 10 ** 6 + 10)
f[0] = 1
for i in range(1, 2 * 10 ** 6 + 10):
    f[i] = (f[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(f[a+b], f[a]), f[b])

ans = 0
d += 1
r += 1
ans += comb(d, r)
ans += comb(u, l)
ans -= comb(d, l)
ans -= comb(u, r)
print(ans % mod)

Buggy submission (verdict: Runtime Error):
u, l, d, r = map(int, input().split())
mod = 10 ** 9 + 7

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

f = [0] * (2 * 10 ** 6 + 2)
f[0] = 1
for i in range(1, 2 * 10 ** 6 + 2):
    f[i] = (f[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(f[a+b], f[a]), f[b])

ans = 0
d += 1
r += 1
ans += comb(d, r)
ans += comb(u, l)
ans -= comb(d, l)
ans -= comb(u, r)
print(ans % mod)
Problem p02922 (python)

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

ac = 1
ans = 0
while ac < b:
    ans += 1
    ac += a - 1

print(ans)

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

a = []
a.append(b[0])
for i in range(n-2):
    a.append(min(b[i], b[i+1]))
a.append(b[n-2])
print(sum(a))
Problem p02993 (python)

Fixed submission:
s = input()
ans = True
for i in range(3):
    ans = ans and (s[i] != s[i+1])
if ans: print('Good')
else: print('Bad')

Buggy submission (verdict: Runtime Error):
s = set(input())
ans = True
for i in range(3):
    ans = ans and (s[i] != s[i+1])
if ans: print('Good')
else: print('Bad')
Problem p03032 (python)

Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(n+1):
    for r in range(l, n+1):
        ava = sorted(v[:l] + v[r:])
        takeop = len(ava)
        if takeop <= k:
            value = sum(ava)
            for i in range(min(takeop, k - takeop)):
                if ava[i] >= 0:
                    break
                else:
                    value -= ava[i]
            maxvalue = max(maxvalue, value)
print(maxvalue)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(k+1):
    r = k - l
    leftmax = 0 
    for take in range(l+1):
        ava = sorted(v[:take])
        value = sum(ava)
        for back in range(min(take, l - take, n)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        leftmax = max(leftmax, value)
    rightmax = 0
    for take in range(r+1):
        ava = sorted(v[n-take:])
        value = sum(ava)
        for back in range(min(take, r - take, n)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        rightmax = max(rightmax, value)
    maxvalue = max(maxvalue, leftmax + rightmax)
print(maxvalue)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(k+1):
    r = k - l
    leftmax = 0 
    for take in range(l+1):
        ava = sorted(v[:take])
        value = sum(ava)
        for back in range(min(take, l - take)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        leftmax = max(leftmax, value)
    rightmax = 0
    for take in range(r+1):
        ava = sorted(v[n-take:])
        value = sum(ava)
        for back in range(min(take, r - take)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        rightmax = max(rightmax, value)
    maxvalue = max(maxvalue, leftmax + rightmax)
print(maxvalue)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    print(u, c)
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])
Problem p03111 (python)

Fixed submission:
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
inf = 10 ** 10
def dfs(k, a, b, c):
    if k == n:
        if 0 in (a,b,c):
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c) - 30
    ret = [0] * 4
    ret[0] = dfs(k+1, a + l[k], b, c) + 10
    ret[1] = dfs(k+1, a, b + l[k], c) + 10
    ret[2] = dfs(k+1, a, b, c + l[k]) + 10
    ret[3] = dfs(k+1, a, b, c)
    return min(ret)
print(dfs(0, 0, 0, 0))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))
mintime = 10**20
for i in range(n-k+1):
    left = x[i]
    right = x[i+k-1]
    abss = (abs(left), abs(right))
    if left * right >= 0:
        mintime = min(mintime, max(abss))
    else:
        mintime = min(mintime, min(abss) * 2 + max(abss))
print(mintime)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))
mintime = 10**20
for i in range(n-k+1):
    left = x[i]
    right = x[i+k-1]
    abss = (abs(left), abs(right))
    if left * right >= 0:
        mintime = min(mintime, max(abss))
    else:
        mintime = min(mintime, min(abss) * 2 + max(abss))
print(mintime)