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

from operator import itemgetter
import bisect
import heapq
N,M = [int(x) for x in input().split()]
work = {}
for _ in range(N):
    a,b = [int(x) for x in input().split()]
    if(a in work):
        work[a].append(-b)
    else:
        work[a] = [-b]

#%%
cand = []
cnt = 0
for i in range(1,M+1):
    if(i in work):
        cand += work[i]
    heapq.heapify(cand)
    if(len(cand)==0):
        continue
    x = heapq.heappop(cand)
    cnt += -x

print(cnt)


### FIXED CODE ###

from operator import itemgetter
import bisect
import heapq
import sys
input = sys.stdin.readline

def main():
    N,M = [int(x) for x in input().split()]
    work = {}
    for _ in range(N):
        a,b = [int(x) for x in input().split()]
        if(a in work):
            work[a].append(-b)
        else:
            work[a] = [-b]

    cand = []
    heapq.heapify(cand)
    cnt = 0
    for i in range(1,M+1):
        if(i in work):
            for x in work[i]:
                heapq.heappush(cand,x)
        if(len(cand)==0):
            continue
        x = -heapq.heappop(cand)
        cnt += x

    print(cnt)

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

import copy

n = int(input())

columns = [int(input()) for i in range(n)]

i = 0

while i < n:
    max_value = sorted(set(columns))[-1]
    if max_value == columns[i]:
        tmp = copy.copy(columns)
        del tmp[i]
        print(sorted(set(tmp))[-1])
    else:
        print(max_value)
    i += 1

### FIXED CODE ###

import copy
n = int(input())
 
columns = [int(input()) for i in range(n)]

sorted_columns = sorted(columns, reverse = True)

for i in range(n):
    if sorted_columns[0] == columns[i]:
        print(sorted_columns[1])
    else:
        print(sorted_columns[0])
### BUGGY CODE ###

N = int(input())
S = input()

ans = N
for n in range(0, N):
  west_side = S[:n].count('W')
  east_side = S[n+1:].count('E')
  
  ans = min(ans, west_side+east_side)
  
print(ans)

### FIXED CODE ###

N=int(input())
S=input()

w_cusum_list = []
w = 0
for i in range(N):
  if S[i] == 'W':
    w += 1
  w_cusum_list.append(w)
    
e_cusum_list = []
e = 0
for i in range(1, N):
  if S[-i] == 'E':
    e += 1
  e_cusum_list.append(e)

minn = min(w_cusum_list[-1], e_cusum_list[-1])
for i in range(1, N):
  sumn = w_cusum_list[i-1] + e_cusum_list[N-i-1]
  if minn > sumn:
    minn = sumn

print(minn)
### BUGGY CODE ###

N = int(input())
S = input()

ans = 0
for i in range(N):
    i = i + 1
    for j in range(N-i):
        j = i + j + 1
        for k in range(N-j):
            k = k + j + 1
            if S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[i-1] != S[k-1]:
                if j-i != k-j:
                    ans += 1


print(ans)

### FIXED CODE ###

N = int(input())
S = input()
T = [0]*3

for i in range(N):
    if S[i] == "R":
        T[0] += 1
    elif S[i] == "G":
        T[1] += 1
    else:
        T[2] += 1
ans = T[0]*T[1]*T[2]
t = N // 2

for i in range(t):
    i = i+1
    j = 0
    while j + 2*i < N:
        if S[j] != S[j + i] and S[j] != S[j + 2*i] and S[j+i] != S[j + 2*i]:
            ans -= 1
        j += 1

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

n = int(input())
a = list(map(int, input().split()))
b = [ x for x in set(a) if a.count(x)>1]
c = [ x for x in set(a) if a.count(x)>3]
b.sort(reverse=True)
c.sort(reverse=True)
m = len(b)
if m<2:
    if len(c)<1:
        print(0)
    else:
        print(c[0]*c[0])
else:
    if len(c)<1:
        print(b[0]*b[1])
    else:
        ans = max(b[0]*b[1],c[0]*c[0])
        print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 1
j = 1
l = []
while i<n:
    if a[i]==a[i-1]:
        l.append(a[i])
        i+=2
    else:
        i+=1
l.append(0)
l.append(0)
print(l[0]*l[1])
### BUGGY CODE ###

#print("UNKO"[2:3])

