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

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=len(format(max(l),"b"))
x=[None]*n
xl=[0]*a
for i in range(n):
  b=format(l[i],"b")
  x[i]=b.zfill(a)
for i in range(a):
  for j in range(n):
    if x[j][i]=="1":
      xl[i]+=1
c=format(k,"b")
if len(c)>a:
  c,d=c[:len(c)-a],c[len(c)-a:]
  ans=int("0b"+c,2)*(2**a)*n
  check=0
  for i in range(a):
    if check==0:
      if d[i]=="1":
        if xl[i]>=n-xl[i]:
          ans+=xl[i]*(2**(a-i-1))
          check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
else:
  c=c.zfill(a)
  ans=0
  check=0
  for i in range(a):
    if check==0:
      if c[i]=="1":
        if xl[i]>=n-xl[i]:
          ans+=xl[i]*(2**(a-i-1))
          check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
l=list(map(int,input().split()))
a=len(format(max(l),"b"))
x=[None]*n
xl=[0]*a
for i in range(n):
  b=format(l[i],"b")
  x[i]=b.zfill(a)
for i in range(a):
  for j in range(n):
    if x[j][i]=="1":
      xl[i]+=1
c=format(k,"b")
if len(c)>a:
  c,d=c[:len(c)-a],c[len(c)-a:]
  ans=int("0b"+c,2)*(2**a)*n
  check=0
  for i in range(a):
    if check==0:
      if d[i]=="1":
        if xl[i]>=n-xl[i]:
        ans+=xl[i]*(2**(a-i-1))
        check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
else:
  c=c.zfill(a)
  ans=0
  check=0
  for i in range(a):
    if check==0:
      if d[i]=="1":
        if xl[i]>=n-xl[i]:
        ans+=xl[i]*(2**(a-i-1))
        check=1
        else:ans+=(n-xl[i])*(2**(a-i-1))
      else:ans+=xl[i]*(2**(a-i-1))
    else:
      ans+=max(xl[i],n-xl[i])*(2**(a-i-1))
print(ans)
Problem p03146 (python)

Fixed submission:
s = int(input())
n = 0
if s==1 or s == 2:
  print("4")
elif s==3:
  print("9")
if s >=4:
  s = 2*s
  while s % 2 == 0:
    s = s/2
    n += 1
    if s!=1 and s%2 == 1:
      s = 3*s+1
      n+=1
    if s == 1:
      print(n+1)
      break

Buggy submission (verdict: Runtime Error):
s = int(input())
n = 0
if s==1 or s == 2:
  print("4")
elif s==3:
  print("9")
if s >=4:
  while s % 2 == 0:
  s = s/2
  n += 1
  if s!=1 and s%2 == 1:
    s = 3*s+1
    n+=1
  if s == 1:
    print(n+2)
    break
Problem p03147 (python)

Fixed submission:
n=int(input())
flowers=[0]+list(map(int,input().split()))
ans=0
for i in range(n):
  ans+=max(flowers[i+1]-flowers[i],0)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
flowers=[0]+list(map(int,input().split()))
ans=0
for i in range(1,n+1):
  ans+=max(flowers[i+1]-flowers[i],0)
