Harryxun/stf_run huggingface dataset:
from math import gcd
from functools import reduce
from collections import deque

N = int(input())

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

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)

### FIXED CODE ###

from fractions import gcd
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
L = deque([0])
R = deque([0])

for i in range(N):
  L.append(gcd(L[i],A[i]))
for i in range(N)[::-1]:
  R.appendleft(gcd(R[0],A[i]))

ans = []
for i in range(N):
  ans += [gcd(L[i], R[i+1])]
print(max(ans))
n,m = map(int,input().split())
d = {}
for _ in range(m):
    x,y = map(int,input().split())
    d[x-1] = d.get(x-1,[]) + [y-1]
memo = {}
def dp(i):
    if i not in d:
        return 0
    if i not in memo:
        memo[i] = 0
        for nei in d[i]:
            memo[i] = max(memo[i],dp(nei)+1)
    return memo[i]
ans = 0
for i in range(n):
    ans = max(ans,dp(i))
print(ans)

### FIXED CODE ###

from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))
x=int(input())
    ans=x
    while True:
        flag=False
        for i in range(2,int(x**0.5)):
            if ans%i==0:
                flag=True
                break
        if flag:
            ans+=1
            continue
        else:
            break
    print(ans)
resolve()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x=int(input())
    ans=x
    while True:
        flag=False
        for i in range(2,int(x**0.5)):
            if ans%i==0:
                flag=True
                break
        if flag:
            ans+=1
            continue
        else:
            break
    print(ans)
resolve()
Not found

### FIXED CODE ###

a,b,c,x,y = map(int,input().split())
anlist=[]
for i in range(max(x,y)+1):
    ans = 2*c*i+a*max(0,x-i)+b*max(0,y-i)
    anlist.append(ans)
print(min(anlist))
N=int(input())
P=[list(map(int,input().split()))]
from functools import reduce
from operator import add, mul
result =reduce(mul, P[0])

if result>10**18:
    print(-1)
else:
    print(result)


### FIXED CODE ###

a,b=map(int,input().split())
print(a*b)
from math import gcd # Python3.6以降
# --------------------------------------------------------------

# n以下の素数列挙: O-nlogn
def primes(n):
    prs = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            prs.append(i)
    return prs

n    = int(input())
lis  = list(map(int,input().split()))
soin = [0]*(10**6)
cnt  = 0
ans  = ''

for i in range(n):
    soin[lis[i]] += 1

for i in primes(10**6):
    for j in range(1,10**6):
        if i*j >= 10**6:
            break
        cnt += soin[i*j]
        if cnt > 1:
            ans = 'pairwise coprime'
            break

if ans == '':
    for i in range(n-1):
        if i==0:
            tmp = gcd(lis[i],lis[i+1])
        else:
            tmp = gcd(tmp,lis[i+1])
    
    if tmp==1:
        ans = 'setwise coprime'
    else:
        ans = 'no coprime'

print(ans)

### FIXED CODE ###

from math import gcd # Python3.6以降
# --------------------------------------------------------------

# n以下の素数列挙: O-nlogn
def primes(n):
    prs = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            prs.append(i)
    return prs

n    = int(input())
lis  = list(map(int,input().split()))
A    = 10**6
nlis = [0]*A
flg_pairwise = True

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

for i in primes(A):
    cnt = 0
    for j in range(i-1,A,i):
        cnt += nlis[j]
    if cnt > 1:
        flg_pairwise = False
        break

if flg_pairwise:
    print('pairwise coprime')
else:
    for i in range(n-1):
        if i==0:
            tmp = gcd(lis[i],lis[i+1])
        else:
            tmp = gcd(tmp,lis[i+1])

    if tmp==1:
        print('setwise coprime')
    else:
        print('not coprime')
from sys import stdin
import math
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 1000000007
    n = I()
    a = LI()
    a.sort(reverse=True)
    ans = 0
    dig = int(math.log2(a[0])) + 1
    for i in range(dig):
        c0 = 0
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
            else:
                c0 += 1
        ans += (c0*c1*2**i)%mod
    ans %= mod
    print(ans)

### FIXED CODE ###

