Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
n,k=map(int,input().split())

def comb(n,r):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

blue,red=k,n-k
if red==0:
  print(0)
else:
  mod=10**9+7
  for i in range(1,k+1):
    print((comb(red+1,i)*comb(blue-1,i-1))%mod)

Fixed submission:
n,k=map(int,input().split())

mod=10**9+7
ans=n-k+1
print(ans)
for i in range(2,k+1):
  ans=(ans*(n-k-i+2)*(k-i+1)*pow(i*(i-1),mod-2,mod))%mod
  print(ans)

Buggy python submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
n,k=map(int,input().split())

def comb(n,r):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

blue,red=k,n-k
mod=10**9+7
for i in range(1,k+1):
  print((comb(red+1,i)*comb(blue-1,i-1))%mod)

Fixed submission:
n,k=map(int,input().split())

mod=10**9+7
ans=n-k+1
print(ans)
for i in range(2,k+1):
  ans=(ans*(n-k-i+2)*(k-i+1)*pow(i*(i-1),mod-2,mod))%mod
  print(ans)
Buggy python submission (verdict: Runtime Error):
N = [int(i) for i in input().split()][0]

ls = []
for i in range(N):
  a,b = [i for i in input().split()]
  tmp = [str(a),int(b)]
  ls.append(tmp)

new_ls = sorted(ls, key=lambda x:x[1], reverse=True)
new_ls = sorted(new_ls, key=lambda x:x[0])

for next,l in enumerate(new_ls):
  for i,tmp in enumerate(ls):
    if l[0]==tmp[0] and l[1]==tmp[1]:
      print(i+1)
      continue

Fixed submission:
A,P = [int(i) for i in input().split()]

print((A*3+P)//2)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N = [int(i) for i in input().split()][0]

ls = []
for i in range(N):
  a,b = [i for i in input().split()]
  tmp = [str(a),int(b)]
  ls.append(tmp)

new_ls = sorted(ls, key=lambda x:x[1], reverse=True)
new_ls = sorted(new_ls, key=lambda x:x[0])

for next,l in enumerate(new_ls):
  for i,tmp in enumerate(ls):
    if l[0]==tmp[0] and l[1]==tmp[1]:
      print(i+1)
      continue

Fixed submission:
A,P = [int(i) for i in input().split()]

print((A*3+P)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]),reverse=True)
cnt=0
for b,c in BC:
  if cnt>=n: break
  for _ in range(b):
    A.append(c)
A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]),reverse=True)
cnt=0
for b,c in BC:
  for _ in range(b):
    if cnt>=n: break
    A.append(c)
    cnt+=1
A.sort(reverse=True)
print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]),reverse=True)
cnt=0
for b,c in BC:
  if cnt>=n: break
  for _ in range(b):
    A.append(c)
A.sort(reverse=True)
print(sum(A[:n]))

Fixed submission:
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]),reverse=True)
cnt=0
for b,c in BC:
  for _ in range(b):
    if cnt>=n: break
    A.append(c)
    cnt+=1
A.sort(reverse=True)
print(sum(A[:n]))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

for b,c in BC:
  A.sort()
  idx=bisect.bisect_left(A,c)
  for i in range(min(b,idx)):
    A[i]=c
print(sum(A))

Fixed submission:
n,m=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(m)]

BC.sort(key=lambda x:(x[1],x[0]),reverse=True)
cnt=0
for b,c in BC:
  for _ in range(b):
    if cnt>=n: break
    A.append(c)
    cnt+=1
A.sort(reverse=True)
print(sum(A[:n]))
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N=map(int,input().split())

