Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ans=0
k=0
i=m//n
while k==0:
    if m%i==0:
        ans=i
        k=1
    i-=1
    
print(ans)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    divisors.reverse()
    return divisors

l=make_divisors(m)

for i in l:
    if i*n<=m:
        print(i)
        import sys
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,m=map(int,input().split())
ans=0

if n==1:
    print(m)
    sys.exit()

for i in range(1,(m//n)+1):
    if m%i==0:
        ans=i
        
print(ans)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    divisors.reverse()
    return divisors

l=make_divisors(m)

for i in l:
    if i*n<=m:
        print(i)
        import sys
        sys.exit()

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ans=0
for i in range(1,(m//n)+1):
    if m%i==0:
        ans=i
        
print(ans)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    divisors.reverse()
    return divisors

l=make_divisors(m)

for i in l:
    if i*n<=m:
        print(i)
        import sys
        sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())

def c(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))

def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct

l=factorize(m)
mod=10**9+7
ans=1
for i,j in l:
    ans*=c(j+n-1,j)
    ans=ans%mod

print(ans)

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

def c(n,m):
    import math
    if n-m<0:
        return 0
    return(math.factorial(n)//math.factorial(n-m)//math.factorial(m))

def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct

l=factorize(m)
mod=10**9+7
ans=1
for i,j in l:
    ans*=c(j+n-1,j)
    ans=ans%mod

print(ans)
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())

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

a.sort()
i=0
ans=0

while x>0:
    if x-a[i]>=0:
        x-=a[i]
        ans+=1
    else:
        x=0
    i+=1

print(ans)

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

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

a.sort()
i=0
ans=0

while x>0 and i<n:
    if x-a[i]>=0:
        x-=a[i]
        ans+=1
    else:
        x=0
    if i==n-1:
        if x>0:
            ans-=1
    i+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
import math

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

x=[abs(int(i)-xs) for i in input().split()]

a=x[0]
for i in range(n):
    a=math.gcd(a,x[i])

print(a)


Fixed submission:
def gcd(a, b):

	while b:

		a, b = b, a % b

	return a

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

x=[abs(int(i)-xs) for i in input().split()]

ans=x[0]
for i in range(n):
    ans=gcd(ans,x[i])

print(ans)

Buggy python submission (verdict: Runtime Error):
import math

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

x=[abs(int(i)-xs) for i in input().split()]


print(math.gcd(*x))

Fixed submission:
def gcd(a, b):

	while b:

		a, b = b, a % b

	return a

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

x=[abs(int(i)-xs) for i in input().split()]

ans=x[0]
for i in range(n):
    ans=gcd(ans,x[i])

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
import reduce
n,xs=map(int,input().split())

x=[abs(int(i)-xs) for i in input().split()]

def gc(numbers):
    return reduce(math.gcd, numbers)

print(gc(x))

Fixed submission:
def gcd(a, b):

	while b:

		a, b = b, a % b

	return a

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

x=[abs(int(i)-xs) for i in input().split()]

ans=x[0]
for i in range(n):
    ans=gcd(ans,x[i])

print(ans)

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

x=[abs(int(i)-xs) for i in input().split()]

def gc(numbers):
    return reduce(math.gcd, numbers)

print(gc(x))

Fixed submission:
def gcd(a, b):

	while b:

		a, b = b, a % b

	return a

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

x=[abs(int(i)-xs) for i in input().split()]

ans=x[0]
for i in range(n):
    ans=gcd(ans,x[i])

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

ans=0
j=2
l=1

if k%2==1:
    ans=int(n/k)**3

if k%2==0:
    for i in range(1,n+1):
        a=k-i
        while a<1:
            a+=k
        c=a
        while a<=n:
            b=c
            while a+b<k:
                b+=k
            if (a+b)%k==0:
                while b<=n:
                    ans+=1
                    b+=k
            a+=k    
    
                
print(ans)

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

ans=0

if k%2==1:
    ans=int(n/k)**3
else:
    ans=int(n/k+0.5)**3+(n//k)**3
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
h,w=map(int,input().split())

b=[]
d=[]
for i in range(w):
    d.append(i)

for i in range(h):
    a=input()
    if a!="."*w:
        b.append(a)
    else:
        h-=1
        
for i in range(w):
    c=0
    for j in range(h):
        if b[j][i]=="#":
            c+=1
    if c==0:
        del(d[i])
            
for i in range(h):
    for j in d:
       sys.stdout.write(b[i][j]) 
    print("")

Fixed submission:
import sys
h,w=map(int,input().split())

b=[]
d=[]
k=0
for i in range(w):
    d.append(i)

for i in range(h):
    a=input()
    if a!="."*w:
        b.append(a)
    else:
        h-=1
        
for i in range(w):
    c=0
    for j in range(h):
        if b[j][i]=="#":
            c+=1
    if c==0:
        del(d[k])
    else:
        k+=1
            
for i in range(h):
    for j in d:
       sys.stdout.write(b[i][j]) 
    print("")
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())

print((a-1)*(b-1))

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

print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
s=int(input())
k=int(input())

st=str(s)
l=len(st)
i=0
a=0
n=0
m=0

while n<1:
    if int(st[m])==1:
        m+=1
        a+=1
    else:
        n=1

if a>=k:
    print(1)

else:
    while i<=l:
        if int(st[i])!=1:
            print(int(st[i]))
            i=l+1
        else:
            i+=1

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

st=str(s)
l=len(st)
i=0
a=0
n=0
m=0

while n<1:
    if int(st[m])==1:
        m+=1
        a+=1
    else:
        n=1
    if a==l:
        n=1

if a>=k:
    print(1)

else:
    while i<=l:
        if int(st[i])!=1:
            print(int(st[i]))
            i=l+1
        else:
            i+=1

Buggy python submission (verdict: Runtime Error):
s=int(input())
k=int(input())

st=str(s)
l=len(st)
i=0
a=0
n=0
m=0

while n<1:
    if int(st[m])==1:
        m+=1
        a+=1
    else:
        n=1

if a==k:
    print(1)

else:
    while i<=l:
        if int(st[i])!=1:
            print(int(st[i]))
            i=l+1
        else:
            i+=1

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

st=str(s)
l=len(st)
i=0
a=0
n=0
m=0

while n<1:
    if int(st[m])==1:
        m+=1
        a+=1
    else:
        n=1
    if a==l:
        n=1

if a>=k:
    print(1)

else:
    while i<=l:
        if int(st[i])!=1:
            print(int(st[i]))
            i=l+1
        else:
            i+=1
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
k=0

if n==0:
    print(0)

while k<1:
    if n==0:
        k=1
    else:
        if n%2==0:
            a.append(0)
            n=n/(-2)
        else:
            a.append(1)
            n=(n-1)/(-2)
            
for i in (reversed(a)):
    print(i,end="")

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

if a%b==0:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(i) for i in input().split()]

ans=0

for r in range(n):
    for l in range(r+1):
        if sum(a[l:r+1])%m==0:
            ans+=1

print(ans)

Fixed submission:
import collections

n,m=map(int,input().split())
a=[int(i) for i in input().split()]

s=0
ans=0
l=[]

for i in a:
    s+=i
    l.append(s%m)

c=collections.Counter(l)

for p,q in c.items():
    if int(p)==0:
        ans+=q*(q+1)//2
    else:
        ans+=q*(q-1)//2


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[int(i) for i in input().split()]

ans=0

for r in range(n):
    for l in range(r+1):
        if sum(a[l:r+1])%m==0:
            ans+=1

print(ans)

Fixed submission:
import collections

n,m=map(int,input().split())
a=[int(i) for i in input().split()]

s=0
ans=0
l=[]

for i in a:
    s+=i
    l.append(s%m)

c=collections.Counter(l)

for p,q in c.items():
    if int(p)==0:
        ans+=q*(q+1)//2
    else:
        ans+=q*(q-1)//2


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]
b=n*(-1)
k=0
ans=0

