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

Fixed submission:
li,lia = [],[]
total = 0
for i in range(5):
    a = input()
    li.append(a)
for i in range(5):
    lia.append(li[i][-1])
lib = [int(s) for s in lia]
b = lib.count(0)
for i in range(b):
    lib.remove(0)
for i in range(5):
    total += (int(li[i])//10+1)*10
if len(lib) >= 1:
    total -= 10*(1+b)
else:
    total -= 10*(b)
if len(lib) >= 1:
    total += min(lib)
if total <= 0:
    print(0)
else:
    print(total)

Buggy submission (verdict: Runtime Error):
li,lia = [],[]
total = 0
for i in range(5):
    a = input()
    li.append(a)
for i in range(5):
    lia.append(li[i][-1])
lib = [int(s) for s in lia]
b = lib.count(0)
for i in range(b):
    lib.remove(0)
for i in range(5):
    total += (int(li[i])//10+1)*10
total -= 10*(1+b)
total += min(lib)
print(total)

Buggy submission (verdict: Runtime Error):
li1 = []
ans = 0
count = 0
for i in range(5):
    a = int(input())
    li1.append(a)
if sum(li1) == 0:
    print(0)
else:
    for i in range(5):
        if li1[i] % 10 == 0:
            ans += li1[i]
            count += 1
            li1[i] = 0
    for i in range(count):
        li1.remove(0)
    li2 = [s % 10 for s in li1]
    ans += min(li2)-10
    for i in range(len(li1)):
        ans += (li1[i] // 10 + 1) * 10
    print(ans)

Buggy submission (verdict: Runtime Error):
li1 = []
ans = 0
count = 0
for i in range(5):
    a = int(input())
    li1.append(a)
for i in range(5):
    if li1[i] % 10 == 0:
        ans += li1[i]
        count += 1
        li1[i] = 0
for i in range(count):
    li1.remove(0)
li2 = [s % 10 for s in li1]
ans += min(li2)-10
for i in range(len(li1)):
    ans += (li1[i] // 10 + 1) * 10
print(ans)

Buggy submission (verdict: Runtime Error):
li = [int(input()) for i in range(5)]
a,b,c,d,e = li[0],li[1],li[2],li[3],li[4]
a1,b1,c1,d1,e1 = int(str(a)[-1]),int(str(b)[-1]),int(str(c)[-1]),int(str(d)[-1]),int(str(e)[-1])
for i in range(1,11):
    if a1 == i:
        plus = i+(li[0])//10*10
        li.remove(li[0])
        break
    if b1 == i:
        plus = i+(li[1])//10*10
        li.remove(li[1])
        break
    if c1 == i:
        plus = i+(li[2])//10*10
        li.remove(li[2])
        break
    if d1 == i:
        plus = i+(li[3])//10*10
        li.remove(li[3])
        break
    if e1 == i:
        plus = i+(li[4])//10*10
        li.remove(li[4])
        break
for i in range(4):
    if li[i] % 10 != 0:
        li[i] = (li[i] // 10 + 1)*10
print(sum(li)+plus)
Problem p03210 (python)

Fixed submission:
s = int(input())
if s == 3 or s == 5 or s == 7:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = int(input())
is s == 3 or s == 5 or s == 7:
    print("YES")
else:
    print("NO")
Problem p03282 (python)

Fixed submission:
n = input()
b = int(input())
lenn = len(n)
count = 0
for i in range(lenn):
    if n[i] == "1":
        count += 1
    else:
        break
if count >= b:
    print(1)
else:
    print(n[count])

Buggy submission (verdict: Runtime Error):
n = input()
b = input()
if n[0] == "1":
    print(n[1])
else:
    print(n[0])
Problem p03284 (python)

Fixed submission:
n,k = map(int,input().split())
if n % k == 0:
    print(0)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
n,k = int(input())
if n % k == 0:
    print(0)
else:
    print(1)
Problem p03351 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
count = 0
if abs(b-a) <= d and abs(c-b) <= d:
    count = 1
elif abs(c-a) <= d:
    count = 1
if count != 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
if abs(b-a) =< d and abs(c-b) =< d:
    print("Yes")
else:
    print("No")
Problem p03385 (python)

Fixed submission:
n = input()
if n.count("a") == 1 and n.count("b") == 1 and n.count ("c") == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
n.sort()
if n[0] == "a" and n[1] == "b" and n[2] == "c":
    print("Yes")
else:
    print("No")
Problem p03543 (python)

Fixed submission:
n = input()
for i in range(2):
    if n[i] == n[i+1] and n[i+1] == n[i+2]:
        print("Yes")
        exit()
print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(2):
    if n[i] == n[i+1] and n[i+1] == n[i+2]:
        print("Yes")
        exit()
print("No")
Problem p03597 (python)

Fixed submission:
n = int(input())
a = int(input())
print(n**2-a)

Buggy submission (verdict: Runtime Error):
n = int(input())
a - int(input())
print(n**2-a)
Problem p03637 (python)

Fixed submission:
n = int(input())
li = list(map(int,input().split()))
lis = []
x = 0
y = 0
z = 0
for i in range(n):
    if li[i] % 4 == 0:
        x += 1
    elif li[i] % 2 == 0:
        y = 1
    else:
        z += 1
if y == 0:
    if x + 1 >= z:
        print("Yes")
    else:
        print("No")
else:
    if x >= z:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
li = list(map(int,input().split()))
lis = []
x = 0
y = 0
z = 0
for i in range(n):
    if li[i] % 4 == 0:
        x += 1
    elif li[i] % 2 == 0:
        y = 1
    else:
        z += 1
if y = 0:
    if x >= y + 1:
        print("Yes")
    else:
        print("No")
else:
    if x >= y:
        print("Yes")
    else:
        print("No")
Problem p03657 (python)

Fixed submission:
li = list(map(int,input().split()))
li.append(li[0]+li[1])
for i in range(3):
    if li[i] % 3 == 0:
        print("Possible")
        exit()
print("Impossible")

Buggy submission (verdict: Runtime Error):
li = list(map(int,input().split()))
li.append(a+b)
for i in range(3):
    if li[i] % 3 == 0:
        print("Possible")
        exit()
print("Impossible")
Problem p03729 (python)

Fixed submission:
a,b,c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c = input().split()
if a[-1] == b[1] and b[-1] == c[1]:
    print("YES")
else:
    print("NO")
Problem p03759 (python)

Fixed submission:
a,b,c = map(int,input().split())
if b - a == c - b:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if b - a = c - b:
    print("YES")
else:
    print("NO")
Problem p03943 (python)

Fixed submission:
a,b,c = map(int,input().split())
if a + b == c or a + c == b or b + c == a:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if a + b == c pr a + c == b or b + c == a:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if sum(a,b,c) % 2 == 0:
    print("Yes")
else:
    print("No")
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print(int((a+b)*h/2))

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
print((a+b)*h/2)
Problem p02760 (python)

Fixed submission:
B=[];bingo=0
import numpy as np
A=np.zeros((3,3),dtype=int)
for i in range(3):
  a,b,c=map(int,input().split())
  A[i][0]=a
  A[i][1]=b
  A[i][2]=c
N=int(input())
for i in range(N):
  B.append(int(input()))
#print(A)
#print(B)
for i in range(3):
  for j in range(3):
    for k in range(N):
      if A[i][j]==B[k]:
        A[i][j]=0
#print(A)
for i in range(3):
  if sum(A[i][:])==0:
    bingo=bingo+1
for i in range(3):
  if A[0][i]+A[1][i]+A[2][i]==0:
    bingo=bingo+1
if A[0][0]+A[1][1]+A[2][2]==0:
  bingo=bingo+1
if A[2][0]+A[1][1]+A[0][2]==0:
  bingo=bingo+1
print("Yes" if bingo>=1 else "No")

Buggy submission (verdict: Runtime Error):
B=[];bingo=0
import numpy as np
A=np.zeros((3,3),dtype=int)
for i in range(3):
  a,b,c=map(int,input().split())
  A[i][0]=a
  A[i][1]=b
  A[i][2]=c
N=int(input())
for i in range(N):
  B.append(int(input()))
#print(A)
#print(B)
for i in range(3):
  for j in range(3):
    for k in range(N):
      if A[i][j]==B[k]:
        A[i][j]=0
#print(A)
for i in range(3):
  if sum(A[i][:])==0:
    bingo=bingo+1
for i in range(3):
  if sum(A[0][i])==0 or sum(A[1][i])==0 or sum(A[2][i])==0:
    bingo=bingo+1
if A[0][0]+A[1][1]+A[2][2]==0:
  bingo=bingo+1
if A[2][0]+A[1][1]+A[0][2]==0:
  bingo=bingo+1
print("Yes" if bingo>=1 else "No")

Buggy submission (verdict: Runtime Error):
B=[];bingo=0
import numpy as np
A=np.zeros((3,3),dtype=int)
for i in range(3):
  a,b,c=map(int,input().split())
  A[i][0]=a
  A[i][1]=b
  A[i][2]=c
N=int(input())
for i in range(N):
  B.append(int(input()))
#print(A)
#print(B)
for i in range(3):
  for j in range(3):
    for k in range(N):
      if A[i][j]==B[k]:
        A[i][j]=0
#print(A)
for i in range(3):
  if sum(A[i][:])==0:
    bingo=bingo+1
for i in range(3):
  if sum(A[0][i])==0 or sum(A[1][i])==0 or sum(A[2][i])==0:
    bingo=bingo+1
if A[0][0]+A[1][1]+A[2][2]==0:
  bingo=bingo+1
if A[2][0]+A[1][1]+A[0][2]==0:
  bingo=bingo+1
print("Yes" if bingo>=1 else "No")
print(sum(A[:][1]))
print(sum(A[1][:]))
print(bingo)
Problem p03000 (python)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))
p=1
dt=0
i=1
for i in range(N):
  dt=dt+L[i]
  if dt<=X:
    p=p+1
  else:
    break
print(p)

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))
p=1
dt=0
i=1
while dt<=X:
  dt=dt+L[i-1]
  i=i+1
  if dt<=X and p<=N+1:
    p=p+1
  #print(dt)
print(p)

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))
p=1
dt=0
i=1
while dt<=X:
  dt=dt+L[i-1]
  i=i+1
  if dt<=X:
    p=p+1
  #print(dt)
