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

Fixed submission:
from collections import deque
import sys
def main():
    H,W = list(map(int,sys.stdin.readline().split()))
    place_h = [0,-1,0,1]
    place_w = [1,0,-1,0]
    black = 0
    q = deque([])
    dist = []
    A = []
    for i in range(H):
        a = sys.stdin.readline().split()
        a = list(a[0])
        dist_sub = []
        for j in range(W):
            if a[j] == "#":
                black += 1
                q.append([i,j])
                dist_sub.append(0)
            else:
                dist_sub.append(-1)
        A.append(a)
        dist.append(dist_sub)

    ans = 0
    
    while len(q) > 0:
        vh,vw = q.popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q.append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
                if ans < dist[nvh][nvw]:
                    ans = dist[nvh][nvw]

    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
import numpy
H,W = list(map(int,input().split()))
A = [input().split() for i in range(H)]
place_h = [0,-1,0,1]
place_w = [1,0,-1,0]
black = 0
q = []
dist = [[-1 for i in range(W)] for j in range(H)]
for i in range(H):
    A[i] = list(A[i][0])
    for j in range(W):
        if A[i][j] == "#":
            black += 1
            q.append(deque([[i,j]]))
            dist[i][j] = 0

while len(q)>0:
    i = 0
    while i < black:
        if len(q[i]) == 0:
            q.pop(i)
            black -= 1
            continue
        vh,vw = q[i].popleft()
        for m in range(4):
            nvh = vh+place_h[m]
            nvw = vw+place_w[m]
            if 0<=nvh<H and 0<=nvw<W and dist[nvh][nvw] == -1:
                q[i].append([nvh,nvw])
                dist[nvh][nvw] = dist[vh][vw]+1
        i+=1
print(numpy.amax(dist))
Problem p03803 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N, M = map(int,input().split())
if N==1:
    N=14
if M==1:
    M=14
if N>M:
    print("Alice")
elif M>N:
    print("Bob")
else:
    print("Draw")

Buggy submission (verdict: Runtime Error):
N,M=list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(M)]
seen = [-1 for i in range(N)]
count = 0
def dfs(x):
    global count
    if sum(seen) == N:
        count += 1
        return
    
    for i in range(M):
        if a[i][0] == x and seen[a[i][1]-1] == -1:
            seen[a[i][1]-1] = 1
            dfs(a[i][1])
            seen[a[i][1]-1] = -1
        if a[i][1] == x and seen[a[i][0]-1] == -1:
            seen[a[i][0]-1] = 1
            dfs(a[i][0])
            seen[a[i][0]-1] = -1
seen[0] = 1
dfs(1)
print(count)
Problem p02897 (python)

Fixed submission:
a=0
n=int(input())
a+=n//2
if n%2 == 1:
    a+=1
print(a/n)

Buggy submission (verdict: Runtime Error):
n=int(input())
if n == 1:
  print(1)
elif n%2 == 0:
  print(0.5):
else:
  print(0.6)
Problem p03072 (python)

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

Buggy submission (verdict: Runtime Error):
n= int(input())
a=[]
c=1
for i in range(n):
    h=int(input().split)
    a.append(h)
d=a[0]
for b in range(n-1):
    if d <= a[b+1]:
        c+=1
    d=a[b+1]
print(c)

Buggy submission (verdict: Runtime Error):
n= int(input())
a=[]
c=1
for i in range(n):
    h=int(input())
    a.append(h)
for b in range(n-1):
    if a[b] <= a[b+1]:
        c+=1
print(c)
Problem p03073 (python)

Fixed submission:
import math
s=str(input())
b=''
c=0
d=math.ceil(len(s)/2)
if s[0]=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
if len(s) != len(b):
    b = b[:-1]
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
import math
s=str(input())
b=''
c=0
d=math.ceil(len(s)/2)
if len(s) == 1:
    print(0)
elif s[0]=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
if len(s) != len(b):
    b = b[:-1]
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
s=str(input())
b=''
c=0
d=int(round(len(s)/2))
if len(s) == 1:
    print(0)
elif s[0]=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
if len(s) != len(b):
    b = b[:-1]
    print(b)
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
s=str(input())
a=0
b=''
c=0
d=round(int(len(s)/2))
if len(s) == 1:
    print(0)
elif len(s)%2 ==1:
    for v in range(d+1):
        if v < d and s[v+a]== '0':
            b+='01'
        elif v < d and s[v+a] =='1':
            b +='10'
        elif b[-1] == '0':
            b+= '1'
        else:
            b+= '0'
        a+=1
