Harryxun/stf_run huggingface dataset:
n = int(input());
s = [0]*n;
for i in range(n) :
	s_pre = list(input());
	s_pre.sort();
	s[i] = s_pre;


s.sort(key=lambda x:(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]));

ans = 0;
for i in range(1,n) :
	ok = 1;
	k = 1;
	while s[i-k][9]==s[i][9] :
		#for j in range(10) :
			#if s[i-k][j] != s[i][j] :
				#ok = 0;
		if  s[i-k]==s[i]:
			ans += 1;
		k += 1;

print(ans);

### FIXED CODE ###

import math

n = int(input());
s = [0]*n;
for i in range(n) :
	s_pre = list(input());
	s_pre.sort();
	s[i] = s_pre;


s.sort(key=lambda x:(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]));

ans = 0;
ren = 0;
for i in range(1,n) :
	ok = 1;
	if s[i-1]==s[i]:
		ans += 1;
		ans += ren;
		ren += 1;
	else :
		ren = 0;

print(ans);
N, M, X, Y = list(map(int,input().split(' ')))
x = list(map(int,input().split(' ')))
y = list(map(int,input().split(' ')))

ans = 'War'
for i in range(X,Y+1):
  if  max(x) < i <= min(y) and X < i <=y:
    ans ='No War'
    break
    

print(ans)    
    
    
    
    
  


### FIXED CODE ###

N, M, X, Y = list(map(int,input().split(' ')))
x = list(map(int,input().split(' ')))
y = list(map(int,input().split(' ')))

ans = 'War'
for i in range(X+1,Y+1):
  if  max(x) < i <= min(y):
    ans ='No War'
    break
    

print(ans)
N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 2N, Q =  map(int, (input().split(' ')))
S = str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = [0] * N
print(N)
print(Q)
print(S)
i = 0
while i < len(S):
    if S[i] == "A":
        if S[i+1] == "C":
            save[i] = 1
        i += 1
    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))




    elif S[i] == "C":
        i += 1
    else:
        i+=1

for left, right in lr:
    print(sum(save[left-1: right-1]))





### FIXED CODE ###

N, Q =  map(int, (input().split(' ')))
S = ' '+str(input())
lr = [tuple(map(int, input().split(' '))) for _ in range(Q)]
save = ''
#i = 0
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, h, x):
        while h <= self.size:
            self.tree[h] += x
            h += h & -h

bit = Bit(N)     # 要素数を与えてインスタンス化
i = 1
while i < len(S)-1:
    if S[i] == "A":
        if S[i+1] == "C":
            bit.add(i, 1)    # a2に10を加える
        else:
            pass
    i += 1

for left, right in lr:
    print(bit.sum(right-1) - bit.sum(left-1)) # a1～a6の合計を返す => 9
n,d=map(int,input().split())
lists=[list(map(int,input().split())) for x in range(n)]
answer=0
for i in range(1,n):
  for j in range(i+1,n+1):
    count=o
    for y in range(d):
      count+=(lists[j-1][y]-lists[i-1][y])**2
    t=count**(1/2)
    if t.is_integer():
      answer+=1
print(answer)

### FIXED CODE ###

n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    sum=0
    for dd in range(d):
      sum+=(l[i][dd]-l[j][dd])**2
    if sum**0.5==int(sum**0.5):
      cnt+=1
print(cnt)
import numpy as np
N,M = map(int,input().split())
nodes = [[False]* N for j in range(N)]
for m in range(M):
	a,b = map(int,input().split())
	nodes[a-1][b-1] = True
	nodes[b-1][a-1] = True
mat1 = np.matrix(nodes,dtype=bool)
mat2 = mat1.copy()
A = [mat1.tolist()]
for i in range(10):
	mat2 = mat2.dot(mat1)
	a = mat2.tolist()
	A.append(a)

white = [i for i in range(N)]
Colour = [0] * N
paint = []
Q = int(input())
for q in range(Q):
	line = list(map(int,input().split()))
	paint.append(line)
