Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
dstb=[1]+[6**i for i in range(1,7)]+[9**j for j in range(1,6)]
DP=[10**5]*(N*2)
DP[0]=0
for i in range(N+1):
  for j in dstb:
    DP[i+j]=min(DP[i+j], DP[i]+1)

print(DP[N])


Fixed submission:
N=int(input())
dstb=[1]+[6**i for i in range(1,7)]+[9**j for j in range(1,6)]
DP=[10**5]*(10**5*2)
DP[0]=0
for i in range(N+1):
  for j in dstb:
    DP[i+j]=min(DP[i+j], DP[i]+1)

print(DP[N])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
n,c = map(int,input().split())
cost = [list(map(int,input().split())) for i in range(c)]
grid = [list(map(int,input().split())) for i in range(n)]
sum0 = []
sum1 = []
sum2 = []
for color in range(c):
  s0,s1,s2 = 0,0,0
  for i in range(n):
    for j in range(n):
      x = grid[i][j]-1
      if (i+j)%3 == 0:
        s0 += cost[x][color]
      elif (i+j)%3 == 1:
        s1 += cost[x][color]
      else:
        s2 += cost[x][color]
  sum0.append((s0,color))
  sum1.append((s1,color))
  sum2.append((s2,color))
ans = 10**18
for a,b,c in product(sum0,sum1,sum2):
  if a[1] != b[1] and b[1] != c[1] and c[1] != a[1]:
    ans = min(ans,a[0]+b[0]+c[0])
print(ans)

Fixed submission:
from itertools import product
n,c = map(int,input().split())
cost = [list(map(int,input().split())) for i in range(c)]
grid = [list(map(int,input().split())) for i in range(n)]
sum0 = []
sum1 = []
sum2 = []
for color in range(c):
  s0,s1,s2 = 0,0,0
  for i in range(n):
    for j in range(n):
      x = grid[i][j]-1
      if (i+j)%3 == 0:
        s0 += cost[x][color]
      elif (i+j)%3 == 1:
        s1 += cost[x][color]
      else:
        s2 += cost[x][color]
  sum0.append((s0,color))
  sum1.append((s1,color))
  sum2.append((s2,color))
ans = 10**18
for a,b,c in product(sum0,sum1,sum2):
  if a[1] != b[1] and b[1] != c[1] and c[1] != a[1]:
    ans = min(ans,a[0]+b[0]+c[0])
print(ans)
Buggy python submission (verdict: Runtime Error):
n=input()
ls = [10**i for i in range(1,6)]
if int(n) in ls:
  print(10)
else:
  print(sum([list(n)[i] for i in range(len(n))]))

Fixed submission:
n=input()
ls = [10**i for i in range(1,6)]
if int(n) in ls:
  print(10)
else:
  print(sum([int(list(n)[i]) for i in range(len(n))]))
Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
rng = 300100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)

