Problem:


Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6



Sample input:
4
2 2 1 3


Sample output:
7

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
ans = 0
min_a = a[0]

for i in range(len(a)-1):
    ans += min_a
    if min_a > a[i+1]:
        min_a = a[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=list(map(int,input().split()))
b = sorted(a)
b = b[::-1]
print(b)
x = 0
y = 0
z = 0
for i in range(n):
    y += sorted([x, z])[0]
    z = x
    if i == 0:
        x = b[0]
        z = b[0]
    elif i < 3:
        if b[i] < x:
            x = b[i]
print(y)

Submission status: Wrong Answer

Solution code:
# Q4
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N = I()
A_list = LI()

ans = sum([i for i in sorted(A_list, reverse=True)[:-1]])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

print(sum(A) - min(A))

Submission status: Wrong Answer

Solution code:
import numpy as np


def _run(N, As):
    As.sort()
    friendries = np.array(As, dtype=np.int32)
    print(np.sum(friendries[1:]))


def _main():
    N = int(input())
    As = list(map(int, input().split()))
    _run(N, As)


if __name__ == "__main__":
    _main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
# print(a)
print(sum(a[2:]) + a[-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
#print(a)
a.sort(reverse=True)
#print(a)
sum = 0
for i in range(len(a)-1):
    sum += a[i]
print(sum)

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)


N = n1()
A = nn()

A.sort(reverse=True)
print(sum(A[:-1]))

Submission status: Wrong Answer

Solution code:
#from itertools import combinations 
import sys
import math as mt
input=sys.stdin.buffer.readline  
t=1


#t=int(input())
for _ in range(t):
    n=int(input())
      
    #n,m,k=map(int,input().split())
    l=list(map(int,input().split()))
    suma=sum(l[:])
    mini=min(l[:])
    print(suma-mini)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
ans=0
for i in range((N//2)+1):
  for j in range(2):
    ans+=A[i]
if (N//2)%2==1:
  ans-=A[i]
else:
  ans=ans-(A[i]*2)
if N//2!=0:
  ans-=A[0]

print(max(ans,0))

Submission status: Wrong Answer

Solution code:
n = int(input())

inputs = []

my_input = input().split(" ")

for i in range(len(my_input)):
	inputs.append(int(my_input[i]))

inputs.sort(reverse=True)

inputs = inputs[:-1]

print(sum(inputs))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
total=0

list.sort(a, reverse=True)
print(a)
if N %2== 0:
	for i in range(int(N/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
else:
	for i in range(int((N-1)/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
	total += a[int((N-1)/2)]
print(total)

Submission status: Wrong Answer

Solution code:
import heapq
n = int(input())
A = sorted(map(int, input().split()), reverse=True)

ans = 0
conf = [-A[0]]
for i, a in enumerate(A[1:]):
    x = -heapq.heappop(conf)
    ans += x
    heapq.heappush(conf, -a)
    if i == 0:
        continue
    heapq.heappush(conf, -a)
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

h = []
comfort = a[0]
heapq.heappush(h, (a[1], a[0], a[1]))
for i in range(N-2):
    val = heapq.heappop(h)
    comfort += val[0]
    heapq.heappush(h, (min(val[1], a[i]), val[1], a[i]))
    heapq.heappush(h, (min(val[2], a[i]), val[2], a[i]))
print(comfort)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(sum(A[1:]))

Submission status: Wrong Answer

Solution code:
num = (int)(input())
a = sorted(list(map(int, input().split(" "))), reverse=True)
print(sum(a[:-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))

b = sorted(a)[::-1]
if N == 1:
    print(a[0])
elif N == 2:
    print(a[0])
elif N > 2 and N % 2 == 0:
    print(b[0] + sum(b[1:N//2]) * 2)
elif N > 2 and N % 2 == 1:
    print(b[0] + sum(b[1:(N-1)//2]) * 2 + b[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(sum(a[1:]))

Submission status: Wrong Answer

Solution code:
N=input()
A=list(map(int,input().split()))
print(sum(A)-min(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
print(sum(A)-min(A))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    As = LI()
    As.sort()
    As.reverse()

    print(sum(As) - As[-1])


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Wrong Answer

Solution code:
N = int(input())
As = sorted(list(map(int, input().split())), reverse = True)
N -= 1
i = 1
ans = 0
while N > 0:
  if N >= i:
    ans += As[i-1] * i
    N -= i
  else:
    ans += As[i-1] * N
    N = 0
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split())  )
a.sort()
print( sum(a[2:]) + a[-2] )

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i in range(n-2):
    ans+=a[i]
ans+=a[1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list = list(map(int,input().split()))

a_list = sorted(a_list, reverse=True)

print(sum(a_list[0:-1]))

Submission status: Wrong Answer

Solution code:
def abc173_d():
    N = int(input())
    a =  list(map(int,input().split()))

    a_new = sorted(a,reverse=True)


    sum = 0
    for i in range(N-2):
        sum += a_new[i]
    sum += a_new[1]
    print(sum)



abc173_d()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
print(sum(A) - min(A))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=sorted([int(i) for i in input().split()],reverse=True)
print(sum(l[:n-1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input().split()
for i in range(N): A[i]=int(A[i])
A.sort()
#print(A)
r=0
for i in range(N):
  if i>0: r+=A[i]
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, input().split()))
count = 0
min_value = min(S)
min_index = S.index(min_value)
S[min_index] = 0

print(sum(S))

Submission status: Wrong Answer

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

print(sum(A)-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
print(sum(a[1:]))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

A.sort(reverse=True)
ans = sum(A[:-1])
print(ans)

Submission status: Wrong Answer

Solution code:

def abc173_d():
    N = int(input())
    a =  list(map(int,input().split()))

    a_new = sorted(a,reverse=True)
    print(a_new)


    sum = 0
    for i in range(N-2):
        sum += a_new[i]
    sum += a_new[1]
    print(sum)



abc173_d()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
ans=0
for i in range((N//2)+1):
  for j in range(2):
    ans+=A[i]
if (N//2)%2==1:
  ans-=A[i]
if N//2!=0:
  ans-=A[0]

print(max(ans,0))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)

S = A[0]
step = 2

print(S)
for i in range(1,N-1):
  S += (A[(i+1)//2])
  print(S)

print(S)

Submission status: Wrong Answer

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

print(sum(a) - min(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
i = list(map(int, input().split()))

sorti = sorted(i, reverse=True)

sorti = sorti + [sorti[0]]
sorti.insert(0, sorti[-2])
    
ans = 0
for index, x in enumerate(sorti):

    if index == 0:
        continue
    if index == n:
        break
    
    if sorti[index-1] <= sorti[index+1]:
        ans += sorti[index+1]
    elif sorti[index+1] <= sorti[index-1]:
        ans += sorti[index-1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))

print(sum(A)-min(A))

Submission status: Wrong Answer

Solution code:
def main1():
    N=int(input())
    A=list(map(int,input().split()))
    A.sort(reverse=True)
    print(sum(A)-A[-1])
main1()

Submission status: Wrong Answer

Solution code:
N=int(input())
lis2=list(map(int,input().split()))
lis2.sort()
print(sum(lis2[1:]))

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
mini = A[0]

for i in range(1, N):
    ans += mini
    mini = min(mini, A[1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
A.sort(reverse=True)

res = A[0]
cnt = 1
for i in range(1, N):
    cnt += 2
    res += 2 * A[i]
    if cnt > N - 1:
        res -= A[i]
        break
    elif cnt == N - 1:
        break

print(res)

Submission status: Wrong Answer

Solution code:
#D
N = int(input())
A = list(map(int,input().split()))

A.sort()
A.reverse()

sc = 0
sc += A.pop(0)

c=0
for i in range(10**6):
    if c>=N-2:
        break
    p=A.pop(0)
    sc+=p
    c+=1
    if c>=N-2:
        break
    p=A.pop(0)
    sc+=p
    c+=1
        
print(sc)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=sum(a[:-1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
A = sorted(LI())
print(sum(A[1:]))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a=sorted(a)
print(a[-1]+a[-2]*(n-2))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
b = sorted(a,reverse=True)
x = math.ceil(len(b)/2)
y = b[:x]
z = sum(y*2)-y[0]
if x%2==1:
    print(z-y[-1])
else:
    print(z)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=input().split()
for i in range(N): A[i]=int(A[i])
A.sort()
print(A)
r=0
for i in range(N):
  if i>0: r+=A[i]
print(r)

Submission status: Wrong Answer

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

A.sort(reverse = True)

#print(A)

D =[0]
count = 0

for i in range(len(A)):
    D.sort()
    if len(D)== 1:
        count += D[0]
        D.append(A[0])
        del A[0]
        #print(count)
    else:
        count += D[1]
        D.append(A[0])
        del A[0]
        #print(count)


print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = 0
ans += A[0]
if n > 2:
    ans += sum(A[1:(n+1) // 2]) * 2
    if n % 2 == 1:
        ans -= A[(n+1) // 2]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    comp = list(map(int, input().split()))
    comp.sort(reverse=True)
    
    fin = n - 2
    p = comp[0]
    for i in range(1, n):
        if fin == 1:
            p += comp[i+1]
            break
        elif fin == 0:
            break

        p += comp[i]*2
        fin -= 2

    print(p)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
total=0

list.sort(a, reverse=True)

if N %2== 0:
	for i in range(int(N/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
else:
	for i in range(int((N-1)/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
	total += a[int(N/2 - 1)]
print(total)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
print(sum(a[:-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split())) 
ans = 0
a.sort()
for i in range(n):
    ans += a[i]
print(ans-a[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a_li = list(map(int,input().split()))
a_li.sort(reverse=1)
m = a_li[0]
l = a_li[0]
r = a_li[0]
ans = 0
for i in range(1,n):
    if l < r:
        ans += l
        l = a_li[i]
    else:
        ans += r
        r = a_li[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
ans = 0
for i in range(N-1):
    ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split())) 
A.sort(reverse=True)

print( A[0] + A[1]*(N-2) )

Submission status: Wrong Answer

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


print(sum(sorted(a)[1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
max1i = n-1
max2 = 0
for i in range(n) :
    if A[i] == A[0] :
        continue
    max2 = A[i]
    max1i = i
    break

print(A[0]*max1i+max2*(n-i-1))

Submission status: Wrong Answer

Solution code:
n = int(input())
goods = [int(x) for x in input().split()]

goods.sort(reverse=True)
score = 0
if len(goods) == 3:
    print(goods[0] + goods[1])
else:
    if len(goods) % 2 == 0:
        r = int(len(goods) / 2)
        score += goods[0]
        for i in range(1, r):
            score += goods[i] * 2
        
    else:
        r = int((len(goods) - 1) / 2)
        score += goods[0]
        score += goods[r + 1]
        for i in range(1, r):
            score += goods[i] * 2
    print(score)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

Ans_sum = A[0]

for n in range(2,N):
    Ans_sum += A[1]

print(Ans_sum)

Submission status: Wrong Answer

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

print(sum(A) - 1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import OrderedDict, defaultdict
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
#import numba

def run():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)

    val_list = []
    heappush(val_list, (-min(A[0], A[1]), A[0], A[1]))
    ans = A[0]
    for a in A[2:]:
        val, a1, a2 = heappop(val_list)
        ans += -val
        heappush(val_list, (-min(a1, a), a1, a))
        heappush(val_list, (-min(a2, a), a2, a))
    print(ans)



if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
print(sum(A[:-1]))

Submission status: Wrong Answer

Solution code:
print(int(input())-1)
A=input()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
print(sum(A) - A[-1])

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=sorted(lmp())
ans=0
for i in range(n):
    ans+=a[(i+1)//2]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
print(sum(a[1:]))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
total=0

list.sort(a, reverse=True)
print(a)
if N %2== 0:
	for i in range(int(N/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
else:
	for i in range(int((N-1)/2)):
		if i == 0:
			total += a[i]
		else:
			total += a[i]*2
	total += a[int(N/2 - 1)]
print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

comfort = 0
last = A[0]

for ni in A[1:]:
    comfort += last
    last = ni

print(comfort)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
S=0
for i in range(N):
    S+=A[N//2]
print(S-A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
ar = sorted(list(map(int, input().split())), reverse=True)
arr = [ar[0]]
ans = 0
for i in range(1, n):
    ans += min(arr)
    arr.append(ar[i])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import math


def minu_int(i):
    return -1*int(i)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


N = z()
A = zz()

A = sorted(A, reverse=True)
if (N == 2):
    print(max(A))
    exit()
elif (N == 3):
    print(sum(A[:2]))
    exit()
else:
    ans = sum(A[:-2])
    ans += A[1]
    # for i in range(N):
    #     ans +=
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

nums.pop(-1)
print(sum(nums))

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N = int(input())
    A = [int(x) for x in input().split(" ")]
    A.sort(reverse=True)
    print(sum(A[:-1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

A = sorted(A)[::-1]

ans = 0
for i, a in enumerate(A):
    if i==0:
        ans += a
        itr = 2
    else:
        ans += a
        itr += 1
        if itr >= N:
            break
        ans += a
        itr += 1
        if itr >= N:
            break

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
print(sum(a[:-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

if N <= 1:
    print(0)
    exit()

A.sort()

res = A[-1]


for i in range(1,N):
    res += 2*A[-1-i]
    if 1 + 2*i == N-1:
        break
    if 1 + 2*i == N:
        res -= A[-1-i]
        break

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans = A[0]
for i in range(N-2):
    ans += min(A[i],A[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
max1i = n-1
max2 = 0
print(A)
for i in range(n) :
    if A[i] == A[0] :
        continue
    max2 = A[i]
    max1i = i
    break

print(A[0]*max1i+max2*(n-i-1))

Submission status: Wrong Answer

Solution code:
#D
N=int(input())
A_list=list(map(int,input().split()))
A_list.sort(reverse=True)
ans=sum(A_list[:-1])
print(ans)

Submission status: Wrong Answer

Solution code:
comfort=0
N=int(input())
mylist=list(map(int,input().split()))[:N]

mylist.sort()#O(nlogn)
mylist.reverse()#O(n)

if N>1:
    comfort=mylist[0]

for i in range(2,N):
    comfort+=min(mylist[i-1],mylist[i-2])
    
  
print(comfort)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split(' ')))
b = sorted(b, reverse=True)
b.pop()
point = sum(b)


print(point)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(N) for N in input().split()]
A1 = sorted(A)
x = sum(A1)-A1[0]
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)

print(sum(a)-a[-1])

Submission status: Wrong Answer

Solution code:
#=input()
n=int(input())
#=map(int,input().split())
#=map(str,input().split())
l=list(map(int,input().split()))
m=min(l)
s=0
for x in l:
    s += x
print(s-m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i in range(n-1):
    ans+=a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input =sys.stdin.readline

N=int(input().rstrip('\n'))
As=[int(x) for x in input().rstrip('\n').split()]
As_s=sorted(As)
print(sum(As_s[1:]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
print(sum(A[0:-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
print(sum(a[:n-1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    n = int(args[0])
    A = sorted(map(int, args[1].split()), reverse=True)

    Q = deque()

    ret = 0
    for i in range(-(-n//2)):
        if 0 < i:
            ret += min(A[-1], A[1])
        if i % 2:
            Q.appendleft(A[i])
        else:
            Q.append(A[i])

    for i in range(len(Q)):
        ret += min(Q[i], Q[i-1])

    return str(sum(A[:-1]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_sort = sorted(A)

ans = sum(A_sort) - A_sort[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())
    a_s = list(map(int, input().split()))

    a_s.sort()

    print(sum(a_s[1:]))


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4
2 2 1 3"""
        output = """7"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """7
1 1 1 1 1 1 1"""
        output = """6"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:

def main():
  n = int(input())

  arr = sorted(map(int, input().split()), reverse=True)

  ans = 0

  F = [arr[0], arr[0]]

  for i in range(1, n):
    f = arr[i]
    ans += F[i % 2]
    F[(i + 1) % 2] = f

  print(ans)


main()

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[int(x) for x in input().split()]
x.sort(reverse=True)
f=1
ans=x[0]
ans+=(n-2)*x[1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a= list(map(int, input().split()))
a.sort()
ans=sum(a)-a[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
confort = 0
for a in A[:n-1]:
    confort = confort + a

print(confort)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
print(sum(A[:N-1]))

Submission status: Wrong Answer

Solution code:
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
a = LI()
a.sort(reverse=True)
ans = sum(a[:2])
if n<=3:
	print(ans)
else:
	ans = sum(a[:3])
	for i in range(3,n-1):
		if i%2 == 1:
			ans+=a[i-2]
		else:
			ans+=a[i-1]
	print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    comp = list(map(int, input().split()))
    comp.sort(reverse=True)
    
    fin = n - 2
    p = comp[0]
    for i in range(1, n):
        p += comp[i]*2
        fin -= 2
        if fin == 1:
            p += comp[i+1]
            break
        elif fin == 0:
            break

    print(p)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = 0
for num in range(len(A)-1):
  ans += A[num]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)

for i in range(n):
	if i==0:
		conf = {A[i]:1}
		ans = 0
	else:
		add=max(conf.keys())
		ans+=add
		conf[A[i]] =2
		if conf[add] >1:
			conf[add] -= 1
		else:
			conf.pop(add)

	#print(conf, ans)

print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)


l = [a[0]]
ans = 0

for i in range(1,len(a)):
    ans += l[-1]
    l.append(a[1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse=True)
    A.pop(-1)
    print(sum(A))
    return 0

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a.sort()
a.reverse()
a.pop()
print(sum(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split())  )
a.sort()
#print(a)
print( sum(a[1:]) )

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
print(A)
print(sum(A[0:-1]))

Submission status: Wrong Answer

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    b = sorted(a)
    c = sum(b[n // 2:-1])
    print(2 * c + a[-1])
    if (n - 1) % 2 == 0:
        print(a[n//2] + 2 * c + a[-1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
a = sorted(a, reverse=True)

sum = a[0]
for i in range(0,n-2):
    sum += min(a[i],a[i+1])

print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
print(sum(l)-min(l))