elif s[0]=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
s=str(input())
a=[0]
b=''
c=0
d=int(len(s)/2)
if d == 0:
    print(0)
elif a=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)

Buggy submission (verdict: Runtime Error):
s=str(input())
a=[0]
b=''
c=0
d=int(len(s)/2)
if a=='0':
    for i in range(d):
        b+="01"
else:
    for i in range(d):
        b+="10"
for u in range(len(s)):
    if s[u] != b[u]:
        c+=1
print(c)
Problem p03075 (python)

Fixed submission:
a=[]
for i in range(5):
    b=int(input())
    a.append(b)
c=int(input())
if a[4] - a[0] <= c:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(4):
    b=int(input())
    a.append(b)
c=int(input())
if a[0] - a[4] <= c:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
a=[]
for i in range(4):
    b=int(input())
    a.append(b)
c=int(input())
if max(a) - min(a) =< c:
    print('Yay!')
else:
    print(':(')
Problem p03208 (python)

Fixed submission:
n,k = map(int,input().split())
a=[]
c=[]
for i in range(n):
    b=int(input())
    a.append(b)
a.sort()
for u in range(n-k+1):
    d=a[u+k-1]-a[u]
    c.append(d)
print(min(c))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a=[]
c=[]
for i in range(n):
    b=int(input())
    a.append(b)
a.sort()
for u in range(n-2):
    d=a[u+k-1]-a[u]
    c.append(d)
print(min(c))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split)
a=[]
c=[]
for i in range(n):
    b=int(input())
    a.append(b)
sorted(a)
for u in range(n-1):
    d=a[u+k-1]-a[u]
    c.append(d)
print(min(c))
Problem p02897 (python)

Fixed submission:
num_odd = lambda x: x/2 if x % 2 == 0 else x/2 + 1 
 
import fileinput
for line in fileinput.input():
    try:
        N = int(line.strip())
    except:
        continue
 
    print(1.0 * num_odd(N) / N)

Buggy submission (verdict: Runtime Error):
is_odd = lambda x: x % 2 == 0