print(p)
Problem p03030 (python)

Fixed submission:
N=int(input())
p=1
S=[]
A=[]
U=[]
T=[]
L= [list(map(str,input().split())) for i in range(N)]
for j in range(1,N+1):
  L[j-1].append(j)
L.sort(key=lambda x: x[0])
#print(L)
S=L[:]
S.sort(reverse=True,key=lambda x: int(x[1]))
#print(S)
T.append(L[0][0])
for i in range(1,N):
  if L[i-1][0]!=L[i][0]:
    T.append(L[i][0])
#print(T)
for j in range(len(T)):
  for k in range(N):
    if S[k][0]==T[j]:
      A.append(S[k][2])
for i in range(N):
  print(A[i])

Buggy submission (verdict: Runtime Error):
N=int(input())
p=1
S=[]
A=[]
U=[]
T=[]
L= [list(map(str,input().split())) for i in range(N)]
for j in range(1,N+1):
  L[j-1].append(j)
L.sort(key=lambda x: x[0])
#print(L)
S=L[:]
S.sort(reverse=True,key=lambda x: int(x[1]))
#print(S)
T.append(L[0][0])
for i in range(1,N-1):
  if L[i-1][0]!=L[i][0]:
    T.append(L[i][0])
#print(T)
for j in range(len(T)):
  for k in range(N):
    if S[k][0]==T[j]:
      A.append(S[k][2])