from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 10**9 + 7
    n = I()
    a = LI()
    ans = 0
    for i in range(60):
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
        ans += ((n-c1)*c1*(2**i)%mod)%mod
    print(ans%mod)
N = int(input())
s = [0] * N
d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in range(N):
    s[i] = input()
    if s[i][0] == "M":
        d['M'] += 1
    elif s[i][0] == "A":
        d['A'] += 1
    elif s[i][0] == "R":
        d['R'] += 1
    elif s[i][0] == "C":
        d['C'] += 1
    elif s[i][0] == "H":
        d['H'] += 1

total = 1
count = 0
del_keys = []
for k, v in d.items():
    if v == 0:
        del_keys.append(k)
    else:
        total *= v
        count += 1

print(d)
for key in del_keys:
    del d[key]

if count < 3:
    print(0)
    exit()
elif count == 3:
    print(total)
    exit()
elif count == 4:
    ans = 0
    for k, v in d.items():
        ans += total / v
    print(int(ans))
    exit()
elif count == 5:
    ans = 0
    d_lst = list(d)
    for i in range(4):
        for j in range(i+1, 5):
            ans += total / (d_lst[i] * d_lst[j])
    print(int(ans))


### FIXED CODE ###

from collections import Counter
from itertools import combinations

n = int(input())
s = [input()[0] for _ in range(n)]
lc = Counter(s)

con = []
for c in 'MARCH':
    if c in lc:
        con.append(lc[c])

ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c