white2 = white[:]
paint.reverse()
for p in paint:
	v,d,c = p[0],p[1],p[2]
	if d == 0 and v - 1 in w:
		Colour[v - 1] = c
		white2.remove(v - 1)
		continue
	elif d == 0:
		continue
	else:
		for w in white:
			if d == 1:
				if not A[0][v - 1][w]:
					continue
				else:
					Colour[w] = c
					white2.remove(w)
			else:
				if A[d - 1][v - 1][w] or A[d - 2][v - 1][w]:
					Colour[w] = c
					white2.remove(w)
		if len(white2) == 0:
			break
	if v - 1 in white:
		Colour[v - 1] = c
		if v - 1 in white2:
			white2.remove(v - 1)
	white = white2[:]

for C in Colour:
	print(C)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
A = A[N:]
B = A[::2]
print(sum(B))
import collections

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])



### FIXED CODE ###

from collections import Counter

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])
N, A, B = map(int, input().split())

if(A > B):
  print(0)
elif (A == B):
    print(1)
  else:
    print(0)
else:
  if (N == 1):
    print(0)
  else:
    print((B-A)*(N-2) + 1)

### FIXED CODE ###

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

if(A > B):
  print(0)
elif (A == B):
    print(1)
else:
  if (N == 1):
    print(0)
  else:
    print((B-A)*(N-2) + 1)
n,q,k = map(int,input().split())
attend = [k-q for i in range(n)]
a = 0
for i in range(q):
    a = int(input())
    attend[a-1]+= 1
for i in range(n):
    if (attend[i] <= 0):
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n,k,q = map(int,input().split())
attend = [k-q for i in range(n)]
a = 0
for i in range(q):
    a = int(input())
    attend[a-1]+= 1
for i in range(n):
    if (attend[i] <= 0):
        print("No")
    else:
        print("Yes")
N = int(input())
P = list(map(int, input().split()))

c = 0
for i in range(N):
    flag = 1
    for j in range(i):
        if P[j] < P[i]: 
            flag = 0 
            break
    if flag > 0:
        c += 1

print(c)

### FIXED CODE ###

N, M = map(int, input().split())
print("YNeos"[N!=M::2])
N, K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range (N-1)]

import sys
sys.setrecursionlimit(10**10)
edge = [[] for _ in range(N)]
for u,v in AB:
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

MOD = 10**9+7
mod = 10 ** 9 + 7
MAX = K+10
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def cominit():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2,MAX):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
def cmb(n,r):
    if n < 0 or r < 0 or r > n:return 0
    if r > n/2: r = n-r        
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod
    
cominit()



visited = [False]*N
visited[0] = True
def dfs(s,ans):
    M = len(edge[s])-1*(s!=0)
    if M==0:
        return ans
    if s==0:
        ans *= fac[max(0, K-1)] * finv[max(0,K-1-M)]
        ans %= MOD
    else:
        ans *= fac[max(0,K-2)] * finv[max(0, K-2-M)]
        ans %= MOD

    for nv in edge[s]:
        if visited[nv]:continue
        visited[nv] = True
        ans = dfs(nv, ans)
    
    return ans

print(dfs(0,K))





### FIXED CODE ###

N, K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range (N-1)]

import sys
sys.setrecursionlimit(10**9)
edge = [[] for _ in range(N)]
for u,v in AB:
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

MOD = 10**9+7
mod = 10 ** 9 + 7
MAX = K+10
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def cominit():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2,MAX):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
def cmb(n,r):
    if n < 0 or r < 0 or r > n:return 0
    if r > n/2: r = n-r        
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

def permu(n,r):
    if n<=0 or r<=0 or r>n: return 0
    return (fac[n]*finv[n-r])%MOD
cominit()



visited = [False]*N
visited[0] = True
def dfs(s,ans):
    M = len(edge[s])-1*(s!=0)
    if M==0:
        return ans
    if s==0:
        ans *= permu(K-1, M)
        ans %= MOD
    else:
        ans *= permu(K-2, M)
        ans %= MOD

    for nv in edge[s]:
        if visited[nv]:continue
        visited[nv] = True
        ans = dfs(nv, ans)
    
    return ans

