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

n, d, a  = map(int,input().split())
x_b = []
x_b2 = []
x = [0]*n
h_b = []
h = [0]*n
for i in range(n):
    x_temp,h_temp = map(int,input().split())
    x_b.append({'key':i, 'val':x_temp})
    x_b2.append(x_temp)
    h_b.append(h_temp)

x_b.sort(key = lambda x_b : x_b['val'])

for i in range(n):
    ind = x_b[i]['key']
    x[i] = x_b2[ind]
    h[i] = h_b[ind]

ans = 0
for i in range(n):
    if (h[i] <= 0):
        continue
    at_num = ((h[i] -1 )// a) + 1
    ans += at_num
    h[i] -= at_num * a
    x_origin = x[i]
    while(True):
        i += 1
        if(i >= n):
            break
        if(x_origin + 2*d >= x[i]):
            h[i] -= at_num * a
        else:
            break

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
# 二分木
import bisect


n,d,a = map(int,input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()
x = [ tmp[0] for tmp in xh]
damage = [0] * (n+1)

ans = 0
for i in range(n):
    damage[i+1] += damage[i]
    if( damage[i+1] >= xh[i][1] ):
        continue
    atk_num = (xh[i][1] - damage[i+1] - 1)//a +1
    ans += atk_num
    damage[i+1] += atk_num * a
    right = bisect.bisect_right(x, xh[i][0] + 2*d)
    if( right < n):
        damage[right+1] -= atk_num * a

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

n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
for r in range(1,n+1):
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
  tmp.append(cnt)

for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

### FIXED CODE ###

n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])
### BUGGY CODE ###

n,x,y = map(int,input().split())
dists = [0]*(n)
for i in range(n):
    for j in range(i):
        dist = min(abs(i-j),abs(i+1-x)+1+abs(j+1-y),abs(j+1-x)+1+abs(i+1-y))
        dists[dist] = dists[dist]+1
    
for i in range(len(dists) - 1):
    print(dists[i+1])

### FIXED CODE ###

n,x,y = map(int,input().split())
dists = [0]*(n)
for i in range(1,n+1):
    for j in range(1,i):
        dist = min(abs(i-j),abs(i-x)+1+abs(j-y),abs(j-x)+1+abs(i-y))
        dists[dist] = dists[dist]+1
    
for i in range(len(dists) - 1):
    print(dists[i+1])
### BUGGY CODE ###

import sys
N, M, K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

Asum=[0]
Bsum=[0]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
for i in range(len(Asum)):
    for j in range(len(Bsum)):
        if Asum[i]>K:
            print(m)
            sys.exit()
        elif Asum[i]+Bsum[j]<=K and m<i+j:
            m=i+j
print(m)
        

### FIXED CODE ###

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

Asum=[0]
Bsum=[0]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
j=M

for i in range(len(Asum)):
    if Asum[i]>K:
        break
    while Asum[i]+Bsum[j]>K:
        j-=1
    if m<i+j:
        m=i+j
        
print(m)
### BUGGY CODE ###

n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]
cnt = 0
# O(3*N) でギリギリ？pythonだと微妙かも
for a in A:
    for b in B:
        for c in C:
            if a<b<c and len(set([a, b, c]))>1:
                cnt+=1
print(cnt)

### FIXED CODE ###

# バイナリサーチで解く。
# Bの要素を基準にしてa<b<cとなるものを選ぶ。すべての配列はソート済みとして、
# a<bとなる最大のa, b<cとなる最小のcを選び、それら独立する事象の数の積を足していく

n = int(input())
A, B, C = [list(sorted(map(int, input().split())))  for _ in range(3)]

cnt = 0

def bs_left(lis, target):
    # ソート済みのlisのうちtargetがどこに入るか（index）
    # 要素がtargetと重複する場合はより小さいインデックスを返す。すなわち「lisのうちtarget未満となる最大の要素のインデックス」
    # ex) min(lis)=mとするとtarget<=mのとき0
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if lis[mid]<target:
            low = mid+1
        else:
            high = mid
    return low

