Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# cook your dish here
D,g = map(int,input().split())
p = []
c = []

for i in range(D):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)

#print(p)

d = [0]
cnt = 0

while d[-1] < g:
    while p[-1] == 0:
        p.pop(len(p)-1)
        c.pop(len(p)-1)
    k = -1
    
    r = d[-1] + (len(p))*100
    for i in range(len(p)):
        if len(d) >= p[i] and p[i] != 0:
            w = d[len(d)-p[i]] + 100*(i+1)*p[i] + c[i]
 #           print(p[i],i,c[i],len(d),w)
            if w > r:
                r = w
                k = i
    if k == -1:
        cnt += 1
        
    else:
        p[-1] += cnt
        p[k] = 0
        cnt = 0
        
    d.append(r)

#print(d)
print(len(d)-1)

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

d,g = map(int,input().split())
p = []
s = []
for i in range(d):
    x,y = map(int,input().split())
    p.append(x)
    s.append(100*(i+1)*x+y)

ans = 10**10
for i in range(1<<(d+1)):
    cnt = 0
    res = 0
    tank = []
    for j in range(d):
        if (i>>j)&1 == 1:
            cnt += s[j]
            res += p[j]
        else:
            tank.append([100*(j+1),p[j]])
    if cnt >= g:
        ans = min(ans,res)
    else:
        while cnt < g and tank[-1][1] > 0:
            cnt += tank[-1][0]
            tank[-1][1] -= 1
            res += 1
        if cnt >= g:
            ans = min(ans,res)
print(ans)

Buggy python submission (verdict: Runtime Error):
# cook your dish here
D,g = map(int,input().split())
p = []
c = []

for i in range(D):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)

#print(p)

d = [0]
cnt = 0

while d[-1] < g:
    while p[-1] == 0:
        p.pop(len(p)-1)
        c.pop(len(p)-1)
    k = -1
    
    r = d[-1] + (len(p))*100
    for i in range(len(p)):
        if len(d) >= p[i] and p[i] != 0:
            w = d[len(d)-p[i]] + 100*(i+1)*p[i] + c[i]
 #           print(p[i],i,c[i],len(d),w)
            if w > r:
                r = w
                k = i
    if k == -1:
        cnt += 1
        
    else:
        p[-1] += cnt
        p[k] = 0
        
    d.append(r)

#print(d)
print(len(d)-1)

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

d,g = map(int,input().split())
p = []
s = []
for i in range(d):
    x,y = map(int,input().split())
    p.append(x)
    s.append(100*(i+1)*x+y)

ans = 10**10
for i in range(1<<(d+1)):
    cnt = 0
    res = 0
    tank = []
    for j in range(d):
        if (i>>j)&1 == 1:
            cnt += s[j]
            res += p[j]
        else:
            tank.append([100*(j+1),p[j]])
    if cnt >= g:
        ans = min(ans,res)
    else:
        while cnt < g and tank[-1][1] > 0:
            cnt += tank[-1][0]
            tank[-1][1] -= 1
            res += 1
        if cnt >= g:
            ans = min(ans,res)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# your code goes here
a=int(input())
if a%2 == 0:
	k = a
else:
	k = a + 1
while k>0:
	if k %2== 0 and k % a ==0:
		print(k)
		quit()
	k = k + 2

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

Buggy python submission (verdict: Time Limit Exceeded):
# your code goes here
a=int(input())
if a%2 == 0:
	k = a
else:
	k = a + 1
while k>0:
	if k %2== 0 and k % a ==0:
		print(k)
		quit()
	k = k + a

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

Buggy python submission (verdict: Time Limit Exceeded):
# your code goes here
a=int(input())
k = a
while k>0:
	if k %2== 0 and k % a ==0:
		print(k)
		quit()
	k = k +1

Fixed submission:
a=int(input())
if a%2 == 0:
	print(a)
else:
	print(a*2)
Buggy python submission (verdict: Runtime Error):
1.	n = int(input())
2.	a = list(map(int, input().split()))
3.	tmp = [a[x] - (x+1) for x in range(0,n)]
4.	tmp.sort()
5.	b = tmp[n // 2]
6.	print(sum((abs(tmp[i] - b) for i in range(0,n))))


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))

