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

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
aa = [0,0]
for i in range(n):
    if a[i] > aa[-1]:
        aa[-1] = a[i]
    else:
        if a[i] >= aa[-2]:
            aa[-2] = a[i]

if aa[-1] == aa[-2]:
    for i in range(n):
        print(aa[-1])
else:
    for i in range(n):
        if i == a.index(aa[-1]):
            print(aa[-2])
        else:
            print(aa[-1])

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
maxi = max(a)
s = sorted(a,reverse=True)
 
for i in range(n):
    if a[i] != maxi:
        print(maxi)
    else:
        print(s[1])
### BUGGY CODE ###

N,M=map(int,input().split())
X=[[] for x in range(N+1)]
city=[]
for i in range(M):
    P,Y=map(int,input().split())
    city.append((P,Y))
    X[P].append(Y)
S=[0]*(N+1)
for p,y in city:
    if S[p]==0:
        X[p].sort()
        S[p]=1
    num=X[p].index(y)+1
    print("%06d"%p+"%06d"%num)

### FIXED CODE ###

# ABC113 D 

N,M=map(int,input().split())

P=[[] for _ in [0]*(N+1)]

for i in range(M):
    p,y=map(int,input().split())
    P[p].append((y,i))
    
from bisect import bisect_left as bl

res=[]
for p in range(N+1):
    Y=P[p][:]
    if not Y:
        continue
    
    sortY=sorted(list(set(Y)))
        
    zatY=[]
    for t_y in Y:
        zatY.append(bl(sortY,t_y))
    
    for index in zatY:
        y,i=sortY[index]
        num=10**12+p*10**6+index+1
        res.append((str(num)[1:],i))

res=[y for y,i in sorted(res,key=lambda x:x[1])]
print(*res,sep='\n')
### BUGGY CODE ###

import bisect

N, Q = [int(x) for x in input().split()]
data = []
for i in range(N):
    S, T, X = [int(x) for x in input().split()]
    data.append([X, S, T])
data.sort()
D = [int(input()) for _ in range(Q)]

ans = [-1]*Q
for X, S, T in data:
    l = bisect.bisect_left(D, S - X - 0.5)
    r = bisect.bisect_right(D, T - X - 0.5)
    for i in range(l, r):
        if ans[i] == -1:
            ans[i] = X

for i in range(Q):
    print(ans[i])

### FIXED CODE ###

import sys
input=sys.stdin.readline
from bisect import bisect_left
n,q=map(int,input().split())
stop=[]
for i in range(n):
	s,t,x=map(int,input().split())
	stop.append((s,t,x))
stop.sort(key=lambda x:x[2])
d=[int(input())for i in range(q)]
R=[-1]*q
ans=[-1]*q
for s,t,x in stop:
	#lからrにある区間のansをxに更新したい
	l=bisect_left(d,s-x)
	r=bisect_left(d,t-x)
	while l<r:
		if R[l]==-1:#最左がまだ確定していない場合
			ans[l]=x
			R[l]=r
			l+=1
		else:
			l=R[l]#確定しているところを飛ばす
for x in ans:
	print(x)
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

AB = [ a+b for a in A for b in B] 
ABC = [ab+c for ab in AB for c in C]
ABCs = sorted(ABC, reverse=True)[:K]
for i in range(K):
  print(ABCs[i])

### FIXED CODE ###

X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

AB = [ a+b for a in A for b in B]
AB = sorted(AB, reverse=True)
AB = AB[:3000]
ABC = [ab+c for ab in AB for c in C]
ABCs = sorted(ABC, reverse=True)[:K]
for i in range(K):
  print(ABCs[i])
### BUGGY CODE ###

n, h = map(int,input().split())
a = []
b = []
for i in range(n):
    ca, cb = map(int,input().split())
    a.append(ca)
    b.append(cb)