N,Q=map(int,input().split())
S=input()
LR=[[list(map(int,input().split())),i,0] for i in range(Q)]
LR=sorted(LR,key=lambda x: x[0][0])
minl=min([i[0][0] for i in LR])
maxr=max([i[0][1] for i in LR])
Qidx=0
for i in range(minl-1,maxr-1):
    if S[i]+S[i+1]=="AC":
        for q in range(Qidx,Q):
            if i<LR[q][0][0]-1:
                break
            if i+1>LR[q][0][1]-1:
                continue
            LR[q][2]+=1

LR=sorted(LR,key=lambda x: x[1])
for i in LR:
    print(i[2])


### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
LR=[map(int,input().split()) for i in range(Q)]

data=[0 for i in range(N)]
for i in range(N-1):
    data[i+1]=data[i]
    if S[i]+S[i+1]=="AC":
        data[i+1]+=1
for l,r in LR:
    print(data[r-1]-data[l-1])
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    for i in range(2, N):
        for k in range(1, K + 1):
            dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k]))

    print(dp[-1])


main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [float('inf') for _ in range(N)]
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    for i in range(2, N):
        k = 1
        for k in range(1, K + 1):
            dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k]))
    print(dp[-1])


main()
### BUGGY CODE ###

n,k,q,*a=map(int,open(0).read().split())
s=sorted
m=1e18
for b in a:
    i=[i for i,t in enumerate(a)if t<b]
    l=s(sum([s(a[i+1:j])[::-1][k-1:]for i,j in zip([-1]+i,i+[n])],[]))
    if len(l)>=q:m=min(m,l[q-1]-b)
print(m)

### FIXED CODE ###

n,k,q,*a=map(int,open(0).read().split())
s=sorted
m=1e18
for b in a:
    i=[i for i,t in enumerate(a)if t<b]
    l=s(u for t in[s(a[i+1:j])[::-1][k-1:]for i,j in zip([-1]+i,i+[n])]for u in t)
    if len(l)>=q:m=min(m,l[q-1]-b)
print(m)
### BUGGY CODE ###

# sys.stdin.readline()
import sys
input = sys.stdin.readline
import math

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
# A.sort(reverse=True)

for i in range(M):
    a = max(A) // 2
    j = A.index(max(A))
    A[j] = a


print(sum(A))

### FIXED CODE ###

# sys.stdin.readline()
import sys
import time
input = sys.stdin.readline
import math
import heapq

N,M = (int(x) for x in input().split())
A = list(map(int, input().split()))
A = [-i for i in A]
# print(A)
heapq.heapify(A)
# print(heapq.heappop(A))

# t1 = time.time()
for i in range(M):
    a = -heapq.heappop(A) // 2
    heapq.heappush(A, -a)
    # j = A.index(max(A))
    # A[j] = a
    # A[0] = A[0]//2
    # A.sort(reverse=True)
    # if sum(A) <1:
    #     break

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

A, B, K = map(int,input().split())
for i in range(A, B + 1):
  if i < A + K or i > B - K: print(i) 

### FIXED CODE ###

A, B, K = map(int,input().split())
for i in range(A, min(A + K, B + 1)):
  print(i) 
for i in range(max(B - K, A) , B):
  if i + 1 >= A + K: print(i + 1)
### BUGGY CODE ###

N = int(input())

count = 0
ABC = [0]*3

for a in range(1,N+1):
  for b in range(1,N+1):
    D = b*a
    if D >= N:
      break
    else:
#      print(a, b, N-D)
      count = count + 1
print(count)

### FIXED CODE ###

N = int(input())

count = 0
count2 = 0
ABC = [0]*3

for a in range(1,N):
  if N % a == 0:
    x = int(N/a)-1
  else:
    x = int(N/a)
  count = count + x
#  print(x)

print(count)
### BUGGY CODE ###