def sunuke(b):
    ans=0
    for i in range(n):
        ans+=abs(a[i]-b-i-1) 
    return ans 
        
while k<1:
    if sunuke(b)<sunuke(b+1):
        print(sunuke(b))
        k=1
    else:
        b+=1

Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]

for i in range(n):
    a[i]-=i+1

a.sort()
if n % 2 == 0:
    print(sum(a[int(n / 2):]) - sum(a[:int(n / 2)]))
else:
    print(sum(a[int((n + 1) / 2):]) - sum(a[:int((n - 1) / 2)]))
Buggy python submission (verdict: Runtime Error):
N=int(input())

if N<1000:
    print(“ABC”)
else:
    print(“ABD”)

Fixed submission:
N=int(input())
if N<1000:
    print("ABC")
else:
    print("ABD")

Buggy python submission (verdict: Runtime Error):
N=int(input())

if N<1000:
    print(“ABC”)
else:
    print(“ABD”)

Fixed submission:
N=int(input())
if N<1000:
    print("ABC")
else:
    print("ABD")
Buggy python submission (verdict: Time Limit Exceeded):
n,C=map(int,input().split())
d=[]
c=[]
for i in range(C):
    d.append([int(j) for j in input().split()])
for i in range(n):
    c.append([int(j) for j in input().split()])