ans=0
for r in range(N//R+1):
  for g in range(N//G+1):
    if R*r+G*g>N: continue
    if (N-R*r-G*g)%B!=0: continue
    ans+=1
print(ans)

Fixed submission:
R,G,B,N=map(int,input().split())

ans=0
for r in range(N//R+1):
  for g in range(N//G+1):
    if R*r+G*g>N: continue
    if (N-R*r-G*g)%B!=0: continue
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())

ans=[]
for i in range(n+1):
  ans.append(s[:i].count('#')+s[i:].count('.'))
print(min(ans))

Fixed submission:
n = int(input())
s = input()


cost = 0
bc = 0
for it in s:
    if it =="#":
        bc += 1
    elif bc > 0:
        cost += 1
        bc -= 1

print(cost)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
S=input()

T='0'+S+'0'

ans,cnt=0,0
for i,(a,b) in enumerate(zip(S,S[1:])):
  if a=='0' and b=='1':
    cnt+=1
  elif cnt==k and a=='1' and b=='0':
    ans=max(ans,i+1)
    break
else:
  print(n)
  exit()
  
S,cnt=[::-1],0
for i,(a,b) in enumerate(zip(S,S[1:])):
  if a=='0' and b=='1':
    cnt+=1
  elif cnt==k and a=='1' and b=='0':
    ans=max(ans,i+1)
    break
else:
  print(n)
  exit()
  
x,y=[],[]
for i,(a,b) in enumerate(zip(T,T[1:])):
  if a==b: continue
  if a=='0':
    x.append(i)
  else:
    y.append(i)
for a,b in zip(x,y[k:]):
  ans=max(ans,b-a)
print(ans)

Fixed submission:
n,k=map(int,input().split())
S=input()

T='0'+S+'0'
ans,cnt=0,0
for i,(a,b) in enumerate(zip(S,S[1:])):
  if a=='0' and b=='1':
    cnt+=1
  elif cnt==k and a=='1' and b=='0':
    ans=max(ans,i+1)
    break
else:
  print(n)
  exit()
  
S,cnt=S[::-1],0
for i,(a,b) in enumerate(zip(S,S[1:])):
  if a=='0' and b=='1':
    cnt+=1
  elif cnt==k and a=='1' and b=='0':
    ans=max(ans,i+1)
    break
else:
  print(n)
  exit()
  
x,y=[],[]
for i,(a,b) in enumerate(zip(T,T[1:])):
  if a==b: continue
  if a=='0':
    x.append(i)
  else:
    y.append(i)
for a,b in zip(x,y[k:]):
  ans=max(ans,b-a)
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

print(ceil(n/min(a,b,c,d,e)+4))

Fixed submission:
import math
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

print(math.ceil(n/min(a,b,c,d,e)+4))
Buggy python submission (verdict: Time Limit Exceeded):
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

for i in range(Q):
  L = [int(i) for i in input().split()]
  s = S[L[0]-1:L[1]]

  cnt = 0
  for i in range(0,len(s)):
    if s[i]=='A':
      if i+1!=len(s) and s[i+1]=='C':
        cnt+=1
  print(cnt)


Fixed submission:
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

cnt=0
num=[0]
for i in range(len(S)):
  if S[i-1]=='A':
    if S[i]=='C':
      cnt+=1
  num.append(cnt)

for i in range(Q):
  L = [int(i) for i in input().split()]
  print(num[L[1]]-num[L[0]])

Buggy python submission (verdict: Time Limit Exceeded):
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

for i in range(Q):
  L = [int(i) for i in input().split()]
  s = S[L[0]-1:L[1]]

  cnt = 0
  for i in range(0,len(s)):
    if s[i]=='A':
      if i+1!=len(s) and s[i+1]=='C':
        cnt+=1
  print(cnt)

        

Fixed submission:
tmp = [int(i) for i in input().split()]
N,Q = tmp[0],tmp[1]
S = [str(i) for i in input().split()][0]

cnt=0
num=[0]
for i in range(len(S)):
  if S[i-1]=='A':
    if S[i]=='C':
      cnt+=1
  num.append(cnt)

for i in range(Q):
  L = [int(i) for i in input().split()]
  print(num[L[1]]-num[L[0]])
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
for i in range(n):
  for j in range(k+1):
    if i+j<n:
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<len(dp):
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<n:
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<len(dp):
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf')]*n
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<n:
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<len(dp):
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<len(dp):
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
print(dp[-1])

Fixed submission:
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<len(dp):
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i]-H[i+j]))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros((n,3),int)
for i in range(3):
  dp[0][i]=ABC[0][i]
for i in range(n-1):
  for j in range(3):
    dp[i+1][j]=max(dp[i][(j+1)%3]+ABC[i+1][j], dp[i][(j+2)%3]+ABC[i+1][j])
print(max(dp[-1]))

Fixed submission:
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

x,y,z=0,0,0
for a,b,c in ABC:
  x,y,z=max(y,z)+a,max(x,z)+b,max(x,y)+c
print(max(x,y,z))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros((n,3),int)
for i in range(n):
  for j in range(3):
    dp[i][j]=max(dp[i-1][(j+1)%3]+ABC[i][j], dp[i-1][(j+2)%3]+ABC[i][j])