print(ans)
Problem p03160 (python)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(l[i]-l[i-2]),dp[i-1]+abs(l[i]-l[i-1]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
dp=[["" for i in range(len(t)+1)] for j in range(len(s)+1)]
for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=join(dp[i-1][j-1],s[i-1])
        else:
            A=len(dp[i-1][j])
            B=len(dp[i][j-1])
            if A>=B:
                dp[i][j]=dp[i-1][j]
            else:
                dp[i][j]=dp[i][j-1]
print(dp[-1][-1])
Problem p03206 (python)

Fixed submission:
D = int(input())
a_dict={22:"Christmas Eve Eve Eve",23:"Christmas Eve Eve",24:"Christmas Eve",25:"Christmas"}
print(a_dict[D])

Buggy submission (verdict: Runtime Error):
D = int(input())
a_dict={22:Christmas Eve Eve Eve,23:Christmas Eve Eve,24:Christmas Eve,25:Christmas}
print(a_dict[D])
Problem p03211 (python)

Fixed submission:
s=input()
ans=1000
l=len(s)
for i in range(l-2):
  if ans>abs(753-int(s[i:i+3])):
    ans=abs(753-int(s[i:i+3]))
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
ans=1000
l=len(s)
for i in range(l-2):
  if ans>abs(753-s[i:i+3]):
    ans=abs(753-s[i:i+3])
print(ans)
Problem p03220 (python)

Fixed submission:
N = int(input())
t,a = map(int,input().split())
height = list(map(int,input().split()))
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
ans = float(10**7)
lst = []
for i in range(N):
  if ans > subduction[i]:
    ans = subduction[i]
    lst.append(i)
print(lst[-1]+1)

Buggy submission (verdict: Runtime Error):
N = int(input())
t,a = map(int,input().split())
height = [int(input()) for i in range(N)]
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
print(min(subduction))

Buggy submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
height = [int(input()) for i in range(N)]
subduction = [float(abs(t-height[i]*0.006-a)) for i in range(N)]
print(min(subduction))
Problem p03227 (python)

Fixed submission:
a=input()
print(a if len(a)==2 else a[::-1])

Buggy submission (verdict: Runtime Error):
print(input() if len(input())==2 else input()[::-1])
Problem p03231 (python)

Fixed submission:
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
ans=n*m//g
stepn=n//g
stepm=m//g
for i in range(g):
    if s[stepn*i]!=t[stepm*i]:print(-1);exit()
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
ans=n*m//g
stepn=n//g
stepm=m//g
for i in range(g):
    if s[stepn*i]!=t[stepm*i]:print(-1);exit()
print(ans)
Problem p03240 (python)

Fixed submission:
n=int(input())
data=[list(map(int,input().split())) for i in range(n)]
data.sort(key=lambda x:x[2],reverse=True)
def cal(y,x,datum,height):
  return max(height-(abs(y-datum[1])+abs(x-datum[0])),0)==datum[2]
for i in range(101):
  for j in range(101):
    height=abs(i-data[0][1])+abs(j-data[0][0])+data[0][2]
    flag=0
    for k in data[1:]:
      if not cal(i,j,k,height):
        flag=1
        break
    if flag:pass
    else:print(j,i,height);exit()

Buggy submission (verdict: Runtime Error):
N=int(input())
info=[list(map(int,input().split())) for i in range(N)]
info.sort(key=lambda x:x[2],reverse=True)
for i in range(101):
  for j in range(101):
    height=info[0][2]+abs(info[0][0]-i)+abs(info[0][1]-j)
    for h in range(1,N):
      if info[h][2]+abs(info[h][0]-i)+abs(info[h][1]-j)!=height;break
    print(i,j,height);exit()
Problem p03243 (python)

Fixed submission:
n = int(input())
a = 111
for i in range(9):
  if a*i < n <= a*(i+1):
    print(a*(i+1))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = 111
for i in range(9):
  if a*i < n <= a*(i+1)
  print(a*(i+1))
Problem p03244 (python)

Fixed submission:
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common()[0][1]-o.most_common()[1][1],e.most_common()[0][1]-e.most_common()[1][1]))
  else:  
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common()[0][0]==e.most_common()[0][0]:
    print(ans+min(o.most_common[1][1]-o.most_common[0][1],e.most_common[1][1]-e.most_common[0][1]))
  else:  
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
nums=list(map(int,input().split()))
a=set(nums)
if len(a)==1:
  print(n//2)
else:
  odd=nums[::2]
  even=nums[1::2]
  o=Counter(odd)
  e=Counter(even)
  ans=n-o.most_common()[0][1]-e.most_common()[0][1]
  if o.most_common[0][0]==e.most_common[0][0]:
    print(ans+min(o.most_common[1][1]-o.most_common[0][1],e.most_common[1][1]-e.most_common[0][1]))
  else:  
    print(ans)
Problem p03254 (python)

Fixed submission:
n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
if m>sum(ch):
  print(n-1)
else:
  sum=0
  i=0
  while sum<m and ans!=n:
    sum+=ch[ans]
    ans+=1
    if sum > m:
      ans-=1
      break
  print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
sum=0
i=0
while sum<m:
  sum+=ch[ans]
  ans+=1
  if sum > m:
    ans-=1
    break
print(ans)
Problem p03261 (python)

Fixed submission:
n=int(input())
shiritori=[]
for i in range(n):
  shiritori.append(input())
check=set(shiritori)
if len(check)!=n:
  print("No")
else:
  flag=0
  for i in range(n-1):
    if shiritori[i][-1]!=shiritori[i+1][0]:
      flag=1
      break
  if flag==0:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
shiritori = [list(input()) for i in range(n)]
for i in range(n-1):
  if shiritori[i][-1] != shiritori[i+1][0]:
    print("No")
    break
  if i =n-2:
    print("Yes")
Problem p03274 (python)

Fixed submission:
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  l,r=i,i+k-1
  d=min(abs(c[l]),abs(c[r]))+abs(c[l]-c[r])
  if d<ans:
    ans=d
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  lit=c[i:i+k]
  if lit[0]*lit[-1]>0:
    d=abs(lit[0])+abs(lit[-1])+min(abs(lit[0]),abs(lit[-1]))
  else:
    d=max(abs(lit[0],abs(lit[-1])))
  if d<ans:
    ans=d
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
c=list(map(int,input().split()))
ans=10**100
for i in range(n-k+1):
  lit=c[i:i+k]
  if lit[0]*lit[-1]>0:
    d=abs(lit[0])+abs(lit[-1])+min(abs(lit[0]),abs(lit[-1]))
  else:
    d=max(abs(lit[0],abs(lit[-1])))
  if d<ans:
    d=ans
print(ans)
Problem p03289 (python)

Fixed submission:
from collections import Counter
s=input()
a=len(s)
counter = Counter(s[2:a-1])
if s[0]!="A":
  print("WA")
  
elif counter["C"]!=1:
  
    print("WA")
else:
  
  s[1:].replace("C","c",1)
  if s[1:].replace("C","c",1).islower()==False:
    print("WA")
  else:
    print("AC")

Buggy submission (verdict: Runtime Error):
from collections import Counter
s=input()
a=len(s)
counter = Counter(s[2:a-2])
if s[0]!="A":
  print("WA")
  break
else:
  if counter("C")!=1:
    print("WA")
else:
  s.replace("A","a",1)
  s.replace("C","c",1)
  if s.islower()==False:
    print("WA")
  else:
    print("AC")
Problem p03308 (python)

Fixed submission:
n=int(input()) 
num=list(map(int,input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dif=abs(num[i]-num[j])
    if dif>ans:
      ans=dif
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input()) 
num=list(int,input().split())
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dif=abs(num[i]-num[j])
    if dif>ans:
      ans=dif
print(ans)
Problem p03316 (python)

Fixed submission:
n=input()
l=len(n)
s=0
for i in range(l):
  s+=int(n[i])
if int(n)%s==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n=input()
l=len(n)
s=0
for i in range(l):
  s+=int(n[i])
if n%s==0:
  print("Yes")
else:
  print("No")
Problem p03352 (python)

Fixed submission:
n=int(input())
if n<=3:
  print(1)
else:
  ans=[]
  for i in range(2,int(n**(1/2)+1)):
    e=2
    while i**e<=n:
      if i**(e+1)>n:
        ans.append(i**e)
        break
      e+=1
  print(max(ans))

Buggy submission (verdict: Runtime Error):
n=int(input())
if n<=3:
  print(1)
else:
  ans=4
  for i in range(2,int(n**(1/2)+1)):
    e=2
    while i**e<=n:
      if i**e>ans:
        ans=i**e
print(ans)
Problem p03354 (python)

Fixed submission:
n,m=map(int,input().split())
p=list(map(int,input().split()))
class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for i in range(N)]
    
    def merge(self, a, b):
        if self.issame(a,b):
            return
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
        self.size[pb] += self.size[pa]
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r
    
    def issame(self, x, y):
        return self.root(x) == self.root(y)
    
    def getsize(self, x):
        return self.size[self.root(x)]

uf=UnionFind(2*n)
for i in range(n):
    uf.merge(i,p[i]+n-1)
for i in range(m):
    x,y=map(int,input().split())
    x-=1;y-=1
    uf.merge(x,y)
ans=0
for i in range(n):
    ans+=int(uf.issame(i,i+n))
print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind(object):
    def __init__(self, N):
        self.parent = [i for i in range(N)]
 
    def merge(self, a, b):
        pa = self.root(a)
        pb = self.root(b)
        self.parent[pa] = pb
    
    def root(self, x):
        p = self.parent[x]
        if p == x:
            return x
        else:
            r = self.root(p)
            self.parent[x] = r
            return r
n,m=map(int,input().split())
a=list(map(int,input().split()))
uf=UnionFind(n)
for i in range(m):
  a,b=map(int,input().split())
  if a>b:a,b=b,a
  uf.merge(a-1,b-1)
print(sum(1 for i in range(n) if uf.parent[i]==uf.parent[a[i]-1]))
Problem p03355 (python)

Fixed submission:
s=input()
n=int(input())
lst=[]
for i in range(len(s)):
  for j in range(i+1,min(i+n+1,len(s)+1)):
    lst.append(s[i:j])
sub=set(lst)
sub=sorted(sub)
print(sub[n-1])

Buggy submission (verdict: Runtime Error):
s=input()
n=int(input())
lst=[]
for i in range(len(s)):
  for j in range(i+1,min(i+n+1,len(s)+1)):
    lst.append(s[i:j])
sub=set(lst)
sub.sort()
print(sub[n-1])
Problem p03379 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
l=b[:n//2]
u=b[n//2:]
for i in a:
  if i <= l[-1]:
    print(u[0])
  else:
    print(l[-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=b[n//2]
d=b[n//2+1]
if c==d:
  for i in range(n):print(c)
else:
  for i in range(n):
    if a[i]<=c:print(d)
    else:print(c)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
for i in range(n//2):
  print(a[n//2+1])
for i in range(n//2):
  print(a[n//2])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input()))
for i in range(n//2):
  print(a[n//2+1])
for i in range(n//2):
  print(a[n//2])
Problem p03386 (python)

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

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
if 2*k=>b-a+1:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)
Problem p03401 (python)

Fixed submission:
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
ans=sum(abs(l[i+1]-l[i]) for i in range(n+1))
for i in range(1,n+1):
  if l[i-1]<=l[i]<=l[i+1] or l[i-1]>=l[i]>=l[i+1]:
    print(ans)
  else:
    print(ans-2*min(abs(l[i-1]-l[i]),abs(l[i+1]-l[i])))

Buggy submission (verdict: Runtime Error):
n=int(input())
de=list(map(int,input().split()))
de.insert(0,0)
de.append(0)
di=[]
for i in range(n+1):
  di.append(abs(de[i]-de[i+1]))
ans=sum(di)
for i in range(1,n+1):
  if max(de[i-1],de[i],de[i+1])==de[i] or min(de[i-1],de[i],de[i+1])==de[i]:
    print(ans-2*min(di[i],di[i+1]))
  else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
de=list(map(int,input().split()))
de.insert(0,0)
de.append(0)
di=[]
for i in range(n+1):
  di.append(abs(di[i]-di[i+1]))
ans=sum(di)
for i in range(n):
  print(ans-2*di[i])
Problem p03416 (python)

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

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
ans=0
for i in range(a,b+1):
  s=str(i)
  if i[0]==i[4] and i[1]==i[3]:
    ans+=1
print(ans)
Problem p03423 (python)

Fixed submission:
print(int(input())//3)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    m=(r-l)//d
    ans=0
    for j in range(1,m+1):
        ans+=abs(gya[l+j*d-1][0]-gya[l+d*(j-1)-1][0])+abs(gya[l+j*d-1][1]-gya[l+d*(j-1)-1][1])
    print(ans)
Problem p03427 (python)

Fixed submission:
n=input()
l=len(n)
flag=0
for i in range(1,l):
  if n[i]!="9":
    flag=1
    break
ans=int(n[0])-1+9*(l-1)
if flag==1:
  print(ans)
else:
  print(ans+1)

Buggy submission (verdict: Runtime Error):
n=input()
l=len(n)
flag=0
for i in range(l-1):
  if n[-i]!=9:
    flag=1
    break
ans=int(n[0]-1)+9*(l-1)
if flag==1:
  print(ans)
else:
  print(ans+1)
Problem p03435 (python)

Fixed submission:
nums=[]
for i in range(3):
  nums.append(list(map(int,input().split())))
subd=[]
for i in range(3):
  subd.append([nums[i][0]-nums[i][1],nums[i][1]-nums[i][2]])
for i in range(3):
  subd.append([nums[0][i]-nums[1][i],nums[1][i]-nums[2][i]])
if subd[0]==subd[1] and subd[1]==subd[2] and subd[3]==subd[4] and subd[4]==subd[5]:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
num=[]
for i in range(3):
  nums.append(list(map(int,input().split())))
subd=[]
for i in range(3):
  subd.append([nums[i][0]-nums[i][1],nums[i][1]-nums[i][2]])
for i in range(3):
  subd.append([nums[0][i]-nums[1][i],nums[1][i]-nums[2][i]])
if subd[0]==subd[1] and subd[1]==subd[2] and subd[3]==subd[4] and subd[4]==subd[5]:
  print("Yes")
else:
  print("No")
Problem p03436 (python)

Fixed submission:
from collections import deque
h,w=map(int,input().split())
field=[["#" for i in range(w+2)]]+[["#"]+list(input())+["#"] for i in range(h)]+[["#" for i in range(w+2)]]
queue=deque([[1,1]])
cost=[[50000 for i in range(w)]for j in range(h)]
cost[0][0]=0
while queue:
  now=queue.popleft()
  for i in [(-1,0),(1,0),(0,1),(0,-1)]:
    if field[now[0]+i[0]][now[1]+i[1]]=="#":continue
    if cost[now[0]+i[0]-1][now[1]+i[1]-1]!=50000:continue
    queue.append((now[0]+i[0],now[1]+i[1]))
    cost[now[0]+i[0]-1][now[1]+i[1]-1]=cost[now[0]-1][now[1]-1]+1
cnt=0
for i in range(h+2):
  for j in range(w+2):
    if field[i][j]=="#":cnt+=1
cnt-=(h+w)*2+4
blackable=h*w-cnt
if cost[-1][-1]==50000:print(-1)
else:
  print(blackable-cost[-1][-1]-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w=map(int,input().split())
field=["#" for i in range(w+2)]+[["#"]+list(input())+["#"] for i in range(h)]+["#" for i in range(w+2)]
queue=deque([[1,1]])
cost=[[50000 for i in range(w)]for j in range(h)]
cost[0][0]=0
while queue:
  now=queue.popleft()
  for i in [(-1,-1),(-1,1),(1,1),(1,-1)]:
    if field[now[0]+i[0]][now[1]+i[1]]=="#":continue
    if cost[now[0]+i[0]-1][now[1]+i[1]-1]!=50000
    if cost[now[0]+i[0]-1][now[1]+i[1]-1]>cost[now[0]-1][now[1]-1]+1:
      cost[now[0]+i[0]-1][now[1]+i[1]-1]=cost[now[0]-1][now[1]-1]+1
cnt=0
for i in range(h+2):
  for j in range(w+2):
    if field[i][j]=="#":cnt+=1
cnt-=(h+w)*2+4
blackable=h*w-cnt
if cost[-1][-1]==50000:print(-1)
else:
  print(blackable-cost[-1][-1])
Problem p03437 (python)

Fixed submission:
x,y=map(int,input().split())
if x%y==0:
  print(-1)
else:
  flag=0
  for i in range(10**18//x):
    if (i*x)%y!=0:
      print(i*x)
      flag=1
      break
  if flag==0:
    print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=0;r=n-1
print(0);seat0=input()
if seat0="Vacant";exit()
while True:
  mid=(l+r)//2
  print(mid)
  seat=input()
  if seat=="Vacant":
    exit()
  if mid%2==0:
    if seat!=seat0:
      r=mid
    else:
      l=mid
  elif mid%2==1:
    if seat==seat0:
      l=mid
    else:
      r=mid

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split)
if x%y==0:
  print(-1)
else:
  flag=0
  for i in range(10**18//x):
    if (i*x)%y!=0:
      print(i*x)
      flag=1
      break
    if flag==0:
      print(-1)
Problem p03449 (python)

Fixed submission:
n=int(input())
l=[]
ans=0
for i in range(2):
  l.append(list(map(int,input().split())))
for i in range(n):
  c=sum(l[0][:i+1])+sum(l[1][i:])
  if c>ans:ans=c
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[]
ans=0
for i in range(2):
l.append(list(map(int,input().split())))
for i in range(n):
  c=sum(l[0][:i+1])+sum(l[1][i:])
  if c>ans:ans=c
print(ans)
Problem p03478 (python)

Fixed submission:
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n)[i])
  return re
for i in range(n+1):
  if a<=digitsum(i)<=b:
    ans+=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n[i]))
  return re
for i in range(n):
  if a<=digitsum(i)<=b:
    ans+=i
print(ans)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n[i]))
  return re
for i in range(n):
  if a<=digitsum(i)<=b:
    ans+=i
print(i)
Problem p03487 (python)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
c=b.most_common()
ans=0
for i in range(len(c)):
  if c[i][0]>c[i][1]:
    ans+=c[i][1]
  else:
    ans+=c[i][1]-c[i][0]
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
c=b.most_common()
ans=0
for i in range(len(c)):
  ans+=abs(int(c[0])-c[1])
print(ans)
Problem p03495 (python)

Fixed submission:
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
if len(dif)==0:
  print(0)
else:
  for i in range(len(dif)+1):
    if i == 0:
      cnt.append(dif[0])
    if i == len(dif):
      cnt.append(N-dif[-1])
      break
    cnt.append(dif[i]-dif[i-1])
  cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
  n = 0
  if len(cnt)<=K:
    print(0)
  else:
    for i in range(K):
      n+=cnt[i]
    print(N-n)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
for i in range(len(dif)+1):
  if i == 0:
    cnt.append(dif[0])
  if i == len(dif):
    cnt.append(N-dif[-1])
    break
  cnt.append(dif[i]-dif[i-1])
cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
n = 0
if len(cnt)<=K:
  print(0)
else:
  for i in range(K):
    n+=cnt[i]
  print(N-n)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
for i in range(len(dif)+1):
  if i == 0:
    cnt.append(dif[0])
  if i == len(dif):
    cnt.append(N-dif[-1])
  cnt.append(dif[i]-dif[i-1])
cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
n = 0
if len(cnt)<=K:
  print(0)
else:
  for i in range(K):
    n+=cnt[i]
  print(N-n)