peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import fractions
n, X = map(int, input().split())
x = list(map(int, input().split()))
d = abs(X - x[0])
for i in range(1, n):
    d = fractions.gcd(d, abs(X - x[i]))
print(d)
# Judge status: Wrong Answer
user = str(input().upper())
for i in user:
    if user.count(i) == 2:
        print("Yes")
# Judge status: Accepted
#! /usr/bin/env python3

a=int(input())
reslt= a + a**2+a**3
print(reslt)
# Judge status: Wrong Answer
a,b = map(int,input().split())

if a * b <= 0:
    print("Zero")
elif a <= 0 and (b - a) % 2 == 0:
    print("Negetive")
else:
    print("Positive")
# Judge status: Wrong Answer
N,K=(int(x) for x in input().split())
p=list(map(int, input().split()))
ld = sorted(p, reverse=True)
l=(ld[:K])
print(sum(l))
# Judge status: Accepted
R = int(input())
A = list(map(int,input().split()))

S = [ 0 for i in range(R) ]

for i in A :
  idx = i - 1
  S[idx] += 1

for i in S :
  print(i)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
if a==b and b==c:
  print('YES')
else:
  print('NO')
# Judge status: Accepted
s = input()
k = int(input())

for i in range(k):
  if s[i] != "1":
    print(s[i])
    break
else:
  print(1)
# Judge status: Accepted

from bisect import bisect_left

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

X.sort()
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        k = bisect_left(X, X[i] + X[j])
        ans += k - j - 1

print(ans)
# Judge status: Accepted
import sys
stdin = sys.stdin
def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int,stdin.readline().split()))
    mod = 10**9+7
    ans = 0
    for i in range(61):
        bits = 0
        for x in A:
            if (x>>i)&1:
                bits += 1
        ans += ((bits*(N-bits))* 2**i) %mod
    ans %= mod
    print(ans)