print(max(dp[-1]))

Fixed submission:
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

x,y,z=0,0,0
for a,b,c in ABC:
  x,y,z=max(y,z)+a,max(x,z)+b,max(x,y)+c
print(max(x,y,z))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros((n,3),int)
for i in range(n):
  for j in range(3):
    dp[i][j]=max(dp[i-1][(j+1)%3]+ABC[i][j], dp[i-1][(j+2)%3]+ABC[i][j])
print(max(dp[-1]))

Fixed submission:
n=int(input())
ABC=[list(map(int,input().split())) for _ in range(n)]

x,y,z=0,0,0
for a,b,c in ABC:
  x,y,z=max(y,z)+a,max(x,z)+b,max(x,y)+c
print(max(x,y,z))
Buggy python submission (verdict: Time Limit Exceeded):
# W分の配列を用意、全Wに対してVが最大になるものを見つける
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(N)]

dp=[-1]*(W+1)
dp[0]=0
for i in range(N):
  w,v=WV[i]
  for j in range(W-w,-1,-1): # 逆順じゃないと同じものを二つ選べる
    if dp[j]!=-1:
      dp[j+w]=max(dp[j+w],dp[j]+v)
print(max(dp))

Fixed submission:
import numpy as np
n,w=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros(w+1,int)
for i in range(n):
  w,v=WV[i]
  dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
# W分の配列を用意、全Wに対してVが最大になるものを見つける
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(N)]

dp=[-1]*(W+1)
dp[0]=0
for w,v in WV:
  for i in range(W-w,-1,-1):
    if dp[i]!=-1:
      dp[i+w]=max(dp[i+w],dp[i]+v)
print(max(dp))

Fixed submission:
import numpy as np
n,w=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(n)]

dp=np.zeros(w+1,int)
for i in range(n):
  w,v=WV[i]
  dp[w:]=np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(N)]

dp=[-1]*(W+1)
dp[0]=0
for i in range(N):
  w,v=WV[i]
  for j in range(W-w,-1,-1):
    if dp[j]!=-1:
      dp[j+w]=max(dp[j+w],dp[j]+v)
print(max(dp))

Fixed submission:
import numpy as np
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for _ in range(N)]

dp=np.full(10**5+10,10**18,int)
dp[0]=0
for w,v in WV:
  np.minimum(dp[v:], dp[:-v].copy()+w, out=dp[v:])