def bs_right(lis, target):
    low, high = 0, len(lis)
    while low<high:
        mid = (low+high)//2
        if target<lis[mid]:
            high = mid
        else:
            low = mid+1
    return low

for b in B:
    # 探索のときにちゃんとみているので a!=b and b!=cみたいな条件は必要ない
    cnt += (bs_left(A, b) * (n-bs_right(C, b)))
print(cnt)
### BUGGY CODE ###

def sol():
    s=input()
    q=int(input())
    x=0
    for i in range(q):
        l=[i for i in input().split()]
        if l[0]=="1":
            x=(x+1)%2
        elif l[1]=="1":
            if x==0: s=l[2]+s
            else: s=s+l[2]
        elif l[1]=="2":
            if x==0: s=s+l[2]
            else: s=l[2]+s
    print(s if x==0 else s[::-1])

if __name__=="__main__":
    sol()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def sol():
    s=input().rstrip()
    q=int(input())
    x=0
    a,b="",""
    for i in range(q):
        l=tuple([i for i in input().split()])
        if l[0]=="1":
            x=(x+1)%2
        elif l[1]=="1":
            if x==0: a=l[2]+a
            else: b=b+l[2]
        elif l[1]=="2":
            if x==0: b=b+l[2]
            else: a=l[2]+a
    s=a+s+b
    print(s if x==0 else s[::-1])

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

import itertools
from scipy.misc import comb

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

ans = [0, 0]
max_comb = 0
combs = {}
for a_i, a_j in itertools.combinations(a, 2):
    if a_j > a_i:
        tmp = a_j
        a_j = a_i
        a_i = tmp

    if (a_i, a_i - a_j) in combs:
        continue

    c = comb(a_i, a_j, exact=True)
    combs[(a_i, a_j)] = c
    if c > max_comb:
        max_comb = c
        ans[0], ans[1] = a_i, a_j

print(ans[0], ans[1])

### FIXED CODE ###

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

a_i = max(a)
a_j = 0
min_d = float('inf')
for a_k in a:
    if a_k == a_i:
        continue
    d = abs(a_i / 2 - a_k)
    if d < min_d:
        min_d = d
        a_j = a_k
print(a_i, a_j)
### BUGGY CODE ###

from math import gcd
K = int(input())
gcd_list = []
for k in range(1,K+1):
    a = k
    for l in range(1,K+1):
        b = l
        for m in range(1,K+1):
            c = m
            d = gcd(a,b)
            e = gcd(c,d)
            gcd_list.append(e)
print(sum(gcd_list))

### FIXED CODE ###

from math import gcd
K = (int(input())+1)
gcd_list = [gcd(m,gcd(k,l)) for k in range(1,K) for l in range(1,K) for m in range(1,K)]
print(sum(gcd_list))
### BUGGY CODE ###

N, K = map(int, input().split())
count = 1
while True:
    N = N // K
    count += 1
    if N == 1:
        break
print(count)

### FIXED CODE ###

N, K = map(int, input().split())
q = ''
while True:
    q += str(N % K)
    N = N // K
    if N == 0:
        break
print(len(q))
### BUGGY CODE ###

n = int(input())
lis = list(map(int,input().split()))
prod = 1
for i in lis:
        prod=prod*i
print(prod) if(prod<=1000000000000000000) else print(-1)

### FIXED CODE ###

n = int(input())
lis = list(map(int,input().split()))
prod = 1
if 0 in lis:
    print(0)
    exit(0)
for i in lis:
    if(prod>1000000000000000000):
        print(-1)
        exit(0)
    prod=prod*i
print(prod) if(prod<=1000000000000000000) else print(-1)
### BUGGY CODE ###

N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[-1]) % 10
a, b = a + t, a + (10 - t)
N = N[:-1]
while len(N) != 0:
    t = int(N[-1]) % 10
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
    N = N[:-1]
print(min(a, b + 1))


### FIXED CODE ###

N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)
### BUGGY CODE ###

#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

# 円周率 pi
"""import math
pi_ = math.pi"""