print(dfs(0,K)%MOD)
V

### FIXED CODE ###

R = int(input())
G = int(input())

print(2*G-R)
a,b,c,k=map(int,input().split())
n=k-a-b
if n>=0 
    print(a-n)
elif n<0 and a<=k:
    print(a)
elif n<0 and a>k:
    print(k)

### FIXED CODE ###

a,b,c,k=map(int,input().split())
n=k-a-b
if n>=0: 
    print(a-n)
elif n<0 and a<=k:
    print(a)
elif n<0 and a>k:
    print(k)
tmp = input()
A = int(tmp.split()[0])
B = int(tmp.split()[1])
 
res = 0
if A%2 == 0:
	if B%2 == 0:
		res = B^((B-A)/2%2)
	else :
		res = (B-A+1)/2%2
else :
	if B%2 == 0:
		res = A^B^((B-A-1)/2%2)
	else :
		res = A^((B-A)/2%2)

print(res)

### FIXED CODE ###

tmp = input()
A = int(tmp.split()[0])
B = int(tmp.split()[1])
 
res = 0
if A%2 == 0:
	if B%2 == 0:
		res = B^(int((B-A)/2)%2)
	else :
		res = int((B-A+1)/2)%2
else :
	if B%2 == 0:
		res = A^B^(int((B-A-1)/2)%2)
	else :
		res = A^(int((B-A)/2)%2)
print(res)
n = int(input())
a = list(map(int, input().split()))

r = -1
s = 0

ans = 0
for l in range(n):
    while r < n and not (s & a[r+1]):
        s ^= a[r+1]
        r += 1
    ans += r - l + 1
    s ^= a[l]

print(ans)


### FIXED CODE ###

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

r = 0
s = 0

ans = 0
for l in range(n):
    while r < n and not (s & a[r]):
        s ^= a[r]
        r += 1
    ans += r - l
    s ^= a[l]

print(ans)
n,k = 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,k):
  if n == 1:
    if k == 0:
      return 0
    else:
      return 1
  elif k <= a[n-1]+1:
    return f(n-1,k-1)
  elif k == p[n]:
    return p[n-1]+1
  elif k <= a[n]*2+3:
    return p[n-1]+1+f(n-1,k-2-a[n-1])
print(f(n,k))



### FIXED CODE ###

n,k = 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,k):
  if n == 0:
    if k == 0:
      return 0
    else:
      return 1
  if k == 0:
    return 0
  elif k <= a[n-1]+1:
    return f(n-1,k-1)
  else:
    return p[n-1]+1+f(n-1,k-2-a[n-1])
print(f(n,k))
from collections import Counter
a=input()
c=Counter(a)
if n==1:print(1)
else:
    ans=n*(n-1)//2
    for i in c.values():
        if i==1:continue
        else:ans-=i*(i-1)//2
    print(ans+1)


### FIXED CODE ###

from collections import Counter
a=input()
c=Counter(a)
n=len(a)
if n==1:print(1)
else:
    ans=n*(n-1)//2
    for i in c.values():
        if i==1:continue
        else:ans-=i*(i-1)//2
    print(ans+1)
a, b = map(int(input()))

print(max(a + b, a - b, a * b))

### FIXED CODE ###

a, b = map(int, input().split())
print(max(a + b, a - b, a * b))
l,r=map(int(input().split()))
d=int(input())