l1=[0 for i in range(C+1)]
l2=[0 for i in range(C+1)]
l3=[0 for i in range(C+1)]

for i in range(n):
    for j in  range(n):
        if (i+j+2)%3==0:
            for k in range(1,C+1):
                l1[k]+=d[c[i][j]-1][k-1]
        if (i+j+2)%3==1:
            for k in range(1,C+1):
                l2[k]+=d[c[i][j]-1][k-1]
        if (i+j+2)%3==2:
            for k in range(1,C+1):
                l3[k]+=d[c[i][j]-1][k-1]
ans=10**100
for i in range(1,C+1):
    for j in range(1,C+1):
        for k in range(1,C+1):
            if i!=j and i!=k and j!=k:
                ans=min(ans,l1[i]+l2[j]+l3[k])
print(ans)

Fixed submission:
n,C=map(int,input().split())
d=[]
c=[]
for i in range(C):
    d.append([int(j) for j in input().split()])
for i in range(n):
    c.append([int(j) for j in input().split()])
l1=[0 for i in range(C+1)]
l2=[0 for i in range(C+1)]
l3=[0 for i in range(C+1)]

for i in range(n):
    for j in  range(n):
        if (i+j+2)%3==0:
            for k in range(1,C+1):
                l1[k]+=d[c[i][j]-1][k-1]
        if (i+j+2)%3==1:
            for k in range(1,C+1):
                l2[k]+=d[c[i][j]-1][k-1]
        if (i+j+2)%3==2:
            for k in range(1,C+1):
                l3[k]+=d[c[i][j]-1][k-1]
ans=10**100
for i in range(1,C+1):
    for j in range(1,C+1):
        for k in range(1,C+1):
            if i!=j and i!=k and j!=k:
                ans=min(ans,l1[i]+l2[j]+l3[k])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

ans=[]

for i in range(n):

    ans.append(s[0:i].count("W")+s[i+1:n].count("E"))
    
print(min(ans))


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

a=0
b=0
e=[]
w=[0]
ans=[]

for i in s:
    if i==("E"):
        a+=1
    else:
        b+=1
    e.append(a)
    w.append(b)
        
for i in range(n):
    ans.append(e[n-1]-e[i]+w[i])

print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()

ans=n

for i in range(n):

    ans=min(ans,s[0:i].count("W")+s[i+1:n].count("E"))
    
print(ans)

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

a=0
b=0
e=[]
w=[0]
ans=[]