# エラトステネスの篩
"""def Erato(n):
    prime = []
    is_prime = [True] * (n+1)
    p = 0
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,n+1):
      if is_prime[i] == True:
        prime.append(i)
        p += 1
        for j in range(2 * i,n+1,i):
          is_prime[j] = False
    return p"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  import fractions
  k = int(input())
  L = []
  ans = 0
  for a in range(1,k+1):
    for b in range(1,k+1):
      L.append(fractions.gcd(a,b))
  Llen = len(L)
  for c in range(1,k+1):
    for i in range(0,Llen):
      ans += fractions.gcd(c,L[i])
  print(ans)
if __name__ == '__main__':
  main()

### FIXED CODE ###

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def main():
  k = int(input())
  ans = 0
  for a in range(1,k+1):
    for b in range(1,k+1):
      for c in range(1,k+1):
        ans += gcd(a,gcd(b,c))
  print(ans)
if __name__ == '__main__':
  main()
### BUGGY CODE ###

#DAGの最長有向パスをトポロジカルソートで解く
N,M=map(int,input().split(' '))
x=[0]*M
y=[0]*M
z=[0]*(N+1)
key=[0]*(N+1)
for i in range(M):
    x[i],y[i]=map(int,input().split(' '))
n=set(i for i in range(1,N+1))
while len(n)>0:
    for i in n:
        if i not in y:
            n.remove(i)
            for j in range(M):
                if i==x[j]:
                    if z[y[j]]<=z[x[j]]:
                        z[y[j]]=z[x[j]]+1
                    x[j],y[j]=0,0
            break
print(max(z))

### FIXED CODE ###

from collections import defaultdict, deque

N, M = map(int, input().split())
es = [[int(x) for x in input().split()] for _ in range(M)]

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1
length=defaultdict(int)

q = deque(set(i for i in range(1,N+1))-set(ins.keys()))
length=defaultdict(int)
while q:
    v1 = q.popleft()
    for v2 in outs[v1]:
        ins[v2] -= 1
        if length[v2]<=length[v1]:
            length[v2]=length[v1]+1
        if ins[v2] == 0:
            q.append(v2)

print(max(length.values()))
### BUGGY CODE ###

n, k = map(int,input().split())
array = list(map(int,input().split()))

s = set(array)
s = sorted(s)
num = len(s)
cnt = 0

ary = []

for item in s:
  ary.append(array.count(item))

ary.sort() 

for i in range(num-k):
  cnt+=ary[i]
  
print(cnt)


### FIXED CODE ###

n, k = map(int,input().split())
array = list(map(int,input().split()))

box = [0]*200000

for item in array:
  box[item-1] += 1
  
box.sort(reverse=True)

cnt = 0
for i in range(k):
  cnt += box[i]
  
print(n-cnt)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())

for i in range(1,n+1):
    cnt=0
    for j in range(1,42):
        for k in range(1,42):
            for l in range(1,42):
                if j**2+k**2+l**2+j*k+k*l+l*j==i:
                    cnt+=1
                    break
                elif j**2+k**2+l**2+j*k+k*l+l*j>i:
                    break
    print(cnt)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n=int(input())

a=[0]*(n)
for j in range(1,n+1):
    for k in range(1,n+1):
        for l in range(1,n+1):
            if j**2+k**2+l**2+j*k+k*l+l*j>n:
                break
            else:
                a[j**2+k**2+l**2+j*k+k*l+l*j-1]+=1

for i in a:
    print(i)
### BUGGY CODE ###

import copy
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def D159():
    N = int(input())
    A = input().split()
    #sum = 0
    for i in range(0, N):
        sum = 0
        A_ = copy.deepcopy(A)
        del A_[i]
        num = list(set(A_))
        for j in num:
            if A_.count(j) > 1:
                sum += combinations_count(A_.count(j), 2)
        print(sum)

if __name__ == "__main__":
    D159()

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)
### BUGGY CODE ###

n,*a=map(int,open(0).read().split())
t,v=sum(a),[1]
for q in a:
  if(v:=v+[min(2*(v[-1]-q),t:=t-q)])[-1]<0:print(-1);exit()
print(sum(v))

### FIXED CODE ###

from itertools import accumulate
n=int(input())
a=list(map(int,input().split()))
c=list(accumulate(a))
b=[0]*(n+1)
#大きくしすぎてしまう場合がある
#いや上限を考えろや
def f():
    global n,a,b
    for i in range(n+1):
        if i==0:
            b[0]=min(c[n]-c[0],1)
        else:
            b[i]=min(2*(b[i-1]-a[i-1]),c[n]-c[i-1])

    if n==0:
        if a[0]!=1:
            print(-1)
        else:
            print(1)
    elif b[n]!=a[n]:
        print(-1)
    else:
        print(sum(b))
        #print(b)
f()
### BUGGY CODE ###

S = str(input())
Q = int(input())

ans = S

for i in range(Q) :
  Qn = list(map(str, input().split()))
  
  if Qn == ["1"] :
    ans = ans[::-1]
  else :
    if Qn[1] == "1" :
      ans = Qn[2] + ans
    if Qn[1] == "2" :
      ans = ans + Qn[2]

print(ans)

### FIXED CODE ###

S = str(input())
Q = int(input())

fwd = ""
rev = ""
now = 1

for i in range(Q) :
  Qn = list(map(str, input().split()))
  
  if Qn == ["1"] :
    now *=-1
  else :
    if now == 1 :
      if Qn[1] == "1" :
        fwd = Qn[2] + fwd
      if Qn[1] == "2" :
        rev = rev + Qn[2]
    else : 
      if Qn[1] == "1" :
        rev = rev + Qn[2]
      if Qn[1] == "2" :
        fwd = Qn[2] + fwd

ans = fwd + S + rev
if now == -1 :
  ans = ans[::-1]
print(ans)
### BUGGY CODE ###

N, M = list(map(int, input().split()))
start = []
end = []
for i in range(M):
    a, b = list(map(int, input().split()))
    if a == 1 or b == 1:
        start.append(a*b)
    if a == N or b == N:
        end.append(a * b / N)
flag = 0
for i in start:
    if i in end:
        print("POSSIBLE")
        flag = 1
        break
if not(flag):
    print("IMPOSSIBLE")


### FIXED CODE ###

N, M = list(map(int, input().split()))
start = set([])
end = set([])
for i in range(M):
    a, b = list(map(int, input().split()))
    if a == 1 or b == 1:
        start.add(a*b)
    if a == N or b == N:
        end.add(a * b / N)
flag = 0
for i in start:
    if i in end:
        print("POSSIBLE")
        flag = 1
        break
if not(flag):
    print("IMPOSSIBLE")
### BUGGY CODE ###

import bisect as b
n = int(input())

d = [0]*n
for el in map(int, input().split()):
    d[el-1] += 1

d.sort()

for k in range(1, n+1):
    l = 0
    r = n//k + 1
    while(l+1 < r):
        c = (l+r)//2
        i = b.bisect_left(d, c)
        total = sum(d[:i]) + c * (n - i)
        if total >= k * c:
            l = c
        else:
            r = c
    print(l)

### FIXED CODE ###

import bisect as b
n = int(input())

d = [0]*n
for el in map(int, input().split()):
    d[el-1] += 1

d.sort()

s = [0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + d[i]

for k in range(1, n+1):
    l = 0
    r = n//k + 1
    while(l+1 < r):
        c = (l+r)//2
        i = b.bisect_left(d, c)
        total = s[i] + c * (n - i)
        if total >= k * c:
            l = c
        else:
            r = c
    print(l)
### BUGGY CODE ###

mod = 10**9 + 7


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


A = [format(a, "060b")[::-1] for a in A]

answer = 0
for i in range(60):
    x, y = 0, 0
    for a in A:
        if a[i] == "0":
            x += 1
        else:
            y += 1
    answer += (x * y) * 2**i
    answer %= mod


print(answer)


### FIXED CODE ###

mod = 10**9 + 7


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


A = [format(a, "060b")[::-1] for a in A]

answer = 0
for i in range(60):
    x, y = 0, 0
    for a in A:
        if a[i] == "0":
            x += 1
        else:
            y += 1
    answer += (x * y) * 2**i
    answer %= mod


print(answer)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        left = j+1
        right = N-1
        while a+b <= L[right]:
            if right==j:
                break
            right-=1
        ans += right - left + 1
print(ans)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        right = bisect_left(L, a+b, j+1, N) - 1
        ans += right - j
print(ans)
### BUGGY CODE ###

x = int(input())
ans = []
if x == 1:
    print(1)
    exit()

for i in range(1, x + 1):
    for j in range(2, 101):
        for k in range(2, 101):
            number = j ** k
            if number == i:
                ans.append(i)
print(max(ans))


### FIXED CODE ###

x = int(input())
if x == 1:
    print(1)
    exit()

for i in reversed(range(1, x + 1)):
    for j in range(2, 101):
        for k in range(2, 101):
            number = j ** k
            if number == i:
                print(i)
                exit()
### BUGGY CODE ###

import numpy as np
n = int(input())
a = [x+1 for x in range(n)]
b = a[1::]+[1]
a = np.array(a)
b = np.array(b)

c = a%b
print(sum(c))

### FIXED CODE ###

n = int(input())
print((n*(n-1)//2))
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for i in range(q):
  l,r=map(int,input().split())
  d=s[l-1:r]
  print(d.count("AC"))
  



### FIXED CODE ###

n,q=map(int,input().split())
s=input()
dp=[0]*n
count=0
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    dp[i]=1+count
    count+=1
  else:
    dp[i]=count

#print(dp)
for i in range(q):
  l,r=map(int,input().split())
  print(dp[r-2]-dp[l-2])
### BUGGY CODE ###

import sys
N = int(input())
if N < 3 or 2 * (10**5) < N:
	print("error\nボールは3個以上200000以下")
	sys.exit()

A = list(map(int, input().split()))
k = 0
while not k == len(A):
	# k番目の要素を除外したリストを作成
	tmp = [v for i, v in enumerate(A) if not i == k]
	# 何回等しくなったかflagで確認
	flag = 0
	j = 0
	while not j == len(tmp) - 1:
		h = j + 1
		while not h == len(tmp):

			if (tmp[j] == tmp[h]) and (not j == h):
				flag += 1
			h += 1
		j += 1
	print(flag)
	k += 1

### FIXED CODE ###

N=int(input())
A=list(input().split())
check=[0]*N
for i in range(N):
	check[int(A[i])-1]+=1
num=0
for i in range(N):
	num+=check[i]*(check[i]-1)//2
for i in range(N):
	if check[int(A[i])-1]!=2:
		print(num-(check[int(A[i])-1]-1))
	else:
		print(num-1)
### BUGGY CODE ###

import sys

input = sys.stdin.readline
x,y,a,b,c = map(int,input().split())

pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
import itertools
pl_ac = [0] + list(itertools.accumulate(pl))
ql_ac = [0] + list(itertools.accumulate(ql))
rl_ac = [0] + list(itertools.accumulate(rl))

dada = max(ql[-1], pl[-1], rl[-1])

import bisect
ans = 0
#　赤色をi個食べるとすると無職x-i
for i in range(x+1):
    tmp = 0
    if i > a or x - i > c or b + c - (x - i) < y:
        continue
    #あか
    tmp += pl_ac[-1] - pl_ac[-1-i]
    # #無職
    # tmp += rl_ac[-1] - ql_ac[-1-(x-i)]
    #残りの無職
    if x-i == 0:
        rl_c = rl[:]
    else:
        rl_c = rl[:-(x-i)]
    # ub以上のりんご何個ある？
    ub = dada + 1

    lb = -1
    while True:
        if ub == lb:
            target = ub
            break
        target = (ub + lb) // 2 + 1
        idx = bisect.bisect_left(ql, target)
        idx2 = bisect.bisect_left(rl_c, target)
        if (b - idx) + (c - (x - i) - idx2) >= y:
            lb = target
        else:
            ub = target - 1
    idx = bisect.bisect_left(ql, target)
    idx2 = bisect.bisect_left(rl_c, target)
    tmp += ql_ac[-1] - ql_ac[idx]
    tmp += rl_ac[-1] - rl_ac[idx2]
    gg = (b - idx) + (c - (x - i) - idx2) - y
    if gg > 0:
        tmp -= target * gg
    ans = max(tmp, ans)

print(ans)

### FIXED CODE ###

x,y,a,b,c = map(int,input().split())
pl = list(map(int,input().split()))
ql = list(map(int,input().split()))
rl = list(map(int,input().split()))

pl = sorted(pl)
ql = sorted(ql)
rl = sorted(rl)
ansl = pl[-x:] + ql[-y:]

ansl += rl

ansl = sorted(ansl)
print(sum(ansl[-(x+y):]))
### BUGGY CODE ###

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

Rcnt = 0
Gcnt = 0

excep = 0

for i in range(len(S)):
    if S[i] == 'R':
        Rcnt += 1
    elif S[i] == 'G':
        Gcnt += 1
    for j in range(1, len(S)):
        if i+j+j < len(S) and S[i] != S[i+j]:
            if S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
                excep += 1

RGBcalc = Rcnt * Gcnt * (N - Rcnt - Gcnt)

print(RGBcalc - excep)

### FIXED CODE ###



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

Rcnt = 0
Gcnt = 0

excep = 0

for i in range(len(S)):
    if S[i] == 'R':
        Rcnt += 1
    elif S[i] == 'G':
        Gcnt += 1
    for j in range(1, len(S)):
        if i+j+j < len(S) and S[i] != S[i+j]:
            if S[i] != S[i+j+j] and S[i+j] != S[i+j+j]:
                excep += 1
        elif i+j+j >= len(S):
            break

print(Rcnt * Gcnt * (N - Rcnt - Gcnt) - excep)
### BUGGY CODE ###

H, N = map(int, input().split())
Cost=[]
for i in range(N):
  A, B = map(int, input().split())
  Cost.append((A, B))
#  Cost.append((A, B, A/B))
#Cost = sorted(Cost, key=lambda row: row[0], reverse=True)
#sortedCost = sorted(Cost, key=lambda row: row[2], reverse=True)

DP=[float('inf')]*(H+2)
DP[0]=0
DP[1]=0
for i in range(2,H+2):
    for j in range(N):
      if i-Cost[j][0]>=0:
          DP[i]=min(DP[i], DP[i-Cost[j][0]]+Cost[j][1])
      else:
          DP[i]=min(DP[i], Cost[j][1])

print(DP[H+1])

### FIXED CODE ###

H, N = map(int, input().split())
#Cost=[]
#for i in range(N):
#  A, B = map(int, input().split())
#  Cost.append([A, B])
Cost=[[int(x) for x in input().split()] for _ in range(N)]
#  Cost.append((A, B, A/B))
#Cost = sorted(Cost, key=lambda row: row[0], reverse=True)
#sortedCost = sorted(Cost, key=lambda row: row[2], reverse=True)
#print(Cost)

DP=[float('inf')]*(H+2)
DP[0]=0
DP[1]=0
for i in range(2,H+2):
    for j in range(N):
      if i-Cost[j][0]>=0:
          DP[i]=min(DP[i], DP[i-Cost[j][0]]+Cost[j][1])
      else:
          DP[i]=min(DP[i], Cost[j][1])

print(DP[H+1])
### BUGGY CODE ###

n = int(input())
lis = list(map(int,input().split()))
count = 0
for i,l in enumerate(lis):
    if i == 0:
        count += 1
    elif l <= min(lis[0:i]):
        count += 1
print(count)

### FIXED CODE ###

import sys
n = int(input())
lis = list(map(int,input().split()))
count = 0
mi = 0
for i,l in enumerate(lis):
    if i == 0:
        mi = l
        count += 1
    else:
        if l < mi:
            mi = l
        if mi >= l:
            count += 1
print(count)