Harryxun/stf_run huggingface dataset:
def max_minus_min(areas):
    # print("areas", areas)
    return max(areas) - min(areas)
 
def solve2(h, w):
    area1 = h * (w // 2)
    area2 = h * w - area1
    return area1, area2
 
def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h
        ans = min(ans, max_minus_min([area1, *solve2(h, w - w2)]))
        ans = min(ans, max_minus_min([area1, *solve2(w - w2, h)]))
    return ans
 
H, W = map(int, input().split())
print(min(solve(H,W), solve(W,H)))

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# import array
# from bisect import *
# from collections import *
# import fractions
# import heapq 
# from itertools import *
# import math
# import re
# import string

def max_minus_min(areas):
    # print("areas", areas)
    return max(areas) - min(areas)

def solve2(h, w):
    area1 = h * (w // 2)
    area2 = h * w - area1
    return [area1, area2]

def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h
        ans = min(ans, max_minus_min([area1] + solve2(h, w - w2)))
        ans = min(ans, max_minus_min([area1] + solve2(w - w2, h)))
    return ans

H, W = map(int, raw_input().split())
print(min(solve(H,W), solve(W,H)))
N, X = map(int, input().strip().split())

b = 'P'
for _ in range(N):
  b = 'B'+b+'P'+b+'B'

print(b[:X].count('P'))

### FIXED CODE ###

N, X = map(int, input().split())
a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))
import sys

for line in sys.stdin.readlines():
     x, y = line.split(" ")

x = int(x)
y = int(y)

divide = 1

if x > y:
    x, y = y, x

for i in range(2, x + 1):
    if x % i == 0 and y % i == 0:
        divide *= i
        x /= i
        y /= i
        i -= 1

print divide

### FIXED CODE ###

import sys

def div(x, y):
    if x % y == 0:
        print y
    else:
        div(y, x%y)


line = sys.stdin.readline()
x, y = line.split(" ")

x = int(x)
y = int(y)

if x < y:
    x, y = y, x

if x == y:
    print x

else:
    div(x, y)
K, N=map(int, input().split())
A=list(map(int, input().split()))

for i in range (N-2):
    A_length=list(A[i+1]-A[i])
A_length.append = [K-(A[N-1]-A[0])]
print(K-(max(A_length)))

### FIXED CODE ###

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

A_length_max = K-A[N-1]+A[0]
for i in range (N-1): #0, 1, 2, ...N-2
    A_length_max=max(A_length_max, A[i+1]-A[i])
print(K-A_length_max)
n,k=map(int,input().split())
import math

ans = 0
if n >(k-1):
    ans += (n-k+1)/n


for i in range(1,min(k,n+1)):
    temp = 1/n
    tval = k/i
    p = int(math.log2(tval))+1

    ans +=temp*(0.5**p)
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
import math

ans = 0
if n >(k-1):
    ans += (n-k+1)/n

for i in range(1,min(k,n+1)):
    if math.log(k/i,2)-int(math.log(k/i,2))== 0:
        p = int(math.log(k/i,2))
    else:
        p = int(math.log(k/i,2))+1
    ans +=(1/n)*(0.5**p)