for i in range(N):
  print(A[i])
Problem p03160 (python)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
cost=0
t1,t2=0,0
A=[0]*(N)
i=1
while i<N:
  if i==1:
    A[i]=abs(H[i]-H[i-1])
    #print(i,A[i])
  elif i==2:
    t1=abs(H[i]-H[i-2])
    t2=abs(H[i]-H[i-1])+abs(H[i-2]-H[i-1])
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  else:
    t1=abs(H[i]-H[i-1])+A[i-1]
    t2=abs(H[i]-H[i-2])+A[i-2]
    A[i]=min(t1,t2)
    #print(i,A[i],t1,t2)
  i=i+1
#print(A)
print(A[N-1])

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=list(map(int,input().split()))
cost =10000
DP=[0]*N
DP[0]=0
DP[1]=abs(H[1]-H[0])
for i in range(2,N):
  cost=10000
  for k in range(1,K+1):
    if (i-k)==-1:
      break
    cost=min(cost,(abs(H[i]-H[i-k])+DP[i-k]))
    #print(H[i],H[i-k],DP[i-k])
    DP[i]=cost
    #print(DP[i],i)
print(DP[N-1])
Problem p03238 (python)

Fixed submission:
N=int(input())
if N==1:
  print("Hello World")
else:
  A=int(input())
  B=int(input())
  print(A+B)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N==1:
  print("Hello World")