print(np.where(dp<=W)[0][-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()

E1=E[0][1]
O1=O[0][1]
if E[0][0]==O[0][0]:
  print(n//2)
elif E1==O1==n//2:
  print(0)
else:
  E2=E[1][1] if len(E)>1 else 0
  O2=O[1][1] if len(O)>1 else 0
  if E2!=0 and O2!=0:
    print(min(n//2-E2+n//2-O1,n//2-E1+n//2-O2))
  else:
    print(min(n//2-E2+n//2-O1,n//2-E1+n//2-O2))

Fixed submission:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))

E=Counter(V[::2]).most_common() + [(0, 0)]
O=Counter(V[1::2]).most_common() + [(0, 0)]
if E[0][0]!=O[0][0]:
  print(n-E[0][1]-O[0][1])
else:
  print(n-max(E[1][1]+O[0][1],E[0][1]+O[1][1]))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
vs=[int(i) for i in input().split()]
vs1=[v for i,v in enumerate(vs) if i%2==0]
vs2=[v for i,v in enumerate(vs) if i%2==1]

ans=0
if len(list(set(vs)))==1:
  ans+=len(vs2)
if len(list(set(vs1)))!=1:
  tmp=[]
  for uniq in list(set(vs1)):
    tmp.append(n/2-vs1.count(uniq))
  ans+=min(tmp)
if len(list(set(vs2)))!=1:
  tmp=[]
  for uniq in list(set(vs2)):
    tmp.append(n/2-vs2.count(uniq))
  ans+=min(tmp)

print(int(ans))

Fixed submission:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))

E=Counter(V[::2]).most_common() + [(0, 0)]
O=Counter(V[1::2]).most_common() + [(0, 0)]
if E[0][0]!=O[0][0]:
  print(n-E[0][1]-O[0][1])
else:
  print(n-max(E[1][1]+O[0][1],E[0][1]+O[1][1]))
Buggy python submission (verdict: Runtime Error):
n,m,x,y=map(int,input().split())
xs=input().split()
ys=input().split()
xs=[int(i) for i in xs]
ys=[int(i) for i in ys]

xs.sort()
ys.sort()
flag=0
if xs[-1]<y:
  threshold=xs[-1]+1
if ys[0]>threshold:
    print('No War')
    flag=1
if flag==0:
  print('War')

Fixed submission:
n,m,x,y=map(int,input().split())
xs=input().split()
ys=input().split()
xs=[int(i) for i in xs]
ys=[int(i) for i in ys]

xs.sort()
ys.sort()
flag=0
if xs[-1]<y:
  z=xs[-1]+1
  if z==x or z==y:
    pass
  elif ys[0]>=z:
      print('No War')
      flag=1
if flag==0:
  print('War')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

AB.sort(key=lambda x:x[1])
bridge=[True]*(n-1)
for a,b in AB:
  if bridge[a-1:b-1].count(False)==0:
    bridge[b-2]=False
print(bridge.count(False))

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

AB.sort(key=lambda x:(x[1],x[0]))
end=AB[0][1]
ans=1
for a,b in AB[1:]:
  if end<=a:
    end=b
    ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

AB.sort(key=lambda x:x[1])
bridge=[True]*(n-1)
for a,b in AB:
  if False not in bridge[a-1:b-1]:
    bridge[b-2]=False
print(bridge.count(False))

Fixed submission:
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

AB.sort(key=lambda x:(x[1],x[0]))
end=AB[0][1]
ans=1
for a,b in AB[1:]:
  if end<=a:
    end=b
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())

tmp=0
for i in range(1,a):
  if tmp<a:
    tmp+=i
  else:
    break
print(tmp+i-b)

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

print(int((b-a)*(b-a+1)/2-b))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
S=['*']+list(input())+['*']

ans=n
for i in range(1,n+2):
  ans=min(ans,S[:i].count('W')+S[i:].count('E'))
print(ans)

Fixed submission:
n=int(input())
S=input()

E_num=S.count('E')
W_num=0
ans=n
for i in range(n):
  if S[i]=='E':
    E_num-=1
    ans=min(ans,E_num+W_num)
  else:
    ans=min(ans,E_num+W_num)
    W_num+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.misc import comb
n=int(input())
A=list(map(int,input().split()))

A.sort()
max_,num=0,0
for a in A:
  if max_<comb(A[-1],a):
    max_=comb(A[-1],a)
    num=a
print(A[-1],num)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))

A.sort()
num=float('inf')
for i in range(n-1):
  if abs(num-A[-1]/2)>abs(A[i]-A[-1]/2):
    num=A[i]
print(A[-1],num)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())

tmp=[i for i in range(a,b+1)]
ans=[]
for a in tmp[:k]:
  ans.append(a)
for a in tmp[-k:]:
  ans.append(a)
out=list(set(ans))
out.sort()
print(*out,sep='\n')

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

ans=[]
for i in range(k):
  if a+i<=b and a+i not in ans:
    ans.append(a+i)
for i in range(k):
  if b-i>=a and b-i not in ans:
    ans.append(b-i)
ans.sort()
print(*ans,sep='\n')
Buggy python submission (verdict: Runtime Error):
from queue import Queue
h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]

memo=[[-1]*w for _ in range(h)]
def bfs(q):
  x,y,cnt=q.get()
  if x<0 or x>=w or y<0 or y>=h:
    return
  elif S[y][x]=='#':
    return
  elif memo[y][x]<0:
    memo[y][x]=cnt
    q.put([x-1,y,cnt+1])
    q.put([x+1,y,cnt+1])
    q.put([x,y-1,cnt+1])
    q.put([x,y+1,cnt+1])

q=Queue()
q.put([0,0,0])
while not q.empty():
  bfs(q)
if memo[y-1][x-1]==-1:
  print(-1)
  exit()
cnt=0
for i in range(h):
  cnt+=S[i].count('.')
print(cnt-memo[h-1][w-1]-1)

Fixed submission:
from queue import Queue
h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]

memo=[[-1]*w for _ in range(h)]
def bfs(q):
  x,y,cnt=q.get()
  if x<0 or x>=w or y<0 or y>=h:
    return
  elif S[y][x]=='#':
    return
  elif memo[y][x]<0:
    memo[y][x]=cnt
    q.put([x-1,y,cnt+1])
    q.put([x+1,y,cnt+1])
    q.put([x,y-1,cnt+1])
    q.put([x,y+1,cnt+1])

