Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

str_s = input()
int_k = int(input())

pattern = set()

for f in range(len(str_s) + 1):
    for t in range(f + 1, len(str_s) + 1):
        pattern.add(str_s[f:t])

print(sorted(list(pattern))[int_k - 1])




### FIXED CODE ###

str_s = input()
int_k = int(input())

result = list()
for f in range(len(str_s)):
    pattern = set()
    for t in range(f + 1, f + 1 + int_k):
        pattern.add(str_s[f:t])
        result = sorted(set(result + list(pattern)))[:int_k]

print(result[-1])
### BUGGY CODE ###

import itertools
import sys
input = sys.stdin.readline

H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = []
for m in range(M):
  h, w = map(int, input().split())
  Hsum[h-1] += 1
  Wsum[w-1] += 1
  hw.append(str(h-1)+"_"+str(w-1))

hmax_ind = list(map(lambda x: True if x == max(Hsum) else False, Hsum))
hmax_ind = list(itertools.compress(range(len(Hsum)), hmax_ind))
wmax_ind = list(map(lambda x: True if x == max(Wsum) else False, Wsum))
wmax_ind = list(itertools.compress(range(len(Wsum)), wmax_ind))
 
res = []
for n in itertools.product(hmax_ind, wmax_ind):
  res.append(str(n[0])+"_"+str(n[1]))

if len(set(res).intersection(set(hw))) == len(res):
  print(max(Hsum) + max(Wsum)-1)
else:
  print(max(Hsum) + max(Wsum))

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
H, W, M = map(int, input().split())
Hsum = [0] * H
Wsum = [0] * W
hw = set()
for m in range(M):
  h, w = map(lambda x: int(x) - 1, input().split())
  Hsum[h] += 1
  Wsum[w] += 1
  hw.add((h, w))

mh = max(Hsum)
mw = max(Wsum)
hidx = [i for i, _ in enumerate(Hsum) if _ == mh]
widx = [i for i, _ in enumerate(Wsum) if _ == mw]
 
if len(hidx) * len(widx) > M:
  print(mh + mw)
else:
  fi_flg = False
  for h in hidx:
    for w in widx:
      if (h, w) not in hw:
        print(mh + mw)
        fi_flg = True
        break
    if fi_flg:
      break
  if fi_flg is False:
    print(mh + mw - 1)
### BUGGY CODE ###

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import bisect
mod=998244353
n=int(input())
d=[]
N=1<<(n.bit_length())
t=[-1 for i in range(2*N-1)]

def ud(i,x):
  i+=N-1
  t[i]=x
  while i:
    i=(i-1)//2
    if t[i*2+1]>t[i*2+2]:t[i]=t[i*2+1]
    else:t[i]=t[i*2+2]
     

def qr(a,b):
    a+=N-1
    b+=N-1
    L = -1
    R = -1
    while a < b:
      if a&1==0:
         if L<t[a]:L = t[a]
      if b&1==0:
         b-=1
         if R<t[b]:R = t[b]
      
      a>>=1
      b>>=1
      
         
    return max(L, R)
 
for i in range(n):
  d.append([int(i) for i in input().split()])
d=sorted(d)
dx=[]
dd=[]
for i,j in d:
  dx.append(i)
  dd.append(j)
for i in range(n)[::-1]:
 j=bisect.bisect_left(dx,dx[i]+dd[i])
 tt=qr(i,j)
 if j-1>tt:ud(i,j-1)
 else:ud(i,tt)
dp=[0 for i in range(n+1)]
dp[-1]=1
for i in range(n)[::-1]:
  dp[i]+=dp[i+1]
  dp[i]%=mod
  dp[i]+=dp[t[i+N-1]+1]
  dp[i]%=mod
print(dp[0])

### FIXED CODE ###

def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import bisect
mod=998244353
n=int(input())
d=[]
N=1<<(n.bit_length())
t=[-1 for i in range(2*N-1)]