print(ans)
import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(input())
    edge = [[] for _ in range(N)]
    
    for _ in range(N-1):
        a,b = map(int,input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        
    for i in range(N):
        if len(edge[i]) == 1:
            st = i
            break
    dep = [-1 for _ in range(N)]
    dep[st] = 0
    
    q = deque([st])
    while q:
        now = q.pop()
        for fol in edge[now]:
            if dep[fol] == -1:
                dep[fol] = dep[now]+1
                q.append(fol)
    
    if max(dep)%3 == 1:
        print("second")
    else:
        print("first")

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N = int(input())
    if N == 1:
        print("First")
        exit()
    edge = [[] for _ in range(N)]
    
    for _ in range(N-1):
        a,b = map(int,input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        
    dep = [-1 for _ in range(N)]
    dep[0] = 0
    q = deque([0])
    while q:
        now = q.popleft()
        for fol in edge[now]:
            if dep[fol] == -1:
                dep[fol] = dep[now]+1
                q.append(fol)
    
    st = dep.index(max(dep))
    dep = [-1 for _ in range(N)]
    dep[st] = 0
    q = deque([st])
    while q:
        now = q.popleft()
        for fol in edge[now]:
            if dep[fol] == -1:
                dep[fol] = dep[now]+1
                q.append(fol)
                
    if max(dep)%3 == 1:
        print("Second")
    else:
        print("First")

if __name__ == "__main__":
    main()
S=input()
 
acgt_list=[]
for i in range(len(S)):
  for j in range(i+1,len(S)+1):
    slen=len(S[i:j])
    temp=0
    for s in S[i:j] :
      if s=='A' or s=='C' or s=='G' or s== 'T':
        temp+=1      
    if temp==slen:
      acgt_list.append(slen)
      
print(max(acgt_list))

### FIXED CODE ###

S=input()
 
acgt_list=[0]
for i in range(len(S)):
  for j in range(i+1,len(S)+1):
    slen=len(S[i:j])
    temp=0
    for s in S[i:j] :
      if s=='A' or s=='C' or s=='G' or s== 'T':
        temp+=1      
    if temp==slen:
      acgt_list.append(slen)
      
print(max(acgt_list))
n, m = map(int, input().split())
People = {x+1:[] for x in range(10**6+1)}

for _ in range(m):
    l, r, d = map(int, input().split())
    People[l].append([r, d])
    People[r].append([l, -d])

Place = ['x' for _ in range(10**6+1)]

min_num = 10**7
for i in range(1,n+1):
    if len(People[i]) == 0:
        pass
    else:
        min_num = min(min_num, i)

if m != 0:
    Place[min_num] = 0
    ans = 'Yes'
    for i in range(min_num,min_num+n):
        Related = People[i]
        for related in Related:
            person = related[0]
            place = related[1]
            if Place[person] == 'x':
                Place[person] = Place[i] + place
            elif Place[person] != Place[i] + place:
                ans = 'No'
                break
else:
    ans = 'Yes'

print(ans)

### FIXED CODE ###

from collections import deque

n, m = map(int, input().split())
People = {x+1:[] for x in range(10**6+1)}

for _ in range(m):
    l, r, d = map(int, input().split())
    People[l].append([r, d])
    People[r].append([l, -d])

INF = 10**10
Visited = [INF for i in range(10**6+1)]

def bfs(v):
    dq = deque()
    dq.append(v)
    Visited[v] = 0
    check = True
    while dq:
        now = dq.popleft()
        Related = People[now]
        for related in Related:
            if Visited[related[0]] == INF:
                dq.append(related[0])
                Visited[related[0]] = Visited[now] + related[1]
            elif Visited[related[0]] != Visited[now] + related[1]:
                check = False
    return check

ans = 'Yes'
for i in range(1,10**6+1):
    if Visited[i] == INF:
        if bfs(i) == False:
            ans = 'No'

print(ans)
n = input()
x = list(map(int,input().split()))
count = 1
for i in range(1,n):
  if min(x[0:i-1])>=x[i]:
    count+=1
print(count)

### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
count = 1
m = x[0]

for i in range(1,n):
  if m >=x[i]:
    count+=1
    m = x[i]
  
print(count)
N=input()
A=int(input())
B=0
for i in N:
    B+=int(i)
if A%B==0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N=input()
A=int(N)
B=0
for i in N:
	B+=int(i)
	
if A%B==0:
    print("Yes")
else:
    print("No")
# -*- coding: utf-8 -*-

import sys

a, b = [int(e) for e in raw_input().split()]

ans = 'Even'
if (a & 1) and (b & 1):
    ans = 'Odd'
    
sys.stdout.write('%s\n' % (ans))
sys.stdout.flush()


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

n, a, b = [int(e) for e in raw_input().split()]
# print n, a, b
# print n*a, b
# print min(n*a, b)

sys.stdout.write('%d\n' % ( min(n*a, b) ))
sys.stdout.flush()
import bisect

n,k= map(int,input().split())
x = [int(i) for i in input().split()]

idx = bisect.bisect_left(x,0)
"""
if x[idx] == 0:
    x.insert(idx,0)
"""

ans = 10**100

if x[idx] == 0:
    print(ans)

print(ans)
exit()

for i in range(k+1):
    #print(idx-i,idx+k-1-i)
    if i == 0 and idx+k-1 < n:
        ans = min(ans, x[idx+k-1])
    elif idx - i < 0 or idx+k-1-i >= n:
        continue
    else:
        ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])
        ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])

print(ans)

### FIXED CODE ###

import bisect

n,k= map(int,input().split())
x = [int(i) for i in input().split()]

idx = bisect.bisect_left(x,0)
"""
if x[idx] == 0:
    x.insert(idx,0)
"""
ans = 10**100