main()
# Judge status: Accepted
n=int(input())
a=[int(input())for i in range(n)]
c=0
l=[]
l2=[]
for i in a:
    if i!=0:
        l.append(i)
    else:
        l2.append(sum(l)//2)
        l=[]
l2.append(sum(l)//2)
print(sum(l2))
# Judge status: Wrong Answer
a,b,c = map(int,input().split())

if (c-a-b)**2 > 4*a*b:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
X,Y, A,B, C = list(map(int , input().split()))
P = list(map(int , input().split()))
Q = list(map(int , input().split()))
R = list(map(int , input().split()))
R.sort(reverse=True)
P.sort(reverse=True)
Q.sort(reverse=True)

Z = P[:X]+Q[:Y]
for i in range(len(Z)):
    if Z[i]<R[0]:
        Z.insert(i,R[0])
        Z.pop(-1)
        R.pop(0)
    if len(R)==0:
        break
w = sum(Z)
print(w)
# Judge status: Accepted
def main():
    n = int(input())
    t, a = map(int, input().split())
    h = list(map(int, input().split()))
    # s = input()

    mini = 10**10
    ans = 0
    for i, x in enumerate(h):
        c = t - x * 0.006
        if abs(a - c) < mini:
            mini = abs(a - c)
            ans = i+1

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
l=list(map(int,input().split()))
l.sort()
print(int(str(l[2])+str(l[1]))+l[0])
# Judge status: Wrong Answer
n = int(input())

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

check = [1]*n
p = 1
ans = 1
total = 1
for i in range(n):
    total += 1
    check[p-1] = 0
    p = a[p-1]
    if a[p-1] == 2:
        ans = 0
        break

if ans == 0:
    print(total)
else:
    print("-1")
# Judge status: Wrong Answer
N = int(input())

ans = 0
div = 1000000007
pairs = N // 3 + 1
if N > 2:
    ans += 1


def paircheck(n, b):
    a, mod = divmod(n, b)
    # if a == 2 and mod > 0:
    # return b
    if a > 2 and mod > 0:
        return (a-2) * b
    elif a > 2 and mod == 0:
        return (a-3) * b + 1
    return 0


for i in range(1, pairs):
    ans += paircheck(N, i+1)

print(ans)
# Judge status: Accepted
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
a = Counter(l)
b = a.most_common()
c = []
for i,j in b:
    if j>=4:
        c.append(i)
        c.append(i)
    elif j>=2:c.append(i)
c.sort()
print(c[-1]*c[-2] if len(c)>=2 else 0)
# Judge status: Accepted
N = int(input())
ans = 'No'
ls = []
for i in range(N):
    d1,d2 = map(int,input().split())
    ls.append([d1,d2])
ii = 0
for i in range(N):
    if ls[i][0] == ls[i][1]:
        ii += 1
    else:
        ii = 0

    if ii == 3:
        ans = 'Yes'
        break
print(ans)
# Judge status: Wrong Answer
n = int(input())
A = list(map(int,input().split()))
c = [0]*10
add = 0
for i in range(n) :
    if A[i]>=3200 :
        add += 1
        continue
    a = A[i]//400
    c[a] = 1

print(sum(c),min(sum(c)+add,8))
# Judge status: Accepted
n = int(input())
# = map(int, input().split())
p = list(map(int, input().split()))
# = [int(input()) for _ in range()]
cnt = 0
for i in range(1, n - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
        cnt += 1
print(cnt)
# Judge status: Wrong Answer
a, b, c, d = map(int, input().split())
if b <= c or d <= a:
    print("0")
elif c <= a and b <= d:
    print(b-a)
elif a <= c and d <= b:
    print(d-c)
else:
    print(abs(c-b))
# Judge status: Accepted
A,B,C=input().split()
if A==B and A==C:
    print("No")
elif A!=B and A!=C and B!=C:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
import collections
N,K=map(int,input().split())
a=[]
while K>0:
  K=K-1
  d=int(input())
  a.append(map(str,input().split()))
e=collections.Counter(a)
p=N-len(e)
print(p)
# Judge status: Wrong Answer
w,h,x,y=list(map(int,input().split()))
ans=0
if max(w-x,x)>max(h-y,y):s=max(w-x,x)*h
elif max(w-x,x)<max(h-y,y):s=w*max(h-y,y)
else:
  s=max(w-x,x)*h
  ans=1
print(s,ans)
# Judge status: Accepted
import sys
from itertools import accumulate

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()

ans = INF
accum = list(accumulate(A))
for s in accum:
    t = accum[-1] - s
    ans = min(ans, abs(s - t))
print(ans)
# Judge status: Accepted
def ii():return int(input())
def mi():return map(int,input().split())

a=[]
for _ in range(3):
  a+=list(mi())
n=ii()
b=[]
for i in range(n):
  b+=ii(),

def ana(x):
  if x in b:
    return 1
  else:
    return 0

c=[ana(aa) for aa in a]

oks="012 345 678 036 147 258 048 246".split()

for ok in oks:
  res=1
  for j in list(ok):
    res*=c[int(j)]
  if res==1:
    print("Yes")
    exit()
print("No")
# Judge status: Accepted
S = input()
T = input()

S_len = len(S)
T_len = len(T)
A_sum = []
count = 0

for i in range(S_len - T_len + 1):
    for j in range(T_len):
        if S[i+j] == T[j]:
            count += 1
    A_sum.append(count)
    count = 0

ans = T_len - max(A_sum) 

print(ans)
# Judge status: Accepted
K, X = map(int, input().split())
ans = list(range(X-K+1,X+K,1))
print(*ans)
# Judge status: Accepted
import sys
import heapq
from collections import Counter
from math import sqrt

n = int(input())
a_s = [int(i) for i in sys.stdin.readline().split()]
a_s.sort()
_max = max(a_s)
ct = Counter(a_s)
cnt = 0
ls = [False] * (10**6+1)
for a in a_s:
    if ls[a]:
        cnt += 1
        continue
    elif ct[a] > 1:
        cnt += 1
    for i in range(a, _max+1, a):
        if ls[i]:
            continue
        if i % a == 0:
            ls[i] = True

print(n - cnt)
# Judge status: Wrong Answer
n = int(input())
s = [int(input()) for i in range(n)]
o = 0
flag = True
if sum(s)%10 == 0:
  if min(s)%10 != 0:
    o = sum(s)-min(s)
  else:
    while(flag):
      for i in sorted(s):
        if i%10 == 0:
          pass
        else:
          o = sum(s)-min(s)
          break
      else:
        break
print(o)
# Judge status: Wrong Answer
input1 = int(input())
while input1 > 999:
    input1 -= 1000
print(1000 - input1)
# Judge status: Accepted
n = int(input())
a = int(input())


if n%500 <= a:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
A, B, C, D = map(int, input().split())

if C/B >= A/D:
  if C%B != 0 and A%D == 0:
    print("No")
    exit()
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n, a, b = map(int, input().split())

mini = a * (n - 1) + b
maxi = b * (n - 1) + a

print(max(maxi - mini + 1, 0))
# Judge status: Accepted
n, m, X, Y = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

for Z in range(X+1, Y+1):
   if (max(x) < Z and min(y) >= Z):
      print('No War')
      exit()
print('War')
# Judge status: Wrong Answer
n = int(input())
a = map(int, input().split())
now = 1
if 0 in a:
    print("0")
    exit()
for one in a:
    now *= one
    if now > 1e18:
        print("-1")
        exit()

print(now)
# Judge status: Accepted
N = int(input())
dic = {1:0,2:0,4:0}
List = list(map(int,input().split()))
for item in List:
  if item%4 == 0:
    dic[4] += 1
  elif item %2 == 0:
    dic[2] += 1
  else:
    dic[1] += 1
Answer = 'No'
if dic[4] != 0 and dic[4]+1 >= dic[1]+dic[2]:
  Answer = 'Yes'
elif dic[4]>=dic[1]:
  Answer = 'Yes'
print(Answer)
# Judge status: Accepted
s = list(input().split())[1]
print("A"+s[0]+"C")
# Judge status: Accepted
import math
X = int(input())
t = math.ceil((-1 + (1+8*X)**(1/2))/2)
print(t)
# Judge status: Wrong Answer
s = int(input())
count = 0
while(True):
    if s%2 == 0:
        s = int(s/2)
    else:
        s = 3*s +1
    count += 1
    if s == 1 or 2 or 4:
        print(count+2)
        break
    else:
        pass
# Judge status: Accepted
n=input()
if n[-1]=='3':
  print("bon")
elif n[-1]=='0' or n[-1]=='1' or n[-1]=='6' or n[-1]=='8':
  print("pon")
else:
  print("hon")
# Judge status: Accepted
def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = 0
    for a in A:
        ans += a//2
    prev = 0
    for a in A:
        new = a%2
        if prev == 1:
            if new == 1:
                ans += 1
            elif a>0:
                prev = 1
            else:
                prev = 0
        prev = prev^new
    return ans
print(solve())
# Judge status: Wrong Answer
A,B,C = map(int,input().split())
K = int(input())
cnt = 0
for _ in range(K):
	if A>B:
		B *= 2
		cnt += 1

for _ in range(K-cnt):
	if B>C:
		C *= 2

if (A<B) and (B<C):
	print('Yes')
else:
	print('No')
# Judge status: Accepted
N, M = map(int, input().split())
ab = []

n1 = set()
nN = set()

for _ in range(M):
    a, b = map(int, input().split())
    if (a == 1) or (b == 1):
        n1.add(b if a == 1 else a)
    if (a == N) or (b == N):
        nN.add(b if a == N else a)

ans = 'IMPOSSIBLE'
if len(n1 & nN) > 0:
    ans = 'POSSIBLE'
print(ans)
# Judge status: Accepted
import math
def main():
  n = int(input())
  num=[0]*87
  num[0]=2
  num[1]=1
  for i in range(2,n+1):
    num[i]=num[i-1]+num[i-2]
  print(num[n])
    
main()
# Judge status: Accepted
N = int(input())
s = list(map(int,input().split()))

sorted_s = sorted(s)
print(sorted_s[(N//2)] - sorted_s[(N//2-1)])
# Judge status: Accepted
N = int(input())
S = str(N)
if(len(S) == 1): print(S); exit(0)
if(len(S) == 2): print(max(N // 10 + N % 10, N // 10 - 1 + 9)); exit(0)
for i in range(1, len(S)):
    if(int(S[i]) != 9):
        print(int(S[0]) - 1 + (len(S) - 1) * 9)
        exit(0)
print(int(S[0]) + (len(S) - 1) * 9)
# Judge status: Wrong Answer
from fractions import gcd

n = int(input())
t = [int(input()) for _ in range(n)]
cm = []

if n == 1:
    print(*t)
    exit()

t.sort()

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

for i in range(n-1):
    cm.append(lcm(t[i], t[i+1]))

print(max(cm))
# Judge status: Accepted
import sys
#import numpy as np
#import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
n,x=map(int,input().split())
a=list(map(int,input().split()))
res=0
for i in range(n-1):
    s=a[i]+a[i+1]
    if s>x:
        a[i+1]-=(s-x)
        res+=(s-x)
        if a[i+1]<0:
            a[i+1]=0
print(res)
# Judge status: Accepted
s=input()
t=input()

s = sorted(s)
t = sorted(t, reverse=True)

if s < t:
    print('Yes')

else:
    print('No')
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
aj = min(a)

for i in a:
    if aj < min(i, ai - i):
        aj = i
    
print(ai, aj)
# Judge status: Wrong Answer
import itertools

input_moji = input()

count = 0

lis = ['dream','dreamer', 'erase','eraser']

origin_list = ['dream','dreamer', 'erase','eraser']
for i in itertools.product(origin_list, repeat=2):
    total = "".join([str(_) for _ in i])
    if input_moji == total:
        count += 1
        print('YES')

if count == 0:
    print('NO')
# Judge status: Accepted
N = int(input())
print(round((N/2)+0.01))
# Judge status: Accepted
k, a, b = map(int, input().split())
if k <= a:
    print(k+1)
else:
    # 交換しないほうがお得
    if a+2 >= b:
        print(k+1)
    # 交換したほうがお得
    else:
        print(a+(b-a)*((k-(a-1))//2)+((k-(a-1))%2))
# Judge status: Wrong Answer
# mathモジュールをインポート
import math

# 円の面積を求める関数
def circle(r):
  return r*r*math.pi

r = input().rstrip()
r = int(r)

# 円の面積
r_circle = circle(r)

# 半径1の円の面積
one_r_circle = circle(1)

ans = r_circle / one_r_circle
print(ans)
# Judge status: Wrong Answer
s = input()
t = input()

if len(s) >= 1 and len(s) <= 10 and len(t) == len(s) + 1:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n = int(input())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
ans = 0
cross = 0
for i in range(n):
    front = min(alis[i]-cross, blis[i])
    cross = min(alis[i+1], blis[i]-front)
    ans += front + cross
print(ans)
# Judge status: Accepted
a, b, n = map(int, input().split())
ans = 0
# floor(a * x / b)
# = floor(a * floor(x / b) + a * (x / b - floor(x / b)))
# = a * floor(x / b) + floor(a * (x / b - floor(x / b))))
print(int(a * min(b - 1, n) / b))
# Judge status: Accepted
S = input()
ans = 0
lsATCG = ['A','T','C','G']
count = 0
for s in S:
    if s in lsATCG:
        count += 1
    else:
        ans = max(ans,count)
        count = 0
ans = max(ans,count)
print(ans)
# Judge status: Accepted
x = input()
count = 0
ans = len(x)
for i in range(len(x)):
    if x[i] == "S":
        count += 1
    else:
        if count > 0:
            count -= 1
            ans -= 2
print(ans)
# Judge status: Accepted
W,a,b=map(int,input().split())
thre =0 
res =0
if a<=b:
  thre = a+W
  if thre >= b:
    res = 0
  else:
    res = b-thre
else:
  thre=b+W
  if thre >= a:
    res = 0
  else:
    res = a-thre
print(res)
# Judge status: Wrong Answer
N = int(input())
List = []
for i in range (2):
  List.append(list(map(int, input().split())))
sumList1 = [0]*N
sumList2 = [0]*N
for i in range(N):
  if i == 0:
    sumList1[i] = List[0][i]
    sumList2[N-1-i] = List[1][N-1-i]
  else:
    sumList1[i] = List[0][i]+sumList1[i-1]
    sumList2[N-1-i] = List[1][i]+sumList1[N-i]
res = 0
for i in range(N):
  res = max(sumList1[i]+sumList2[i],res)
print(res)
# Judge status: Accepted
s=list(input())
t=list(input())
for i in range(len(s)-len(t),-1, -1):
    for j in range(len(t)):
        if not (s[i+j] == t[j] or s[i+j] == '?'):
            break
    else:
        s[i:i+len(t)] = t
        for i in range(len(s)):
            if s[i] == '?':
                s[i] = 'a'
        print(''.join(s))     
        break
else:
    print('UNRESTORABLE')
# Judge status: Wrong Answer
w,h,n = map(int,input().split())
d = [0,w,0,h]
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        d[0] = x
    elif a == 2:
        d[1] = x
    elif a == 3:
        d[2] = y
    else:
        d[3] = y
print(max(0,(d[1]-d[0]))*max(0,(d[3]-d[2])))
# Judge status: Accepted
sx,sy,tx,ty=map(int,input().split())
def pans(l,c):
    for i in range(l):
        print(c,end="")
H=ty-sy
W=tx-sx
pans(H,"U")
pans(W,"R")
pans(H,"D")
pans(W+1,"L")
pans(H+1,"U")
pans(W+1,"R")
pans(1,"D")
pans(1,"R")
pans(H+1,"D")
pans(W+1,"L")
pans(1,"U")
# Judge status: Wrong Answer
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for a in range(A+1):
    print("a=",a)
    for b in range(B+1):
        print("b=",b)
        for c in range(C+1):
            print("c=",c)
            if 500*a+100*b+50*c == X:
                cnt += 1

print(cnt)
# Judge status: Accepted
import math
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A +1):
    Y = X -i*500
    
    for j in range(B + 1):
        Z = Y - j*100
        if Z >= 0 and Z/50 <= C:
            count += 1

print(str(count))
# Judge status: Accepted
n = int(input())
p = [ int(x) for x in input().split() ]
q = sorted(p)

cnt = 0
for i in range(n):
    if p[i] != q[i]:
        cnt += 1

print("YES" if cnt <= 2 else "NO")
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

def getPoint(X, size):
  l = 0
  r = len(X)-1
  while 1 < r-l:
    center = (l+r)//2
    if size < X[center]:
      r = center
    else:
      l = center
  return r-1

count = 0
for a in A:
  for i in range(getPoint(B, a), len(B)):
    if a < B[i]:
      for j in range(getPoint(C, B[i]), len(C)):
        if B[i] < C[j]:
          count += 1
print(count)
# Judge status: Wrong Answer
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
if N>=M: print(0);exit()
if N==1: print(M-1);exit()
L = []
for i in range(len(X)-1):
    L.append(X[i+1]-X[i])
L.sort()
L = L[:-(N-1)]
print(sum(L))
# Judge status: Accepted
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    S = input()
    T = input()

    ret = 2*N
    for i in range(N):
        if S[i:]==T[:N-i]:
            ret = 2*N-(N-i)
            break
    print(ret)



if __name__ == '__main__':
    main()
# Judge status: Accepted
K = int(input())
S = input()

if len(S) > K:
    S = S[:K] + '...'

print(S)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
count = 0
countb = 0
min = min(A)
for i in A:
    if i % 2 == 0:
        count += 1

    if i % min == 0:
        countb += 1

if countb == N:
    print(A[0])
elif count == N:
    print(2)
else:
    print(1)
# Judge status: Accepted
import fractions
A,B,C,D = map(int,input().split())
g = C * D // fractions.gcd(C,D)
# A
cntA = 0
cntA += (A-1) // C
cntA += (A-1) // D
cntA -= (A-1) // g

# B
cntB = 0
cntB += B // C
cntB += B // D
cntB -= B // g

cnt = cntB - cntA
cnt = (B - A + 1) - cnt

print(cnt)
# Judge status: Accepted
from itertools import permutations
from bisect import bisect_left

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

permutation = list(permutations(range(1, n+1)))
a = bisect_left(permutation, p)
b = bisect_left(permutation, q)

print(abs(a - b))
# Judge status: Accepted
B,W = map(int,input().split())
A,V = map(int,input().split())
T = int(input())
if A < B:
    if A-V*T >= B-W*T:
        print('YES')
    else:
        print('NO')
elif A > B:
    if A+V*T <= B+W*T:
        print('YES')
    else:
        print('NO')
# Judge status: Wrong Answer
X, A, B = map(int, input().split())

if B - A <= 0:
    print('delicious')
elif B - A < X:
    print('safe')
else:
    print('dangerous')
# Judge status: Wrong Answer
string=input()
t=False
for i in range (3):
  if string[i]=="7":
    t=True
if t==True:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
def solve():
    sx, sy, tx, ty = map(int, input().split())
    ans = ""
    ans += "R"*(tx-sx)+"U"*(ty-sy)
    ans += "L"*(tx-sx)+"D"*(ty-sy)
    ans += "D"+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"
    ans += "U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+"R"
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
# Judge status: Accepted
N, M = map(int, input().split())

if N >= 3 and M >= 3:
  print(N*M - (2*N + 2*M - 4))
elif N == 2 or M == 2:
  print(0)
elif N == 1 and M == 1:
  print(1)
elif N == 1:
  print(M - 2)
elif M == 1:
  print(N - 2)
else:
  print(1)
# Judge status: Accepted
n,l=map(int,input().split())
s=[]
for i in range(n):
  s.append(input())
s=sorted(s)
for i in range(n):
  print(s[i], end='')
# Judge status: Wrong Answer
import numpy as np
N,M = map(int,input().split(" "))
Min = 1
Max = N

for _ in range(M):
    L,R = map(int,input().split(" "))
    if L>Min:
        Min=L
    if R<Max:
        Max=R
print(Max-Min+1)
# Judge status: Accepted
from itertools import groupby as gb
n,k,g,t,p,s=map(lambda v:v if v[0] in "rsp" else int(v),open(0).read().split())
r,ss,pa=0,0,0
l=[""]*k
for x,i in enumerate(list(s)):
  if l[x%k]==i:l[x%k]="";continue
  if i=="r":pa+=1
  elif i=="s":r+=1
  else:ss+=1
  l[x%k]=i
print(r*g+ss*t+pa*p)
# Judge status: Accepted
try:
  N = int(input())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  __ = a_[N:]
  b = sorted(__, reverse=True)
  c = [b[i] for i in range(len(b)) if i%2!=0]
  print(sum(c))
except EOFError:
  pass
# Judge status: Wrong Answer
A, B = map(int, input().split())

if A > B:
    print("Alice")
elif A < B:
    print("Bob")
else:
    print("Draw")
# Judge status: Wrong Answer
n = int(input())
m = n
order = 0
while m > 3:
    m = m / 3
    order += 1
rem = n - 3**order
msb = rem // 3
lsb = rem % 3
if lsb == 0:
    lsb = msb + 1
elif lsb == 2:
    lsb = msb
elif lsb == 1:
    lsb =  msb - 1
print(msb*10+lsb)
# Judge status: Accepted
import itertools
n,m,q= map(int, input().split())
g = []
for _ in range(q):
    z = list(map(int, input().split()))
    g.append(z)
seq = []
for i in range(1,m+1):
  seq.append(i)
f = [0]
for i in list(itertools.combinations_with_replacement(seq, n)):
  ans = 0
  for j in g:
    if i[j[1]-1]-i[j[0]-1] == j[2]:
      ans += j[3]
  f.append(ans)
print(max(f))
# Judge status: Wrong Answer
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    keyence = "keyence"
    s = readline().rstrip()
    lenS = len(s)
    cnt = 0
    for i in range(1, 7):
        if s.count(keyence[0:i]) > 0:
            idx = s.index(keyence[0:i]) + i
            if s[idx:lenS].count(keyence[i:7]) > 0:
                print("YES")
                return
    print("NO")


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import bisect
x,y,a,b,c=map(int,input().split())
A=sorted(list(map(int,input().split())))[::-1]
B=sorted(list(map(int,input().split())))[::-1]
C=sorted(list(map(int,input().split())))[::-1]

l=A[:x]+B[:y]
l=sorted(l)
lim=l[0]

for tt in C:
    if lim>tt:
        continue
    index=bisect.bisect_left(l,tt)
    l.insert(index,tt)
    lim=l[-x-y+1]
l=l[::-1]
print(sum(l[:x+y]))
# Judge status: Accepted
N, K = [int(i) for i in input().split(" ")]
H = [int(i) for i in input().split(" ")]
H.sort()

monster = H[0:N-K]

if K >= N:
    print(0)
else:
    print(sum(monster))
# Judge status: Accepted
A, B = map(int, input().split())
S = input()
print("Yes" if S[A]=="-" and (S[:A]+S[A+1:]).isdecimal() else "No")
# Judge status: Accepted
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
if n==m:
  print('Yes' if a==b else 'No')
  exit()
for i in range(n-m):
  for k in range(n-m):
    if all(b[j] in a[i+j][k:k+m+1] for j in range(m)):
      print('Yes')
      exit()
print('No')
# Judge status: Accepted
N = int(input())
A = [int(input()) for _ in range(N)]
B = sorted(A,reverse=True)
x = B[1]
y = B[0]
m = A.index(max(A))

for i in range(N):
  if i == m:
    print(x)
  else:
    print(y)
# Judge status: Accepted
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    ans = 0
    cnt = 1
    i = 0
    for n in range(N-1):
        ans += A[i]
        cnt += 1
        if cnt == 2:
            i += 1
            cnt = 0
    
    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
A, B, C, X, Y = map(int, input().split())
C = min(2*C, A+B)

ans = 0
ans += C*min(X, Y)
if X > Y:
  ans += min(C, A) * abs(X-Y)
else:
  ans += min(C, B) * abs(X-Y)
print(ans)