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

Fixed submission:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(1)

    return arr

n = int(input())
ln = factorization(n)
ans = 0
for i in range(1, max(ln) + 1):

    ln = [x for x in ln if x >= i]
    ans += len(ln)
    ln = list(map(lambda x: x - i, ln))
    if sum(ln)==0:
        break
import sys

if n == 1:
    print(0)
    sys.exit()
print(ans)

Buggy submission (verdict: Runtime Error):
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(1)

    return arr

n = int(input())
ln = factorization(n)
ans = 0
for i in range(1, max(ln) + 1):
    for j in range(len(ln)):
        if ln[j] < i:
            ln.pop(j)
    ans += len(ln)
    ln = list(map(lambda x: x - i, ln))
    if ln == [] or sum(ln)==0:
        break
print(ans)
Problem p02664 (python)

Fixed submission:
s = list(str(input()))
for i in range(len(s)):
    if s[i] == '?':
        s[i] = 'D'
print(''.join(s))

Buggy submission (verdict: Runtime Error):
s = list(str(input()))
for i in range(len(s)):
    if s[-(i + 1)] == '?':
        if s[-(i + 2)] == 'P':
            s[-(i + 1)] = 'D'
        else:
            s[-(i + 1)] = 'D'
print(''.join(s))
Problem p02861 (python)

Fixed submission:
import math
a = int(input())
t = [list(map(int, input().split())) for i in range(a)]
x = 0
for i in range(a):
    for j in range(a):
        x = x + ((t[i][0]-t[j][0])**2 +(t[i][1]-t[j][1])**2)**0.5
print(x*math.factorial(a-1)/(math.factorial(a)))

Buggy submission (verdict: Runtime Error):
import math
import numpy as np
a = int(input())
t = [list(map(int, input().split())) for i in range(a)]
x = 0
for i in range(a):
    for j in range(a):
        x = x + np.sqrt((t[i][0]-t[j][0])**2 +(t[i][1]-t[j][1])**2)
print(x*math.factorial(a-1)/(math.factorial(a)))
Problem p02882 (python)

Fixed submission:
import math
a, b, x = map(int, input().split())
if x == a**2 * b:
    print(0)
else:
    if x >= (0.5 * a**2 * b):
        z = (math.atan(a**3/(2*(a**2*b - x))))
        print(90 - math.degrees(z))
    else:
        z = (math.atan(2*x/(a * b**2)))
        print(90 - math.degrees(z))

Buggy submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
if x >= (0.5 * a**2 * b):
    z = (math.atan(a**3/(2*(a**2*b - x))))
    print(90 - math.degrees(z))
else:
    z = (math.atan(2*x/(a * b**2)))
    print(90 - math.degrees(z))
Problem p02885 (python)

Fixed submission:
a, b = map(int, input().split())
def curtain(a,b):
    if a <= b*2:
        return 0
    else:
        return a - b * 2
print(curtain(a,b))

Buggy submission (verdict: Runtime Error):
 a, b = map(int, input().split())
def curtain(a,b):
    if a <= b*2:
        return 0
    else:
        return a - b * 2
print(curtain(a,b))
Problem p02888 (python)

Fixed submission:
import bisect
N = int(input())
#ソートしておく
L = sorted(list(map(int, input().split())))
ans = 0
 
#短い2辺を総当たりで選択
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    #小さい順に並べた時の成立条件
    # l1 + l2 > l3
    l12 = L[i] + L[j]
    #l2の隣から　l12以下のところまで全部が対象、成立しない場合
    #ans += max(bisect.bisect_left(L, l12) - j - 1, 0)
    ans += bisect.bisect_left(L, l12) - j - 1
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n = int(input())
h = list(map(int, input().split()))
h.sort()
x = 0
def triangle(n,h):
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[k] <= h[j] + h[i] :
                    x = x + 1
    return x
print(triangle(n,h))

Buggy submission (verdict: Runtime Error):
import scipy.misc.comb
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = comb(n, 3, exact = True)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = comb(n, 3, exact = True)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))

Buggy submission (verdict: Runtime Error):
nCr = {}
def cmb(a, b):
    if a == 0 or a == b: return 1
    if a == 1: return b
    if (a,b) in nCr: return nCr[(a,b)]
    nCr[(a,b)] = cmb(a-1,b) + cmb(a-1,b-1)
    return nCr[(a,b)]
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = cmb(n, 3)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))