import fileinput
for line in fileinput.input():
	print(sum([1 for x in range(1, x) if is_odd(x)]/x)
Problem p02897 (python)

Fixed submission:
n = int(input())
p = 0
for i in range(n+1):
    if i % 2 == 1:
        p += 1
print('{:.10}'.format(p/n))

Buggy submission (verdict: Runtime Error):
import math
from fractions import gcd


a, b = map(int, input().split())
g = gcd(a, b)


s = int(math.sqrt(g))

f = {}
for i in range(2, s+1):
    while g % i == 0:
        f[i] = f.get(i, 0) + 1
        g = g/i
if g != 1:
    f[g] = f.get(g, 0) + 1

print(len(f)+1)

Buggy submission (verdict: Runtime Error):
import math


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([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

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

    return arr


a, b = list(map(int, input().split()))
g = math.gcd(a, b)
if g == 1:
    print(factorization(g))
    print('1')
else:
    print(factorization(g))
    print(len(factorization(g))+1)

Buggy submission (verdict: Runtime Error):
import math


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([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

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

    return arr


a, b = list(map(int, input().split()))
g = math.gcd(a, b)
if g == 1:
    print(factorization(g))
    print('1')
else:
    print(factorization(g))
    print(len(factorization(g))+1)
Problem p03631 (python)

Fixed submission:
n = int(input())
if n//100 == n%10:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(inout())
if n//100 == n%10:
  print('YES')
else:
  print('NO')
Problem p03329 (python)

Fixed submission:
n = int(input())
dp = [i for i in range(n+1)]
for i in range(n+1):
    power = 1
    while 6**power <= i:
        dp[i] = min(1+dp[i-6**power],dp[i])
        power += 1
    power = 1
    while 9**power <= i:
        dp[i] = min(1+dp[i-9**power],dp[i])
        power += 1
print(dp[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
dp = [float("Inf")]*(n+1)
for i in range(6):
    dp[i] = i
for i in range(n+1):
    power = 1
    while i >= 6 ** power:
        dp[i] = min(dp[i],dp[i-6**power]+1)
        power += 1
    power = 1
    while i >= 9 ** power:
        dp[i] = min(dp[i],dp[i-9**power]+1)
        power += 1
print(dp[n])
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)

def dfs(v,d):
    memo[v] = d
    for i in graph[v]:
        if memo[i[0]] != -1:continue
        dfs(i[0],d+i[1])
        
n = int(input())
graph = [[] for _ in range(n)]
memo = [-1]*n
for i in range(n-1):
    x,y,z = map(int,input().split())
    graph[x-1].append([y-1,z])
    graph[y-1].append([x-1,z])
q,k = map(int,input().split())
ary = [list(map(int,input().split())) for _ in range(q)]
dfs(k-1,0)
print(*[memo[x-1]+memo[y-1] for x,y in ary],sep="\n")

Buggy submission (verdict: Runtime Error):
def dfs(v,d):
    memo[v] = d
    for i in graph[v]:
        if memo[i[0]] != -1:continue
        dfs(i[0],d+i[1])

n = int(input())
graph = [[] for _ in range(n)]
memo = [-1]*n
for i in range(n-1):
    x,y,z = map(int,input().split())
    graph[x-1].append([y-1,z])
    graph[y-1].append([x-1,z])
q,k = map(int,input().split())
ary = [list(map(int,input().split())) for _ in range(q)]
dfs(k-1,0)
for x,y in ary:
    print(memo[x-1]+memo[y-1])

Buggy submission (verdict: Runtime Error):
def dfs(v,d,p):
    memo[v] = d
    flag = False
    for i in graph[v]:
        if memo[i[0]] != -1:continue
        dfs(i[0],d+i[1],v)
    sub_tree[v].append(v)
    for j in graph[v]:
        if j[0] == p:continue
        sub_tree[v] += sub_tree[j[0]]
    if p == k-1:arr.append(sub_tree[v])
n = int(input())
graph = [[] for _ in range(n)]
memo = [-1]*n

for i in range(n-1):
    x,y,z = map(int,input().split())
    graph[x-1].append([y-1,z])
    graph[y-1].append([x-1,z])
q,k = map(int,input().split())
sub_tree = [[] for _ in range(n)]
arr = []
ary = [list(map(int,input().split())) for _ in range(q)]
dfs(k-1,0,0)
arr.pop()
a = [0,0]
for i in range(q):
    for j in range(len(arr)):
        if ary[i][0] in arr[j]:
            a[0] = j
        if ary[i][1] in arr[j]:
            a[1] = j
    if a[0] == a[1]:
        print(memo[ary[i][0]-1]+memo[ary[i][1]-1])
    else:
        print(memo[ary[i][0]-1]+memo[ary[i][1]-1])
Problem p03804 (python)

Fixed submission:
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
r = any([r[j:j+m] for r in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print("Yes" if r else "No")

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
flag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j:j+m] == b[0] and a[i+1][j:j+m] == b[1]:
            flag = 1
print("Yes" if flag == 1 else "No")

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
print(a,b)
flag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j:j+m] == b[0] and a[i+1][j:j+m] == b[1]:
            flag = 1
print("Yes" if flag == 1 else "No")

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
flag = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][i:i+m] == b[0] and a[i+1][i:i+m] == b[1]:
            flag = 1
print("Yes" if flag == 1 else "No")
Problem p03307 (python)

Fixed submission:
n = int(input())
if n % 2==0:
    print(n)
else:
    print(2*n)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
print(n*2/math.gcd(n,2))
Problem p03315 (python)

Fixed submission:
inp = input()
plus = int(inp.count("+"))
minus = int(inp.count("-"))
print(plus-minus)

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

ans = math.ceil((n-1)/(k-1))
print(ans)

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

ans = int((n-k)/(k-1)+2)
print(ans)

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

ans = int((n-k)/(k-1)+2)
Problem p02915 (python)

Fixed submission:
n=int(input())
print(n**3)

Buggy submission (verdict: Runtime Error):
n=input()
print(n**3)

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

Buggy submission (verdict: Runtime Error):
N=input()
print(int(N**3))

Buggy submission (verdict: Runtime Error):
N=input()
print(N**3)

Buggy submission (verdict: Runtime Error):
N=input()
ans = N**3
print(ans)

Buggy submission (verdict: Runtime Error):
N=input()
 print(N^3)
Problem p02990 (python)

Fixed submission:
import math
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_//(r_*n_r_)

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

for i in range(1, k+1):
  if n-k+1 >= i:
    ans =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
  else:
    ans = 0
  print(ans)

Buggy submission (verdict: Runtime Error):
import math
def cmb(n, r):
    return math.factorial(n)/(math.factorial(r)*math.factorial(n-r) )

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

for i in range(1, k+1):
    if n-k+1 >= i:
        ans =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
    else:
        ans = 0
    print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_//(r_*n_r_)

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

for i in range(1, k+1):
  if n-k+1 >= i:
    ans =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
  else:
    ans
  print(ans)

Buggy submission (verdict: Runtime Error):
    def cmb(n, r):
      n_ = math.factorial(n)
      n_r_ = math.factorial(n-r) 
      r_ = math.factorial(r)
      return n_//(r_*n_r_)
     
    n,k = list(map(int, input().split(" ")))
     
    for i in range(1, k+1):
      if n-k+1 >= i:
        ni =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
        print(int(ni))
      else:
        print(0)

Buggy submission (verdict: Runtime Error):
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_//(r_*n_r_)

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

for i in range(1, k+1):
  if n-k+1 >= i:
    ni =  cmb(n-k+1,i)*cmb(k-1,i-1)%(10**9+7)
    print(int(ni))
    else:
      print(0)

Buggy submission (verdict: Runtime Error):
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_//(r_*n_r_)
 
i = list(map(int, input().split(" ")))
k = i[1]
n = i[0]
a = 1000000007
 
for i in range(1, k+1):
  if n-k+1 >= i:
  	ni =  cmb(n-k+1,i)*cmb(k-1,i-1)
  	print(int(ni%a))
  else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_//(r_*n_r_)

i = list(map(int, input().split(" ")))
k = i[1]
n = i[0]
a = 1000000007

for i in range(1, k+1):
  if n-k+1 > 0:
  	ni =  cmb(n-k+1,i)*cmb(k-1,i-1)
  	print(int(ni%a))
  else:
    print(0)

Buggy submission (verdict: Runtime Error):
import math
def cmb(n, r):
  n_ = math.factorial(n)
  n_r_ = math.factorial(n-r) 
  r_ = math.factorial(r)
  return n_/(r_*n_r_)

i = list(map(int, input().split(" ")))
k = i[1]
n = i[0]
a = 1000000007

for i in range(1, k+1):
  ni =  cmb(n-k+1,i)*cmb(k-1,i-1)
  print(int(ni%a))
Problem p02970 (python)

Fixed submission:
N,D = map(int,input().split())
a = N%(2*D+1)
b = N//(2*D+1)
if a==0:
  print(int(b))
else:
  print(int(b+1))

Buggy submission (verdict: Runtime Error):
N,D = map(int,input().split())
a = N%(2*D+1)
b = N//(2*D+1)
if a=0:
  print(int(b))
else:
  print(int(b+1))

Buggy submission (verdict: Runtime Error):
N,D = map(int,input().split())
a = N%(2*D+1)
b = N//(2*D+1)
if a=0:
  print(b)
else:
  print(int(b+1))
Problem p03011 (python)

Fixed submission:
x = list(map(int,input().split()))
b = sum(x)-max(x)
print(b)

Buggy submission (verdict: Runtime Error):
x = list[map(int,input().split())]
b = sum(x)-max(x)
print(b)
Problem p03332 (python)

Fixed submission:
n, a, b, k = map(int, input().split())
MOD = 998244353

a_max =  min(k // a, n) + 1
pair = []
for i in range(a_max):
    if (k - a * i) % b == 0:
        j = (k - a * i) // b
        if j <= n:
            pair.append([i % MOD,j % MOD])

inv = [0] * (n + 1)
inv[1] = 1
for i in range(2, n + 1):
    inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD

nCr = [0] * (n + 1)
nCr[0] = 1
for r in range(1, n + 1):
    nCr[r] = (nCr[r - 1] * (n - r + 1) * inv[r]) % MOD

result = 0
for p in pair:
    result += (nCr[p[0]] % MOD) * (nCr[p[1]] % MOD)

if result == 0:
    print(1)
else:
    print(result % MOD)

Buggy submission (verdict: Runtime Error):
n, a, b, k = map(int, input().split())
MOD = 998244353

inv = [0] * ( n + 1)
inv[1] = 1
for i in range(2, n + 1):
    inv[i] = (-(MOD // i) * inv[MOD % i]) % MOD

nCr = [0] * ( n + 1)
nCr[0] = 1
for i in range(1, n+1):
    nCr[i] = nCr[i-1] * (n - i + 1) * inv[i] % MOD

result = 0
maxA = min(n, k//a)
for i in range(maxA):
    if ( k - a * i) % b == 0:
        j = ( k - a * i) // b
        result += nCr[i] * nCr[j] % MOD
if result == 0:
    print(1)
else:
    print(result % MOD)
Problem p03013 (python)

Fixed submission:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, M: int, a: "List[int]"):
    i = 2
    arr = [1, 1]
    seek = 0
    while seek < len(a) and a[seek]==1:
        arr[1] = 0
        seek+=1
    while i<=N:
        if seek < len(a) and i == a[seek]:
            arr[0], arr[1] = arr[1], 0
            seek+=1
        else:
            arr[0], arr[1] = arr[1], (arr[0]+arr[1])%MOD
        i+=1
    print(arr[1])

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
 
MOD = 1000000007  # type: int
 
def solve(N: int, M: int, a: "List[int]"):
    i = 2
    arr = [1, 1]
    seek = 0
    while a[seek]==1:
        arr[1] = 0
        seek+=1
    while i<=N:
        if seek < len(a) and i == a[seek]:
            arr[0], arr[1] = arr[1], 0
            seek+=1
        else:
            arr[0], arr[1] = arr[1], (arr[0]+arr[1])%MOD
        i+=1
    print(arr[1])
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, a)
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, M: int, a: "List[int]"):
    i = 2
    arr = [1, 1]
    seek = 0
    while a[seek]==1:
        arr[1] = 0
        seek+=1
    while i<=N:
        if seek < len(a) and i == a[seek]:
            arr[0], arr[1] = arr[1], 0
            seek+=1
        else:
            arr[0], arr[1] = arr[1], (arr[0]+arr[1])%MOD
        i+=1
    print(arr[1])

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()
Problem p03041 (python)

Fixed submission:
N,K=[int(a) for a in input().split()]
S=input()
print(S[:K-1]+{"A":"a","B":"b","C":"c"}[S[K-1]]+S[K:])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

N=int(input())
edges = [[] for i in range(N)]
colors = [-1]*N
for i in range(N-1):
    u,v,w=[int(a) for a in input().split()]
    edges[u-1].append((v-1,w))
    edges[v-1].append((u-1,w))
 
diff = lambda n: 1 if n==0 else 0
 
def dfs(prev,curr):
    for node,d in edges[curr]:
        if node==prev:
            continue
        colors[node] = colors[curr] if d%2==0 else diff(colors[curr])
        dfs(curr,node)
 
colors[0]=0
dfs(1000000,0)
for i in range(N):
    print(colors[i])
Problem p03107 (python)

Fixed submission:
from collections import deque
sin = input()
queue = deque(maxlen=len(sin))
for s in sin:
    if len(queue)>0 and queue[-1] != s:
        queue.pop()
    else:
        queue.append(s)
#print("".join(arr))
print(len(sin)-len(queue))

Buggy submission (verdict: Runtime Error):
S = str(input())
i, ans = (0, 0)
while i>=0 and i<len(S)-1:
    print(S)
    if S[i]!=S[i+1]:
        S = S[:i]+S[i+2:] if i+2<len(S) else S[:i]
        ans += 2
        i = max(0, i-1)
    else:
        i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
sin = input()
queue = deque(maxlen=len(sin))
for s in sin:
    if len(queue)>0 and queue[-1] != s:
        queue.pop()
    else:
        queue.append(s)
#print("".join(arr))
print(len(sin)-len(queue))
Problem p03137 (python)

Fixed submission:
N, M = [int(a) for a in input().split(" ")]
X = sorted([int(a) for a in input().split(" ")])
intervals = sorted([a-b for a, b in zip(X[1:], X[:-1])])[::-1]
if M > N:
    print(sum(intervals) - sum(intervals[:N-1]))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N, M = [int(a) for a in input().split(" ")]
X = sorted([int(a) for a in input().split(" ")])
intervals = [a-b for a, b in zip(X[1:], X[:-1])]
prev, curr = [0]*(M-1), [0]*(M-1)

if M==1:
    print(0)
else:
    maxv = 0
    for i in range(M-1):
        maxv = max(intervals[i], maxv)
        prev[i] = maxv

    for i in range(N-2):
        curr[i+1] = -10**10
        for j in range(i+2, M-1):
            curr[j] = max(prev[j-2]+intervals[j], curr[j-1])
        prev, curr = curr, prev
    print(sum(intervals)-prev[-1])
Problem p03272 (python)

Fixed submission:
N,I=[int(a) for a in input().split(" ")]
print(N-I+1)

Buggy submission (verdict: Runtime Error):
N,I=[int(a) for a in input().split(" ")]
print(N-i+1)
Problem p02897 (python)

Fixed submission:
import math
n=int(input())
print(math.ceil(n/2)/n)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
       a〔int(input())〕=i
print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
print(math.ceil(n/2)/n)
Problem p02915 (python)

Fixed submission:
k = int(input())
print(k**3)

Buggy submission (verdict: Runtime Error):
k = int(input())
print(k**k