q=Queue()
q.put([0,0,0])
while not q.empty():
  bfs(q)
if memo[h-1][w-1]==-1:
  print(-1)
  exit()
cnt=0
for i in range(h):
  cnt+=S[i].count('.')
print(cnt-memo[h-1][w-1]-1)
Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
C=int(input())
X=int(input())

total,out=0,0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a*500+b*100+c*50 == 0:
        out+=1
        
print(out)

Fixed submission:
inputs=[int(input()) for _ in range(3)]

val=inputs[0]-inputs[1]

syo=val//inputs[2]
print(val-(inputs[2]*syo))
Buggy python submission (verdict: Runtime Error):
tmp=input()
tmp=tmp.split('')
a,b=tmp[0],tmp[1]
c=a*b
if c%2 == 0:
	print('Even')
else:
	print('odd')

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

c=a*b
if c%2 == 0:
	print('Even')
else:
	print('Odd')
Buggy python submission (verdict: Runtime Error):
n=int(input())
CSF=[list(map(int,input().split())) for _ in range(n-1)]

for i in range(n):
  ans=0
  for c,s,f in CSF[i:]:
    if ans<s:
      ans=s
    else:
      ans+=f-t%f
    ans+=c
  print(ans)

Fixed submission:
n=int(input())
CSF=[list(map(int,input().split())) for _ in range(n-1)]

for i in range(n):
  ans=0
  for c,s,f in CSF[i:]:
    if ans<s:
      ans=s
    elif ans%f!=0:
      ans+=f-ans%f
    ans+=c
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

ans=0
for a in set(A):
  cnt=A.count(a)
  if cnt==a:
    continue
  elif cnt<a:
    ans+=cnt
  else:
    ans+=min(cnt-a,cnt)
print(ans)

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

c=Counter(A)
ans=0
for key, value in c.items():
  if key!=value:
    if key>value:
      ans+=value
    else:
      ans+=value-key
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

ans=0
for a in set(A):
  if A.count(a)==a:
    continue
  elif A.count(a)<a:
    ans+=A.count(a)
  else:
    ans+=min(A.count(a)-a,A.count(a))
print(ans)

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

c=Counter(A)
ans=0
for key, value in c.items():
  if key!=value:
    if key>value:
      ans+=value
    else:
      ans+=value-key
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))

ans=0
for a in set(A):
  if A.count(a)==a:
    continue
  elif A.count(a)<a:
    ans+=A.count(a)
  else:
    cnt=0
    while True:
      if A.count(a)==a or A.count(a)==0:
        break
      else:
        A.remove(a)
        cnt+=1
    ans+=cnt
print(ans)

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

c=Counter(A)
ans=0
for key, value in c.items():
  if key!=value:
    if key>value:
      ans+=value
    else:
      ans+=value-key
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
tmp=input()
tmp=tmp.split(' ')
a=[]
for i in range(N):
  a.append(int(tmp[i]))
  
if all(x % 2 == 0 for x in a) == False:
  print(0)
else:
  count=0
  while all(x % 2 == 0 for x in a) == True:
    a=[x/2 for x in a]
    count+=1
    
  print(count)

Fixed submission:
s=input()
a,b,c=s[0],s[1],s[2]

print(int(a)+int(b)+int(c))

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

print(a+b+c)

Fixed submission:
s=input()
a,b,c=s[0],s[1],s[2]

print(int(a)+int(b)+int(c))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=list(map(int,input().split()))

cnt=[]
for a in set(A):
  cnt.append(A.count(a))
cnt.sort()
ans=0
while len(cnt)>k:
  ans+=cnt[0]
  cnt=cnt[1:]
print(ans)

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

cnt=sorted(Counter(A).values())
print(sum(cnt[:-k]))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()
ans=0
for a in A:
  bidx=bisect.bisect_right(B,a)
  if bidx==len(B): break
  for b in B[bidx:]:
    cidx=bisect.bisect_right(C,b)
    if cidx==len(B): break
    ans+=len(C)-cidx
print(ans)


Fixed submission:
import bisect
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()
ans=0
for b in B:
  aidx=bisect.bisect_left(A,b)
  cidx=bisect.bisect_right(C,b)
  ans+=aidx*(len(C)-cidx)
print(ans)