print(ans)
s = input()
a = ['Sunny', 'Cloudy', 'Rainy','Sunny', 'Cloudy', 'Rainy']
print(a[a.index(s)+1]

### FIXED CODE ###

s = str(input())
a = ['Sunny', 'Cloudy', 'Rainy','Sunny', 'Cloudy', 'Rainy']
print(a[a.index(s)+1])
n, k = list(map(int, input().split()))
values = list(map(int, input().split()))
print(sum(sorted(values)[:k])

### FIXED CODE ###

n, k = list(map(int, input().split()))
values = list(map(int, input().split()))
print(sum(sorted(values)[:k]))
n, x, m = map(int, input().split())

lst = set()
num = []
for i in range(1, n + 1):
    lst.add(x), num.append(x)
    x = x ** 2 % m
    if x in lst:
        break
cnt, idx = i, num.index(x)
div, mod = divmod(n - cnt, len(num) - idx)
ans = sum(num[:idx + mod])
ans += sum(num[idx:]) * (div + 1)
print(ans)


### FIXED CODE ###

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

lst = set()
num = []
for i in range(1, n + 1):
    lst.add(x), num.append(x)
    x = x ** 2 % m
    if x in lst:
        cnt, idx = i, num.index(x)
        div, mod = divmod(n - cnt, len(num) - idx)
        ans = sum(num[:idx + mod])
        ans += sum(num[idx:]) * (div + 1)
        break
else:
    ans = sum(num)
print(ans)
def merge(A, left, mid, right):

    n1 = mid-left
    n2 = right-mid
    #L = [0 for i in range(n1+1)]
    #R = [0 for i in range(n2+1)]
    #for i in range(n1):
    #    L[i] = A[left+i]
    #for i in range(n2):
    #    R[i] = A[mid+i]
    L = A[left:mid]
    R = A[mid:right]
    L[n1] = float('inf')
    R[n2] = float('inf')
    i = 0
    j = 0
    global cnt

    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i+1
        
        else:
            A[k] = R[j]
            j = j+1
    return cnt

def mergeSort(A, left, right):
    if left+1 < right:
         mid = (left+right) // 2
         mergeSort(A, left, mid)
         mergeSort(A, mid, right)
         merge(A, left, mid, right)
    else:
        return 0

n = input()
A = list(map(int, input().split()))
cnt = 0
mergeSort(A, 0, len(A))
print(*A)
print(str(cnt))

### FIXED CODE ###

def merge(A, left, mid, right):

    n1 = mid-left
    n2 = right-mid
    #L = [0 for i in range(n1+1)]
    #R = [0 for i in range(n2+1)]
    #for i in range(n1):
    #    L[i] = A[left+i]
    #for i in range(n2):
    #    R[i] = A[mid+i]
    L = A[left:mid]
    R = A[mid:right]
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0
    j = 0
    global cnt

    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i = i+1
        
        else:
            A[k] = R[j]
            j = j+1
    return cnt

def mergeSort(A, left, right):
    if left+1 < right:
         mid = (left+right) // 2
         mergeSort(A, left, mid)
         mergeSort(A, mid, right)
         merge(A, left, mid, right)
    else:
        return 0

n = input()
A = list(map(int, input().split()))
cnt = 0
mergeSort(A, 0, len(A))
print(*A)
print(str(cnt))
S = list(input())

p = S[0]+S[1]
q = S[2]+S[3]

p_flag = 0
q_flag = 0

if int(q) = 0 and int(p) == 0:
    print('NA')
elif int(p) == 0:
    print('YYMM')
elif int(q) == 0:
    print('MMYY')
else:
    if int(p) > 12:
        p_flag = 1
    if int(q) > 12:
        q_flag = 1

    if p_flag and q_flag:
        print('NA')
    elif p_flag:
        print('YYMM')
    elif q_flag:
        print('MMYY')
    else:
        print('AMBIGUOUS')


### FIXED CODE ###

S = list(input())

p = S[0]+S[1]
q = S[2]+S[3]

p_flag = 0
q_flag = 0

if int(p) == 0 and int(q) == 0:
    print('NA')
elif int(p) == 0:
    if int(q) < 13:
        print('YYMM')
    else:
        print('NA')
elif int(q) == 0:
    if int(p) < 13:
        print('MMYY')
    else:
        print('NA')
else:
    if int(p) > 12:
        p_flag = 1
    if int(q) > 12:
        q_flag = 1

    if p_flag and q_flag:
        print('NA')
    elif p_flag:
        print('YYMM')
    elif q_flag:
        print('MMYY')
    else:
        print('AMBIGUOUS')
N,K = map(int,input().split())
list = list(map(int,input().split()))
list.sort(reverse=True)
seki = 1
seki1 = 1
seki2 = 1
if list[0] <= 0 and K % 2 != 0:
    for i in range(K):
        seki *= list[i]
elif N == K:
    for i in range(K):
        seki *= list[i]
else:
    for i in range(K):
        seki1 *= list[i]
    list.sort()
    for i in range(K):
        seki2 *= list[i]
    if (seki2 >= seki1) and (seki2 >= 0):
        seki = seki2
    elif (seki2 >= seki1) and (seki2 < 0):
        while seki2 < 0:
            i = 0
            seki2 = seki2 / list[i] * list[K+1+i]
            i += 1
        seki = seki2
    elif (seki1 > seki2) and (seki1 >= 0):
        seki = seki1
    else:
        list.sort(reverse=True)
        while seki1 < 0:
            i=0
            seki1 = seki1 / list[i] * list[K+1+i]
            i += 1
        seki = seki1

print(seki % ((10**9)+7))


### FIXED CODE ###

N = int(input())

N = N - 1000
for j in range (10):
    if N - (1000*j) <= 0 :
        print(abs(N-(1000*j)))
        break
t = input()
lent = len(t)
maxt = ""
if lent = 1:
  print(D)
else:
  while len(maxt) = lent:
    if len(maxt) // 2 = 0:
      maxt + "P"
    else:
      maxt + "D"
  
  print(maxt)

### FIXED CODE ###

t = input()
tt = t.replace("?", "D")
print(tt)
N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(list(map(deno, np.arange(1,N+1)))) / N
print(pro)

### FIXED CODE ###

N, K = map(int, input().split())
import math
def deno(x):
    if x >= K:
        return 1
    else:
        count = math.ceil(math.log(K/x, 2))
        return 1 / (2 ** count)
pro = sum(map(deno, range(1,N+1))) / N
print(pro)
N = int(input())
d = list(map(int, input().split()))

x = sorted(d, reverse=True)

ans = 1
for i in range(N-1):
    if x[i] - x[i+1] >0:
        ans += 1
    else:
        continue


print(ans)


### FIXED CODE ###

N = int(input())
d = [int(input()) for i in range(N)]

x = sorted(d, reverse=True)

ans = 1
for i in range(N-1):
    if x[i] - x[i+1] >0:
        ans += 1
    else:
        continue


print(ans)
n = int(input())

a = n // 4
b = n // 7
count = 0

for i in range(a + 1):
    n = n - i * 4
    for j in range(b + 1):
        if 4 * i + 7 * j == n:
            print(yes)
            count += 1
            break
        else:
            pass

if count == 0:
    print("No")
else:
    pass

### FIXED CODE ###

n = int(input())

count = 0

for i in range(26):
    for j in range(15):
        if 4 * i + 7 * j == n:
            count += 1
            break
        else:
            pass

if count == 0:
    print("No")
else:
    print("Yes")
n, k = map(int, input().split())
x = list(map(int, input().split()))

for i in range(n):
    if x[i] >= 0:
        ori = i
        break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = abs(0 - x[i]) + abs(x[i + k - 1] - x[i])
    res = min(res, time)

print(res)


### FIXED CODE ###

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

if x[0] >= 0:
    print(x[k - 1])
    exit()
elif x[n - 1] < 0:
    print(abs(x[n - k]))
    exit()
else:
    for i in range(n):
        if x[i] >= 0:
            ori = i
            break

f_inf = float("inf")
res = f_inf
for i in range(max(ori - k, 0), min(ori + k, n) - k + 1):
    time = min(abs(x[i + k - 1] - x[i]) + abs(x[i + k - 1]), abs(x[i]) + abs(x[i + k - 1] - x[i]))
    res = min(res, time)

print(res)
# 入力をプログラムで扱えるように受け取ること
    a, b = map(int, input().split())
    # print(a, b)
     
    # 受け取った入力値を使い、適切に処理（計算）する
    answer = a * b
     
    # 計算した結果を出力する
    print(answer) 

### FIXED CODE ###

# 入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())
# print(a, b)

# 受け取った入力値を使い、適切に処理（計算）する
anser = a * b

# 計算した結果を出力する
print(anser)
s = input()
if s == ABC:
  print("ARC")
else:
  print("ABC")

### FIXED CODE ###

s = input()
if s == "ABC":
  print("ARC")
else:
  print("ABC")
print(int(r*r))















































### FIXED CODE ###

print(int(input())**2)














###################################################################
# import bisect
# import heapq
# from copy import deepcopy
from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

# n, k = map(int, input().split())
# a = list(map(int, input().split()))
s = deque(input())
q = int(input())
rev = False
for i in range(q):
    que = input()
    if que[0] == '1':
        rev = not rev
    else:
        que = list(que.split())
        if (int(que[1])==1 and not rev) or (int(que[1])==2 and rev):
            s.appendleft(que[2])
        else:
            s.append(que[2])

if rev: ans = s[::-1]
else: ans = s
print(ans)


### FIXED CODE ###

# import bisect
# import heapq
# from copy import deepcopy
from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math

# n, k = map(int, input().split())
# a = list(map(int, input().split()))
s = deque(input())
q = int(input())
rev = False
for i in range(q):
    que = input()
    if que[0] == '1':
        rev = not rev
    else:
        que = list(que.split())
        if (int(que[1])==1 and not rev) or (int(que[1])==2 and rev):
            s.appendleft(que[2])
        else:
            s.append(que[2])

if rev: ans = ''.join(reversed(s))
else: ans = ''.join(s)
print(ans)
a,b = map(int,input().split())
if (b == 100):
    AB = a * 1000 + b
else if(b > 9):
    AB = a * 100 + b
else:
    AB = a * 10 + b
cnt = 1
ans = False
while(True):
    x = cnt * cnt
    if(x == AB):
        ans = True
    if(x > AB):
        break
    cnt += 1
if(ans):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a,b = map(int,input().split())
if (b == 100):
    AB = a * 1000 + b
elif(b > 9):
    AB = a * 100 + b
else:
    AB = a * 10 + b
cnt = 1
ans = False
while(True):
    x = cnt * cnt
    if(x == AB):
        ans = True
    if(x > AB):
        break
    cnt += 1
if(ans):
    print("Yes")
else:
    print("No")
for x in range(2 ** N + 1):
#     print("===========", x, ans)
    for m in range(M):
        c = 0
        for k in range(1, ks_list[m][0]+1):
            ks_mk = -ks_list[m][k]
            if int(format(x,'b').zfill(10)[ks_mk]) == 1:
                c += 1
#             print(ks_list, ks_list[m][k], ks_mk, format(x,'b').zfill(10), format(x,'b').zfill(10)[ks_mk])
#         print(c, p[m])
        if c % 2 != p[m]:
#             print("break")
            break
        if m == M-1:
            ans += 1
#     print(ans, ks_list, c, p)

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
s = [list(map(lambda s: int(s) - 1, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
# print(s)
# print(p)
ret = 0
for i in range(2 ** N):
    on = list(map(int, bin(i)[2:]))
#     print(on)
    on = ([0] * N + on)[-N:]
#     print(on)
    for si, pi in zip(s, p):
        if sum(on[sij] for sij in si) % 2 != pi:
            break
    else:
        ret += 1
print(ret)
from collections import Counter
N = int(input())
S = counter([input() for i in range(N)])
most = S.most_common()[0][1]
ans = []
for name num in S.items:
  if num != most:
    break
  ans.append(name)
ans.sort()
for a in ans:
  print(a)

### FIXED CODE ###

from collections import Counter
N = int(input())
S = Counter([input() for i in range(N)])
most = S.most_common()[0][1]
ans = []
for name, num in S.items():
  if num != most:
    continue
  ans.append(name)
ans.sort()
for a in ans:
  print(a)
import numpy as np
def main():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    l=[]
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(int(sum))

def main2():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    l=A[0]
    r=A[0]
    for i,num in enumerate(A,start=0):
        sum+=min(l,r)
        if l<r:
            r=num
        else:
            l=num
    print(int(sum))


if __name__ == "__main__":
    # main()
    main2()

### FIXED CODE ###

if __name__ == "__main__":
    N=input()
    N=int(N)
    x=N//1000
    if N%1000==0:
        print(0)
    else:
        print((x+1)*1000-N)
#coding:utf-8
#1_5_A
def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False

    res = solve(i+1, m) or solve(i+1, m-numbers[i])
    return res

n = int(input())
numbers = list(map(int, input().split()))
q = int(input())

for i in range(q):
    if solve(0, int(input())):
        print("yes")
    else:
        print("no")

### FIXED CODE ###

#coding:utf-8
#1_5_A
from itertools import combinations

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

numbers = set()
for i in range(1, n+1):
    for com in combinations(A, i):
        numbers.add(sum(com))

for m in ms:
    if m in numbers:
        print("yes")
    else:
        print("no")
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    product = arr[0]
    if 0 in arr:
        product = 0
    else:
        for i in range(1, n):
            product *= arr[i]
            if product > (10**18):
                product = -1
                break
    print(product)

### FIXED CODE ###

if __name__ == '__main__':
    a, b = map(int, input().split())
    print(a*b)
from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0
for a in range(1,N):
	for b in range(a):
      	c = 0
        for i in range(D):
			c += (lst[a][i]-lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
          	tot += 1
print(tot)

### FIXED CODE ###

from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0

for a in range(1,N):
    for b in range(a):
        c = 0
        for i in range(D):
            c += (lst[a][i] - lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
            tot += 1
print(tot)
from collections import defaultdict

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

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if A[idx] < k and idx-1 <= len(A):
      A[idx] = k
      idx += 1
    else:
      break
  else:
    continue
  break
      
      
print(sum(A))
  

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

from collections import defaultdict

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

dict = defaultdict(int)

for i in range(M):
  B, C = map(int, input().split())
  dict[C] += B

idx = 0
for k, v in sorted(dict.items(), key=lambda x: -x[0]):
  for _ in range(v):
    if idx+1 <= len(A):
      if A[idx] < k:
      	A[idx] = k
      	idx += 1
      else:
        print(sum(A))
        exit()
    else:
      print(sum(A))
      exit()
      
      
print(sum(A))