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:
import numpy as np
if __name__ == "__main__":
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    l=[]
    A=np.sort(A)
    A=np.flip(A)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
if __name__ == "__main__":
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A])
    l=[]
    A=np.sort(A)
    A=np.flip(A)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
idx = 1
for i in range(1, n - 1):
    if i % 2 == 1:
        idx += 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)

ans = A[0]

idx = 1
cnt = 0
for i in range(2,N):
    ans += A[idx]
    cnt += 1
    if cnt == 2:
        idx += 1
        c = 0

print(ans)

Submission status: Wrong Answer

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

A.sort(reverse = True)

ans = A[0]

idx = 1
cnt = 0
for i in range(2,N):
    ans += A[idx]
    cnt += 1
    if cnt == 2:
        idx += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
s=0
for i in A:
  s+=i
s=s-A[N-1]
print(s)

Submission status: Wrong Answer

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

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

min_num = a[0]
for num in a:
    result += num
    if min_num > num:
        min_num = num

result -= min_num
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
ans = 2 * sum(a[1:n // 2]) + a[0]
if n % 2 == 1:
    ans += a[n // 2 + 1]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a)-a[-1]-a[-2]+a[1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


N=6
a=[2,3,4,5,6,7]

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

ans =a[0]
flag=0
print(7+6+6+5+5) 
if len(a)%2 !=0:
    for i in range(1,int((len(a))/2)+1):
        for j in range(2):
            ans +=a[i]
            print(a[i])
    print(ans-a[int((len(a))/2)])
else:
    for i in range(1,(len(a))//2):
        for j in range(2):
            ans +=a[i]
            print(a[i])
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int , input().split())),reverse=True)
com = []
ans = 0
for num in a[0:n-1]:
    com.append(num)
    ans = ans + min(com)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aList.sort()
aList = aList[::-1]

bf = aList[0]
af = aList[0]
ksum = 0
for i in range(1, n):
    t = aList[i]
    if bf < af :
        ksum += bf
        af = t
    else:
        ksum += af
        bf = t
print(ksum)

Submission status: Wrong Answer

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

first = True
com = []
ans = 0
for num in a:

    if(first):
        com.append(num)
        first = False
        continue
    else:
        ans = ans + min(com)
        com.append(num)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
aList = list(map(int, input().split()))
aList.sort()
aList = aList[::-1]

bList = []
bList.append(aList[0])
ksum = 0
#print('    blist:%s' % str(bList))

for i in range(1, n):
    #print('  t: %d' % t)
    t = aList[i]
    k = bList[0] if bList[0] <bList[-1] else  bList[-1]
    #print('  k:%d' % k)
    ksum += k

    if i%2 == 1:
        bList.append(t)
    else:
        bList.insert(0,t)
    #print('    blist:%s' % str(bList))

print(ksum)

Submission status: Wrong Answer

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

A.sort()
A.pop(0)
print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A1=[A.pop()]
A.reverse()
ans=0
f=True
for a in A:
  if(f):
    A1.insert(0,a)
    ans += min([A1[1],A1[-1]])
  else:
    A1.append(a)
    ans += min([A1[0],A1[-2]])
  f = not f
print(ans)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

happy = A[0]
circle = [A[0], A[1]]
for i in range(2, N):
    mid = len(circle)//2
    circle.insert(mid, A[i])
    if mid%2==0:
        happy += min(circle[mid], circle[mid+1])
    else:
        happy += circle[mid+1]

print(happy)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

happy = A[0]
circle = [A[0], A[1]]
for i in range(2, N):
    circle.insert(-1, A[i])
    happy += min(circle[-1], circle[-3])

print(happy)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

happy = A[0]
circle = [A[0], A[1]]
for i in range(2, N):
    circle.insert(-1, A[i])
    happy +=  min(circle[-1], circle[-3])

print(happy)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

happy = A[0]
circle = [A[0], A[1]]
for i in range(2, N):
    circle.insert(len(circle)-1, A[i])
    happy += min(circle[-1], circle[-3])

print(happy)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

happy =  0
circle = [A[0], A[1]]
for i in range(2, N):
    circle.insert(len(circle)-2, A[i])
    happy += min(circle[-1], circle[-3])

print(happy)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(A[1:]))