H,W = map(int,input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
 
#差分だけで良い，これを*1 or -1していく
diff = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        diff[i][j] = abs(A[i][j] - B[i][j])
        
 # i,jマスにおいて，偏りがkになれるかどうかでDP
K = 6401 #適当
kk = int((K-1)/2)
dp = [[[False]*K for _ in range(W)] for _ in range(H)]
 
dp[0][0][kk+diff[0][0]] = True
dp[0][0][kk-diff[0][0]] = True
 

for i in range(H):
    for j in range(W):
        a= min((i+j)*80,kk)
        for k in range(kk-a,kk+a+1):
            if i-1>=0:
                if k+diff[i][j]<K:
                    if dp[i-1][j][k+diff[i][j]]:
                        dp[i][j][k] =True
                if k-diff[i][j]>=0:
                    if dp[i-1][j][k-diff[i][j]]:
                        dp[i][j][k] =True
            if j-1>=0:
                if k+diff[i][j]<K:
                    if dp[i][j-1][k+diff[i][j]]:
                        dp[i][j][k] =True
                if k-diff[i][j]>=0:
                    if dp[i][j-1][k-diff[i][j]]:
                        dp[i][j][k] =True
ans = K


for k in range(K):
    if dp[H-1][W-1][k]:
        ans = min(ans,abs(k-kk))
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W = map(int,input().split())
#差分だけで良い，これを*1 or -1していく
diff = [list(map(int, input().split())) for _ in range(H)]

for i in range(H):
    B = list(map(int,input().split()))
    for j in range(W):
        diff[i][j] = abs(diff[i][j] - B[j])
        
 # i,jマスにおいて，偏りがkになれるかどうかでDP
#dp[i][j]にはkという数字にたどり着けるかどうかを示す2進数を入れる

dp = [[False]*W for _ in range(H)]
ofs = 80*(H+W)


dp[0][0]=(1<<(ofs+diff[0][0]) | 1>>(ofs-diff[0][0]))
 
for i in range(H):
    for j in range(W):
        if i>0:
            dp[i][j]|=(dp[i-1][j]<<diff[i][j] | dp[i-1][j]>>diff[i][j])
        if j>0:
            dp[i][j]|=(dp[i][j-1]<<diff[i][j] | dp[i][j-1]>>diff[i][j])


#0のところから見て，最初に1が出てきたところが答え
for k in range(ofs):
    if (dp[-1][-1]>>(k+ofs)&1):
        print(k)
        break
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import itertools


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    com = list( itertools.product(A,B,C) )

    S = list(map(lambda c: sum(c), com))
    S.sort(reverse=True)

    for k in range(K):
        print(S[k])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import itertools


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    ABC = []
    for x in range(X):
        for y in range(Y):
            if ((x+1)*(y+1)) > K:
                break
            for z in range(Z):
                if ((x+1)*(y+1)*(z+1)) > K:
                    break
                ABC.append(A[x]+B[y]+C[z])

    ABC.sort(reverse=True)

    for k in range(K):
        print(ABC[k])



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

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

n = int(input())
str_list = []
for i in range(n):
    str_list.append(input())

ans = 0
for i in range(n):
    for j in range(1, len(str_list)):
        if sorted(str_list[0]) == sorted((str_list[j])):
            ans += 1
    str_list.pop(0)
print(ans)

### FIXED CODE ###

n = int(input())
str_list = ["".join(sorted(input())) for i in range(n)]
ans = 0
str_dic = {}

for i in range(n):
    if str_list[i] in str_dic:
        str_dic[str_list[i]] += 1
    else:
        str_dic[str_list[i]] = 0

for v in str_dic.values():
    ans += v*(v+1)/2

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

def main():
    n, m = map(int, input().split())
    arr = list(map(int, input().split()))

    for i in range(m):
        b, c = map(int, input().split())
        arr += [c] * b

    arr.sort(reverse=True)
    print(sum(arr[:n]))


main()

### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    s = 0

    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x: x[1], reverse=True)

    arr = []
    sum_b = 0
    for b, c in bc:
        arr += [c] * b
        sum_b += b
        if sum_b >= n:
            break

    arr += a
    arr.sort(reverse=True)
    print(sum(arr[:n]))


main()
### BUGGY CODE ###

H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

### FIXED CODE ###

H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)
### BUGGY CODE ###

import sys, heapq
from collections import defaultdict
def input():
	return sys.stdin.readline()[:-1]

class DijkstraList():
	#隣接リスト版
	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
	def __init__(self, adj, start):
		self.list = adj
		self.start = start
		self.size = len(adj)

	def solve(self):
		#self.dist = [float("inf") for _ in range(self.size)]
		self.dist = defaultdict(lambda :10**30)
		self.dist[self.start] = 0
		#self.prev = [-1 for _ in range(self.size)]
		self.q = []
		self.cnt = 0

		heapq.heappush(self.q, (0, self.start))

		while self.q and self.cnt < self.size:
			u_dist, u = heapq.heappop(self.q)
			if self.dist[u] < u_dist:
				continue
			for v, w in self.list[u]:
				if self.dist[v] > u_dist + w:
					self.dist[v] = u_dist + w
					#self.prev[v] = u
					heapq.heappush(self.q, (self.dist[v], v))
			self.cnt += 1
		return

	def distance(self, goal):
		return self.dist[goal]

