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 sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) 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 II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
AS=LI()
AS.sort(reverse=True)
# print(AS)

i, j = AS[0], AS[1]
HQ=[]
heapq.heappush(HQ, (-i, -j))
# print(HQ)
res = AS[0]
for n in range(2, len(AS)):
    k = AS[n]
    i, j = heapq.heappop(HQ)
    i *= -1
    j *= -1
    res += min(i, j)
    heapq.heappush(HQ, (-k, -i))
    heapq.heappush(HQ, (-k, -j))
    # print("i: {} j: {} k:{} res:{}".format(i,j,k,res))
    # print(HQ)

print(res)

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    A = sorted(A, reverse=True)
    print(sum(A[:-1]))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L.sort(reverse=True)

ans = -L[0]
i = 0
while n > 0:
  ans += L[i]*min(n,2);
  n -= 2
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
#print(A)
ans = A[0]
Q = [(A[1],A[0])]
heapify(Q)
for i in range(2,N):
  nxt = A[i]
  s,t = heappop(Q)
  #s *= -1; t*= -1 #正に戻す
  ans += s
  heappush(Q,(nxt,s))
  heappush(Q,(nxt,t))
print(ans)

Submission status: Wrong Answer

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

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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


last_x = A[0]
last_y = A[0]
ans = 0
for i in range(1, n):
  if last_x<last_y:
    ans += last_x
    last_y = A[i]
  else:
    ans += last_y
    last_x = A[i]
    
print(ans)

Submission status: Wrong Answer

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