for i in s:
    if i==("E"):
        a+=1
    else:
        b+=1
    e.append(a)
    w.append(b)
        
for i in range(n):
    ans.append(e[n-1]-e[i]+w[i])

print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
b=[bin(int(i))[2:] for i in input().split()]
ind=0
i=0
l=[0]*20
ans=0
tmp=0
for i in range(n):
    if i>0 and ind<n:
        for j in range(len(b[i-1]))[::-1]:
            if b[i-1][j]=="1":
                l[j-len(b[i-1])]-=1
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]-=1
    ans+=ind-i
    while ind<n:
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]+=1
        if 2 in l:
            break
        else:
            ind+=1
            ans+=1
print(ans)

    










Fixed submission:
n=int(input())
b=[bin(int(i))[2:] for i in input().split()]
ind=0
i=0
l=[0]*20
ans=0
tmp=0
for i in range(n):
    if i>0 and ind<n:
        for j in range(len(b[i-1]))[::-1]:
            if b[i-1][j]=="1":
                l[j-len(b[i-1])]-=1
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]-=1
    ans+=ind-i
    while ind<n:
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]+=1
        if 2 in l:
            break
        else:
            ind+=1
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
x=int(input())
p=x**0.5
ans=[]
for i in range(1,p+1):
  j=2
  while True:
    if i**j<=x:
      ans.append(i**j)
    else:
      break
    j+=1
print(max(ans))

Fixed submission:
x=int(input())
import math
p=math.ceil(x**0.5)
ans=[1]
for i in range(2,p+1):
  j=2
  while True:
    if i**j<=x:
      ans.append(i**j)
    else:
      break
    j+=1
print(max(ans))

Buggy python submission (verdict: Runtime Error):
x=int(input())
p=x**0.5
ans=[]
for i in range(1,p+1):
  j=2
  while True:
    if i**j<=p:
      ans.append(i**j)
    else:
      break
    j+=1
print(max(ans))

Fixed submission:
x=int(input())
import math
p=math.ceil(x**0.5)
ans=[1]
for i in range(2,p+1):
  j=2
  while True:
    if i**j<=x:
      ans.append(i**j)
    else:
      break
    j+=1
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())

sl=[]
l=len(s)
x=0
for i in range(l):
    if i>k:
        x=i-k
    for j in range(x,i+1):
        sl.append(s[j:i+1])
              
li=[]
for i in sl:
    if i not in li:
        li.append(i)
        
li.sort()

print(li[k-1])

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

l=list(s)

import collections
c=collections.Counter(l)
li=c.most_common()
from operator import itemgetter
li.sort(key=itemgetter(0))

co=0
p=[]
for i in range(min(5,len(li))):
    for j in range(len(s)):
        if l[j]==li[i][0]:
            for e in range(min(len(s)-j,k)):
                co+=1
                p.append(s[j:j+e+1])

q=collections.Counter(p)
ans=q.most_common()
ans.sort(key=itemgetter(0))   

print(ans[k-1][0])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())

sl=[]
l=len(s)
for i in range(l):
    for j in range(i+1):
        sl.append(s[j:i+1])
              
li=[]
for i in sl:
    if i not in li:
        li.append(i)
        
li.sort()

print(li[k-1])

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

l=list(s)

import collections
c=collections.Counter(l)
li=c.most_common()
from operator import itemgetter
li.sort(key=itemgetter(0))

co=0
p=[]
for i in range(min(5,len(li))):
    for j in range(len(s)):
        if l[j]==li[i][0]:
            for e in range(min(len(s)-j,k)):
                co+=1
                p.append(s[j:j+e+1])

q=collections.Counter(p)
ans=q.most_common()
ans.sort(key=itemgetter(0))   

print(ans[k-1][0])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())

sl=[]
l=len(s)
for i in range(l):
    for j in range(i+1):
        sl.append(s[j:i+1])
        