for i in range(k+1):
    #print(idx-i,idx+k-1-i)
    if i == 0 and idx+k-1 < n:
        ans = min(ans, x[idx+k-1])
    elif idx - i < 0 or idx+k-1-i >= n:
        continue
    else:
        ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])
        ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])

if idx == n:
    ans = -x[-k]

print(ans)
N, M, K=[int(i) for i in input().split(" ")]
a=[int(i) for i in input().split(" ")]
b=[int(i) for i in input().split(" ")]

if (N>10**7) | (M>10**7) |(K>10**7):
    print(0)
else:
    time=0
    a_idx=0
    b_idx=0
    count=0
    while time<K:
        count+=1
        try:
            if a_idx+1==N:
                time+=b[b_idx]
                b_idx+=1
                if time>K:
                    count-=1
                continue
            elif b_idx+1==M:
                time+=a[b_idx]
                a_idx+=1
                if time>K:
                    count-=1
                continue    

            if a[a_idx]<b[b_idx]:
                time+=a[a_idx]
                a_idx+=1

            elif a[a_idx]>b[b_idx]:
                time+=b[b_idx]
                b_idx+=1
            else:
                try:
                    a_com=a_idx
                    b_com=b_idx
                    while True:
                        if a[a_com]>b[b_com]:
                            time+=a[a_idx]
                            a_idx+=1
                            break
                        elif a[a_com]<b[b_com]:
                            time+=b[b_idx]
                            b_idx+=1
                            break
                        a_com+=1
                        b_com+=1
                except:
                    time+=a[a_idx]
                    a_idx+=1
            if time>K:
                count-=1            
        except:
            break
    print(count)       

### FIXED CODE ###

a=int(input())
print(a+a**2+a**3)
if N % 10 == 2 or N % 10 == 4 or N % 10 == 5 or N % 10 == 7 or N % 10 == 9:
  print('hon')
elif N % 10 == 0 or N % 10 == 1 or N % 10 == 6 or N % 10 == 8:
  print('pon')
else:
  print('bon')

### FIXED CODE ###

n = int(input())

n_onesplace = n%10

if n_onesplace==2 or n_onesplace==4 or n_onesplace==5\
    or n_onesplace==7 or n_onesplace==9:
    print('hon')
elif n_onesplace==0 or n_onesplace==1 or\
    n_onesplace==6 or n_onesplace==8:
    print('pon')
else:
    print('bon')
print("YNeos"[eval(input().replace(" ","*")%2==0)::2])

### FIXED CODE ###

print("YNeos"[eval(input().replace(" ","*"))%2==0::2])
A = input()
B = input()
C = input()

xa = 0
xb = 0
xc = 0

#配列の次のカードの文字を返す
def next(X, i):
    if X[i] == 'a':
        return A[xa]
    elif X[i] == 'b':
        return B[xb]
    else:
        return C[xc]

h = 'A'
xa += 1
k = next(A, xa - 1) #最初

while True:
    if k == 'a':
        h = 'A'
        xa += 1
        if xa < len(A):
            k = next(A, xa - 1)
    elif k == 'b':
        h = 'B'
        xb += 1
        if xb < len(B):
            k = next(B, xb - 1)
    else:
        h = 'C'
        xc += 1
        if xc < len(C):
            k = next(C, xc - 1)

print(h)


### FIXED CODE ###

A = input()
B = input()
C = input()

xa = 0
xb = 0
xc = 0

h = 'A'
k = A[0] #最初の１枚を抜く
xa += 1

while True:

    if k == 'a':
        h = 'A'
        if xa < len(A):
            k = A[xa]
            xa += 1
        else:
            break
    elif k == 'b':
        h = 'B'
        xb += 1
        if xb < len(B):
            k = B[xb]
            xb += 1
        else:
            break
    elif k == 'c':
        h = 'C'
        xc += 1
        if xc < len(C):
            k = C[xc]
            xc += 1
        else:
            break

print(h)
import math
N = int(inport())
 
print(math.factorial(N)%(10**9+7))

### FIXED CODE ###

import math
N = int(input())
 
print(math.factorial(N)%(10**9+7))
n = int(input())

l = []
for i in range(n-1, 1, -1):
    if (n/i).is_integer() == True: 
        l.append(i)
        l.append(n/i)
        break
        
if l[0] < 10 and l[1] < 10:
    print('Yes')
else:
    print("No")

### FIXED CODE ###