a.sort(reverse=True)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > a[0]:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//a[0]
        h -= a[0] * (h//a[0])
        if h > 0:
            h -= a[0]
            cnt += 1
print(cnt)

### FIXED CODE ###

n, h = map(int,input().split())
a = []
b = []
for i in range(n):
    ca, cb = map(int,input().split())
    a.append(ca)
    b.append(cb)

amax = max(a)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > amax:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//amax
        h -= amax * (h//amax)
        if h > 0:
            h -= amax
            cnt += 1
print(cnt)
### BUGGY CODE ###

import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
def lcm_n(nums):
    return functools.reduce(lcm, nums)

n = ni()
a = na()

a_lcm = lcm_n(a)
ans = 0
for ai in a:
    ans += a_lcm // ai
    ans %= mod
print(ans)

### FIXED CODE ###

import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
def lcm_n(nums):
    return functools.reduce(lcm, nums)

n = ni()
a = na()
a_lcm = lcm_n(a)
ans = 0
for ai in a:
    ans += a_lcm // ai
ans %= mod
print(ans)
### BUGGY CODE ###

from sys import stdin
n = int(stdin.readline().rstrip())
sary = [stdin.readline().rstrip() for _ in range(n)]

res = 0
for i in range(n):
    for j in range(i+1, n):
        if str(sorted(sary[i])) == str(sorted(sary[j])):
            res += 1

print(res)

### FIXED CODE ###

from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = sorted(["".join(sorted(stdin.readline().rstrip())) for _ in range(n)])

gr = groupby(sary)

res = 0

for k, g in gr:
    num = len(list(g))
    if  num >= 2:
        res += num * (num - 1) // 2

print(res)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
adj = [set() for _ in range(N)]
colors = dict()
ed = []
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].add(b)
    adj[b].add(a)
    colors[(a, b)] = 0
    ed.append([a, b])

col = max(len(v) for v in adj)
cand = set([v for v in range(1, col+1)])

s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break

Q = [[s, -1, -1]]
while Q:
    cur, prev, NG = Q.pop()
    for nex, c in zip(adj[cur]-{prev}, cand-{NG}):
        colors[(min(cur, nex), max(cur, nex))] = c
        Q.append([nex, cur, c])
print(col)
for a, b in ed:
    print(colors[(a, b)])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
adj = [set() for _ in range(N)]
colors = dict()
ed = []
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    adj[a].add(b)
    adj[b].add(a)
    ed.append([a, b])

col = max(len(v) for v in adj)

s = -1
for i, a in enumerate(adj):
    if len(a) == col:
        s = i
        break

Q = [[s, -1, -1]]
while Q:
    cur, prev, NG = Q.pop()
    c = 0
    for nex in adj[cur]:
        if nex == prev:
            continue
        else:
            c += 1
        if c == NG:
            c += 1
        colors[min(cur, nex)*N + max(cur, nex)] = c
        Q.append([nex, cur, c])
print(col)
for a, b in ed:
    print(colors[a*N + b])
### BUGGY CODE ###

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

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2
    ans[k]+=sum(f.values())
    ans[k]-=f[k]

for i in range(n):
    print(int(ans[a[i]]))


### FIXED CODE ###

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

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
s=sum(f.values())
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2 + s- f[k]

for i in range(n):
    print(int(ans[a[i]]))
### BUGGY CODE ###

N, K, C, = map(int,input().split())
S = list(input())
ans = []

def solve(index, K):
    i = 0
    cnt = 0
    while i < N:
        if S[i] == 'o' and i != index:
            cnt += 1
            i += C + 1
        else:
            i += 1
    return cnt < K

if not (solve(-1, K+1)):
    pass
else:
    index = 0
    while index < N:
        if S[index] == 'x':
            index += 1
        elif solve(index, K):
            ans.append(index + 1)
            index += C + 1
        else:
            index += 1

    for i in ans:
        print(i)

### FIXED CODE ###

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

def solve(List):
    ans = []
    i = 0
    while i < N:
        if List[i] == 'o':
            ans.append(i+1)
            i += C
        i += 1
    return ans

n = solve(S)

if len(n) > K:
    pass
else:
    r = solve(S[::-1])
    r = list(map(lambda x: N+1-x, r[::-1]))
    ans = list(set(n) & set(r))
    ans.sort()
    for i in ans:
        print(i)
### BUGGY CODE ###

import math
a, b, c = map(int,input().split())

for i in range(10**7):
    n = a * i
    if n % b == c:
        print('YES')
        quit()
print('NO')

### FIXED CODE ###

a, b, c = map(int,input().split())

for i in range(b):
    n = a * i
    if n % b == c:
        print('YES')
        quit()
print('NO')
### BUGGY CODE ###

def main():
    x, y = map(int, input().split())
    if x == y:
        return print('-1')
    for i in range(1000000000):
        if (i * x) % y != 0:
            return print(i*x)
main()


### FIXED CODE ###

def main():
    x, y = map(int, input().split())
    if x % y == 0:
        return print('-1')
    for i in range(1000000000):
        if (i * x) % y != 0:
            return print(i*x)
main()
### BUGGY CODE ###

k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
  for y in range(k + 1):
    for z in range(k + 1):
      if x + y + z == s:
        ans += 1
 
print(ans)
      

### FIXED CODE ###

# https://atcoder.jp/contests/abc051/tasks/abc051_b
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            ans += 1

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

HP,n = map(int,input().split())
s = [tuple(map(int,input().split())) for i in range(n)]

dp = [float('inf')]*(HP+1) #0~HP
dp[0] = 0
for damage, cost in s:
    for hp in range(HP):
        next_idx = min(hp+damage, HP)
        dp[next_idx] = min(dp[next_idx], dp[hp]+cost)
print(dp[-1])

### FIXED CODE ###

HP,n = map(int,input().split())
s = [tuple(map(int,input().split())) for i in range(n)]

#dp[damage] := モンスターにdamageを与える最小コスト
dp = [float('inf')]*(HP+1) #0~HP
dp[0] = 0
for damage, cost in s:
    for hp in range(HP):
        next_idx = min(hp+damage, HP)
        dp[next_idx] = min(dp[next_idx], dp[hp]+cost)
print(dp[-1])
### BUGGY CODE ###

import bisect

n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]

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