print(r//d-l//d)

### FIXED CODE ###

l,r,d = map(int,input().split())

if l%d ==0:
  print(r//d - l//d +1)
else:
  print(r//d-l//d)
#!/usr/bin/env python3


def f(a, b):
    return (a, b) if a < b else (b, a)


def dfs(s, p):
    for k, t in enumerate(g[s]):
        idx = rev[f(s, t)]
        if t == p or ans[idx] > 0:
            continue
        ans[idx] = k + 1
        dfs(t, s)

n = int(input())
g = [[] for _ in range(n)]
rev = {}
for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)
    rev[(a, b)] = i
ans = [0] * (n - 1)
dfs(0, -1)
print(max(ans), *ans, sep='\n')


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)


def f(a, b):
    return (a, b) if a < b else (b, a)


def dfs(s, p):
    used = {}
    for t in g[s]:
        idx = rev[f(s, t)]
        if ans[idx] > 0:
            used[ans[idx]] = True 
    c = 1
    for t in g[s]:
        idx = rev[f(s, t)]
        if t == p or ans[idx] > 0:
            continue
        while c in used:
            c += 1
        ans[idx] = c
        c += 1
        dfs(t, s)
        

n = int(input())
g = [[] for _ in range(n)]
rev = {}
for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)
    rev[(a, b)] = i
ans = [0] * (n - 1)
dfs(0, -1)
print(max(ans), *ans, sep='\n')
while True:
    try:
        a, b, n = map(int, input().split())
    except:
        break

    sum = 0
    s = list(str(a/b))
    for i in s[2:2+n]:
        sum += int(i)

    print(sum)

### FIXED CODE ###

while True:
    try:
        a, b, n = map(int, input().split())
    except:
        break

    s = str(a/b)
    sum = 0
    x = s.index(".")+1
    for i in s[x:x+n]:
        sum += int(i)

    print(sum)