else:
  A,B=map(int,input().split())
  print(A+B)
Problem p03282 (python)

Fixed submission:
S=list(input())
K=int(input())
#print(S)
i=0;p=0;q=0
while i!=len(S):
  if S[i]!="1":
    p=1
    q=i
    if K<i+1:
      print("1")
    else:
      print(S[i])
    break
  i=i+1
if p==0:
  print("1")

Buggy submission (verdict: Runtime Error):
S=list(input())
K=int(input())
#print(S)
i=0;p=0
while S[i]=="1":
  p=p+1
  i=i+1
#print(p)
print(S[p])
Problem p03324 (python)

Fixed submission:
D,N=map(int,input().split())

if D==0:
  if N!=100:
    print(N)
  else:
    print(101)
elif D==1:
  if N!=100:
    print(N*100)
  else:
    print(10100)
else:
  if N!=100:
    print(N*10000)
  else:
    print(1010000)

Buggy submission (verdict: Runtime Error):
D,N=map(int,input().split())
L=[]
if D==0:
  for i in range(1,100):
    L.append(i)
elif D==1:
  for i in range(100,10000,100):
    L.append(i)
elif D==2:
  for i in range(10000,1000000,10000):
    L.append(i)
print(L[N-1])

Buggy submission (verdict: Runtime Error):
D,N=map(int,input().split())
s=0
L=[]
if D==0:
  for i in range(1,100):
    L.append(i)
elif D==1:
  for i in range(100,10000,100):
    L.append(i)
elif D==2:
  for i in range(10000,1000000,10000):
    L.append(i)
print(L[N-1])
Problem p03435 (python)

Fixed submission:
C=[0]*3;A=[0]*3
d1=0;d2=0;e1=0;e2=0;z=0;p=0
for i in range(3):
  c1,c2,c3=map(int,input().split())
  C[i]=[c1,c2,c3]
  A[i]=[0,0,0]
 
d1=C[1][0]-C[0][0];d2=C[2][0]-C[0][0]
e1=C[0][1]-C[0][0];e2=C[0][2]-C[0][0]
z=C[0][0]
A[0][0]=z;A[0][1]=z+e1;A[0][2]=z+e2
A[1][0]=z+d1;A[1][1]=z+e1+d1;A[1][2]=z+d1+e2
A[2][0]=z+d2;A[2][1]=z+d2+e1;A[2][2]=z+d2+e2
 
#print(C)
for i in range(3):
  for j in range(3):
    if C[i][j]==A[i][j]:
      p=p+1
print("Yes" if p==9 else "No")