Buggy submission (verdict: Runtime Error):
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = cmb(n, 3)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
n = int(input())
h = list(map(int, input().split()))
def triangle(n,h):
    x = comb(n, 3, exact = True)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1, n):
                if h[i] >= h[j] + h[k] or h[j] >= h[i] + h[k] or h[k] >= h[j] + h[i]:
                    x = x - 1
    return x
print(triangle(n,h))
Problem p02898 (python)

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split())) 
h_refined = [ i for i in h if i >=  k]
print(len(h_refined))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
h_1 h_2 h_3 ... h_n
h = list(map(int, inpnt().split())) 
h_refined = [ i for i if i >=  k]
print(len(h_refined))
Problem p02899 (python)

Fixed submission:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a2 = np.argsort(a) + 1
a3 = map(str, a2) 
mojiretsu = ' '.join(a3)

print(mojiretsu)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a2 = sorted(a)
a3 = [ a2[i + 1] for i in a2 ]
print(a3)
Problem p03147 (python)

Fixed submission:
n = int(input())
s = list(map(int, input().split()))
cost = s[0]
for i in range(1, n):
    if s[i - 1] < s[i]:
        cost += s[i] - s[i - 1]
print(cost)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(int(input()))
cost = s[0]
for i in range(1, n):
    if s[i - 1] < s[i]:
        cost += s[i] - s[i - 1]
print(cost)
Problem p03352 (python)

Fixed submission:
import math
x = int(input())
ans = []
for j in range(1, math.ceil(math.sqrt(x)) + 1):
    for k in range(2,x + 2):
        if j ** k <= x:
            ans.append(j ** k)
print(max(ans))

Buggy submission (verdict: Runtime Error):
import math
x = int(input())
ans = []
for j in range(math.ceil(math.sqrt(x))):
    for k in range(2,x):
        if j ** k <= x:
            ans.append(j ** k)
print(max(ans))
Problem p03455 (python)

Fixed submission:
d, g  = map(int, input().split())
if d * g  % 2 == 1:
    print('Odd')
else:
    print('Even')

Buggy submission (verdict: Runtime Error):
d, g  = map(int, input().split())
if d % 2 == 1 and f % 2 == 1:
    print('Odd')
else:
    print('Even')
Problem p03486 (python)

Fixed submission:
import sys
s = sorted(list(str(input())))
t = sorted(list(str(input())), reverse = True)
u = min(len(s), len(t))
for i in range(min(len(s), len(t))):
    if s[i] < t[i]:
        print('Yes')
        sys.exit()
    if s[i] > t[i]:
        print('No')
        sys.exit()
if s[0:u] == t[0:u] and len(s) < len(t):
    print('Yes')
elif s[0:u] == t[0:u] and len(s) >= len(t):
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
s = sorted(list(str(input())))
t = sorted(list(str(input())), reverse = True)
x = 0
y = 0
for i in range(len(s)):
    if s[i] < t[i]:
        print('Yes')
        sys.exit()
    if s[i] > t[i]:
        print('No')
        sys.exit()
if s == t[:len(s)] and len(s) < len(t):
    print('Yes') 
elif s == t[:len(s)] and len(s) >= len(t):
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
s = sorted(list(str(input())))
t = sorted(list(str(input())), reverse = True)
x = 0
y = 0
for i in range(len(s)):
    if s[i] < t[i]:
        print('Yes')
        sys.exit()
    if s[i] == t[i]:
        x += 1
if x == len(s) and len(s) < len(t):
    print('Yes') 
elif s == t:
    print('No')

Buggy submission (verdict: Runtime Error):
s = sorted(list(str(input())))
t = sorted(list(str(input())), reverse = True)
x = 0
y = 0
for i in range(len(s)):
    if s[i] < t[i]:
        print('Yes')
        break
    if s[i] == t[i]:
        x += 1
    else:
        y += 1
if x == len(s) and len(s) < len(t):
    print('Yes') 
elif s == t:
    print('No')
elif y == len(s):
    print('No')

Buggy submission (verdict: Runtime Error):
s = sorted(list(str(input())))
t = sorted(list(str(input())), reverse = True)
x = 0
y = 0
for i in range(len(s)):
    if s[i] < t[i]:
        print('Yes')
        break
    if s[i] == t[i]:
        x += 1
    if x == len(s) and len(s) < len(t):
        print('Yes')
        break
    else:
        y += 1
if y == len(s):
    print('No')
Problem p03607 (python)

Fixed submission:
import collections
n = int (input())
ln = []
ln2 = []
for _ in range(n):
    ln.append( int (input()))