h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
m = 2*80*80
DP = [[[0]*m for i in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        k = abs(a[i][j]-b[i][j])
        if i==0 and j==0:
            DP[i][j][k] = 1
        else:
            for l in range((i+j+1)*80+1):
                DP[i][j][l] = DP[i][j-1][abs(l-k)] | DP[i][j-1][l+k] | DP[i-1][j][abs(l-k)] | DP[i-1][j][l+k]
print(DP[-1][-1].index(1))

### FIXED CODE ###

import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

h,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ma = 80*2*80
DP = [[[0]*ma for i in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        k = abs(a[i][j]-b[i][j])
        if i==0 and j==0:
            DP[i][j][k] = 1
            continue
        elif i == 0:
            up = min((i+j+1)*80+1, ma-k)
            for l in range(up):
                DP[i][j][l] = DP[i][j-1][abs(l-k)] | DP[i][j-1][l+k]
        elif j == 0:
            for l in range(up):
                DP[i][j][l] = DP[i-1][j][abs(l-k)] | DP[i-1][j][l+k]
        else:
            for l in range(up):
                DP[i][j][l] = DP[i][j-1][abs(l-k)] | DP[i][j-1][l+k] | DP[i-1][j][abs(l-k)] | DP[i-1][j][l+k]
for i in range(ma):
    if DP[-1][-1][i]:
        print(i)
        exit()
N = int(input())
H = list(map(int, input().split()))
start = N - 1
moves = []
for i in range(N-1, 0, -1):
    if H[i] <= H[i-1]:
        continue
    moves.append(start - i)
    start = i - 1
if H[1] <= H[1]:
    moves.append(start - i + 1)
print(max(moves))

### FIXED CODE ###

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

if N == 1:
    print(0)
    quit()
start = N - 1
moves = []
for i in range(N-1, 0, -1):
    if H[i] <= H[i-1]:
        continue
    moves.append(start - i)
    start = i - 1
if H[1] <= H[0]:
    moves.append(start - i + 1)
print(max(moves))
n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())
map_list.sort(key=lambda x:x[2])

def function():
    x = int(map_list[-1][0])
    y = int(map_list[-1][1])
    h = int(map_list[-1][2])

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(i - x) + abs(j - y) + h
        
            for data in map_list:
                x, y, h = map(int, data)
                if h != max(H - abs(x - i) - abs(y - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H
        if cont_check:
            return i, j, H

i, j, H = function()
print(i, j, H)


### FIXED CODE ###

n = int(input())
map_list = []
for _ in range(n):
    map_list.append(input().split())

def function():
    for i in range(101):
        if int(map_list[i][2]) > 0:
            x = int(map_list[i][0])
            y = int(map_list[i][1])
            h = int(map_list[i][2])
            break
        else:
            continue

    for i in range(101):
        for j in range(101):
            cont_check = True
            H = abs(x - i) + abs(y - j) + h
            
            for data in map_list:
                xx, yy, hh = map(int, data)
                if hh != max(H - abs(xx - i) - abs(yy - j), 0):
                    cont_check = False
                    break
            if cont_check:
                return i, j, H

i, j, H = function()
print(i, j, H)
n = int(input())
a_l = list(map(int, input().split()))
a_l.sort()
b_l = list()

length = len(a_l)
k = 0
for i in range(length):
  if a_l[i] < 0:
    k = i
  else:
    break

b_l = a_l[:k+1]
a_l = a_l[k+1:]
fu = len(b_l)
sei = len(a_l)
ans_l = list()
ans_ll = list()
if sei > fu:
  sa = sei-fu-1
  ans_ll.append(a_l[-1])
  for i in range(fu):
    ans_l.append([b_l[i], a_l[-i-2]])
    ans_ll.append(b_l[i]-a_l[-i-2])
  aa_l = a_l[:sa]
  aa = 0
  for i in range(len(aa_l)-1):
    ans_l.append([aa_l[i], aa_l[i+1]])
    aa = aa_l[i] - aa_l[i+1]
  ans_ll.append(aa)
  ans_ll.sort()
  lent = len(ans_ll)
  for i in range(lent-1):
    ans_l.append([ans_ll[-1], ans_ll[i]])
    ans_ll[-1] = ans_ll[-1]-ans_ll[i]
elif sei < fu:
  sa = fu-sei+1
  ans_ll += b_l[:sa]
  ans_ll.append(a_l[-1])
  b_l = b_l[sa:]
  for i in range(len(b_l)):
    ans_l.append([b_l[i], a_l[-i-2]])
    ans_ll.append(b_l[i]-a_l[-i-2])
  ans_ll.sort()
  lent = len(ans_ll)  
  for i in range(lent-1):
    ans_l.append([ans_ll[-1], ans_ll[i]])
    ans_ll[-1] = ans_ll[-1]-ans_ll[i]
else:
  for i in range(sei):
    if i == 0:
      ans_l.append([a_l[-i-1], b_l[i]])
      ans_ll.append(a_l[-i-1]-b_l[i])
    else:
      ans_l.append([b_l[i], a_l[-i-1]])
      ans_ll.append(b_l[i]-a_l[-i-1])
  ans_ll.sort()
  lent = len(ans_ll)  
  for i in range(lent-1):
    ans_l.append([ans_ll[-1], ans_ll[i]])
    ans_ll[-1] = ans_ll[-1]-ans_ll[i]
    
ans_length = len(ans_l)
print(ans_ll[-1])
for i in range(ans_length):
  a = ans_l[i][0]
  b = ans_l[i][1]
  print(a, b)
  
    
                 
    
    
    
  


### FIXED CODE ###

n = int(input())
a_l = list(map(int, input().split()))
a_l.sort()
b_l = list()

length = len(a_l)
k = 0
for i in range(length):
  if a_l[i] < 0:
    k = i
  else:
    break

b_l = a_l[:k+1]
if len(b_l) != 0:
  min_b = b_l[0]
a_l = a_l[k+1:]
if len(a_l) != 0:
  max_a = a_l[-1]
fu = len(b_l)
sei = len(a_l)
ans_l = list()
ans_n_l = list()
if len(b_l) != 0:
  if len(a_l) != 0:
    for i in range(1, fu):
      ans_l.append([max_a, b_l[i]])
      max_a -= b_l[i]
    for i in range(sei-1):
      ans_l.append([min_b, a_l[i]])
      min_b -= a_l[i]
    
    ans_l.append([max_a, min_b])
    max_a -= min_b
  else:
    max_a = b_l[-1]
    for i in range(1, fu-1):
      ans_l.append([max_a, b_l[i]])
      max_a -= b_l[i]
    ans_l.append([max_a, min_b])
    max_a -= min_b
else:
  min_b = a_l[0]
  for i in range(1, sei-1):
    ans_l.append([min_b, a_l[i]])
    min_b -= a_l[i]
  ans_l.append([max_a, min_b])
  max_a -= min_b
  
print(max_a)
for i in ans_l:
  print(i[0], i[1])
n,m = map(int,input())
l = list(map(int,input().split()))
s = sum(l)
if n-s<0:
  print(-1)
else:
  print(n-s)

### FIXED CODE ###

n,m = map(int,input().split())
l = list(map(int,input().split()))
s = sum(l)
if n-s<0:
  print(-1)
else:
  print(n-s)
NN=int(input())
A=[0]*N
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if x**2+y**2+z**2+x*y+y*z+z*x<=N:
        A[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
for i in range(N):
  print(A[i])

### FIXED CODE ###

N=int(input())
A=[0]*N
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if x**2+y**2+z**2+x*y+y*z+z*x<=N:
        A[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
for i in range(N):
  print(A[i])
import sys

n, q = map(int, sys.stdin.readline().split())
g = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
xs = [0 for _ in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    p -= 1
    xs[p] += x

costs = [0 for i in range(n)]
visited = [False for _ in range(n)]


def rec(prev_v, v, value):
    if visited[v]:
        return
    visited[v] = True
    next_value = value + xs[v]
    costs[v] = next_value
    for next_v in g[v]:
        if next_v == prev_v:
            continue
        rec(v, next_v, next_value)


rec(-1, 0, 0)
print(' '.join(map(str, costs)))



### FIXED CODE ###

import sys

n, q = map(int, sys.stdin.readline().split())
g = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
xs = [0 for _ in range(n)]
for i in range(q):
    p, x = map(int, sys.stdin.readline().split())
    p -= 1
    xs[p] += x

visited = [False for _ in range(n)]
# def rec(prev_v, v, value):
#     if visited[v]:
#         return
#     visited[v] = True
#     next_value = value + xs[v]
#     costs[v] = next_value
#     for next_v in g[v]:
#         if next_v == prev_v:
#             continue
#         rec(v, next_v, next_value)
# rec(-1, 0, 0)

current_node = [0]
while len(current_node) > 0:
    next_node = []
    for v in current_node:
        visited[v] = True
        for next_v in g[v]:
            if visited[next_v]:
                continue
            next_node.append(next_v)
            xs[next_v] += xs[v]
    current_node = next_node

print(' '.join(map(str, xs)))
N, M = map(int, input().split())
P = [i -1 for i in map(int,input().split())]
ss = set([])
point = 0
for i in range(N):
    if point in ss:
        break
    ss.add(point)
    point = P[point]
S = [0]
points = 0
for i in range(len(ss)-1):
    points = P[points]
    S.append(points)
loop = S[S.index(point):]
ll = len(S)
l = len(loop)
if ll >= M:
    print(S[M]+1)
else:
    print(loop[(M-ll)%l]+1)


### FIXED CODE ###

N, M = map(int, input().split())
P = [i -1 for i in map(int,input().split())]
ss = set([])
point = 0
for i in range(N):
    if point in ss:
        break
    ss.add(point)
    point = P[point]
S = [0]
points = 0
for i in range(len(ss)-1):
    points = P[points]
    S.append(points)
loop = S[S.index(point):]
ll = len(S)
l = len(loop)
if ll > M:
    print(S[M]+1)
elif ll == M:
    print(point+1)
else:
    print(loop[(M-ll)%l]+1)
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

a.pop()
ans=0
for i in range(n-1):
    ans+=a[-i-1]
print(ans)

### FIXED CODE ###

import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

a.pop()
ans=0
for i in range(n-1):
    ans+=a[-i-1]
print(ans)