n, m = map(int, input().split())
cost = [10**30 for _ in range(n)]
used = defaultdict(lambda: False)
edges = defaultdict(list)
for _ in range(m):
	p, q, t = map(int, input().split())
	edges[p-1 + t * n].append([q-1 + t * n, 0])
	edges[q-1 + t * n].append([p-1 + t * n, 0])
	if used[p-1 + t * n] == False:
		edges[p-1 + t * n].append([p-1 + 0 * n, 0])
		edges[p-1 + 0 * n].append([p-1 + t * n, 1])
	if used[q-1 + t * n] == False:
		edges[q-1 + t * n].append([q-1 + 0 * n, 0])
		edges[q-1 + 0 * n].append([q-1 + t * n, 1])
	used[p-1 + t * n] = True
	used[q-1 + t * n] = True

#print(edges.items())
d = DijkstraList(edges, 0)
d.solve()
res = d.distance(n-1)
if res > 10**20:
	print(-1)
else:
	print(res)

### FIXED CODE ###

import sys, heapq
from collections import defaultdict
def input():
	return sys.stdin.readline()[:-1]

class DijkstraList():
	#隣接リスト版
	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
	def __init__(self, adj, start):
		self.list = adj
		self.start = start
		self.size = len(adj)

	def solve(self):
		#self.dist = [float("inf") for _ in range(self.size)]
		self.dist = defaultdict(lambda :10**30)
		self.dist[self.start] = 0
		#self.prev = [-1 for _ in range(self.size)]
		self.q = []
		self.cnt = 0

		heapq.heappush(self.q, (0, self.start))

		while self.q and self.cnt < self.size:
			u_dist, u = heapq.heappop(self.q)
			if self.dist[u] < u_dist:
				continue
			for v, w in self.list[u]:
				if self.dist[v] > u_dist + w:
					self.dist[v] = u_dist + w
					#self.prev[v] = u
					heapq.heappush(self.q, (self.dist[v], v))
			self.cnt += 1
		return

	def distance(self, goal):
		return self.dist[goal]

n, m = map(int, input().split())
cost = [10**30 for _ in range(n)]
edges = defaultdict(list)
for _ in range(m):
	p, q, t = map(int, input().split())
	edges[p-1 + t * n].append((q-1 + t * n, 0))
	edges[q-1 + t * n].append((p-1 + t * n, 0))
	if len(edges[p-1 + t * n]) == 1:
		edges[p-1 + t * n].append((p-1 + 0 * n, 0))
		edges[p-1 + 0 * n].append((p-1 + t * n, 1))
	if len(edges[q-1 + t * n]) == 1:
		edges[q-1 + t * n].append((q-1 + 0 * n, 0))
		edges[q-1 + 0 * n].append((q-1 + t * n, 1))

d = DijkstraList(edges, 0)
d.solve()
res = d.distance(n-1)
if res > 10**20:
	print(-1)
else:
	print(res)
### BUGGY CODE ###

def limit_b_arr_idx(B,K):
    j=0
    for j in range(0,len(B)):
            if K < B[j]:
                j -= 1
                break
            else:
                K -= B[j]
    return j
    
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    count,i_a,i_b = 0,0,0
    # ADD A item
    for i_a in range(len(A)):
        if K < A[i_a]:
            i_a -= 1
            break
        else:
            K -= A[i_a]
    # ADD B item
    
    i_b = limit_b_arr_idx(B,K)
    count = (i_a+1) + (i_b+1) # 読んだ本のindexの次のindexが格納されている。
    # 1冊も読めない⇒0
    # idx = i_a,i_bまで読んだ。
    # forの繰り返しをすべて終えた時 +1されるのか?
    for i in range(i_a,-1,-1): # A のアイテムを1つずつ減らしていく。
        K += A[i] # i番目の本を読まなかったとする。
        i_b = limit_b_arr_idx(B,K)
        count = max(count,(i+i_b+1))
    print(count)