n = int(input())
bool = False
for i in range(1, 10, 1):
    for j in range(1, 10, 1):
        if i*j == n:
            bool = True
            break
        else: 
            continue
            
if bool == True:
    print("Yes")
else: 
    print("No")
N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
        A = sorted(A,reverse = False) 
print(sum(A[:-N+1]))

### FIXED CODE ###

N, M = list(map(int,input().split()))
H = list(map(int,input().split()))
H = sorted(H,reverse = False) 

if N == 1:
    print(abs(H[M-1] - H[0]))
else:
    A = []
    for i in range(M-1):
        A.append(H[i+1] - H[i])
    A = sorted(A,reverse = False) 
    print(sum(A[:-N+1]))
n=input()
a=list(map(int,input().split()))

Max=0
Min=10**9

for i in a:
  if(Max<i):
    Max=i
  if(min>i):
    Min=i
print(abs(Max-Min))

### FIXED CODE ###

n=int(input())
mylist=list(map(int,input().split()))
mymax=max(mylist)
mymin=min(mylist)
print(abs(mymax-mymin))
n = int(input())
count = 0
for input in range(n):
    a, b = int(input().split())
    count += b-a+1

print(count)

### FIXED CODE ###

n = int(input())
count = 0
for i in range(n):
    a, b = map(int, input().split())
    count += b-a+1

print(count)
for x in range():

 for i in range(10000):
 
  if x == 0:
    break
  print(Case i : x)

### FIXED CODE ###

i = 1

while True:

 x=int(input())
 if x==0:
  break
 print("Case {0}: {1}".format(i,x))
 i+=1
tg="AC"
n,q=map(int,input().split())
text=input()
ans=[]

def check():
    l,r=map(int,input().split())
    text_=text[l-1:][:r-1]
    count=re.findall(tg,text_)
    ans.append(len(count))
    
for i in range(q):
    check()

for i in ans:
    print(i)

### FIXED CODE ###

n,q=map(int,input().split())
text=input()
sum_=[]
count=0
for i in range(n):
    if text[i-1]=='A' and text[i]=='C':
        count+=1
    sum_.append(count)
for i in range(q):
    l,r=map(int,input().split())
    print(sum_[r-1]-sum_[l-1])
# coding: UTF8
a, b, h = list(map(int, input().split("\n"))) 

S = int((a + b) * h // 2)
print(S)

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())
 