if n%2==0:
  print(sum(a[:n//2])*2-a[0])
else:
  print(sum(a[:n//2])*2+a[n//2+1]-a[0])

Submission status: Wrong Answer

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

A.sort()
print(sum(A) - max(A))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from collections import deque

n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
que = deque()
que.append(a[-1])
for i in range(n-2,-1,-1):
    ans += min(que[0],que[-1])
    if que[0] <= que[-1]:
        que.append(a[i])
    else:
        que.appendleft(a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
 
lst.sort()
in_list = lst[n-1]
sum = 0
lst = lst[:-1]
for i in range(n-1):
  sum += in_list
  if lst[len(lst)-1] < in_list:
    in_list = lst[len(lst)-1]
  lst = lst[:-1]
  
print(sum)

Submission status: Wrong Answer

Solution code:
# Contest No.: ABC173
# Problem No.: D
# Solver:      JEMINI
# Date:        20200705

import sys
import heapq

def main():
    n = int(input())    
    nums = list(map(int, sys.stdin.readline().split()))

    #nums.sort()
    #temp1 = None
    #temp2 = None
    #ans = 0

    # initial
    #temp1 = nums.pop()
    #temp2 = nums.pop()
    #ans += temp1
    #while nums:
    #    ans += temp2
    #    temp1 = temp2
    #    temp2 = nums.pop()

    print(sum(nums) - min(nums))

    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
a = a[::-1]

if n % 2 == 0:
    n -= 1
    ans = a.pop()
    n -= 1
    ans += 2*sum(a[:n//2])
else:
    n -= 1
    ans = a.pop()
    n -= 1
    ans += 2*sum(a[:n//2]) + a[n//2]
print(ans)

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 queue

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
q = queue.Queue()

ans = A[0]
q.put( (A[0], A[1]) )
for i in range(2, len(A)):
  t = q.get()
  ans += min(t[0], t[1])
  q.put((t[0], A[i]))
  q.put((t[1], A[i]))
  
print(ans)

Submission status: Wrong Answer

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

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

A_list = sorted(A_list, reverse=True)

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

Submission status: Wrong Answer

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

a_list.sort()

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

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

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

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

if n % 2 == 0:
    ans = sum(a[: int(n/2)])*2 - a[0]
if n % 2 == 1:
    ans = sum(a[: int(n/2 + 0.5)])*2 -a[0] - a[int(n/2 + 0.5)]
    
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	counts = 0

	for i,val in enumerate(A):
		if i == 0:
			maxs = val
			continue
		if i == 1:
			ans += maxs
			maxs = val
		else:
			ans += maxs
			counts += 1
			if counts == 2:
				maxs = val
				counts = 0

	print(ans)




#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
from heapq import heappop,heappush
n=int(input())
li=list(map(int,input().split()))
L=[]
for i in li:
    heappush(L,-1*i)
ans=0
ans+=(-1*heappop(L))
for i in range(len(L)-1):
    ans+=(-1*heappop(L))
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()))
comf = 0
mincomf = 10**10
for i in range(n):
  comf += a[i]
  mincomf = min(mincomf,a[i])
print(comf-mincomf)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

print(sum(num)-min(num))

Submission status: Wrong Answer

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

a.sort()
comfort = 0

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

print(comfort-a[0])

Submission status: Wrong Answer

Solution code:
import sys;input = lambda : sys.stdin.readline()
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
print(max(sum(a[:n-1]),sum(a[1:])))

Submission status: Wrong Answer

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

if a.count(max(a)) == 2:
   s = sum(a)
else:
    s = sum(a[:-1])
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

if N == 2:
    print(A[0])
    exit()
elif N == 3:
    print(A[0] + A[1])
    exit()

ans = sum(A[:-2]) + A[1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

N = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
ans = 0
for i in range(N):
    if i == 0:
        continue
    elif i == 1:
        ans+=a[0]
        continue
    ans += min(a[i-2],a[i-1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(map(int, input().split()), reverse=True)
if N % 2:
    print(sum(A[: N // 2]) + sum(A[1 : N // 2 + 1]))
else:
    print(sum(A[: N // 2 - 1]) + sum(A[1 : N // 2 + 1]))

Submission status: Wrong Answer

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

main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
b = collections.Counter(a)
c = list(b.items())
now = 0
tnp = 1
l = 0
l += c[0][1]
if (l>=n-1):
    print(c[0][0]*(n-1))
    exit()
now = l*c[0][0]
while True:
    if (l+c[tnp][1]*2>=n-1):
        print(now + (n-l-1)*c[tnp][0])
        break
    else:
        l += c[tnp][1]*2
        now += c[tnp][0]*c[tnp][1]*2
        tnp += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
flag = True
check = min(a)
ans = 0
for i in a:
    if flag and i == check:
        flag = False
    else:
        ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort(reverse=True)
i=0
j=0
res=0
n-=1
while n:
    k=min(2**i,n)
    res+=(k)*arr[j]
    #print(res)
    n-=k
    j+=1
    i+=1
print(res)

Submission status: Wrong Answer

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

Ali.sort(reverse=True)

p = sum(Ali[0:(len(Ali)+1)//2])*2
p -= Ali[0]
if len(Ali)%2 == 1:
  p -= Ali[(len(Ali)+1)//2]
  
print(p)

Submission status: Wrong Answer

Solution code:
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n = ri()
li = rl()
li = li + list(set(li))
li = sorted(li, reverse=True)
print(sum(li[:n-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
ans=0
x=deque([a[0]])
for i in range(1,n):
  ans+=min(x[0],x[-1])
  x.append(a[i])
  x.appendleft(a[i])
print(ans)

Submission status: Wrong Answer

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

ret = sum(A_i)-min(A_i)
print(ret)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


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

    ans = A[0]
    rest = N-2
    i = 1
    while rest > 0:
        if i == len(A):
            break

        if rest >= 2:
            ans += 2 * A[i]
            rest -= 2
        else:
            ans += A[i]
            rest -= 1

    return ans


print(main())

Submission status: Wrong Answer

Solution code:
#create date: 2020-07-05 21:16

import sys
stdin = sys.stdin
from collections import deque

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    a = na()
    a.sort(reverse=True)
    apre = a[0]
    cnt = 1
    q = deque()
    ans = -a[0]
    f = 0
    for ai in a[1:]:
        if ai == apre:
            cnt += 1
        else:
            for i in range(cnt+1):
                q.append(apre)
            apre = ai
            cnt = 1
            f += (cnt+1)
        if f > n:
            break
    for i in range(cnt+1):
        q.append(apre)
    for i in range(n):
        ans += q.popleft()

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().split()
A = []
for s in S:
    A.append(int(s))
A.sort(reverse=True)

result = 0
for i in range(N-1):
    result += A[i]
print(result)

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:
from sys import stdin
from sys import setrecursionlimit
import heapq

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))

a = [-1*i for i in a]

heapq.heapify(a)

before = heapq.heappop(a)*-1
point = 0

while a:
    b = heapq.heappop(a)*-1
    point += before
    before = b

print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]

ans=0

last=0
for i in range(n):
  ans+=last
  last=a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
n_list = list(map(int, input().split()))
res = 0
n_list.sort(reverse=True)

n_list.pop(-1)

for a in n_list:
    res += a

print(res)

Submission status: Wrong Answer

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

print(sum(sorted(A, reverse=True)[:N-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import *
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
ans = 0
for i in range(1,n):
	ans+=a[int(log2(i))]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

sorted_A = sorted(A, reverse=True)
print(sum(sorted_A[:-1]))

Submission status: Wrong Answer

Solution code:
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(lst):  # fix inputs here
    console("----- solving ------")
    # lst = sorted(lst)[::-1]

    return sum(lst) - min(lst)


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return


for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

    res = solve(lst)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    print(res)

Submission status: Wrong Answer

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

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(1, n):
  ans += a[i - 1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
aa.sort(reverse=True)
import queue
q = queue.PriorityQueue()
q.put(aa[0])
cnt = 0
for i in aa[1:]:
    cnt += q.get()
    q.put(i)
    q.put(i)

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())

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

t.sort(reverse=True)

ans = sum(t[:-1])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(map(int,input().split()),reverse=True)
a.pop()
result = max(a)
length = len(a)-1
for i in range(length):
  result += min(a[i:i+2])
  a.insert(0,a.pop())
print(result)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr.sort()
    ans = sum(A_arr[1:])
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(sum(a[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    cnt = 1
    prev = A[0]
    for i in range(1, n):
        if cnt:
            res += prev
            cnt -= 1
        else:
            cnt = i - 1
            prev = A[i - 1]
            res += prev
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sA = sorted(A, reverse=True)

if N % 2 == 0:
    res = sum(sA[:N//2]) * 2 - sA[0]
else:
    res = sum(sA[:N//2]) * 2 - sA[0] + sA[N//2+1]

print(res)

Submission status: Wrong Answer

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

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

# a_sorted = sorted(A, key=lambda x: -x)
ans = sum(A) - min(A)

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.sort(reverse=True)
A = A[0:-1]

print(sum(A))

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())
l = list(map(int, input().split()))
print(sum(l)-min(l))

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    li.sort(reverse=True)
    print(sum(li) - li[-1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
A = list(map(int,input().split()))
heap = []
for i in range(N):
    heapq.heappush(heap,-A[i])
if N==2:
    ans = -heapq.heappop(heap)
elif N==3:
    ans = -heapq.heappop(heap)-heapq.heappop(heap)
else:
    ans = 0
    ans = -heapq.heappop(heap)-2*heapq.heappop(heap)
    for _ in range(N-1-3):
        a = -heapq.heappop(heap)
        ans += a
print(ans)

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(2,len(a)):
    ans+=(a[(i+1)//2])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# Contest No.: ABC173
# Problem No.: D
# Solver:      JEMINI
# Date:        20200705

import sys
import heapq

def main():
    n = int(input())    
    nums = list(map(int, sys.stdin.readline().split()))

    nums.sort()
    temp1 = None
    temp2 = None
    ans = 0

    # initial
    temp1 = nums.pop()
    temp2 = nums.pop()
    ans += temp1
    while nums:
        ans += temp2
        temp1 = temp2
        temp2 = nums.pop()

    print(ans)

    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

A = [int(x) for x in input().split()] #yoko

A.sort(reverse=True)
#print(A)
A1 = A[:n-1]

print(sum(A1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    input()  # n
    friendliness = [int(x) for x in input().split()]
    print(sum(friendliness) - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = []
comf = 0
A = sorted(A, reverse=True)

for i in range(N):
  if i == 0:
    a.append(A[i])
  else:
    comf+=min(a[0], a[-1])
    a.append(A[i])
print(comf)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	nexts = A[1]

	for i,val in enumerate(A):
		if i == 0:
			maxs = val
			continue
		if i == 1:
			ans += maxs
			maxs = val
		else:
			ans += maxs

	print(ans)




#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

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:
N = int(input())
a = list(map(int,input().split()))
total=0
for i in range(N):
	total += a[i]
total -= min(a) 
print(total)

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:
N=int(input())
data_pre=input().split()
data=[int(s) for s in data_pre]
data.sort()
data.reverse()
ans=data[0]+data[1]*(N-2)
print(ans)

Submission status: Wrong Answer

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

if n % 2 == 0:
    ans = sum(a[: int(n/2)])*2 - a[0]
if n % 2 == 1:
    ans = sum(a[: int(n/2 + 0.5)])*2 -a[0] - a[ int(n/2 + 0.5)]
    
print(ans)

Submission status: Wrong Answer

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

a.sort()
ans = 0
for i in range(1,len(a)):
    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 = 0
for i in range(n):
    if i==0:
        ans += 0
    elif i == 1:
        ans += a[0]
    else:
        ans += a[i//2 + 1]
print(ans)

Submission status: Wrong Answer

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

print(sum(l)-min(l))

Submission status: Wrong Answer

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

import collections
count=len(a)-1
ans=0
c = collections.Counter(a)
for i in c.keys():
    if count<=c[i]+1:
        ans+=i*count
        break
    else:
        ans+=i*(c[i]+1)
        count-=c[i]+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
#import bisect
#import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
import itertools
import heapq

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(lambda x: -1*int(x),input().split()))
    heapq.heapify(A)
    l = deque()
    print(A)
    score =0
    c = heapq.heappop(A)
    l.append(c)
    for i in range(N-1):
        c = heapq.heappop(A)
        l.append(c)
        l.append(c)
        current =l.popleft()
        score +=current

    print(-score)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

al = sorted(al)[::-1]
ans = sum(al[:-1])

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
li.sort()
li.reverse()
li.pop()
print(sum(li))

Submission status: Wrong Answer

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

print(li[0]+li[1]*(n-2))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt_a = Counter(a)
    cnt_a = sorted(cnt_a.items(), key=lambda x: x[0], reverse=True)

    ans = 0
    for i, vc in enumerate(cnt_a):
        v, c = vc
        if i == 0:
            ans += v * (c - 1)
        else:
            ans += cnt_a[i - 1][0] + max(0, c - 1) * v
    if len(cnt_a) == 1:
        ans = cnt_a[0][0] * (n - 1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

N=int(sys.stdin.readline())

A=[int(i) for i in sys.stdin.readline().split()]

A.sort(reverse=True)

ans=0
ctr=0
i=0

while(ctr<N-1):
	if(i==0):
		ans+=A[i]
		i+=1
		ctr+=1
	else:
		ans+=A[i]
		i+=1
		ctr+=1
		if(ctr<N-1):
			ans+=A[i]
			ctr+=1

print(ans)

Submission status: Wrong Answer

Solution code:


(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
A = sorted(A, reverse=True)

if N <= 3:
    print(sum(A[:-1]))
else:
    print(sum(A[:-2]) + A[1])

Submission status: Wrong Answer

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

def solve():
    cnt = 0
    ans = 0
    for i in range(N):
        c = 2**i
        for j in range(c):
            if cnt<N-1:
                ans += A[i]
            else:
                return ans
            cnt += 1
print(solve())

Submission status: Wrong Answer

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

a.sort(reverse=True)
cnt = a[0]
for i in range(n-2):
    cnt += min(a[i], a[i+1])

print(cnt)