a.sort()

s=0
if s%2:
  for i in range(n):
    s += abs(a[i]-a[n//2])
  print(s)
else:
  m=10**14
  for i in range(a[n//2-1], a[n//2]+1):
    s = 0
    for j in range(n):
      s += abs(a[j]-i)
    m = min(m,s)
  print(s)


### FIXED CODE ###

n=int(input())
a=[int(x) for x in input().split()]
s=[0 for x in range(n)]
 
for i in range(n):
  a[i] -= i+1
 
a.sort()
 
s = 0
for j in range(n):
  s += abs(a[j]-a[n//2])
print(s)
### BUGGY CODE ###

import math

n = int(input())
r_t = [int(input().strip()) for i in range(n)]

r_i = r_t[0]
r_i_index = 0
diff = -math.inf
for _ in range(1, n):
    r_j = max(r_t[r_i_index+1:])

    tmp_diff = r_j - r_i

    if tmp_diff > diff:
        diff = tmp_diff

    for i in range(r_i_index, n):
        tmp_r_i = r_t[i]
        if tmp_r_i < r_i:
            r_i = tmp_r_i
            r_i_index = r_t.index(r_i)
            break

    if r_i_index + 1 >= n:
        break

print(diff)


### FIXED CODE ###

import math

N = int(input())
R = [int(input().strip()) for _ in range(N)]

maxv = -math.inf
minv = R[0]
for i in range(1, N):

    tmp_maxv = R[i] - minv # 差額をセットする
    # 現在の最大差額と差額の大きい方を最大差額にする
    if maxv < tmp_maxv:
        maxv = tmp_maxv

    # 現在値が最小なら、最小値を更新する
    if R[i] < minv:
        minv = R[i]

print(maxv)
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1,n):
    ti = n-i
    for j in range(1,ti+1):
        if ti%j == 0:
            ans+=1
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1,n):
    if n%i == 0:
        ans+=(n//i)-1
    else:
        ans+=n//i
print(ans)
### BUGGY CODE ###

import math
def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

num = [0] * N

for i in A:
    num[i - 1] = num[i - 1] + 1

a = [0] * N
b = [0] * N

for i in range(N):
    if num[i] >= 3:
        a[i] = comb(num[i] - 1, 2)
        b[i] = comb(num[i] - 1, 1)
    elif num[i] == 2:
        a[i] = 0
        b[i] = 1

for i in A:
    print(sum(a) + sum(b) - b[i - 1])

### FIXED CODE ###

import math

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

num = [0] * N

for i in A:
    num[i - 1] = num[i - 1] + 1

a = [0] * N
b = [0] * N

for i in range(N):
    if num[i] >= 2:
        a[i] = (num[i] - 1) * (num[i] - 2) // 2
        b[i] = num[i] - 1

sum_a = sum(a)
sum_b = sum(b)

for i in A:
    print(sum_a + sum_b - b[i - 1])
### BUGGY CODE ###

# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
L = read_ints()
L.sort()
import numpy as np
L = np.array(L)

cnt = 0
for i in range(N):
    a = L[i]
    L_tmp = L[i+1:]
    for j, b in enumerate(L_tmp):
        L_tmp2 = L_tmp[j+1:]
        cnt += np.sum(L_tmp2 < b+a)

print(cnt)


### FIXED CODE ###

# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
L = read_ints()
L.sort()
# import numpy as np
# L = np.array(L)
from bisect import bisect_left

cnt = 0
for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        # ここで二分探索するか
        cnt += bisect_left(L, a+b) - (j+1)
        # L_tmp = L[j+1:]
        # cnt += np.sum(L_tmp < b+a)

print(cnt)
### BUGGY CODE ###

s = input()

cnt_l = [0]*(len(s)+1)
cnt_r = [0]*(len(s)+1)

for i in range(len(s)+1):
    if i == 0:
        cnt_l[i] = 0
    else:
        if s[i-1] == "<":
            cnt_l[i] = cnt_l[i-1] + 1
        else:
            cnt_l[i] = 0

    if i == len(s):
        cnt_r[i] = 0
    else:
        if s[i] == ">":
            j = i
            tr = 0
            while j < len(s) and s[j] == ">":
                tr += 1
                j += 1
            cnt_r[i] = tr
        else:
            cnt_r[i] = 0

ans = 0
for l, r in zip(cnt_l, cnt_r):
    ans += max(l, r)
print(ans)


### FIXED CODE ###

s = input()

cnt_l = [0]*(len(s)+1)
cnt_r = [0]*(len(s)+1)

for i in range(1, len(s)+1):
    if s[i-1] == "<":
        cnt_l[i] = cnt_l[i-1] + 1
    else:
        cnt_l[i] = 0

for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        cnt_r[i] = cnt_r[i+1]+1
    else:
        cnt_r[i] = 0

ans = 0
for l, r in zip(cnt_l, cnt_r):
    ans += max(l, r)
print(ans)
### BUGGY CODE ###


n, q = [int(x) for x in input().split()]

edge = [[] for _ in range(n)]

counter = [0] * n

for _ in range(n-1):
    a, b = [int(x) for x in input().split()]
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

for _ in range(q):
    a, b = [int(x) for x in input().split()]
    counter[a-1] += b

parent = [0]

for i in parent:
    for v in edge[i]:
        if v in parent:
            continue
        parent.append(v)
        counter[v] += counter[i]
        
print(" ".join(map(str, counter)))

### FIXED CODE ###


# n, q = map(int, input().split())

# edge = [[] for _ in range(n)]

# counter = [0] * 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 _ in range(q):
#     a, b = map(int, input().split())
#     counter[a-1] += b

# parent = [0]
# visited = []

# for i in parent:
#     visited.append(i)
#     for v in edge[i]:
#         if v in visited:
#             continue
#         parent.append(v)
#         counter[v] += counter[i]
        
# for i in range(n):
#     print(counter[i], end=" ")
# print("")

import sys
input = sys.stdin.readline
 
N, Q = [int(x) for x in input().split()]
 
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
 
cost = [0] * N
for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    cost[p - 1] += x
 
next = [0]
s_next = {0}
for i in next:
    for v in edge[i]:
        if v in s_next:
            continue
        s_next.add(v)
        next.append(v)
        cost[v] += cost[i]
 
print(" ".join(map(str, cost)))
### BUGGY CODE ###

N=int(input())
P=[list(map(int,input().split())) for _ in range(N)]
cost=0
PL=[False]*N
count=0
a={}
for i in range(N-1):
    for j in range(i+1,N):
        x=abs(P[i][0]-P[j][0])
        y=abs(P[i][1]-P[j][1])
        r=min(x,y)
        try:
            l=a[r]
            l.append([i,j])
            a[r]=l
        except:
            a[r]=[[i,j]]
c=0
while True:
    if(count>=N-1):
        print(cost)
        break
    try:
        l=a[c]
    except:
        c+=1
        continue
    try:
        t=l[0][0]
        for item in l:
            if(PL[item[0]]==False or PL[item[1]]==False):
                cost+=c
                PL[item[0]]=True
                PL[item[1]]=True
                count+=1
    except:
        if(PL[l[0]]==False or PL[l[1]]==False):
            cost+=c
            PL[l[0]]=True
            PL[l[1]]=True
            count+=1
    c+=1

### FIXED CODE ###

class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]
 
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
def cal(d,xl):
    N=len(xl)
    for i in range(N-1):
        r1=abs(xl[i+1][0]-xl[i][0])
        try:
            l=d[r1]
            l.append([xl[i+1][1],xl[i][1]])
            d[r1]=l
        except:
            d[r1]=[[xl[i+1][1],xl[i][1]]]
    return d
N=int(input())
x=[[0,0] for _ in range(N)]
y=[[0,0] for _ in range(N)]
for i in range(N):
    x[i][0],y[i][0]=list(map(int,input().split()))
    x[i][1],y[i][1]=i,i
x=sorted(x,key=lambda l: l[0])
y=sorted(y,key=lambda l: l[0])
a=cal(cal({},x),y)
p=UnionFind(N)
c=0
cost=0
edgecount=0
while True:
    if(edgecount==N-1):
        print(cost)
        break
    try:
        l=a[c]
        for item in l:
            if(p.union(item[0],item[1])):
                cost+=c
                edgecount+=1
            
        c+=1
    except:
        c+=1
        continue
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy

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

A.sort(reverse=True)
#print(A)

ans = 0
list = []
for i in range(N):
  if ( i==0 ) :
    list.append(A[0])
  else:
    max_index = numpy.argmax(list)
    ans += list[max_index]
    list[max_index] = A[i]
    list.insert(max_index, A[i])
  #print(list,ans)

print(ans)

### FIXED CODE ###

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

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

A.sort(reverse=True)
#print(A)

"""
ans = 0
list = []
for i in range(N):
  if ( i==0 ) :
    list.append(A[0])
  else:
    max_index = list.index(max(list))
    ans += list[max_index]
    list[max_index] = A[i]
    list.insert(max_index, A[i])
  #print(list,ans)
"""

ans = 0
for i in range(N):
  if ( i==0 ) :
    ans += 0
  else:
    ans += A[i//2]

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

from collections import Counter
import math

n, m = list(map(int, input().split(" ")))
a_list = list(map(int, input().split(" ")))

cum_list = [sum(a_list[:i+1]) % m for i in range(n)]

count = Counter(cum_list)
ans = 0
for k in list(count.values()):
    if k > 1:
        ans += math.factorial(k) / (math.factorial(k - 2) * 2)

ans += count[0]
print(int(ans))


### FIXED CODE ###

from collections import Counter
from scipy.misc import comb
 
N, M = map(int, input().split())
A = list(map(int, input().split()))
X = [0]
for a in A:
    X.append((X[-1] + a) % M)
 
X = Counter(X)
ans = 0
for num in X.values():
    ans += comb(num, 2, 1)
 
print(ans)
### BUGGY CODE ###

import itertools
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in itertools.combinations(l,3):
	a,b,c=map(int,i)
	if a<b+c and b<c+a and c<a+b:
		ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
import bisect
for i in range(N):
    for j in range(i+1,N-1):
        m=bisect.bisect_left(l,l[i]+l[j])
        count+=m-(j+1)
print(count)
### BUGGY CODE ###

from operator import itemgetter

n,m,q=map(int,input().split())
l=[]
fa=[m]*n

def check_list(la: list):
    for i in range(len(la)-1):
        if la[i+1]<la[i] or la[i]>m or la[i]<1:
            return False
    
    return True


def dfs(i,a):
    if not check_list(a):
        return -1
    elif i==len(l):
        ret=0
        for i in range(len(a)-1):
            if a[i+1]<a[i] or a[i]>m:
                ret=-1

        for le in l:
            if a[le[1]-1]-a[le[0]-1]==le[2]:
                ret+=le[3]
        return ret
    else:
        c0=a.copy()     # use this (change first)
        c1=a.copy()     # use this (change second)
        c2=a.copy()     # dojn't use this
        c0[l[i][0]-1]=c0[l[i][1]-1]-l[i][2]
        c1[l[i][1]-1]=c1[l[i][0]-1]+l[i][2]
        return max(dfs(i+1,c0),dfs(i+1,c1),dfs(i+1,c2))




for _ in range(q):
    l.append(tuple(map(int,input().split())))

l.sort(key=lambda x:x[3],reverse=True)

print(dfs(0,fa))

### FIXED CODE ###

import itertools
n,m,q=map(int,input().split())

ql=[]
for _ in range(q):
    ql.append(tuple(map(int,input().split())))

def check(t):
    ret=0
    for q in ql:
        if t[q[1]-1]-t[q[0]-1]==q[2]:
            ret+=q[3]

    return ret

print(max(map(check,itertools.combinations_with_replacement(range(1,m+1),n))))