print(int((a+b)*h//2))
import math


def main():
    N = int(input())
    T = []
    A = []
    for i in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

    for i in range(N):
        if math.gcd(A[i], T[i]) != 1:
            A[i] = A[i] // math.gcd(A[i], T[i])
            T[i] = T[i] // math.gcd(A[i], T[i])

    for i in range(N - 1):

        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            if T[i] / T[i + 1] >= A[i] / A[i + 1]:
                A[i + 1] = math.ceil(T[i] / T[i + 1]) * A[i + 1]
                T[i + 1] = math.ceil(T[i] / T[i + 1]) * T[i + 1]
            else:
                T[i + 1] = math.ceil(A[i] / A[i + 1]) * T[i + 1]
                A[i + 1] = math.ceil(A[i] / A[i + 1]) * A[i + 1]
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()

### FIXED CODE ###

import math
from decimal import *

def main():
    N = int(input())
    T = []
    A = []
    for _ in range(N):
        t, a = map(int, input().split())
        T.append(t)
        A.append(a)

    for i in range(N - 1):
        if T[i] / T[i + 1] > 1 or A[i] / A[i + 1] > 1:
            mul = Decimal(max(math.ceil(T[i] / T[i + 1]), math.ceil(A[i] / A[i + 1])))
            A[i + 1] *= mul
            T[i + 1] *= mul
    print(T[N - 1] + A[N - 1])


if __name__ == "__main__":
    main()
a,b = map(int,input().split())
low = int(min(a//0.08,b//0.1))
high = int(max((a+1)//0.08,(b+1)//0.1))
for i in range(low,high+1):
    if int(i*0.08)==a and int(i*0.1)==b:
        print(i);  break
else:
    print(-1)

### FIXED CODE ###

s = input() 
print('No' if (s == 'BBB' or s == 'AAA') else 'Yes')
import math
 
N, M = map(int, input().split())

ans1 = 0
if N != 0:
  ans1 = math.factorial(N)/math.factorial(N-2)/2
ans2 = 0
if N != 0:
  ans2 = math.factorial(M)/math.factorial(M-2)/2
print(int(ans1 + ans2))

### FIXED CODE ###

N, M = map(int, input().split())
 
print(N*(N-1)//2+M*(M-1)//2)
#!/usr/bin/env python3
def main():
    def search_loop(now: int, loop: list):
        """iから探索を初めて，再びiに達するまでに通った点のスコアをリストとして返す"""
        seen[now] = True
        if now == i and loop:
            loops.append(loop)
            return
        loop.append(C[now])
        search_loop(P[now], loop)

    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    # ループを探す
    seen = [False] * N
    loops = []
    for i in range(N):
        if seen[i] is False:
            search_loop(i, [])

    # ループごとの最大スコアを探す
    ans = -10 ** 9
    for loop in loops:
        length = len(loop)
        sum_loop = sum(loop)
        # ループ長よりも操作回数が多く，ループを周回すると得な場合
        if K > length and sum_loop > 0:
            res = sum_loop * (K // length)
            limit = K % length
        # そうじゃない場合
        else:
            res = 0
            limit = K

        loop_temp = loop * 2  # loopリストに同じloopリストを接続する
        for k in range(1, limit + 1):
            for i in range(length):
                ans = max(ans, sum(loop_temp[i:i + k]) + res)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = -10 ** 9
    for start in range(N):
        # ループを探す
        now = start
        loop = []
        total = 0
        while now != start or not loop:
            loop.append(C[now])
            now = P[now]
            total += C[now]
        # ループごとの最大スコアを探す
        length = len(loop)
        # sum_loop = sum(loop)
        # # ループ長よりも操作回数が多いか？，ループを周回すると得か？で場合分け
        # res = 0 if sum_loop <= 0 else sum_loop * (K // length)
        # limit = K if K <= length else K % length
        # for k in range(limit):
        #     res += loop[k]
        #     ans = max(ans, res)
        t = 0
        for i in range(length):
            t += loop[i]
            if i + 1 > K:
                break
            now = t
            if total > 0:
                e = (K - (i + 1)) // length
                now += total * e
            ans = max(ans, now)
    print(ans)


if __name__ == '__main__':
    main()
x1, y1, x2, y2 = map(int, input().split(' '))


xdif = abs(x1 - x2)
ydif = abs(y1 - y2)

if x1<=x2 and y1<=y2:
     x3 = x2 - ydif
     y3 = y2 + xdif
     x4 = x3 - xdif
     y4 = y3 - xdif
elif x1<=x2 and y1>=y2:
     x3 = x2 + ydif
     y3 = y2 + xdif
     x4 = x1 + xdif
     y4 = y1 + ydif
elif x1>=x2 and y1<=y2:
     x3 = x2 - ydif
     y3 = y2 - xdif
     x4 = x1 - ydif
     y4 = y1 - xdif
else:
     x3 = x2 + ydif
     y3 = y2 - xdif
     x4 = x1 + ydif
     y4 = y1 - xdif
     
print(x3, y3, x4, y4)


### FIXED CODE ###

asdf = int(input())
if asdf % 2 == 0:
  k1 = asdf / 2
  Ans = k1 * k1
else:
  k2 = (asdf + 1) / 2
  k3 = k2 - 1
  Ans = k2 * k3
print(int(Ans))
n = int(input())
if n >=2:
  ans = (10**(n-2)*n*(n-1))/(10**9 + 7)
else:
  ans = 0
print(ans)

### FIXED CODE ###

n = int(input())
print((10**n -2*9**n +8**n) % 1000000007)
N = int(input())
num = [0,0,0,0,0]
for i in range(N):
  a = input()
  if a[0]=='M':
    num[0] += 1
  if a[0]=='A':
    num[1] += 1
  if a[0]=='R':
	num[2] += 1
  if a[0]=='C':
	num[3] += 1
  if a[0]=='H':
	num[4] += 1


num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10

print(answer)

### FIXED CODE ###

N = int(input())
num = [0,0,0,0,0]
for i in range(N):
	a = input()
	if a[0]=='M':
		num[0] += 1
	if a[0]=='A':
		num[1] += 1
	if a[0]=='R':
		num[2] += 1
	if a[0]=='C':
		num[3] += 1
	if a[0]=='H':
		num[4] += 1


num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10

print(answer)
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    ans = 0
    a = a[::-1]
    for i in range(n):
        ans += ans[(i + 1) // 2]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    ans = 0
    a = a[::-1]
    for i in range(1, n):
        ans += a[i // 2]
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()