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

Fixed submission:
H, W = map(int, input().split())
s = ["".join(["0"]*(W+2))] + ["0"+input()+"0" for _ in range(H)] + ["".join(["0"]*(W+2))]
failed = False
for i in range(1, H+1):
    for j in range(1, W+1):
        if '#' != s[i][j]:
            continue
        if '#' in [s[i+x][j+y] for x, y in [(0, -1), (-1, 0), (1, 0), (0, 1)]]:
            continue
        else:
            failed = True
            break
    if failed:
        print("No")
        break
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = ["".join(["0"]*(H+2))] + ["0"+input()+"0" for _ in range(H)] + ["".join(["0"]*(H+2))]
failed = False
for i in range(1, W+1):
    for j in range(1, H+1):
        if '#' != s[i][j]:
            continue
        if '#' in [s[i+x][j+y] for x, y in [(0, -1), (-1, 0), (1, 0), (0, 1)]]:
            continue
        else:
            failed = True
            break
    if failed:
        print("No")
        break
else:
    print("Yes")
Problem p03417 (python)

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

if N == 1 and M == 1:
    print(1)
elif N == 1 and M != 1:
    print(M-2)
elif N != 1 and M == 1:
    print(N-2)
else:
    print((N-2)*(M-2))

Buggy submission (verdict: Runtime Error):
if N == 1 and M == 1:
    print(1)
elif N == 1 and M != 1:
    print(M-2)
elif N != 1 and M == 1:
    print(N-2)
else:
    print((N-2)*(M-2))

Buggy submission (verdict: Runtime Error):
def get_z(x, y):
    global N
    return (y+1)*(N+2) + (x+1)

N, M = map(int, input().split())
table = [-1] * (N+2) + [[1, -1][i in [0, N+1]] for i in range(N+2)] * M + [-1] * (N+2)
for y in range(M):
    for x in range(N):
        z = get_z(x, y)
        for t in [(z-(N+3)), (z-(N+2)), (z-(N+1)), z-1, z, z+1, z+N+1, z+N+2, z+N+3]:
            table[t] = table[t] ^ 1
print(sum(1 * (t==0) for t in table))
Problem p03502 (python)

Fixed submission:
N = input()
x = sum(int(i) for i in N)
print("Yes" if int(N) % x == 0 else "No")

Buggy submission (verdict: Runtime Error):
N = input()
x = sum(int(i) for i in N)
print("Yes" if N % x == 0 else "No")
Problem p03547 (python)

Fixed submission:
X, Y = input().split()
X = ord(X)
Y = ord(Y)
if X < Y:
    print("<")
elif X > Y:
    print(">")
else:
    print("=")

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
X = ord(X)
Y = ord(Y)
if X < Y:
    print("<")
elif X > Y:
    print(">")
else:
    print("=")
Problem p03556 (python)

Fixed submission:
N = int(input())
tmp = 1
for i in range(N, 1, -1):
    tmp = int(pow(i, 0.5))
    if tmp * tmp == i:
        break
print(tmp * tmp)

Buggy submission (verdict: Runtime Error):
N = int(input())
for i in range(N, 1, -1):
    tmp = int(pow(i, 0.5))
    if tmp * tmp == i:
        break
print(i)
Problem p03557 (python)

Fixed submission:
import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = map(int, input().split())
C = sorted(map(int, input().split()))
print(sum(bisect.bisect_left(A, b) * (N - bisect.bisect(C, b)) for b in B))

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
print(sum(len(A[:bisect.bisect_left(A, b)]) * len(C[bisect.bisect(C, b)]) b for b in B))
Problem p03565 (python)

Fixed submission:
S = input()
T = input()
ans = []
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        tmp = S[:i] + T + S[i+len(T):]
        ans.append(tmp.replace('?', 'a'))
if ans:
    print(ans[-1])
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

for i in range(len(S)):
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
        S = S[:i] + T
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print("UNRESTORABLE")
Problem p03605 (python)

Fixed submission:
print("Yes" if "9" in input() else "No")

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
for _ in range(N):
    l, r = map(int, input().split())
    ans += (r - l) + 1
print(ans)
Problem p03610 (python)

Fixed submission:
s = input()
print("".join([s[i] for i in range(0, len(s), 2)]))