sl.sort()      
li=[]
for i in sl:
    if i not in li:
        li.append(i)

print(li[k-1])

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

l=list(s)

import collections
c=collections.Counter(l)
li=c.most_common()
from operator import itemgetter
li.sort(key=itemgetter(0))

co=0
p=[]
for i in range(min(5,len(li))):
    for j in range(len(s)):
        if l[j]==li[i][0]:
            for e in range(min(len(s)-j,k)):
                co+=1
                p.append(s[j:j+e+1])

q=collections.Counter(p)
ans=q.most_common()
ans.sort(key=itemgetter(0))   

print(ans[k-1][0])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n=int(input())
s=np.array([list(input()) for i in range(n)])
l=np.zeros((n,n),dtype=np.str)
ans=0
for i in range(n):
    l[:i]=s[n-i:n]
    l[i:]=s[:n-i]
    t=False
    for x in range(n):
        for y in range(x+1,n):
            if l[x][y]!=l[y][x]:
                t=True
                break
        if t:
            break
    if not t:
        ans+=n

print(ans)


Fixed submission:
import numpy as np
n=int(input())
s=np.array([list(input()) for i in range(n)])
s=np.concatenate([s,s])
ans=0
for i in range(n):
    l=s[i:i+n]
    if (l==l.T).all():
        ans+=n
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,d=map(int,input().split())
a=[]
l=[[] for i in range(h*w+1)]
for i in range(h):
    p=[int(j) for j in input().split()]
    a.append(p)
    for j in range(w):
        l[int(p[j])].append(i)
        l[int(p[j])].append(j)

q=int(input())
lr=[]
for i in range(q):
    lr=[int(j) for j in input().split()]
    ans=0
    p=(lr[1]-lr[0])//d
    for j in range(p):
        ans+=abs(l[lr[0]+d*j][0]-l[lr[0]+d*(j+1)][0])+abs(l[lr[0]+d*j][1]-l[lr[0]+d*(j+1)][1])
    print(ans)




Fixed submission:
h,w,d=map(int,input().split())
a=[]
l=[[] for i in range(h*w+1)]
for i in range(h):
    p=[int(j) for j in input().split()]
    a.append(p)
    for j in range(w):
        l[int(p[j])].append(i)
        l[int(p[j])].append(j)
cost=[0 for i in range(h*w+1)]
for i in range(1,h*w+1-d):
    cost[i+d]=cost[i]+abs(l[i+d][0]-l[i][0])+abs(l[i][1]-l[i+d][1])
q=int(input())
lr=[]
for i in range(q):
    lr=[int(j) for j in input().split()]
    print(cost[lr[1]]-cost[lr[0]])

Buggy python submission (verdict: Time Limit Exceeded):
h,w,d=map(int,input().split())
a=[]
l=[[] for i in range(h*w+1)]
for i in range(h):
    p=input().split()
    a.append(p)
    for j in range(w):
        l[int(p[j])].append(i)
        l[int(p[j])].append(j)

q=int(input())
lr=[]
for i in range(q):
    lr=[int(j) for j in input().split()]
    ans=0
    p=(lr[1]-lr[0])//d
    for j in range(p):
        ans+=abs(l[lr[0]+d*j][0]-l[lr[0]+d*(j+1)][0])+abs(l[lr[0]+d*j][1]-l[lr[0]+d*(j+1)][1])
    print(ans)




Fixed submission:
h,w,d=map(int,input().split())
a=[]
l=[[] for i in range(h*w+1)]
for i in range(h):
    p=[int(j) for j in input().split()]
    a.append(p)
    for j in range(w):
        l[int(p[j])].append(i)
        l[int(p[j])].append(j)
cost=[0 for i in range(h*w+1)]
for i in range(1,h*w+1-d):
    cost[i+d]=cost[i]+abs(l[i+d][0]-l[i][0])+abs(l[i][1]-l[i+d][1])