C = collections.Counter(ln)
 
ans = 0
for k, v in C.items():
    if (v%2 != 0):
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int (input())
ln = []
ln2 = []
for _ in range(n):
    ln.append( int (input()))

C = collections.Counter(ln)
 
ans = 0
for v in C.items():
    if (v%2 != 0):
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int (input())
ln = []
ln2 = []
for _ in range(n):
    ln.append( int (input()))

C = collections.Counter(ln)
 
ans = 0
for v in C.items():
    if (v%2 != 0):
        ans += 1

print(ans)
Problem p03612 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    if a[i] == i + 1:
        a[i], a[i + 1] = a[i + 1], a[i]
        ans += 1
        
if a[n - 1] == n:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    if a[i] == i + 1:
        a[i], a[i + 1] = a[i + 1], a[i]
        ans += 1
    if a[n] == n + 1:
        ans += 1
print(ans)
Problem p03627 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
import collections
c =collections.Counter(a)
ln = [i[0] for i in c.items() if i[1] >= 2]
ln.sort(reverse = True)
if len(ln) < 1:
    print(0)
elif c[ln[0]] >= 4:
    print(ln[0] ** 2)
elif len(ln) <= 1:
    print(0)
else:
    print(ln[0] * ln[1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
import collections
c =collections.Counter(a)
ln = [i[0] for i in c.items() if i[1] >= 2]
ln.sort(reverse = True)

if c[ln[0]] >= 4:
    print(ln[0] ** 2)
elif len(ln) <= 1:
    print(0)
else:
    print(ln[0] * ln[1])
Problem p03659 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
z = sum(a)
ln = []
x = 0
for i in range(n - 1):
    x += a[i]
    ln.append(abs(z - 2 * x))
print(min(ln))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
z = sum(a)
ln = []
x = 0
for i in range(1, n):
    x += a[i]
    ln.append(abs(z - 2 * a)
print(min(ln))
Problem p03777 (python)

Fixed submission:
import sys
a, b = map(str, input().split())
if (a, b) == ('H', 'H'):
    print('H')
    sys.exit()
if (a, b) == ('D', 'D'):
    print('H')
    sys.exit()
else:
    print('D')

Buggy submission (verdict: Runtime Error):
a, b = map(str, input().split())
if a == 'H' and b == 'H' or A == ' D' and b = = 'D':
    print('H')
else:
    print('D')
Problem p03853 (python)

Fixed submission:
h, w = map(int, input().split())
a = [list(str(input())) for _ in range(h)]
for i in range(h):
    print(''.join(a[i]))
    print(''.join(a[i]))

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(str(input())) for _ in range(h)]
for i in range(2):
    print(''.join(a[i]))
    print(''.join(a[i]))
Problem p03943 (python)

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

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a.sort()
if a[0] + a[1] == a[2]:
    print('YES')
else:
    pritn('NO')
Problem p02618 (python)

Fixed submission:
import random
import sys
input = sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
cn=sorted(c)
h=cn[12]
P=[k+1 for k,v in enumerate(c) if v>=h]
s=[]
for _ in range(d):
    s.append(list(map(int,input().split())))
# t=[]
# for _ in range(d):
#     t.append(int(input()))
# m=int(input())
t=[]
for _ in range(d):
    z=random.randrange(len(P))
    t.append(P[z])
print(*t)

Buggy submission (verdict: Runtime Error):
import random
import sys
input = sys.stdin.readline
d=int(input())
c=list(map(int,input().split()))
cn=sorted(c)
h=cn[3]
P=[k+1 for k,v in enumerate(c) if v>=h]
s=[]
for _ in range(d):
    s.append(list(map(int,input().split())))
# t=[]
# for _ in range(d):
#     t.append(int(input()))
# m=int(input())
t=[]
for _ in range(d):
    z=random.randrange(len(P))
    t.append(P[z])

m=1000
q=[]
for _ in range(m):
    z2=random.randrange(len(P))
    z1=random.randrange(d)
    q.append(tuple(z1,P[z2]))
p=-float("inf")
for k in range(m):
    ld=[-1]*26
    sc=0
    od=t[q[k][0]-1]
    t[q[k][0]-1]=q[k][1]

    for i in range(d):
        sc+=s[i][t[i]-1]
        ld[t[i]-1]=i

        C=0
        for j in range(26):
            C+=c[j]*(i-ld[j])
        sc-=C
    if p<sc:
        p=sc
    else:
        t[q[k][0]-1]=od

print(*t)
Problem p02642 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
M=max(a)
p=[]
for i in range(n):
    if i+1<=n-1:
        if a[i]==a[i+1]:
            p+=[j for j in range(a[i],M+1,a[i])]
        else:
            p+=[j for j in range(a[i]*2,M+1,a[i])]
    else:
        p+=[j for j in range(a[i]*2,M+1,a[i])]

print(len(set(set(a)-set(p))))

Buggy submission (verdict: Runtime Error):
import math
import sys
n=int(input())
a=list(map(int,input().split()))
a.sort()
M=max(a)
p=[]

for i in range(n):
    p.append([j for j in range(a[i],M+1,a[i])])
print(len(set(set(a)-set(p))))
Problem p02658 (python)

Fixed submission:
import sys
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=a[n-1]
if s==0:
    print(0)
else:
    for i in range(0,n-1):
        s*=a[i]
        if s>10**18:
            print(-1)
            sys.exit()
    print(s)

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
a.sort(reverse=True)
s=a[-1]
if s==0:
    print(0)
else:
    for i in range(0,n-1):
        s*=a[i]
    if s>10**18:
        print(-1)
        sys.exit()
    print(s)
Problem p02705 (python)

Fixed submission:
import math
R=int(input())
l=2*(math.pi)*R

print(l)

Buggy submission (verdict: Runtime Error):
import math
R=int(input())
l=2*(math.pi)*R

print(l)1
Problem p02714 (python)

Fixed submission:
n=int(input())
s=input()
r=[0]*n
g=[0]*n
b=[0]*n
R=0; G=0; B=0
for i in range(n):
    if s[i]=="R":
        r[i]=1
        R+=1
    elif s[i]=="G":
        g[i]=1
        G+=1
    else:
        b[i]=1
        B+=1
s=0
for j in range(n):
    for k in range(n):
        if r[j]==1 and g[k]==1:
            if j!=k:
                j1,k1=(max(j,k),min(j,k))
                if (j1-k1)+j1<n:
                    if b[(j1-k1)+j1]==1:
                        s+=1
                if k1-(j1-k1)>=0:
                    if b[k1-(j1-k1)]==1:
                        s+=1
                if (j1-k1)>1 and (j1-k1)%2==0:
                    if b[k1+(j1-k1)//2]==1:
                        s+=1
print(R*G*B-s)

Buggy submission (verdict: Runtime Error):
def rgb(n,s):

    
    a=s[0]
    if len(s)==3:
        SUM=0

    else:
        SUM=rgb(n-1,s[1:])

        for i in range(1,n-1):
            l=["R","G","B"]
            l.remove(a)
            if s[i] != a:
                b=s[i]

                l.remove(b)
                if l!=[]:
                    c=l[0]
                    p=s.count(c,i+1,2*i)
                    q=s.count(c,2*i+1,n+1)
                    SUM+=p+q
                
    return SUM

n=int(input())
s=input()
print(rgb(n,s))
Problem p02797 (python)

Fixed submission:
n,k,s=map(int,input().split())
a=[]

if (s != 10**9):

    for i in range(k):
        a.append(s)
    for j in range(k,n):
        a.append(s+1)

else:

    for i in range(k):
        a.append(s)
    for j in range(k,n):
        a.append(1)

b=map(str,a)

print(" ".join(b))

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

if s != 10**9 or k==n

    for i in range(k):
        a.append(s)

    for j in range(k,n):
        a.append(s+1)

    b=map(str,a)

    print(" ".join(b))

else:
    for i in range(k):
        a.append(s)
    a.append(1)
    for j in range(k+1,n):
        a.append(0)

    b=map(str,a)

    print(" ".join(b))
Problem p02975 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=a[1]
for i in range(2,n):
    b = b^(a[i])

if b==a[0]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b.count(0)==n:
    print("Yes")
elif n%3==0:
    if b.count(0)==n//3 and b.count(b[n-1])==n-(n//3):
        print("Yes")
    elif b[0]^b[n//3]^b[n-1]==0 and b.count(b[0])==n//3 and b.count(b[n//3])==n//3 and b.count(b[n-1])==n//3:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
b=sorted(a)
if b.count(0)==n:
    print("Yes")
elif n%3==0:
    if b.count(0)==n//3 and b.count(b[n-1])==n-(n//3):
        print("Yes")
    elif b[0]^b[n//3]^b[n-1]==0 and b.count(b[0])==n//3 and b.count(b[n//3])==n//3 and b.count(b[n-1])==n//3:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Problem p02993 (python)

Fixed submission:
s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")

Buggy submission (verdict: Runtime Error):
s=list(int(input()))
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")

Buggy submission (verdict: Runtime Error):
s=int(input())
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")
Problem p03037 (python)

Fixed submission:
n,m=map(int,input().split())
l=0;r=10**6
for i in range(m):
    ln,rn=map(int,input().split())
    l=max(l,ln);r=min(r,rn)
if l>r:
    print(0)
else:
    print(r-l+1)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
d=[]
for _ in range(m):
    d.append(list(map(int,input().split())))
def ID(i):
    if i==1:
        return (d[0][0],d[0][1])
    l,r=ID(i-1)
    L=max(l,d[i-1][0])
    R=min(r,d[i-1][1])
    return (L,R)
s,g=ID(m)
print(max(g-s+1,0))
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n=int(input())
l=[-1]*n
p=[[] for _ in range(n)]
for i in range(n-1):
    ui,vi,wi=map(int,input().split())
    p[ui-1].append([vi,wi])
    p[vi-1].append([ui,wi])

def tr1(x,y):
    #print(x)
    #print(y)
    
    if l[x-1]!=-1:
        return
    l[x-1]=y
    for i in range(len(p[x-1])):
        tr1(p[x-1][i][0],(y+p[x-1][i][1])%2)
tr1(1,0)
for j in range(n):
    print(l[j])

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[-1]*n
p=[[] for _ in range(n)]
for i in range(n-1):
    ui,vi,wi=map(int,input().split())
    p[ui-1].append([vi,wi])
    p[vi-1].append([ui,wi])

def tr1(x,y):
    #print(x)
    #print(y)
    
    if l[x-1]!=-1:
        return
    l[x-1]=y
    for i in range(len(p[x-1])):
        tr1(p[x-1][i][0],(y+p[x-1][i][1])%2)
tr1(1,0)
for j in range(n):
    print(l[j])
Problem p03160 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
D=[10**0 for i in range(n)]

for i in range(n):
    if i==0:
        D[i]=0
    elif i==1:
        D[i]=abs(h[1]-h[0])  
    else:
        D[i]=min(D[i-1]+abs(h[i]-h[i-1]),D[i-2]+abs(h[i]-h[i-2]))
print(D[n-1])

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

A=a.count(1)
B=a.count(2)


dp=[[[0.0]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
def c():
    for k in range(C+1):
        for j in range(B+C+1-k):
            for i in range(n+1-k-j):
                if i==0 and j==0 and k==0:
                    continue
                res=1.0*n
                if i>0:
                    res+=i*dp[i-1][j][k]
                if j>0:
                    res+=j*dp[i+1][j-1][k]
                if k>0:
                    res+=k*dp[i][j+1][k-1]
                dp[i][j][k]=res/(i+j+k)
    print(dp[A][B][C])
c()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
n=int(input())
h=list(map(int,input().split()))
def cst(n):
    if n==1:
        return 0
    elif n==2:
        return abs(h[1]-h[0])
    else:
        return min(cst(n-1)+abs(h[n-1]-h[n-2]),cst(n-2)+abs(h[n-1]-h[n-3]))
n=int(input())
h=list(map(int,input().split()))
A=cst(n)
print(A)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
n=int(input())
h=list(map(int,input().split()))
def cst(n):
    if n==1:
        return 0
    if n==2:
        return abs(h[1]-h[0])
    else:
        return min(cst(n-1)+abs(h[n-1]-h[n-2]),cst(n-2)+abs(h[n-1]-h[n-3]))
n=int(input())
h=list(map(int,input().split()))
A=cst(n)
print(A)
Problem p03162 (python)

Fixed submission:
import sys
sys.setrecursionlimit(int(1e6))

n=int(input())
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
print(max(dp(n,0),dp(n,1),dp(n,2)))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(int(1e6))

n=int(input())
l=[[0,0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    z[i][j]=1
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
s1=dp(n,0)
s2=dp(n,1)
s3=dp(n,2)
print(max(s1,s2,s3))

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

memo=[[-1,-1,-1] for _ in range(n+1)]
memo[0][0]=0
memo[0][1]=0
memo[0][2]=0
def dp(i,j):
    if memo[i][j]!=-1:
        return memo[i][j]
    else:
        memo[i][j]=max(dp(i-1,(j+1)%3)+l[i][j],dp(i-1,(j+2)%3)+l[i][j])
        return memo[i][j]
print(max(dp(n,0),dp(n,1),dp(n,2)))