def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*pow(fctr[n-k],mod-2,mod)*pow(fctr[k],mod-2,mod)%mod
n,a,b,k = map(int,input().split())
pair = []
for i in range(n+1):
  if (k-a*i)%b == 0 and (k-a*i)//b <= n:
    pair.append((i,(k-a*i)//b))
ans = 0
for x,y in pair:
  ans = (ans+cmb(n,x)*cmb(n,y))%mod
print(ans)

Fixed submission:
mod = 998244353
rng = 300100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n,a,b,k = map(int,input().split())
pair = []
for i in range(n+1):
  if (k-a*i)%b == 0 and (k-a*i)//b <= n:
    pair.append((i,(k-a*i)//b))
ans = 0
for x,y in pair:
  ans = (ans+cmb(n,x)*cmb(n,y))%mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 998244353
rng = 300100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n,a,b,k = map(int,input().split())
pair = []
for i in range(n+1):
  if (k-a*i)%b == 0 and (k-a*i)//b <= n:
    pair.append((i,(k-a*i)//b))
ans = 0
for x,y in pair:
  ans = (ans+cmb(n,x)*cmb(n,y))%mod
print(ans)

Fixed submission:
mod = 998244353
rng = 300100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
n,a,b,k = map(int,input().split())
pair = []
for i in range(n+1):
  if (k-a*i)%b == 0 and (k-a*i)//b <= n:
    pair.append((i,(k-a*i)//b))
ans = 0
for x,y in pair:
  ans = (ans+cmb(n,x)*cmb(n,y))%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
N = len(s)
K = int(input())
word = []
for i in range(N):
    for j in range(i, N):
        word.append(s[i:j+1])

word.sort()
print(word[K])

Fixed submission:
s = input()
N = len(s)
K = int(input())
word = []
for i in range(N):
    for j in range(i, min(N, i+K)):
        word.append(s[i:j+1])

word.sort()
word_set = list(set(word))
word_set.sort()
print(word_set[K-1])
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list("."+(input())+"."))
a.insert(0,["."]*(h+2))
a.append(["."]*(h+2))
flg = True
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      for (k,l) in ((i,j+1),(i,j-1),(i+1,j),(i-1,j)):
        if a[k][l] != "#":
          cnt+=1
          if cnt == 4:
            flg = False
    cnt=0
if flg:
  print("Yes")
else:
  print("No")

Fixed submission:
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list("."+(input())+"."))
a.insert(0,["."]*(w+2))
a.append(["."]*(w+2))
flg = True
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      for (k,l) in ((i,j+1),(i,j-1),(i+1,j),(i-1,j)):
        if a[k][l] != "#":
          cnt+=1
          if cnt == 4:
            flg = False
    cnt=0
if flg:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
a = [list(input().rstrip()) for i in range(n)]
ans = 0
for k in range(n):
    for i in range(n):
        for j in range(i+1,n):
            if a[(i+k)%n][j] != a[(j+k)%n][i]:
                break
        else:
            continue
        break
    else:
        ans += n
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = [list(input().rstrip()) for i in range(n)]
ans = 0
for k in range(n):
    for i in range(n):
        for j in range(i+1,n):
            if a[(i+k)%n][j] != a[(j+k)%n][i]:
                break
        else:
            continue
        break
    else:
        ans += n
print(ans)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=[int(input()) for i in range(n)]
print(n+(x-sum(a))//min(a)]

Fixed submission:
n,x=map(int,input().split())
a=[int(input()) for i in range(n)]
print(n+(x-sum(a))//min(a))
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n,c = map(int,input().split())
wv = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]]
n += 2
ansls = []
ls1 = [0]*n
ls2 = [0]*n
ls3 = [0]*n
ls4 = [0]*n
for i in range(1,n):
  w,v = wv[i]
  w -= wv[i-1][0]
  ls1[i] = v-w*2
  ls2[i] = v-w
for i in range(n-2,-1,-1):
  w,v = wv[i]
  w -= wv[i+1][0]
  ls3[n-i-1] = v+w*2
  ls4[n-i-1] = v+w
als1 = list(accumulate(ls1))
als2 = list(accumulate(ls2))
als3 = list(accumulate(ls3))
als4 = list(accumulate(ls4))
als1 = list(accumulate(als1,max))
als2 = list(accumulate(als2,max))
als3 = list(accumulate(als3,max))
als4 = list(accumulate(als4,max))
for i in range(n-1):
  ansls.append(als1[i]+als4[n-2-i])
  ansls.append(als2[i]+als3[n-2-i])
print(max(ansls))

Fixed submission:
from itertools import accumulate
n,c = map(int,input().split())
wv = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]]
n += 2
ansls = []
ls1 = [0]*n
ls2 = [0]*n
ls3 = [0]*n
ls4 = [0]*n
for i in range(1,n):
  w,v = wv[i]
  w -= wv[i-1][0]
  ls1[i] = v-w*2
  ls2[i] = v-w
for i in range(n-2,-1,-1):
  w,v = wv[i]
  w -= wv[i+1][0]
  ls3[n-i-1] = v+w*2
  ls4[n-i-1] = v+w
als1 = list(accumulate(ls1))
als2 = list(accumulate(ls2))
als3 = list(accumulate(ls3))
als4 = list(accumulate(ls4))
als1 = list(accumulate(als1,max))
als2 = list(accumulate(als2,max))
als3 = list(accumulate(als3,max))
als4 = list(accumulate(als4,max))
for i in range(n-1):
  ansls.append(als1[i]+als4[n-2-i])
  ansls.append(als2[i]+als3[n-2-i])
print(max(ansls))

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
n,c = map(int,input().split())
wv = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]]
n += 2
ansls = []
for i in range(n):
  if wv[i][0] > c//2:
    spr = i
    break
for sp in spr-1,spr:
  ls = [0]*n
  lsx = [0]*n
  for i in range(1,sp):
    w,v = wv[i]
    w -= wv[i-1][0]
    ls[i] = v-w*2
    lsx[i] = v-w
  for i in range(n-2,sp-1,-1):
    w,v = wv[i]
    w -= wv[i+1][0]
    ls[i] = v+w*2
    lsx[i] = v+w
  alsf = list(accumulate(ls[:sp]))
  alsl = list(accumulate(ls[sp:][::-1]))
  alsxf = list(accumulate(lsx[:sp]))
  alsxl = list(accumulate(lsx[sp:][::-1]))
  ansls.append(max(alsf)+max(alsxl))
  ansls.append(max(alsl)+max(alsxf))
print(max(ansls))

Fixed submission:
from itertools import accumulate
n,c = map(int,input().split())
wv = [[0,0]]+[list(map(int,input().split())) for i in range(n)]+[[c,0]]
n += 2
ansls = []
ls1 = [0]*n
ls2 = [0]*n
ls3 = [0]*n
ls4 = [0]*n
for i in range(1,n):
  w,v = wv[i]
  w -= wv[i-1][0]
  ls1[i] = v-w*2
  ls2[i] = v-w
for i in range(n-2,-1,-1):
  w,v = wv[i]
  w -= wv[i+1][0]
  ls3[n-i-1] = v+w*2
  ls4[n-i-1] = v+w
als1 = list(accumulate(ls1))
als2 = list(accumulate(ls2))
als3 = list(accumulate(ls3))
als4 = list(accumulate(ls4))
als1 = list(accumulate(als1,max))
als2 = list(accumulate(als2,max))
als3 = list(accumulate(als3,max))
als4 = list(accumulate(als4,max))
for i in range(n-1):
  ansls.append(als1[i]+als4[n-2-i])
  ansls.append(als2[i]+als3[n-2-i])
print(max(ansls))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c=map(int,input().split())
for i in range(a,b+1):
  if i<a+c or i>b-c:
    print(i)

Fixed submission:
a,b,c=map(int,input().split())
if c>(b-a)//2:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+c):
    print(i)
  for i in range(b-c+1,b+1):
    print(i)

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
for i in range(a,b+1):
  if i<a+n or i>b-n:
    print(i)

Fixed submission:
a,b,c=map(int,input().split())
if c>(b-a)//2:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+c):
    print(i)
  for i in range(b-c+1,b+1):
    print(i)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n==3:
  print(22,3,5)
  exit()
if n==4:
  print(2,3,4,9)
  exit()
if n==5:
  print(2,3,4,6,9)
  exit()
a=n//4
b=n%4
ans=[]
for i in range(a):
  ans.extend(6*i+2,6*i+3,6*i+4,6*i+6)
if b==1:
  ans.append(6*a+6)
if b==2:
  ans.extend(6*a+2,6*a+4)
if b==3:
  ans.extend(6*a+2,6*a+3,6*a+4)
print(*ans)

Fixed submission:
n=int(input())
if n==3:
  print(22,3,5)
  exit()
if n==4:
  print(2,3,4,9)
  exit()
if n==5:
  print(2,3,4,6,9)
  exit()
a=n//4
b=n%4
ans=[]
for i in range(a):
  ans.extend((6*i+2,6*i+3,6*i+4,6*i+6))
if a%2==0:
  if b==1:
    ans.append(6*a+6)
  if b==2:
    ans.extend((6*a+2,6*a+4))
  if b==3:
    ans.extend((6*a+2,6*a+4,6*a+6))
else:
  if b==0:
    del ans[-1]
    ans.append(6*a+3)
  if b==1:
    ans.append(6*a+3)
  if b==2:
    ans.extend((6*a+3,6*a+6))
  if b==3:
    ans.extend((6*a+2,6*a+3,6*a+4))
print(*ans)
Buggy python submission (verdict: Runtime Error):
def main():
  import sys
  input = sys.stdin.readline
  import bisect
  import numpy as np
  n = int(input())
  a = list(map(int,input().split()))
  b = list(map(int,input().split()))
  x = max(max(a),max(b)).bit_length()+1
  b = np.array(b,dtype=np.int32)
  ans = 0
  for i in range(1,x+1):
    d = sorted(b&(1<<i)-1)
    t = 1<<(i-1)
    anstmp = 0
    for j in range(n):
      y = a[j]&(1<<i)-1
      t1 = np.searchsorted(d,t-y)
      t2 = np.searchsorted(d,2*t-y)
      t3 = np.searchsorted(d,3*t-y)
      anstmp += (t2-t1)+(n-t3)
    if anstmp%2:
      ans += t
  print(ans)
main()

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

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = max(max(a),max(b)).bit_length()+1
b = np.array(b)
ans = 0
for i in range(1,x+1):
  d = np.sort(np.bitwise_and(b,(1<<i)-1))
  t = 1<<(i-1)
  anstmp = 0
  for j in range(n):
    y = a[j]&(1<<i)-1
    t1 = np.searchsorted(d,t-y)
    t2 = np.searchsorted(d,2*t-y)
    t3 = np.searchsorted(d,3*t-y)
    t4 = np.searchsorted(d,4*t-y)
    anstmp += (t2-t1)+(t4-t3)
  if anstmp%2:
    ans += t
print(ans)

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

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import bisect
import numpy as np
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a = np.array(a)
b = np.array(b)
x = max(max(a),max(b)).bit_length()+1
ans = 0
for i in range(1,x+1):
  c = sorted(np.bitwise_and(a,(1<<i)-1))
  d = sorted(np.bitwise_and(b,(1<<i)-1))
  t = 1<<(i-1)
  anstmp = 0
  for j in range(n):
    t1 = np.searchsorted(d,t-c[j])
    t2 = np.searchsorted(d,2*t-c[j])
    t3 = np.searchsorted(d,3*t-c[j])
    t4 = np.searchsorted(d,4*t-c[j])
    anstmp += (t2-t1)+(t4-t3)
  if anstmp%2:
    ans += t
print(ans)

Fixed submission:
a,b,c=map(int,input().split())
if a+b>=c:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
a=[input() for i in range(n)]
m=int(input())
b=[input() for i in range(m)]
ca = Counter(a)
cb = Counter(b)
ans = 0
for s,n in ca.items():
  ans.append(n-cb[s])
print(max(ans))

Fixed submission:
from collections import Counter
n=int(input())
a=[input() for i in range(n)]
m=int(input())
b=[input() for i in range(m)]
ca = Counter(a)
cb = Counter(b)
ans = [0]
for s,n in ca.items():
  ans.append(n-cb[s])
print(max(ans))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
ans=0
for b in range(k+1,n+1):
  q=n//b
  s=n%b
  ans+=q*(b-k)
  if s>=k:
    ans+=s-k+1
if k==0:
  ans-=n
print(ans)

Fixed submission:
print(input()[0]+input()[1]+input()[2])
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  exit()
ans = []
for i in range(1,a+1):
  ans.append(i*b)
x = (n-a)//(b-1)
y = (n-a)%(b-1)
for i in range(1,b):
  for j in range(1,x+1):
    ans.append(j*b-i)
  if i <= y:
    ans.append((x+1)*b-i)
ans_true = []
for i,x in enumerate(ans):
  ans_true.append((i+1,x))
ans_true.sort(key=lambda x:x[1])
print(*list(zip(*ans_true))[0])


Fixed submission:
n,a,b = map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  exit()
ans = []
for i in range(1,a+1):
  ans.append(i*b)
if b == 1:
  x = list(range(1,n+1))
  print(*x)
  exit()
x = (n-a)//(b-1)
y = (n-a)%(b-1)
for i in range(1,b):
  for j in range(1,x+1):
    ans.append(j*b-i)
  if i <= y:
    ans.append((x+1)*b-i)
ans_true = []
for i,x in enumerate(ans):
  ans_true.append((i+1,x))
ans_true.sort(key=lambda x:x[1])
x = list(zip(*ans_true))[0]
print(*x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nim = []
for i in range(n):
  a,k = map(int,input().split())
  while a%k != 0 and a>k:
    t = a//k
    a -= t+1
  if a<k:
    x = 0
  elif a%k == 0:
    x = a//k
  nim.append(x)
ans = 0
for i in nim:
  ans ^= i
if ans == 0:
  print("Aoki")
else:
  print("Takahashi")

Fixed submission:
n = int(input())
nim = []
for i in range(n):
  a,k = map(int,input().split())
  while a%k != 0 and a>k:
    t = a//k
    if t+1>=a%k:
      a -= t+1
    else:
      y = a%k
      a -= y//(t+1)*(t+1)
  if a<k:
    x = 0
  elif a%k == 0:
    x = a//k
  nim.append(x)
ans = 0
for i in nim:
  ans ^= i
if ans == 0:
  print("Aoki")
else:
  print("Takahashi")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nim = []
for i in range(n):
  a,k = map(int,input().split())
  while a%k != 0 and a>k:
    t = a//k
    a -= t+1
  if a<k:
    x = 0
  elif a%k == 0:
    x = a//k
  nim.append(x)
ans = 0
for i in nim:
  ans ^= i
if ans == 0:
  print("Aoki")
else:
  print("Takahashi")

Fixed submission:
n = int(input())
nim = []
for i in range(n):
  a,k = map(int,input().split())
  while a%k != 0 and a>k:
    t = a//k
    if t+1>=a%k:
      a -= t+1
    else:
      y = a%k
      a -= y//(t+1)*(t+1)
  if a<k:
    x = 0
  elif a%k == 0:
    x = a//k
  nim.append(x)
ans = 0
for i in nim:
  ans ^= i
if ans == 0:
  print("Aoki")
else:
  print("Takahashi")
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(input().split()))
if len(list(set(h)))==3:
  print("Three")
else:
  print("Four")


Fixed submission:
n=int(input())
h=list(input().split())
if len(list(set(h)))==3:
  print("Three")
else:
  print("Four")

Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
if len(list(set(h)))==3:
  print("Three")
else:
  print("Four")

Fixed submission:
n=int(input())
h=list(input().split())
if len(list(set(h)))==3:
  print("Three")
else:
  print("Four")
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
h,w = map(int, input().split(' '))
s = [list(input()) for _ in range(h)]
num_w = 0
for i in range(h):
    num_w += s[i].count("#")
q = Queue()
cnt = 0
q.put((0,0,0))
Z = -1
while not q.empty():
    (x,y,cnt) = q.get()
    s[x][y] = "#"
    if (x,y) == (h-1,w-1):
        Z = cnt
        break
    if x!=h-1 and s[x+1][y]!="#":
        q.put((x+1,y,cnt+1))
    if x!=0 and s[x-1][y]!="#":
        q.put((x-1,y,cnt+1))
    if y!=w-1 and s[x][y+1]!="#":
        q.put((x,y+1,cnt+1))
    if y!=0 and s[x][y-1]!="#":
        q.put((x,y-1,cnt+1))
if Z == -1:
    print(-1)
else:
    print(h*w-Z-1-num_w)


Fixed submission:
from queue import Queue
h,w = map(int, input().split(' '))
s = [list(input()) for _ in range(h)]
num_w = 0
for i in range(h):
    num_w += s[i].count("#")
for i in range(h):
    s[i] = ["#"]+s[i]+["#"]
s.insert(0,["#" for i in range(w+2)])
s.append(["#" for i in range(w+2)])
q = Queue()
cnt = 0
q.put([1,1,0])
s[1][1]="#"
Z = -1
while (not q.empty()):
    x,y,cnt = q.get()
    if (x,y) == (h,w):
        Z = cnt
        break
    for (i,j) in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
        if s[i][j] != "#":
            s[i][j] = "#"
            q.put([i,j,cnt+1])
if Z == -1:
    print(-1)
else:
    print(h*w-Z-1-num_w)

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
h,w = map(int, input().split(' '))
s = [list(input()) for _ in range(h)]
num_w = 0
for i in range(h):
    num_w += s[i].count("#")
q = Queue()
cnt = 0
q.put((0,0,0))
Z = -1
while not q.empty():
    (x,y,cnt) = q.get()
    s[x][y] = "#"
    if (x,y) == (h-1,w-1):
        Z = cnt
        break
    if x!=h-1 and s[x+1][y]!="#":
        q.put((x+1,y,cnt+1))
    if x!=0 and s[x-1][y]!="#":
        q.put((x-1,y,cnt+1))
    if y!=w-1 and s[x][y+1]!="#":
        q.put((x,y+1,cnt+1))
    if y!=0 and s[x][y-1]!="#":
        q.put((x,y-1,cnt+1))
if Z == -1:
    print(-1)
else:
    print(h*w-Z-1-num_w)


Fixed submission:
from queue import Queue
h,w = map(int, input().split(' '))
s = [list(input()) for _ in range(h)]
num_w = 0
for i in range(h):
    num_w += s[i].count("#")
for i in range(h):
    s[i] = ["#"]+s[i]+["#"]
s.insert(0,["#" for i in range(w+2)])
s.append(["#" for i in range(w+2)])
q = Queue()
cnt = 0
q.put([1,1,0])
s[1][1]="#"
Z = -1
while (not q.empty()):
    x,y,cnt = q.get()
    if (x,y) == (h,w):
        Z = cnt
        break
    for (i,j) in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
        if s[i][j] != "#":
            s[i][j] = "#"
            q.put([i,j,cnt+1])
if Z == -1:
    print(-1)
else:
    print(h*w-Z-1-num_w)
Buggy python submission (verdict: Runtime Error):
print((int(input()-int(input()))%int(input()))

Fixed submission:
print((int(input())-int(input()))%int(input()))
Buggy python submission (verdict: Runtime Error):
ans = 0
flg = 0
for i in range(int(input())):
  for j in range(int(input())):
    for k in range(int(input())):
      if flg == 0:
        x = int(input())
      flg+=1
      if 500*i+100*j+50*k==x:
        ans+=1
print(ans)

Fixed submission:
a = [int(input()) for i in range(4)]
ans = 0
for i in range(a[0]+1):
  for j in range(a[1]+1):
    for k in range(a[2]+1):
      if 500*i+100*j+50*k==a[3]:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[list(map(int,input().split())) for i in range(2)]
sm = [sum(a[0])+a[1][n-1]]
for i in range(n-1):
  sm.append(sm[-1]-a[-i-1][0]+a[-i-2][1])
print(max(sm))

Fixed submission:
n=int(input())
a=[list(map(int,input().split())) for i in range(2)]
sm = [sum(a[0])+a[1][n-1]]
for i in range(n-1):
  sm.append(sm[-1]-a[0][-i-1]+a[1][-i-2])
print(max(sm))
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
lsw=[0]*(k*2)
for i in range(n):
  a,b,c=input().split()
  a=int(a)%(k*2)
  b=int(b)%(k*2)
  if c=="B":
    b=(b+k)%(k*2)
  if a>=k:
    b=(b+k)%(k*2)
  lsw[b]+=1
ans=[sum(lsw[:k])]
for i in range(1,k+1):
  ans.append(ans[-1]+lsw[k+i]-lsw[i])
print(max(ans))

Fixed submission:
n,k = map(int,input().split())
xyc = [list(input().split()) for i in range(n)]
for i in range(n):
  x,y,c = xyc[i]
  x = int(x)
  y = int(y)
  xq = x//k
  yq = y//k
  if (xq+yq)%2:
    if c == "B":
      c = "W"
    else:
      c = "B"
  x %= k
  y %= k
  xyc[i] = x,y,c
gridw = [[0 for i in range(k+1)] for j in range(k+1)]
gridb = [[0 for i in range(k+1)] for j in range(k+1)]
for x,y,c in xyc:
  x += 1
  y += 1
  if c == "B":
    gridb[x][y] += 1
  else:
    gridw[x][y] += 1
for grid in gridb,gridw:
  for i in range(1,k+1):
    for j in range(k+1):
      grid[i][j] += grid[i-1][j]
for grid in gridb,gridw:
  for i in range(k+1):
    for j in range(1,k+1):
      grid[i][j] += grid[i][j-1]
nw = gridw[-1][-1]
nb = gridb[-1][-1]
ans = 0
def sm(grid,i,j):
  return grid[i][j]+grid[-1][-1]-grid[-1][j]-grid[i][-1]+grid[i][j]
for i in range(k+1):
  for j in range(k+1):
    x = sm(gridb,i,j)+nw-sm(gridw,i,j)
    ans = max(ans,x,n-x)
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
lsw=[0]*(k*2)
for i in range(n):
  a,b,c=input().split()
  a,b=int(a)%(k*2),int(b)%(k*2)
  if c=="B":
    b=(b+k)%(k*2)
  if a>=k:
    b=(b+k)%(k*2)
  lsw[b]+=1
ans=[sum(lsw[:k])]
for i in range(1,k+1):
  ans.append(ans[-1]+lsw[k+i]-lsw[i])
print(max(ans))

Fixed submission:
n,k = map(int,input().split())
xyc = [list(input().split()) for i in range(n)]
for i in range(n):
  x,y,c = xyc[i]
  x = int(x)
  y = int(y)
  xq = x//k
  yq = y//k
  if (xq+yq)%2:
    if c == "B":
      c = "W"
    else:
      c = "B"
  x %= k
  y %= k
  xyc[i] = x,y,c
gridw = [[0 for i in range(k+1)] for j in range(k+1)]
gridb = [[0 for i in range(k+1)] for j in range(k+1)]
for x,y,c in xyc:
  x += 1
  y += 1
  if c == "B":
    gridb[x][y] += 1
  else:
    gridw[x][y] += 1
for grid in gridb,gridw:
  for i in range(1,k+1):
    for j in range(k+1):
      grid[i][j] += grid[i-1][j]
for grid in gridb,gridw:
  for i in range(k+1):
    for j in range(1,k+1):
      grid[i][j] += grid[i][j-1]
nw = gridw[-1][-1]
nb = gridb[-1][-1]
ans = 0
def sm(grid,i,j):
  return grid[i][j]+grid[-1][-1]-grid[-1][j]-grid[i][-1]+grid[i][j]
for i in range(k+1):
  for j in range(k+1):
    x = sm(gridb,i,j)+nw-sm(gridw,i,j)
    ans = max(ans,x,n-x)
print(ans)
Buggy python submission (verdict: Runtime Error):
print(input().replace("2017","2018))

Fixed submission:
print(input().replace("2017","2018"))