Buggy submission (verdict: Runtime Error):
C=[0]*3;A=[0]*3
d1=0;d2=0;e1=0;e2=0;z=0;p=0
for i in range(3):
  c1,c2,c3=map(int,input().split())
  C[i]=(c1,c2,c3)
  A[i]=(0,0,0)

d1=C[1][0]-C[0][0];d2=C[2][0]-C[0][0]
e1=C[0][1]-C[0][0];e2=C[0][2]-C[0][0]
z=C[0][0]
A[0][0]=z;A[0][1]=z+e1;A[0][2]=z+e2
A[1][0]=z+d1;A[1][1]=z+e1+d1;A[1][2]=z+d1+e2
A[2][0]=z+d2;A[2][1]=z+d2+e1;A[2][2]=z+d2+e2

print(C)
for i in range(3):
  for j in range(3):
    if C[i][j]==A[i][j]:
      p=p+1
print("Yes" if p==9 else "No")
Problem p03436 (python)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
sy = 0
sx = 0
gy = H-1
gx = W-1
c = []
d = [[-1 for i in range(W)] for j in range(H)]
d[sy][sx] = 0
cnt=0
for i in range(H):
	c.append(input())
for j in range(H):
  cnt=cnt+c[j].count(".")

dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
q = deque()
q.append([sy, sx, 0])
while len(q) != 0:
	y, x, w = q[0]
	if y == gy and x == gx:
		break

	for i in range(4):
		ny, nx = y + dirr[i][0], x + dirr[i][1]
		if ny>=0 and nx>=0 and ny<H and nx<W and d[ny][nx] == -1 and c[ny][nx] != "#":
			q.append([ny, nx, w + 1])
			d[ny][nx] = w + 1

	q.popleft()

if d[gy][gx]==-1:
  print(-1)
else:
  print(cnt-w-1)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
sy = 0
sx = 0
gy = H-1
gx = W-1
c = []
d = [[-1 for i in range(W)] for j in range(H)]
d[sy][sx] = 0
cnt=0
for i in range(H):
	c.append(input())
for j in range(H):
  cnt=cnt+c[j].count(".")

dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
q = deque()
q.append([sy, sx, 0])
while len(q) != 0:
	y, x, w = q[0]
	if y == gy and x == gx:
		break

	for i in range(4):
		ny, nx = y + dirr[i][0], x + dirr[i][1]
		if ny>=0 and nx>=0 and ny<H and nx<W and d[ny][nx] == -1 and c[ny][nx] != "#":
			q.append([ny, nx, w + 1])
			d[ny][nx] = w + 1

	q.popleft()

if d[gy][gx]==-1:
  print(-1)
else:
  print(cnt-w-1)
Problem p03485 (python)