Submission status: Wrong Answer

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

AN.sort()
print(sum(AN[1:]))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = a[0]
    for i in range(1, n//2):
        ans += a[i]*2
    if n%2 == 1:
        ans += a[n//2]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

friend.sort(reverse = True)

ans = friend[0]
i = 1
ind = 1
while i < n:
    for j in range(2):
        ans += friend[ind]
        i += 1
        if i == n: break
    ind += 1
print(ans)

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(Q[-1], Q[0])
        if i % 2:
            Q.appendleft(A[i])
        else:
            Q.append(A[i])

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

    return str(ret)


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

Submission status: Wrong Answer

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

x.sort(reverse=True)
print(sum(x)-x[N-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

cf = nums[0]

for i in range(3, n+1, 2):
    nums_min = nums[i-1]
    if i == n:
        cf += nums_min
        print('last')
    else:
        cf += nums_min * 2

print(cf)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

cf = nums[0]

for i in range(2, n, 2):
    nums_min = nums[i-1]
    cf += nums_min * 2

print(cf)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

cf = nums[0]

for i in range(2, n):
    nums_min = min(nums[i-1], nums[i-2])
    cf += nums_min

print(cf)

Submission status: Wrong Answer

Solution code:

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

a[0]=10000000000

m=int((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

print(comfort)

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

print(comfort)

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10000000000

m=floor((n-1)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

print(comfort)

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10000000000

m=floor((n-1)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+1):
      comfort+=(2*a[i])

    comfort+=a[m+1]

print(comfort)

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10000000000

m=floor((n-3)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

print(comfort)

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=1000000000

m=floor((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  if(n%2 ==0):
    for i in range(2,m+2):
      comfort+=(2*a[i])
  else:
    for i in range(2,m+2):
      comfort+=(2*a[i])

    comfort+=a[m+2]

print(comfort)

Submission status: Wrong Answer

Solution code:
n = int(input())
comforts = [int(i) for i in input().split()]
comforts.sort(reverse=True)

print(sum(comforts[:-1]))

Submission status: Wrong Answer

Solution code:
import sys 

def A():
  n = int(sys.stdin.readline().rstrip())
  charge = (n+999)//1000 * 1000 - n
  print(charge)


from collections import Counter
def B():
  n, *s = sys.stdin.read().split() 
  c = Counter(s)
  for v in 'AC, WA, TLE, RE'.split(', '):
    print(f'{v} x {c[v]}')


def C():
  h, w, k = map(int, sys.stdin.readline().split())
  c = [sys.stdin.readline().rstrip() for _ in range(h)]
  tot = 0
  for i in range(1<<h):
    for j in range(1<<w):
      cnt = 0
      for y in range(h):
        for x in range(w):
          if i>>y & 1 or j>>x & 1:
            continue 
          cnt += c[y][x] ==  '#'
      tot += cnt == k
  print(tot)


def D():
  n, *a = map(int, sys.stdin.read().split())
  a.sort()
  print(a[-1] + a[-2]*(n-2))

  

  pass


def E():
  pass


def F():
  pass

if __name__ == "__main__":
  # A() 
  # B()
  # C()
  D()
  E()
  F()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Wrong Answer

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

import bisect
import copy
import collections
import heapq
import itertools
import math
import numpy as np
from operator import itemgetter
import scipy.misc
import sys

"""
#### 入力例 ####
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
"""


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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

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

A = sorted(A)
A = A[::-1]
sumkoko = A.pop(0)

sumkoko += sum(A[0:(N-1)//2]) * 2

print(sumkoko)

Submission status: Wrong Answer

Solution code:

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

A = sorted(A)
A = A[::-1]
sumkoko = A.pop(0)

sumkoko += sum(A[0:(N-1)//2]) * 2
if ((N-1)%2) == 1:
    sumkoko += A[(N-1)//2]

print(sumkoko)

Submission status: Wrong Answer

Solution code:

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

A = sorted(A)
A = A[::-1]
sumkoko = A.pop(0)
print(A)

sumkoko += sum(A[0:(N-1)//2]) * 2
if ((N-1)%2) == 1:
    sumkoko += A[(N-1)//2]

print(sumkoko)

Submission status: Wrong Answer

Solution code:

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

A = sorted(A)
koko = [0] * N
sumkoko = 0

sumkoko = sum(A[N-1:0:-1])

print(sumkoko)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = sorted(LI(), reverse=True)

    if n % 2 == 0:
        return sum(a[:n//2]) * 2 - a[0]

    return sum(a[:n//2+1]) * 2 - a[0] - a[n//2-1]


print(main())

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A.sort()
A.reverse()
Ad = deque()
Ad.append(A[0])
Ad.append(A[1])
sum = A[0]
for i in range(2, N):
    a = Ad.popleft()
    sum += min(a, Ad[-1])
    Ad.append(A[i])

print(sum)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A.sort()
A.reverse()
Ad = deque()
Ad.append(A[0])
Ad.append(A[1])
sum = A[0]
for i in range(2, N):
    a = Ad.popleft()
    sum += min(a, Ad[-1])
    Ad.append(A[i])


print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

final = 0
for i in a:
    final += i 

print(final - min(a))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = a[-1] + a[-2]
cnt = 2
while cnt < n - 1:
    ans += a[-1 * (2 + (1 + cnt) // 2)]
    cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
n = int(input())

arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
ans = 0
q = []
heapq.heappush(q, -arr[0])
for i in range(1, n):
    tmp = heapq.heappop(q)
    tmp *= -1
    ans += tmp
    heapq.heappush(q, -arr[i])
print(ans)

Submission status: Wrong Answer

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

# Aを降順に並び替える
A = sorted(A)[::-1]

# A0 + A1 + A1 + A3 + A3 + ....
sum = 0
for i in range(len(A) - 1):
    if i == 0:
        sum += A[i]
    elif i % 2 == 1:
        sum += A[i]
    elif i % 2 == 0:
        sum += A[i-1]
print(sum)

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:
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

if n == 1:
    ans = 0
elif n == 2:
    ans = a[0]
elif n == 3:
    ans = a[0] + a[1]
elif n > 3:
    ans = a[0] + a[1] * 2 + sum(a[3:-1])

print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)

if n == 1:
    ans = 0
elif n == 2:
    ans = a[0]
elif n == 3:
    ans = a[0] + a[1] * 2
elif n > 3:
    ans = a[0] + a[1] * 2 + sum(a[3:-1])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

score = 0
score += A[0]
for i in range(1,int(N/2)):
    score += A[i]*2
if N%2 == 1:
    score += A[round(N/2)]
print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
ans = a[0]
r = a[1]
l = a[1]

for i in range(2,n):
    ans += max(r,l)
    if r>l:
        r = a[i]
    else:
        l = a[i]
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:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
ans = 0
for i in range(1,n):
    ans += a[i-1]
print(ans)

Submission status: Wrong Answer

Solution code:
input()
lst=[int(i) for i in input().split()]
sm=0 
mn=99999999999
for i in lst :
    mn=min(i,mn)
    sm=sm+i

print(sm-mn)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(A)-sorted(A)[0])

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:
'''Template Starts'''

def _int():
    return int(input())
    
def _ints():
    return map(int, input().split())
    
def _str():
    return input()
    
def _list():
    return list(_ints())
    
'''Template Ends'''

n = _int()
l = sorted(_list())
print(sum(l[2:] + [l[len(l) - 2]]))

Submission status: Wrong Answer

Solution code:
'''Template Starts'''

def _int():
    return int(input())
    
def _ints():
    return map(int, input().split())
    
def _str():
    return input()
    
def _list():
    return list(_ints())
    
'''Template Ends'''

n = _int()
l = _list()
l.remove(min(l))
print(sum(l))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))
A_np = np.array(A_list)
A_sort = np.sort(A_np)[::-1]
comfort = 0
for i in range(1,N):
  if i == 1:
    comfort = comfort + A_sort[i-1]
  else:
    comfort = comfort + min(A_sort[i-1],A_sort[i-2])
print(comfort)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))
A_np = np.array(A_list)
A_sort = np.sort(A_np)[::-1]
comfort = 0
for i in range(1,N):
  comfort = comfort + A_sort[i-1]
print(comfort)

Submission status: Wrong Answer

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

a.sort(reverse=True)
ans = a[0]
cnt = 0

for i in range(2, n):
    j = 1
    if cnt < 2:
        ans += a[i-j-cnt]
        cnt += 1
    if cnt == 2:
        cnt = 0
        j += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H = int(input())
C = list(input().split())
C.sort(reverse=True)
result = 0
for i in range(H-1):
    result += int(C[i])
print(result)

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
An = [int(e) for e in input().split()]

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    ref = sum([e for e in arr]) / len(arr)

    for e in arr:
        if e < ref:
            left.append(e)
        else:
            right.append(e)

    if len(left) == 0:
        return right

    left = quick_sort(left)
    right = quick_sort(right)

    return left + right

p = quick_sort(An)
v0 = p.pop()

q = [v0]
heapq.heapify(q)

s = 0

while p:
    v = heapq.heappop(q)
    newv = p.pop()
    heapq.heappush(q, newv)
    heapq.heappush(q, newv)
    s += v

print(s)

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
An = [int(e) for e in input().split()]

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    ref = sum([e for e in arr]) / len(arr)

    for e in arr:
        if e < ref:
            left.append(e)
        else:
            right.append(e)

    if len(left) == 0:
        return right

    left = quick_sort(left)
    right = quick_sort(right)

    return left + right

p = quick_sort(An)
v0 = p.pop()

q = [v0, v0]
heapq.heapify(q)

s = 0

while p:
    v = heapq.heappop(q)
    newv = p.pop()
    heapq.heappush(q, newv)
    s += v

print(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = sorted(int(x) for x in input().split())
if n == 2:
    print(max(a))
else:
    print(sum(a) - a[0] - a[1] + a[-2])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n = int(input())
a = [int(x) for x in input().split()]
print(sum(a) - min(a))

Submission status: Wrong Answer

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

print(sum(arr[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    a_sort = sorted(a, reverse=True)

    ans = a_sort[0]

    if (n-2) % 2 == 0:
        for i in range(int((n-2)/2)):
            ans += a_sort[i+1]*2

    else:
        for i in range((n-2)//2 + 1):
            ans += a_sort[i+1]*2
            temp = i
        ans -= a_sort[temp]

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = sum(a[:1])
    que = [(-a[1], -a[0])]
    heapq.heapify(que)
    for i in range(2, n):
        x, y = heapq.heappop(que)
        ans += min(-x, -y)
        heapq.heappush(que, (-a[i], x))
        heapq.heappush(que, (-a[i], y))
    return ans

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

Submission status: Wrong Answer

Solution code:
import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = sum(a[:2])
    que = [(a[-2], a[-1])]
    heapq.heapify(que)
    for i in range(2, n):
        x, y = heapq.heappop(que)
        ans += min(x, y)
        heapq.heappush(que, (a[i], x))
        heapq.heappush(que, (a[i], y))
    return ans

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

Submission status: Wrong Answer

Solution code:
def solve(n, a):
    return sum(sorted(a, reverse=True)[:-1])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

n = k()
a = l()

a.sort(reverse = True)

for i in range(n):
    ans += a[i//2]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

n = k()
a = l()

a.sort(reverse = True)

for i in range(0,n,2):
    ans += a[i//2]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

n = k()
a = l()

a.sort()
a.reverse()

b = list(itertools.accumulate(a))
print(b[-1]-a[-1])

Submission status: Wrong Answer

Solution 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()))
import numpy as np

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

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

Submission status: Wrong Answer

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