q=int(input())
lr=[]
for i in range(q):
    lr=[int(j) for j in input().split()]
    print(cost[lr[1]]-cost[lr[0]])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
print(0)
z=input()[0]
if z=="V":
    exit()
def f(i):
    print(i)
    s=input()[0]
    if s=="V":
        exit()
    if i%2==0:
        if s==z:
            return False
        else:
            return True
    else:
        if s==z:
            return True
        else:
            return False

left=0
right=n-1
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid   #ここがleftならansもleft。
    else:
        left=mid

Fixed submission:
n=int(input())
print(0)
z=input()[0]
if z=="V":
    exit()
def f(i):
    print(i)
    s=input()[0]
    if s=="V":
        exit()
    if i%2==0:
        if s==z:
            return False
        else:
            return True
    else:
        if s==z:
            return True
        else:
            return False
f(n-1)
left=0
right=n-1
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid   #ここがleftならansもleft。
    else:
        left=mid
exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(i) for i in input().split()]

l=[]
ans=0

for i in a:
    if not i in l:
        l.append(i)

for i in l:
    if a.count(i)<i:
        ans+=a.count(i)
    elif a.count(i)>i:
        ans+=a.count(i)-i
        
print(ans)

Fixed submission:
import collections
n=int(input())
a=[int(i) for i in input().split()]


ans=0

l=collections.Counter(a)

for i,j in l.most_common():
    if int(i)<j:
        ans+=j-int(i)
    elif int(i)>j:
        ans+=j
        
print(ans)
Buggy python submission (verdict: Runtime Error):
i=input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"
elif a+b+c-d==7:
    x="+"
    y="+"
    z="-"
elif a+b-c+d==7:
    x="+"
    y="-"
    z="+"    
elif a-b+c+d==7:
    x="-"
    y="+"
    z="+"
elif a-b-c+d==7:
    x="-"
    y="-"
    z="+"
elif a-b+c-d==7:
    x="-"
    y="+"
    z="-"
elif a-b-c+d==7:
    x="-"
    y="-"
    z="+"
elif a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")

Fixed submission:
i=input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"
elif a+b+c-d==7:
    x="+"
    y="+"
    z="-"
elif a+b-c+d==7:
    x="+"
    y="-"
    z="+"    
elif a-b+c+d==7:
    x="-"
    y="+"
    z="+"
elif a-b-c+d==7:
    x="-"
    y="-"
    z="+"
elif a-b+c-d==7:
    x="-"
    y="+"
    z="-"
elif a+b-c-d==7:
    x="+"
    y="-"
    z="-"
elif a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")

Buggy python submission (verdict: Runtime Error):
i=input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"

if a+b+c-d==7:
    x="+"
    y="+"
    z="-"
    
    
if a+b-c+d==7:
    x="+"
    y="-"
    z="+"    

if a-b+c+d==7:
    x="-"
    y="+"
    z="+"
    
if a-b-c+d==7:
    x="-"
    y="-"
    z="+"

if a-b+c-d==7:
    x="-"
    y="+"
    z="-"

if a-b-c+d==7:
    x="-"
    y="-"
    z="+"
    
if a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")

Fixed submission:
i=input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])

if a+b+c+d==7:
    x="+"
    y="+"
    z="+"
elif a+b+c-d==7:
    x="+"
    y="+"
    z="-"
elif a+b-c+d==7:
    x="+"
    y="-"
    z="+"    
elif a-b+c+d==7:
    x="-"
    y="+"
    z="+"
elif a-b-c+d==7:
    x="-"
    y="-"
    z="+"
elif a-b+c-d==7:
    x="-"
    y="+"
    z="-"
elif a+b-c-d==7:
    x="+"
    y="-"
    z="-"
elif a-b-c-d==7:
    x="-"
    y="-"
    z="-"
    
    
print(a,end="")
print(x,end="")
print(b,end="")
print(y,end="")
print(c,end="")
print(z,end="")
print(d,end="")
print("=7")