Buggy python submission (verdict: Runtime Error):
import copy
from statistics import mean, median,variance,stdev
N=int(input())
li = list(map(int,input().split()))

for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
if len(li) %2 == 1:
    m = median(li)
    k = 0
    for j in range(0,N):
        k = k + abs(li[j]-m)
else:
    c = copy.copy(li)
    c.sort()
    o = []
    for i in range(c[len(c)//2],c[len(c)//2+1]):
        k = 0
        for j in range(N):
            k = k + abs(li[j]-i)
        o.append(k)
    k = min(o)
print(k)


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N=int(input())
li = list(map(int,input().split()))

for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
while len(d) >= 3:
	d.remove(max(d))
	d.remove(min(d))
for i in range(min(d),max(d)+1):
	k = 0
	for j in range(N):
		k = k + abs(li[j]-i)
	a.append(k)
print(min(a))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))

Buggy python submission (verdict: Runtime Error):
import copy
N=int(input())
li = list(map(int,input().split()))
for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
while len(d) >= 3:
	del d[max(d)]
	del d[min(d)]
for i in range(min(d),max(d)+1):
	k = 0
	for j in range(N):
		k = k + abs(li[j]-i)
	a.append(min(k))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))

Buggy python submission (verdict: Runtime Error):
import copy
N=int(input())
li = list(map(int,input().split()))
for i in range(0,N):
	li[i] = li[i] - i -1
a = []
d = copy.copy(li)
while len(d) >= 3:
	del d[max(d)]
	del d[min(d)]
for i in range(min(d),max(d)+1):
	k = 0
	for j in range(N):
		k = k + abs(li[j]-i)
	a.append(k)
print(a)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))

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

for i in range(0,N):
	li[i] = li[i] - i -1
a = []
for i in range(min(li),max(li)+1):
	k = 0
	for j in range(0,N):
		k = k + abs(li[j]-i)
	a.append(k)
print(min(a))

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
for i in range(0,len(a)):
    a[i] -= (i+1)