### FIXED CODE ###

def get_sum_arr(arr):
    sum_arr = [0]
    N = len(arr)
    for i in range(1,N+1):
        sum_arr.append(sum_arr[i-1] + arr[i-1])
    return sum_arr

def get_max_b(left_time,j,B_sum_arr):
    # [0,1,2,3,4,5]
    while B_sum_arr[j] > left_time and j > 0:
        j -= 1
    return j
def get_max_book_num(A,B,K):
    A_sum_arr,B_sum_arr = get_sum_arr(A),get_sum_arr(B)
    count,i,j = 0,0,len(B_sum_arr)-1
    for i in range(0,len(A_sum_arr)):
        if K < A_sum_arr[i]:
            break
        else:
            left_time = K - A_sum_arr[i]
            j = get_max_b(left_time,j,B_sum_arr)
        count = max(count,(i+j))
    return count
if __name__ == "__main__":
    N,M,K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    print(get_max_book_num(A,B,K))
### BUGGY CODE ###

import operator
from functools import reduce

A, B = map(int, input().split())

result = reduce(operator.xor, range(A, B+1), 0)

print(result)

### FIXED CODE ###

A, B = map(int, input().split())

sum_A = 0
for i in range((A-1) % 4 + 1):
    sum_A = sum_A ^ ((A-1) - i)

sum_B = 0
for i in range(B % 4 + 1):
    sum_B = sum_B ^ (B - i)

result = sum_A ^ sum_B

print(result)
### BUGGY CODE ###

import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b)-10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)


### FIXED CODE ###

import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b) - 10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)
### BUGGY CODE ###

# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

nearest_city = getNearestValue(city_list, x)

max_D = abs(nearest_city-x)
for xx in reversed(range(1, max_D+1)):
    flag = True
    for city in city_list:
        if (abs(city - x) % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

### FIXED CODE ###

import fractions

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

city_list = list(map(int, input().split()))

dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

max_common_value = dist_list.pop(0)

for dist in dist_list:
    # 今までのDと次の都市の距離との最大公約数を見つける
    max_common_value = fractions.gcd(max_common_value, dist)

print(max_common_value)
### BUGGY CODE ###

a,b,k=input().split()
a=int(a)
b=int(b)
k=int(k)
f=True
if a<0 or 10**12<a:
  f=False
if b<0 or 10**12<b:
  f=False
if k<0 or 10**12<k:
  f=False
if not f:
  a=0
  b=0
  print(a,b)
  exit(0)

for i in range(k):
  if a>=1:
    a-=1
  elif b >=1:
    b-=1
print(a,b)

### FIXED CODE ###

a,b,k=map(int,input().split())
if k>=a:
  k-=a
  a=0
else:
  a-=k
  k=0
if k>0:
  b-=k
if b<0:
  b=0
print(a,b)
### BUGGY CODE ###

from collections import Counter
N = int(input())
Si = [input() for _ in range(N)]

count = 0
for i in range(0, N):
    for j in range(i+1, N):
        if Counter(Si[i]) == Counter(Si[j]):
            count += 1
        else:
            pass
print(int(count))   

### FIXED CODE ###

from collections import Counter
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
ans = 0
for i in Counter(S).values():
    ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

from sys import stdin

N, S = map(int, stdin.readline().split())
A = list(map(int, stdin.readline().split()))
M = 998244353
V = max(max(A), S)

ans = 0
cs = [0 for _ in range(V + 1)]
for i, a in enumerate(A):
    dp = [0 for _ in range(V + 1)]
    dp[a] = i + 1
    for s in range(a + 1, S + 1):
        dp[s] = cs[s - a]
    cs = [(a + b) % M for a, b in zip(cs, dp)]
    ans = (ans + (N - i) * dp[S]) % M
print(ans)

### FIXED CODE ###

from sys import stdin

N, S = map(int, stdin.readline().split())
A = list(map(int,stdin.readline().split()))
M = 998244353
V = max(max(A), S)

ans = 0
cs = [0 for _ in range(V + 1)]
for i, a in enumerate(A):
    dp = [0 for _ in range(V + 1)]
    dp[a] = i + 1
    for s in range(a + 1, S + 1):
        dp[s] = cs[s - a]
    cs = [(a + b) % M for a, b in zip(cs, dp)]
    ans = (ans + (N - i) * dp[S]) % M
print(ans)