def ud(i,x):
  i+=N-1
  t[i]=x
  while i:
    i=(i-1)>>1
    if t[i*2+1]>t[i*2+2]:t[i]=t[i*2+1]
    else:t[i]=t[i*2+2]
     

def qr(a,b):
    a+=N-1
    b+=N-1
    L = -1
    R = -1
    while a < b:
      if a&1==0:
         if L<t[a]:L = t[a]
      if b&1==0:
         b-=1
         if R<t[b]:R = t[b]
      
      a>>=1
      b>>=1
      
         
    return max(L, R)
 
for i in range(n):
  d.append([int(i) for i in input().split()])
d.sort()
dx=[]
dd=[]
for i,j in d:
  dx.append(i)
  dd.append(j)
for i in range(n)[::-1]:
 tx=dx[i]+dd[i]
 j=bisect.bisect_left(dx,tx)
 tt=qr(i,j)
 if j-1>tt:ud(i,j-1)
 else:ud(i,tt)
dp=[0 for i in range(n+1)]
dp[-1]=1
for i in range(n)[::-1]:
  dp[i]+=dp[i+1]
  dp[i]%=mod
  dp[i]+=dp[t[i+N-1]+1]
  dp[i]%=mod
print(dp[0])
### BUGGY CODE ###

from collections import deque
def main():
    h, w = map(int, input().split())
    S = list(map(lambda x: int(x) + 1, input().split()))
    G = list(map(lambda x: int(x) + 1, input().split()))
    A = ['#' * (w + 4)] * 2 + ['##' + input() + '##' for _ in range(h)] + ['#' * (w + 4)] * 2
    INF = 1000000
    score = [[INF] * (w + 2) for _ in range(h + 2)]
    score[S[0]][S[1]] = 0
    stack = deque([S])
    walk = ((1, 0), (-1, 0), (0, 1), (0, -1))
    warp = tuple((i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in (walk + ((0, 0), )))
    visited = set()
    while stack:
        y, x = stack.popleft()
        if (y, x) in visited:
            continue
        else:
            visited.add((y, x))
        for dx, dy in walk:
            X = x + dx
            Y = y + dy
            if A[Y][X] == '#': continue
            if score[Y][X] > (s := score[y][x]):
                stack.appendleft([Y, X])
                score[Y][X] = s
        for i, j in warp:
            X = x + j
            Y = y + i
            if A[Y][X] == '#': continue
            if score[Y][X] > (s := score[y][x] + 1):
                stack.append([Y, X])
                score[Y][X] = s
    print(ans if (ans := score[G[0]][G[1]]) != INF else -1)

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque
def main():
    h, w = map(int, input().split())
    S = list(map(lambda x: int(x) - 1, input().split()))
    G = list(map(lambda x: int(x) - 1, input().split()))
    A = [list(input()) for _ in range(h)]
    INF = 100000000
    score = [[INF] * w for _ in range(h)]
    score[S[0]][S[1]] = 0
    visited = [[False] * w for _ in range(h)]
    stack = deque([S])
    dxy = [[1, 0], [-1, 0], [0, -1], [0, 1]]
    while stack:
        y, x = stack.popleft()
        if visited[y][x]:
            continue
        else:
            visited[y][x] = True
        count = 0
        for dx, dy in dxy:
            X = x + dx
            Y = y + dy
            if Y < 0 or Y >= h or X < 0 or X >= w:
                continue
            elif A[Y][X] == '.':
                stack.appendleft([Y, X])
                score[Y][X] = min(score[Y][X], score[y][x])
        if count == 0 and A[y][x] == '.':
            for i in range(-2, 3):
                for j in range(-2, 3):
                    X = x + j
                    Y = y + i
                    if Y < 0 or Y >= h or X < 0 or X >= w:
                        continue
                    if A[Y][X] == '.' and score[Y][X] > score[y][x] + 1:
                        stack.append([Y, X])
                        score[Y][X] = min(score[Y][X], score[y][x] + 1)
    print(score[G[0]][G[1]]) if score[G[0]][G[1]] != INF else print(-1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

k, s = map(int,input().split())
ans = 0

for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z == s:
        ans += 1

print(ans)

### FIXED CODE ###

k, s = map(int,input().split())
ans = 0

for x in range(k+1):
  for y in range(k+1):
    if 0 <= s-x-y <= k:
        ans += 1

print(ans)
### BUGGY CODE ###


def solve(S: str):
    if len(S) < 4:
        return 0
    answer = 0
    for l in range(0, len(S) - 3):
        for r in range(l + 4, len(S) + 1):
            answer += int(S[l:r]) % 2019 == 0
    return answer


def main():
    S = input().strip()
    answer = solve(S)
    print(answer)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

import numpy as np
from collections import Counter

YEAR = 2019


def solve(S: str):
    # S の各桁を modYear 計に修正する
    mod_year = np.arange(1, 10)
    mod_s = []
    for Si in map(int, reversed(S)):
        mod_s.append(mod_year[Si - 1])
        mod_year = (mod_year * 10) % YEAR
    #print(mod_s)
    # mod_s を累積和にする
    cum_sum = 0
    cum_sums = [cum_sum]
    for x in mod_s:
        cum_sum = (cum_sum+x) % YEAR
        cum_sums.append(cum_sum)

    answer = 0
    for _, num in Counter(cum_sums).items():
        answer += (num * (num-1)) // 2   # 1 の時0なので場合分けはいらない
    return answer


def main():
    S = input().strip()
    answer = solve(S)
    print(answer)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
X = input()
M = { X[0:3]:1 }
result = {}

for i in range(3, N) :
	i = X[i]
	keys = M.keys()
	for j in tuple(keys) :
		if (j, i) in result :
			continue
		M[j[0] + j[1] + i] = 1
		M[j[0] + j[2] + i] = 1
		M[j[1] + j[2] + i] = 1
		result[(j, i)] = True
	if len(M) == 1000:
		break

print(len(M))


### FIXED CODE ###

N = int(input())
X = input()
#X = "196341362415710923461093419237419237417234162348162390471092374190237410982374901"*300
#N = len(X)
M = { }
A = set()
A.add(X[0]+X[1])
for i in range(2, N) :
    i = X[i]
    for j in tuple(A):
        M[j + i] = 1
        A.add(j[0]+i)
        A.add(j[1]+i)

    if len(M) == 1000:
        break
print(len(M))
### BUGGY CODE ###

Q=int(input())

n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

from bisect import bisect_left,bisect_right
lr=[]
for i in range(Q):
    lr=list(map(int, input().split()))
    left=bisect_left(primes, lr[0])
    right=bisect_right(primes, lr[1])
    cnt=0
    for p in primes[left:right]:
        if p!=2:
            if primes[bisect_left(primes,(p+1)//2)]==(p+1)//2:
                cnt+=1
    print(cnt)

### FIXED CODE ###

Q=int(input())

n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

from bisect import bisect_left,bisect_right
import numpy as np

ls=[]
rs=[]
for i in range(Q):
    l,r=map(int, input().split())
    ls.append(l)
    rs.append(r)
lmin=min(ls)
rmax=max(rs)
bool_prime=np.zeros(rmax+1,dtype=np.int64)
bool_2007=np.zeros(rmax+1,dtype=np.int64)

for p in primes:
    if p>rmax:
        break
    bool_prime[p]=1
    if p!=2 and bool_prime[(p+1)//2]==1:
        bool_2007[p]=1

cum2007=np.cumsum(bool_2007)
for i in range(Q):
    print(cum2007[rs[i]]-cum2007[ls[i]-1])
### BUGGY CODE ###

import itertools,sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]

N, = I()
A = I()
d = dict()
def dd(n):
    if n in d:
        return d[n]
    else:
        if n < 2:
            return 0
        else:
            d[n] = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
            return d[n]
c = collections.Counter(A)
total = 0
for e in c.items():
    total += dd(e[1])
for e in A:
    print(total -  dd(c[e]) + dd(c[e]-1))


### FIXED CODE ###

import itertools,sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]

N, = I()
A = I()
d = dict()
def dd(n):
    if n in d:
        return d[n]
    else:
        if n < 2:
            return 0
        else:
            d[n] = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
            return d[n]
c = collections.Counter(A)
total = 0
for e in c.items():
    total += dd(e[1])
for e in A:
    print(total -  dd(c[e]) + dd(c[e]-1))
### BUGGY CODE ###

#初期入力
S = input()
Q = int(input())
FQ_dic ={i:tuple() for i in range(Q)}

for i in range(Q):
    FQ_dic[i] =tuple(input().split())
    
#
for fq in FQ_dic.values():
    if      fq[0] =="1":
                S=S[::-1]
    elif    fq[0] =="2":
        if      fq[1]=="1":
                    S = fq[2] + S
        elif    fq[1] =="2":
                    S = S + fq[2]
print(S)

### FIXED CODE ###

#前・左につける変数、後ろ・右につける変数を用意して最後に足す
#前・左は最後にひっくり返す（abc ⇒cba)

#初期入力
import sys
input = sys.stdin.readline
S = input()
S=S.strip("\n")
Q = int(input())
FQ_dic={}
for i in range(Q):
    FQ_dic[i] =input().split()

rev =0
front =""
back =""

for i in range(Q):
   # print(S) 

    if FQ_dic[i][0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし  
        if FQ_dic[i][1]=="1":     #前=左につける 
            if rev %2 ==0:
                front += FQ_dic[i][2]
            else:
                back  += FQ_dic[i][2]  
        else: #                      #後ろ=右につける
            if rev %2 ==0:
                back  += FQ_dic[i][2]  
            else:        
                front += FQ_dic[i][2]
front =front[::-1]
S =front + S + back

if rev %2 ==0:
    print(*S,sep="")
else:
    print(*S[::-1],sep="")
### BUGGY CODE ###

def main():
    """"ここに今までのコード"""

n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7

ans=0
for i in range(60):
    l=sum([a%2 for a in A])
    ans=(ans+l*(n-l)*(2**i))%mod
    A=[a//2 for a in A]
    

#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    """"ここに今までのコード"""
 
n = int(input())
A = [int(a) for a in input().split()]
mod=10**9+7
 
ans=0
for i in range(60):
    l=sum([a%2 for a in A])
    ans=(ans+l*(n-l)*(2**i))%mod
    A=[a//2 for a in A]
    
 
#ans=xor[0]
#for j in range(60-1):
#    ans=((2*ans)+xor[j+1])%mod
print(int(ans)) 
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = list(input())
q = int(input())

rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = ~rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            s.append(ci)
        else:
            s.insert(0, ci)

if rv:
    for i in range(1, len(s)+1):
        print(s[-i], end='')
    print('')
else:
    for si in s:
        print(si, end='')
    print('')

### FIXED CODE ###

import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

front = ''
back = ''
rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = not rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            back += ci
        else:
            front += ci

if rv:
    s = back[::-1] + s[::-1] + front
else:
    s = front[::-1] + s + back
print(s)
### BUGGY CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

S = input()


def solve(S,L):
    tmp = 0
    tmpS = ''
    for i,s in enumerate(S):
        if s == '1':
            tmpS = S[i+1:]
            tmp =  L - 1 - i
            break
    else:
        return 1

    return (2*solve(tmpS,tmp) + solve_bin(tmp))%mod

def solve_bin(b):
    return pow(3,b,mod)

print(solve(S,len(S))%mod)


### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7

def solve(l):
    tmp = 0
    tmpS = ''
    for i in range(l,L):
        if S[i] == '1':
            return (2*solve(i+1) + pow(3,L-1-i,mod))%mod
    else:
        return 1

S = input()
L = len(S)
print(solve(0)%mod)
### BUGGY CODE ###

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

for _ in range(m):
    a.sort()
    a[-1] = int(a[-1] / 2)

print(sum(a))

### FIXED CODE ###

import heapq
n,m = [int(x) for x in input().split()]
a = [int(x)*(-1) for x in input().split()]

heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)* (-tmp_min//2))

print(-sum(a))
### BUGGY CODE ###

job = list()
salary = list()
m_total = 0
count = 0
n,m = map(int,input().split())
for i in range(n):
    a,b = map(int,input().split())
    job.append((a,b))
job.sort()
job.reverse()
for i in range(n):
    a,b = job[i]
    salary.append(b)
    if a + i - count > m :
        count += 1
        salary.remove(min(salary))
k = n - count

print(sum(salary))


### FIXED CODE ###

import heapq
job = list()
salary = list()
n,m = map(int,input().split())

for i in range(n):
    a,b = map(int,input().split())
    job.append((a,b))

job.sort(reverse = True)

for x in job:
    s,t = x
    heapq.heappush(salary,t)
    if s - m > 0:
        heapq.heappop(salary)
    else:
        m -= 1

print(sum(salary))
### BUGGY CODE ###

import copy
n = int(input())
a = list(map(int, input().split()))
a_copy = copy.deepcopy(a)
sum = 0
ans = []
for i in range(n):
    sum = 0
    a = copy.deepcopy(a_copy)
    a.pop(i)
    sum += abs(a[0]) + abs(a[-1])
    for j in range(len(a) - 1):
        sum += abs(a[j] - a[j + 1])

    ans.append(sum)
for i in ans:
    print(i)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
Sum_b = sum(b)
for i in range(len(b) - 1):
    ans = Sum_b - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

x = 1
for i in range(K):
    x *= A[i]

hyo = [0]*N
hyo[K-1] = x

for i in range(K, N):
    hyo[i] = hyo[i-1]//A[i-K]*A[i]
    if hyo[i] > hyo[i-1]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K, N):
    if A[i] > A[i-K]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n=int(input())
num=1
while True:
    if (num*num)*6>n:
        break
    num=num+1
num=num*num
d={}
for i in range(1,n+1):
    d[i]=0
for i in range(1,num+1):
    for j in range(1,num+1):
        for k in range(1,num+1):
            val=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i)
            if val>n:
                continue
            # print(i,end=" ")
            # print(j,end=" ")
            # print(k)
            d[val]=d[val]+1
for i in range(1,n+1):
    print(d[i])

### FIXED CODE ###

n=int(input())
num=100
d={}
for i in range(1,n+1):
    d[i]=0
for i in range(1,num+1):
    for j in range(1,num+1):
        for k in range(1,num+1):
            val=(i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i)
            if val>n:
                continue
            # print(i,end=" ")
            # print(j,end=" ")
            # print(k)
            d[val]=d[val]+1
for i in range(1,n+1):
    print(d[i])
### BUGGY CODE ###

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

# 素因数分解
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      arr.append([i, cnt])
  if temp != 1:
    arr.append([temp, 1])
  if arr == []:
    arr.append([n, 1])
  return arr

counter = defaultdict(int)
p_list = []
for a in A:
  for p, r in factorization(a):
    if counter[p] == 0:
      p_list.append(p)
    counter[p] = max(counter[p], r)
lcm = 1
for p in p_list:
  lcm *= p ** counter[p]
  
answer = 0
for a in A:
  answer = (answer + lcm // a) % MOD

print(answer)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

def gcd(x, y):
  return x if y == 0 else gcd(y, x % y)

def lcm(x, y):
  return x * y // gcd(x, y)

tmp = A[0]
for i in range(1, N):
  tmp = lcm(A[i], tmp)
#print(tmp)

answer = 0
for a in A:
  answer += tmp // a
print(answer % MOD)
### BUGGY CODE ###

import sys

N = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())

mod = 10**9 + 7

cnt = [0] * 61
for a in A:
    for i in range(61):
        if a >> i & 1:
            cnt[i] += 1

ans = 0
p = 1
for i in cnt:
    ans = (ans + (p * i * (N - i)) % mod) % mod
    # ans %= mod
    p = p * 2 % mod
    # p %= mod

print(ans % mod)


### FIXED CODE ###

import sys

N = int(sys.stdin.readline())
A = map(int, sys.stdin.readline().split())

mod = 10**9 + 7

cnt = [0] * 61
for a in A:
    for i in range(61):
        if a >> i & 1:
            cnt[i] += 1

ans = 0
p = 1
for i in cnt:
    ans = (ans + (p * i * (N - i)) % mod) % mod
    # ans %= mod
    p = p * 2 % mod
    # p %= mod

print(ans % mod)
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, a, b = MAP()
h = [INT() for _ in range(n)]
ad = a - b
l = 1
r = 10 ** 9
while r - l > 10:
    c = (r + l) // 2
    hh = deepcopy(h)
    cnt = 0
    for i in range(n):
        hh[i] = max(hh[i] - b * c, 0)
        cnt += (hh[i] + ad - 1) // ad
    if c > cnt:
        r = c
    else:
        l = c
ans = inf
for i in range(max(0, l - 100), r + 100):
    hh = deepcopy(h)
    cnt = 0
    for j in range(n):
        hh[j] = max(hh[j] - b * i, 0)
        cnt += (hh[j] + ad - 1) // ad
    ans = min(ans, max(i, cnt))
print(ans)


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, a, b = MAP()
h = [INT() for _ in range(n)]
ad = a - b
l = 1
r = 10 ** 9
while r - l > 1:
    c = (r + l) // 2
    cnt = 0
    for i in range(n):
        cnt += (max(h[i] - b * c, 0) + ad - 1) // ad
    if c > cnt:
        r = c
    else:
        l = c
ans = inf
for i in range(l, r + 1):
    cnt = 0
    for j in range(n):
        cnt += (max(h[j] - b * i, 0) + ad - 1) // ad
    ans = min(ans, max(i, cnt))
print(ans)
### BUGGY CODE ###

n, a = map(int, input().split())
x = list(map(int, input().split()))

# dp[i][j][k]：　i枚目までのカードをj枚使用して合計kを作れる組み合わせ
dp = [[[0] * (3001) for j in range(n+1)] for i in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
    _x = x[i]
    for j in range(n):
        for k in range(2501):
            dp[i+1][j+1][k+_x] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]

ans = 0
for j in range(1, n+1):
    ans += dp[n][j][j*a]
print(ans)

### FIXED CODE ###

import numpy as np
n, a = map(int, input().split())
x = list(map(int, input().split()))

# dp[i][j][k]：　i枚目までのカードをj枚使用して合計kを作れる組み合わせ
dp = np.zeros((n+1, n+1, 3001)).astype(np.int64)
dp[0][0][0] = 1

for i in range(n):
    _x = x[i]
    for j in range(n):
        dp[i+1, j+1, _x:] += dp[i, j, :-_x]
        dp[i+1, j, :] += dp[i, j, :]

ans = 0
for j in range(1, n+1):
    ans += dp[n, j, j*a]
print(ans)
### BUGGY CODE ###

[n,k]=list(map(int,input().split()))
ablist=[]
suretu=[]
for i in range(n):
    ab=list(map(int,input().split()))
    suretu+=[ab[0]]*ab[1]
suretu=sorted(suretu)
print(suretu[k-1])

### FIXED CODE ###

[n,k]=list(map(int,input().split()))
ablist=[]
for i in range(n):
    ablist.append(list(map(int,input().split())))
ablist=sorted(ablist,key=lambda x:x[0])
bwa=[0]
for i in range(n):
    bwa.append(bwa[-1]+ablist[i][1])
ind=1
while True:
    if bwa[ind-1]<k<=bwa[ind]:
        break
    ind+=1
print(ablist[ind-1][0])