a.sort()
b = [ abs(x  - (a[n//2])) for x in a]
print(sum(b))
Buggy python submission (verdict: Runtime Error):
# your code goes here
import copy
N=int(input())
k = copy.copy(N)
 
a=[]
while k != 0:
	a.append(k%10)
	k = k//10
 
if N%sum(a)==0:
	print('Yes')
else:
	print('No'

Fixed submission:
# your code goes here
import copy
N=int(input())
k = copy.copy(N)

a=[]
while k != 0:
	a.append(k%10)
	k = k//10

if N%sum(a)==0:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
a=int(input())
if a < = 999:
  print('ABC')
 else:
  print('ABD')

Fixed submission:
# your code goes here
a=int(input())

if a <= 999:
	print('ABC')
else:
	print('ABD')
Buggy python submission (verdict: Time Limit Exceeded):
# your code goes here
N=int(input())
s=list(input())
a = [0]*N
for i in range(0,N):
	if s[i]=='E':
		for j in range(0,i):
			a[j] = a[j]+1
	else:
		for j in range(i+1,N):
			a[j] = a[j]+1

print(min(a))

Fixed submission:
N = int(input())
S = input()
 
cnt = S[1:].count("E")
ans = cnt
for i in range(1, N):
    if S[i-1] == "W":
        cnt += 1
    if S[i] == "E":
        cnt -= 1
    ans = min(ans, cnt)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# your code goes here
N=int(input())
s=list(input())
a = []

for i in range(1,N):
	b =s[:i:].count('W')
	c=s[i+1::].count('E')
	a.append(b+c)
a.append(s[1::].count('E'))
print(min(a))

Fixed submission:
N = int(input())
S = input()
 
cnt = S[1:].count("E")
ans = cnt
for i in range(1, N):
    if S[i-1] == "W":
        cnt += 1
    if S[i] == "E":
        cnt -= 1
    ans = min(ans, cnt)
 
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s_list = [input() for _ in range(H)]
ans = 'Yes'
for i in range(1, H - 1):
	for j in range(1, W - 1):
		if s_list[i][j] == '#' and s_list[i-1][j] == s_list[i+1][j] == s_list[i][j-1] == s_list[i][j+1] == '.':
			ans = 'No'
			break
print(ans)

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

if x <= y:
  print(x)
else:
  print(x-1)
Buggy python submission (verdict: Runtime Error):
# cook your dish here
import numpy as np
n =int(input())
a = list(map(int,input().split()))	


d = np.ones((n,n))

c = 0

if n == 1:
    if a[0]== 0:
        print(1)
    else:
        print(0)
    quit()

for i in range(0,n):
    d[0][i] = sum(a[:i+1:])
    if d[0][i] == 0:
        c += 1
for t in range(0,n-1):
    s = 0
    while s <=t:
        d[s+1][t+1] = d[s][t]-a[s]+a[t+1]
        if d[s+1][t+1] == 0:
            c += 1
        s += 1


print(c)

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

c = 0

s = [a[0]]
for i in range(1,n):
    s.append(s[-1]+a[i])

#print(s)
s.sort()
#print(s)

k=1
for i in range(1,n):
    if s[i]==s[i-1]:
        k += 1
    else:
        if k != 1:
            c += k*(k-1)//2
        k = 1
    if i == n-1 and k != 1:
         c += k*(k-1)//2
        
c += s.count(0)
print(c)
Buggy python submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
z=min(x,y)
if a+b>2*c:
    print(z*2*c+min((x-z)*a+(y-z)*b,(x+y-z*2)*2*c))
else:
    print(a*x+b*y)

Fixed submission:
s=list(input())
 
print(700+100*(s.count('o')))
Buggy python submission (verdict: Runtime Error):
a,b,x = map(int,input().split())

if a <= x and a + b >= x:
  print('YES')
else:
	print('NO)  

Fixed submission:
a,b,x = map(int,input().split())
 
if a <= x and a + b >= x:
  print('YES')
else:
	print('NO')
Buggy python submission (verdict: Runtime Error):
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

ans = []
for testcase in range(Q):
    a,b = map(int,input().split())
    p = int((a*b-1)**0.5)
    res = p*2
    if a != b:
        res -= 1
    if p == (a*b - 1)//p:
        res -= 1
    ans.append(res)

print(*ans,sep='\n')

Fixed submission:
import sys,heapq
input = sys.stdin.buffer.readline

Q = int(input())

def f(x,y):
    ma = x*y - 1
    ok = 0
    ng = 10**9 + 1
    while ng - ok > 1:
        mid = (ok+ng)//2
        if mid**2 <= ma:
            ok = mid
        else:
            ng = mid
    return ok

ans = []
for testcase in range(Q):
    a,b = map(int,input().split())
    if a == 1 and b == 1:
        ans.append(0)
        continue
    p = f(a,b)
    res = p*2
    if a != b:
        res -= 1
    if p == (a*b - 1)//p:
        res -= 1
    ans.append(res)

print(*ans,sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
q =int(input())
l = [0]*q
r = [0]*q
for i in range(q):
    l[i],r[i] = map(int,input().split())


for i in range(q):
    c = 0
    x = l[i]
    
    
    jkl = 0
    while x != r[i]+d:
        op = 0
        p = 0
        
        while op != 1:
            j = 0
            
            while op != 1 and j != h:
                if x == a[j][p]:
                    jkl +=1
                    
                    if jkl != 1:
                        c = c +  abs(j-ab) + abs(p-bc)
                    ab = j
                    bc = p
                    j = 0
                    p = 0
                    op = 1
                j +=1
            p +=1
        x += d
        
    print(c)


Fixed submission:
H, W, D = map(int, input().split())
xy = {}
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        xy[A[j]] = (i + 1, j + 1)
 
d = [0] * (H * W + 1)
for i in range(D + 1, H * W + 1):
    x1, y1 = xy[i]
    x2, y2 = xy[i - D]
    d[i] = d[i - D] + abs(x1 - x2) + abs(y1 - y2)
 
Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    ans = d[R] - d[L]
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
a = list(map(int,input().split()))

#始めの人数がn人だった時終わりの人数
def g(n,a,k):
    for i in range(k):
        n = n - (n%a[i])
    return n

#print(g(8,a,k))

s = 0
t = 2 + k*max(a)
for i in range(100):
    m = (s+t)//2
    if g(m,a,k)> 2:
        t = m
    else:
        s = m
    
p = 0
q = 2+k*max(a)
for i in range(100):
    m = (p+q)//2
    if g(m,a,k) >= 2:
        q = m
    else:
        p = m

c = 1
if g(s,a,k) == 2:
    res = s
elif g(t,a,k) == 2:
    res = t
else:
    c = -1

if g(q,a,k) == 2:
    res2 = q
elif g(p,a,k) == 2:
    res2 = p
else:
    c = -1

if c == 1:
    print(res2,res)
else:
    print(-1)

Fixed submission:
k = int(input())
a = list(map(int,input().split()))
a = a[::-1]

c = 2 #min
d = 2 #max
res = 1 #判定

for i in range(k):
    if d < a[i]:
        res = -1
        break
    if i != k-1:
        if c % a[i] != 0 or d % a[i] != 0:
            res = -1
            break
        else:
            d = d + a[i] -1
            p = c%a[i+1]
            q = d%a[i+1]
            if p == 0:
                c2 = c
            else:
                c2 = c + a[i+1]-p
            d2 = d-q
            
            if c2 <= d2:
                c = c2
                d = d2
            else:
                res = -1
                break
    else:
        d = d + a[i] -1
            
        
    
    
if res == -1:
    print(-1)
else:
    print(str(c) + ' ' + str(d))
Buggy python submission (verdict: Runtime Error):
s=list(input())
a = []
n=len(s)
for i in range(n-1):
    if s[i]!= s[i+1]:
        a.append(max(i+1,n-i-1))

print(min(a))

Fixed submission:
s=list(input())

n=len(s)
a = [n]
if n == 1:
    print(1)
else:
    for i in range(n-1):
        if s[i]!= s[i+1]:
            a.append(max(i+1,n-i-1))

    print(min(a))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a = list(map(int,input().split()))
a.sort()

c = 0
d = 0 #i

while d <= n-1:
    s = a.count(a[d])
    if a[d] > s:
        c += s
    else:
        c += s-a[d]
    d = d + s
    
print(c)

Fixed submission:
import bisect
n=int(input())
a = list(map(int,input().split()))
a.sort()
 
c = 0
d = 0 #i
 
while d <= n-1:
    s2 = bisect.bisect_right(a,a[d])
    s = s2-d
    if a[d] > s:
        c += s
    else:
        c += s-a[d]
    d = d + s
    
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    r = [[float("inf")]*n for i in range(n)]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                r[i][j] = min(d[i][j],r[i][k] + r[k][j])
    return r

n = int(input())
a = [[] for i in range(n)]
for i in range(n):
    a[i] = list(map(int,input().split()))
for i in range(n):
    if a[i][i] != 0:
        print(-1)
        exit()


war = warshall_floyd(n,a)

res = 0
for i in range(n):
    for j in range(n):
        if war[i][j] < a[i][j]:
            print(-1)
            exit()
        elif war[i][j] == a[i][j]:
            judge = 1
            for h in range(n):
                if h != i and h != j and war[i][h]+war[h][j] == war[i][j]:
                    judge = -1
            if judge == 1:
                res += war[i][j]
print(res//2)


Fixed submission:
def warshall_floyd(n,d):
    #d[i][j]: iからjへの最短距離
    r = [[float("inf")]*n for i in range(n)]
    for k in range(n):
        for i in range(n):
            for j in range(n):
                r[i][j] = min(d[i][j],r[i][k] + r[k][j])
    return r

n = int(input())
a = [[] for i in range(n)]
for i in range(n):
    a[i] = list(map(int,input().split()))
for i in range(n):
    if a[i][i] != 0:
        print(-1)
        exit()


war = warshall_floyd(n,a)

res = 0
for i in range(n):
    for j in range(n):
        if war[i][j] < a[i][j]:
            print(-1)
            exit()
        elif war[i][j] == a[i][j]:
            judge = 1
            for h in range(n):
                if h != i and h != j and war[i][h]+war[h][j] == war[i][j]:
                    judge = -1
            if judge == 1:
                res += war[i][j]
print(res//2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
input = sys.stdin.readline
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,w,R = map(int,input().split())
r = list(map(int,input().split()))
d = [[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
for i in range(R):
    r[i] -= 1
d = warshall_floyd(d)

res = float("inf")
for v in itertools.permutations(r,R):
    sumd = 0
    for j in range(1,R):
        sumd += d[v[j-1]][v[j]]
    res = min(res,sumd)
print(res)

Fixed submission:
import sys
import itertools
input = sys.stdin.readline
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

n,w,R = map(int,input().split())
r = list(map(int,input().split()))
d = [[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(w):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
for i in range(R):
    r[i] -= 1
d = warshall_floyd(d)

res = float("inf")
for v in itertools.permutations(r,R):
    sumd = 0
    for j in range(1,R):
        sumd += d[v[j-1]][v[j]]
    res = min(res,sumd)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
# cook your dish here
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    if i % 2 == 0:
        b.insert(0,a[i])
    else:
        b.append(a[i])
c = b[::-1]
ass = ''
for i in range(n):
    if n %2 == 0:
        ass += str(c[i]) + ' '
    else:
        ass += str(b[i]) + ' '
print(ass)

    

Fixed submission:
# cook your dish here
n = int(input())
a = list(map(int,input().split()))
c = []
d = []

for i in range(n):
    if i %2 == 0:
        c.append(a[i])
    else:
        d.append(a[i])
c = c[::-1]

b = c + d
c = b[::-1]
ass = ''
for i in range(n):
    if n %2 == 0:
        ass += str(c[i]) + ' '
    else:
        ass += str(b[i]) + ' '
print(ass)

Buggy python submission (verdict: Time Limit Exceeded):
# cook your dish here
n = int(input())
a = list(map(int,input().split()))
b = []

for i in range(n):
    if i % 2 == 0:
        b = [a[i]]+b
    else:
        b.append(a[i])
c = b[::-1]
ass = ''
for i in range(n):
    if n %2 == 0:
        ass += str(c[i]) + ' '
    else:
        ass += str(b[i]) + ' '
print(ass)

    

Fixed submission:
# cook your dish here
n = int(input())
a = list(map(int,input().split()))
c = []
d = []

for i in range(n):
    if i %2 == 0:
        c.append(a[i])
    else:
        d.append(a[i])
c = c[::-1]

b = c + d
c = b[::-1]
ass = ''
for i in range(n):
    if n %2 == 0:
        ass += str(c[i]) + ' '
    else:
        ass += str(b[i]) + ' '
print(ass)
Buggy python submission (verdict: Runtime Error):
n = int(input())

a = list(map(int,int(input())))
a_max = max(a)
a_min = min(a)
if a_max > a_min+1:
    print('No')
    exit()
k = a_max
if a_max == a_min:
    if k == n-1 or 2*k <= n:
        print('Yes')
    else:
        print('No')
else:
    uni = a.count(k-1)
    if k >= uni + 1 and k <= uni + (n-uni)//2:
        print('Yes')
    else:
        print('No')

Fixed submission:
n = int(input())

a = list(map(int,input().split()))
a_max = max(a)
a_min = min(a)
if a_max > a_min+1:
    print('No')
    exit()
k = a_max
if a_max == a_min:
    if k == n-1 or 2*k <= n:
        print('Yes')
    else:
        print('No')
else:
    uni = a.count(k-1)
    if k >= uni + 1 and k <= uni + (n-uni)//2:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]
h.sort()
p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**17
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Fixed submission:
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]

p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**9
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]
h.sort()
p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**18
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Fixed submission:
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]

p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**9
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)