Buggy submission (verdict: Runtime Error):
s = input()
print("".join([s[i] for i in range(0, len(s), 2)))
Problem p03632 (python)

Fixed submission:
A, B, C, D = map(int, input().split())
res = list(set(range(A, B+1)) & set(range(C, D+1)))
try:
    print(res[-1] - res[0])
except:
    print(0)

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
res = list(set(range(A, B+1)) & set(range(C, D+1)))
print(res[-1] - res[0])
Problem p03657 (python)

Fixed submission:
A, B = map(int, input().split())
if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
print("Impossible" if sum(map(int, input.split())) % 3 else "Possible")

Buggy submission (verdict: Runtime Error):
print("Impossible" if sum(map(int, input)) % 3 else "Possible")
Problem p03693 (python)

Fixed submission:
print("NO " if int("".join(input().split())) % 4 else "YES")

Buggy submission (verdict: Runtime Error):
print("NO " if map(int, "".join(input().split())) % 4 else "YES")
Problem p02678 (python)

Fixed submission:
n, m = map(int, input().split())
import sys
sys.setrecursionlimit(10**6)
L=[set() for i in range(n)]
for i in range(m):
    a, b =  map(int, input().split())
    L[a-1] |= {b}
    L[b-1] |= {a}
Y = {range(1, n+1)}
Z = [0]*(n-1) 
S = {1}
def f(X):
    global S, Z
    X_next = set()
    for j in X:
        R = L[j-1]-S
        S |= L[j-1]
        X_next |= R
        for k in R:
            Z[k-2] += j
    if X_next == set():
        print("Yes")
        print('\n'.join(map(str, Z)))
    else:
        return  f(X_next)
f({1})

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L=[set() for i in range(n)]
for i in range(m):
    a, b =  map(int, input().split())
    L[a-1] |= {b}
    L[b-1] |= {a}
Y = {range(1, n+1)}
Z = [0]*(n-1) 
S = {1}
def f(X):
    global S, Z
    X_next = set()
    for j in X:
        R = L[j-1]-S
        S |= L[j-1]
        X_next |= R
        for k in R:
            Z[k-2] += j
    if X_next == set():
        print("Yes")
        print('\n'.join(map(str, Z)))
    else:
        return  f(X_next)
f({1})

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L=[set() for i in range(n)]
for i in range(m):
    a, b =  map(int, input().split())
    L[a-1] |= {b}
    L[b-1] |= {a}
# L=[{2,3}, {4,5}, {1,4}, ...]
# 1→{2,3}→{4,5}
Y = {range(1, n+1)}
Z = [0]*(n-1) 
S = {1}
def f(X):
    global S, Z
    X_next = set()
    for j in X:
        R = L[j-1]-S
        S |= L[j-1]
        X_next |= R
        for k in R:
            Z[k-2] += j
    if X_next == set():
        print("Yes")
        print('\n'.join(map(str, Z)))
    else:
        return  f(X_next)
f({1})

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L=[set() for i in range(n)]
for i in range(m):
    a, b =  map(int, input().split())
    L[a-1] |= {b}
    L[b-1] |= {a}
Y = {range(1, n+1)}
Z = [0]*(n-1) 
S = {1}
def f(X):
    global S, Z
    X_next = set()
    for j in X:
        R = L[j-1]-S
        S |= L[j-1]
        X_next |= R
        for k in R:
            Z[k-2] += j
    if X_next == set():
        print("Yes")
        print(Z[i] for i in range(n-1))
    else:
        return  f(X_next)
f({1})

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
L=[set() for i in range(n)]
for i in range(m):
    a, b =  map(int, input().split())
    L[a-1] |= {b}
    L[b-1] |= {a}
Y = {range(1, n+1)}
Z = [0]*(n-1) 
S = {1}
def f(X):
    global S, Z
    D = set()
    for j in X:
        R = L[j-1]-S
        S |= L[j-1]
        D |= R
        for k in R:
          Z[k-2]=j
    if S == Y:
        print("Yes")
        print(Z[i] for i in range(n-1))
    else:
      f(D)
f({1})
Problem p02691 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

from collections import Counter
P = Counter(L)
Q = Counter(R)
 
ans = 0
for k, v in P.items():
  if k in Q:
    ans += v*Q[k]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

P = collections.Counter(L)
Q = collections.Counter(R)
 
ans = 0
for k, v in P.item():
    if k in Q:
        ans += v*Q[k]
print(ans)
Problem p02694 (python)

Fixed submission:
x = int(input())
import sys
sys.setrecursionlimit(4000)

import math
p = math.log(1.01, 10)
q = int(math.log(x/100, 10)/p)


def f(n):
  if n == 1:
    return 101
  else:
    return int(f(n-1)*1.01)
n = q
while f(n) < x:
  n += 1
else:
  print(n)

Buggy submission (verdict: Runtime Error):
x = int(input())
import sys
sys.setrecursionlimit(2000)

def f(n):
  if n == 1:
    return 101
  else:
    return int(f(n-1)*1.01)
n = 1
while f(n) < x:
  n += 1
else:
  print(n)
Problem p02714 (python)

Fixed submission:
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
R=[]
G=[]
B=[]
for i in range(n):
  if s[i]=="R":
    R.append(i)
  elif s[i]=="G":
    G.append(i)
  else:
    B.append(i)
x = 0
for i in R:
  for j in G:
    if 0 <= 2*j-i <= n-1 and s[2*j-i]=="B":
      x+=1
    if 0 <= 2*i-j <= n-1 and s[2*i-j]=="B":
      x+=1
    if (i+j)%2==0 and s[(i+j)//2]=="B":
      x+=1
print(z-x)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  R=[]
  G=[]
  B=[]
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  x = 0
  for i in R:
    for j in G:
      if 0 <= 2*j-i <= n-1 and s[2*j-i]=="B":
        x+=1
      if 0 <= 2*i-j <= n-1 and s[2*i-j]=="B":
        x+=1
      if (i+j)%2==0 and s[(i+j)//2]=="B":
        x+=1
print(z-x)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  R=[]
  G=[]
  B=[]
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  x = 0
  for i in R:
    for j in G:
      if 0 <= 2*j-i <= n-1 and s[2*j-i]=="B":
        x+=1
      if 0 <= 2*i-j <= n-1 and s[2*i-j]=="B":
        x+=1
      if (i+j)%2==0 and s[(i+j)//2]=="B":
        x+=1
print(z-x)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  R=[]
  G=[]
  B=[]
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  x = 0
  for i in R:
    for j in G:
      for k in B:
        if 2*j==i+k or 2*i==j+k or 2*k==i+j:
          x+=1
print(z-x)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  R=[]
  G=[]
  B=[]
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  x = 0
  for i in R:
    for j in G:
      if (0<= 2*j-i <=n-1 and s[2*j-i] in B) or (0<= 2*i-j <=n-1 and s[2*i-j] in B):
          x += 1
print(z-x)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
a = s.count("R")
b = s.count("G")
c = s.count("B")
z = a*b*c
if z ==0:
  print(0)
else:
  x = 0
  for i in range(n-2):
    for j in range(i+1, n-1):
      if s[i]==s[j]:
        continue
      else:
        if 2*j-i<= n-1 and len({s[i], s[j], s[2*j-i]})==3:
          x += 1
print(z-x)
Problem p02717 (python)

Fixed submission:
x, y, z =map(int, input().split())
A=[z, x, y]
print(' '.join(map(str, A)))

Buggy submission (verdict: Runtime Error):
x, y, z =map(int, input().split())
A=[z, x, y]
print(' '.join(A))
Problem p02732 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
D = Counter(A)
L = list(D.values())

ans = 0
for x in L:
    ans += x*(x-1)//2

for k in range(n):
    print(ans-(D[A[k]]-1))

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split())
from collections import Counter
L = list(Counter(A))
LV = L.values()

ans = 0
for x in LV:
    ans += x*(x-1)//2

for k in range(n):
    print(ans-(A[k]-1))
Problem p02743 (python)

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

if x <= 0:
  print("No")
elif 4*a*b >= x**2:
  print("No")
else:
  print("Yes")

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

A = a+b+2*math.sqrt(a*b)

if A < c:
  print("Yes")
else:
  print("No")

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

A = a+b+2*sqrt(a*b)

if A < c:
  print("Yes")
else:
  print("No")
Problem p02748 (python)

Fixed submission:
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(A)
D = sorted(B)
l = C[0] + D[0]
for i in range(m):
  x, y, c = map(int, input().split())
  k = A[x-1] + B[y-1] -c
  if l > k:
    l = k
print(l)

Buggy submission (verdict: Runtime Error):
a, b, m = map(int, input().split())
A = [map(int, input().split())]
B = [map(int, input().split())]
C = sorted(A)
D = sorted(B)
l = C[0] + D[0]

for i in range(m):
  x, y, c = map(int, input().split())
  k = A[x-1] + B[y-1] -c
  if l > k:
    l = k
  else:
    l = l
print(l)

Buggy submission (verdict: Runtime Error):
a, b, m = map(int, input().split())
A = [map(int, input().split())]
B = [map(int, input().split())]
C = sorted(A)
D = sorted(B)
l = C[0] + D[0]

for i in range(m):
  x, y, c = map(int, input().split())
  k = A[x-1] + B[y-1] -c
  if l > k:
    l = k
  else:
    continue
print(l)
Problem p02756 (python)

Fixed submission:
s = input()
q = int(input())
par = 0
pre = ""
pos = ""

for i in range(q):
  t = input().split()
  if t[0] == "1":
    par += 1
  elif (par + int(t[1]))%2 == 1:
    pre = t[2] + pre
  else:
    pos = pos + t[2]
    
ans = pre + s + pos

if par%2 == 0:
  print(ans)
else:
  print(ans[::-1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split("")) for _ in range(Q)]

for i in range(Q):
  if A[i] == ("1"):
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + "S"
    else:
      S = "S" + A[i][2] 
      
print(S)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = str(input())
Q = int(input())
A = [[input().split("")] for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + str(S)
    else:
      S = str(S) + A[i][2] 
      
print(S)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split("")) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = A[i][2] + S
    else:
      S = S + A[i][2] 
      
print(S)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [(input().split("")) for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
Q = int(input())
A = [[input().split()] for _ in range(Q)]

for i in range(Q):
  if A[i] == ["1"]:
    S = ''.join(list(reversed(S)))
  else:
    if A[i][1] == "1":
      S = S + A[i][2]
    else:
      S = A[i][2] + S
      
print(S)
Problem p02767 (python)

Fixed submission:
import numpy as np
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = np.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
s = n*(m**2) - 2*a*m + b
print(int(s))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = np.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
else:
  break
s = n*(m**2) - 2*a*m + b
print(int(s))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
X = list(map(int, input().split()))
a = sum(X)
b = sum(X[i]**2 for i in range(n))
m = math.floor(a/n)
if m + 1/2 <= a/n:
  m += 1
else:
  break
s = n*(m**2) - 2*a*m + b
print(s)
Problem p02778 (python)

Fixed submission:
s = input()
n = len(s)
X = "x" *n
print(X)

Buggy submission (verdict: Runtime Error):
s = input()
n = len("s")
X = x*n
print("X")

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
X = x*n
print("X")

Buggy submission (verdict: Runtime Error):
s = input()
n = int(len(s))
X = x*n
print(X)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
X = x*n
print(X)
Problem p02780 (python)

Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
Q = [0]
for p in P:
    Q.append(Q[-1] + (p+1)/2)

print(max([Q[i+K]-Q[i] for i in range(N-K+1)]))

Buggy submission (verdict: Runtime Error):
n , k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(1,n+1):
  a_i = (1+p[i])/2
def sigma(a, b):
    s = 0
    for i in range(a, b+1):
        s += a_i
    return s
  
for i in range(n-k+1):
  r_i = sigma(i, i+k-1)
  
M = max(r_i for i in range(n-k+1))
print(M)

Buggy submission (verdict: Runtime Error):
n , k = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
  a_i = (1+p[i])/2
def sigma(a, b):
    s = 0
    for i in range(a, b+1):
        s += a_i
    return s
  
for i in range(n-k+1):
  r_i = sigma(i, i+k-1)
  
M = max(r_i) for i in range(n-k+1)
print(M)
Problem p02783 (python)

Fixed submission:
H, A = map(int, input().split())
n = (H+A-1)//A
print(n)

Buggy submission (verdict: Runtime Error):
H, A = int(input().split())
n = H+A-1//A
print(n)
Problem p02801 (python)

Fixed submission:
print(chr(ord(input())+1))

Buggy submission (verdict: Runtime Error):
N, K, M = map(int, input().split())
L = list(map(int, input().split()))
diff = N*M-sum(L)
if diff <= K:
  print(max(0, diff))
else:
  print(-1)
Problem p02802 (python)

Fixed submission:
n, m = map(int, input().split())
ac = [0]*n
wa = [0]*n
a = 0
w = 0
for i in range(m):
  p, s = input().split()
  p = int(p)-1
  if ac[p] == 0 and s == "AC":
    ac[p] += 1
    a += 1
    w += wa[p] 
  elif ac[p] == 0 and s == "WA":
    wa[p] += 1
print(a,w)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ac = [0]*n
wa = [0]*n
a = 0
w = 0
for i in range(m):
  p, s = input().split()
  p = int(p)-1
  if ac[p] == 0, s == "AC":
    ac[p] += 1
    a += 1
    w += wa[p] 
  elif ac[p] == 0, s == "WA":
    wa[p] += 1
print(a,w)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ac = [0]*n
wa = [0]*n
a = 0
w = 0
for i in range(m):
  p, s = input().split()
  p = int(p)-1
  if ac[p] == 0, s == "AC":
    acs[p] += 1
    a += 1
    w += was[p] 
  elif ac[p] == 0, s == "WA":
    was[p] += 1
print(a,w)
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
print("Yes") if 500*k >= x else print("No")

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print("Yes") if 500*k >= x, else print("No")

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print("Yes" if 500*k >= x, else "No")

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
print("Yes" if 500*k >= x, else "No")
Problem p02813 (python)

Fixed submission:
import itertools 
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
l = list(itertools.permutations([i for i in range(1, n+1)]))
print(abs(l.index(P) - l.index(Q)))

Buggy submission (verdict: Runtime Error):
import itertools 
n = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
l = list(itertools.permutation([i for i in range(1, n+1)]))
print(abs(l.index(P) - l.index(Q)))
Problem p03140 (python)

Fixed submission:
n = int(raw_input())
a = []
for _ in range(3):
  a.append(raw_input())
ans = 0
for i in range(n):
  diff_chars = set()
  for j in range(3):
    diff_chars.add(a[j][i])
  ans += len(diff_chars) - 1
print ans

Buggy submission (verdict: Runtime Error):
n = map(int, raw_input())
a = []
for _ in range(3):
  a.append(raw_input())
ans = 0
for i in range(n):
  diff_chars = set()
  for j in range(3):
    diff_chars.add(a[j][i])
  ans += len(diff_chars) - 1
print ans
Problem p02741 (python)

Fixed submission:
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
N = int(input())
print(l[N-1])

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
 
def common(s1, s2):
	l1 = len(s1)
	l2 = len(s2)
	memo = [[0 for i in range(l1+2)] for j in range(l2+2)]
 
	for idx1,w1 in enumerate(s1):
		for idx2,w2 in enumerate(s2):
			if w1==w2 or w1=='?'or w2=='?':
				memo[idx2+1][idx1+1] = memo[idx2][idx1] + 1
 
	return memo
m1 = 0
m2 = 0
m3 = 0
for l in common(a,b):
	if max(l)>m1:
		m1 = max(l)
for l in common(a,c):
	if max(l)>m2:
		m2 = max(l)
for l in common(b,c):
	if max(l)>m3:
		m3 = max(l)
ans=len(a)+len(b)+len(c)-m1-m2-m3+min([m1,m2,m3])
 
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

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

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

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    counter[p] += x

ans = [0] * n


def f(par, node, count):
    count += counter[node]
    ans[node] = count
    for n in edges[node]:
        if n == par:
            continue
        f(node, n, count)


f(-1, 0, 0)
print(*ans)

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

edges = dict()
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges.setdefault(a, [])
    edges[a].append(b)
    edges.setdefault(b, [])
    edges[b].append(a)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    counter[p] += x

ans = [0] * n


def f(par, node, count):
    count += counter[node]
    ans[node] = count
    for n in edges[node]:
        if n == par:
            continue
        f(node, n, count)


f(-1, 0, 0)
print(*ans)

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

edges = dict()
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges.setdefault(a, [])
    edges[a].append(b)
    edges.setdefault(b, [])
    edges[b].append(a)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    counter[p] += x

ans = ['0'] * n


def f(node, count):
    count += counter[node]
    ans[node] = str(count)
    while len(edges[node]) > 0:
        n = edges[node].pop()
        edges[n].remove(node)
        f(n, count)


f(0, 0)
print(' '.join(ans))