Fixed submission:
A,B=map(int,input().split())
if (A+B)%2!=0:
  print((A+B)//2+1)
else:
  print((A+B)//2)

Buggy submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
if (A+B)%2!=0:
  print((A+B)//2+1)
else:
  print((A+B)//2)

Buggy submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
print((A+B)//2)
Problem p03659 (python)

Fixed submission:
S=[]
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);x=10**10;p=0
S.append(A[0])
for i in range(1,N):
  S.append(S[i-1]+A[i])
#print(S)
C[0]=abs(A[0]-(S[-1]-S[0]))
for i in range(1,N-1):
  C[i]=abs(S[i-1]+A[i]-(S[-1]-S[i]))
  if x>(C[i]):
    x=(C[i])
    p=i
print(abs(S[p-1]+A[p]-(S[-1]-S[p])))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N);C[0]=abs(A[0]-sum(A[1:]));x=10**9;P=0
for i in range(1,N):
  if N-i==1:
    break
  else:
    C[i]=abs(C[i-1]+A[i]-sum(A[i+1:]))
    if x>C[i]:
      x=C[i]
      p=i
print(abs(C[p-1]+A[p]-sum(A[p+1:])))
Problem p03828 (python)

Fixed submission:
def PF(n):
    fs = []
    q = int(n ** 0.5) 
    for i in range(2, q + 1):
        if n % i == 0:
            r = 0
            while n % i == 0:
                n //= i
                r += 1
            fs.append([i, r])
    if n != 1:
        fs.append([n, 1])
    return fs

P=[0]*1000
x=1
N=int(input())
for i in range(2,N+1):
  A=PF(i)
  for j in range(len(A)):
    P[A[j][0]]=P[A[j][0]]+A[j][1]
P.remove(0)
for i in range(len(P)):
  x=(x*(P[i]+1))%(10**9+7)
print(x)

Buggy submission (verdict: Runtime Error):
P=[0]*1000
x=1
N=int(input())
for i in range(2,N+1):
  A=PF(i)
  for j in range(len(A)):
    P[A[j][0]]=P[A[j][0]]+A[j][1]
P.remove(0)
for i in range(len(P)):
  x=(x*(P[i]+1))%(10**9+7)
print(x)
Problem p03910 (python)

Fixed submission:
N=int(input())
S=[1]
for i in range(1,N):
  S.append(S[i-1]+i+1)
p=0
j=0
if N==1:
  print(1)
else:
  while N>=S[j]:
    j += 1
  p=S[j]-N
  for i in range(1,j+2):
    if i!=p:
      print(i)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=[1]
for i in range(1,N):
  S.append(S[i-1]+i+1)
p=0
j=0
while N>=S[j]:
  j += 1
p=S[j]-N
for i in range(1,j+2):
  if i!=p:
    print(i)
Problem p03044 (python)

Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-
import numpy as np

MOD = 10 ** 9 + 7

n = int(input())

# graph = [[-1] * n for _ in range(n)]
graph = np.zeros((n, n), dtype=np.int64)
graph -= 1
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j in range(n):
        if dist[j] == -1 and graph[i][j] != -1:
            dist[j] = dist[i] + graph[i][j]
            que.append(j)

for d in dist:
    print(d % 2)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-
import numpy as np

MOD = 10 ** 9 + 7

n = int(input())

# graph = [[-1] * n for _ in range(n)]
graph = np.zeros((n, n), dtype=np.int)
graph -= 1
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j in range(n):
        if dist[j] == -1 and graph[i][j] != -1:
            dist[j] = dist[i] + graph[i][j]
            que.append(j)

for d in dist:
    print(d % 2)
Problem p03068 (python)

Fixed submission:
# -*- coding utf-8 -*-
N = int(input())
S = input()
K = int(input())

t = S[K - 1]
for s in 'abcdefghijklmnopqrstuvwxyz':
    if s != t:
        S = S.replace(s, '*')
        
print(S)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-
N = int(input())
S = input()
K = int(input())

for s in 'abcdefghijklmnopqrstuvwxyz':
    if s != S[K]:
        S = S.replace(s, '*')
        
print(S)
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()

ac = [0] * (N + 1)
for i in range(N - 1):
    ac[i + 1] = ac[i] + (1 if S[i] == 'A' and S[i + 1] == 'C' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()

ac = [0] * (N + 1)
for i in range(N):
    ac[i + 1] = ac[i] + (1 if S[i ] == 'A' and S[i + 1] == 'C' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(ac[r-1] - ac[l-1])
Problem p03148 (python)

Fixed submission:
# -*- coding utf-8 -*-

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key = lambda x: x[1], reverse = True)    # sort by d

mp_max = 0
op = 0
taberu_ind = set()
pop_cands = []
t_taberu = set()
# greedy for delicious point
for i in range(k):
    op += sushi[i][1]

    t = sushi[i][0]
    if t_taberu.isdisjoint({t}):    # new type
        t_taberu.add(t)
    else:
        pop_cands.append(i)

    taberu_ind.add(i)
mp_max = op + len(t_taberu)**2

# reduce dericious, gain variety
i += 1
j = i
for i in range(i, n):
    if len(pop_cands) == 0:
        break

    pop_ind = pop_cands.pop()
    taberu_ind.remove(pop_ind)

    for j in range(j, n):
        t = sushi[j][0]
        if t_taberu.isdisjoint({t}):
            t_taberu.add(t)
            break
    else:
        break
    
    # calc points
    op -= sushi[pop_ind][1]
    op += sushi[j][1]
    mp = op + len(t_taberu)**2
    mp_max = max(mp_max, mp)

    taberu_ind.add(i)    # not necessary actually
print(mp_max)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key = lambda x: x[1], reverse = True)    # sort by d

mp_max = 0
op = 0
taberu_ind = set()
pop_cands = []
t_taberu = set()
# greedy for delicious point
for i in range(k):
    op += sushi[i][1]

    t = sushi[i][0]
    if t_taberu.isdisjoint({t}):    # new type
        t_taberu.add(t)
    else:
        pop_cands.append(i)

    taberu_ind.add(i)
mp_max = op + len(t_taberu)**2

# reduce dericious, gain variety
i += 1
j = i
for i in range(i, n):
    pop_ind = pop_cands.pop()
    taberu_ind.remove(pop_ind)

    for j in range(j, n):
        t = sushi[j][0]
        if t_taberu.isdisjoint({t}):
            t_taberu.add(t)
            break
    else:
        break
    
    # calc points
    op -= sushi[pop_ind][1]
    op += sushi[j][1]
    mp = op + len(t_taberu)**2
    mp_max = max(mp_max, mp)

    taberu_ind.add(i)

    if len(pop_cands) == 0:
        break

print(mp_max)

Buggy submission (verdict: Runtime Error):
# -*- coding utf-8 -*-

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key = lambda x: x[1], reverse = True)    # sort by d

mp_max = 0
op = 0
taberu_ind = set()
pop_cands = []
t_taberu = set()
# greedy for delicious point
for i in range(k):
    op += sushi[i][1]

    t = sushi[i][0]
    if t_taberu.isdisjoint({t}):    # new type
        t_taberu.add(t)
    else:
        pop_cands.append(i)

    taberu_ind.add(i)
mp_max = op + len(t_taberu)**2

# reduce dericious, gain variety
i += 1
j = i
for i in range(i, n):
    pop_ind = pop_cands.pop()
    taberu_ind.remove(pop_ind)

    for j in range(j, n):
        t = sushi[j][0]
        if t_taberu.isdisjoint({t}):
            t_taberu.add(t)
            break
    else:
        break
    
    # calc points
    op -= sushi[pop_ind][1]
    op += sushi[j][1]
    mp = op + len(t_taberu)**2
    mp_max = max(mp_max, mp)

    taberu_ind.add(i)

print(mp_max)
Problem p03274 (python)

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

k = []
# print(X)

k0 = abs(X[0])
for n in range(0+1, K):
    k0 += X[n] - X[n-1]
k.append(k0)
for i in range(1, len(X)-K+1):
    ki = k[i-1] - (X[i] - X[i-1]) + (X[i+K-1] - X[i+K-2]) - abs(X[i-1]) + abs(X[i])
    k.append(ki)
# print(min(k))

l = []
l0 = abs(X[N-1])
for n in range(N-1, N-K, -1):
    l0 += X[n] - X[n-1]
# print(l0)
l.append(l0)
for i in range(1, len(X)-K+1):
    # print(i, i-1, i+K, i+K-1)
    li = l[i-1] - (X[N-i] - X[N-i-1]) + (X[N-K-i+1] - X[N-K-i]) - abs(X[N-i]) + abs(X[N-i-1])
    # print(li)
    l.append(li)
print(min(min(k), min(l)))

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

k = []
# print(X)

k0 = abs(X[0])
for n in range(0+1, K):
    k0 += X[n] - X[n-1]
# print(k0)
k.append(k0)
for i in range(1, len(X)-K+1):
    # print(i, i-1, i+K, i+K-1)
    ki = k[i-1] - (X[i] - X[i-1]) + (X[i+K-1] - X[i+K-2]) - abs(X[i-1]) + abs(X[i])
    k.append(ki)
print(min(k))