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 string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    A.sort()
    ans = 0
    p = 0
    for i in range(n):
        maxnum = A.pop(-1)
        p += i+1
        if p > n:
            p -= i +1
            break
        else:
            ans += maxnum * (i+1)
    if p == n-1:
        print(ans)
    else:
        ans += maxnum * (n-p-1)
        print(ans)



if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

comfort = list()
comfort.append(A[0])
for i in range(1, N):
    if A[i-1] == A[i]:
        comfort.append(A[i])
    else:
        comfort.append(A[i])
        comfort.append(A[i])

ans = sum(comfort[:N-1])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input().split(' ')
a.sort(reverse=True)
sum=int(a[0])

for i in range(1,int(n/2)):
    sum+=2*int(a[i])
if(n%2!=0):
    sum+=int(a[int(n/2)])
print(sum)

Submission status: Wrong Answer

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

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

alist.sort()
print(sum(alist)-alist[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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:
# 2020/07/05
# AtCoder Beginner Contest 173 - D

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

# Calc
a.sort()
a.reverse()

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

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
ans=a[0]
x=a[0]
y=a[1]
for i in a[2:]:
	ans+=min(x,y)
	if min(x,i)>min(i,y):
		y=i
	else:
		x=i
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(map(int, input().split()))[::-1]


circle = A[:3]
ans = circle[0]
ans += circle[1]


A = A[3:]

for a in A:
  min_idx = -1
  max_val = 0
  for i, ab in enumerate(zip(circle, circle[1:]), start=1):
    tmp = min(ab)
    if tmp > max_val:
      max_val = tmp
      min_idx = i
  tmp = min([circle[0], circle[-1]])
  if tmp < max_val:
    max_val = tmp
    min_idx = 0
  ans += max_val
  circle.insert(min_idx, a)

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
# vim: fileencoding=utf-8


def main():
    n = int(input())
    li = list(map(int, input().split()))
    b = 0
    t = 0
    res = 0
    li.sort(reverse=True)
    for e in li[:-1]:
        if b != 0:
            res += b
            b = 0
        else:
            res += e
        if t == e:
            b = e
        t = e
    print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import sys

def main():

    n = int(input())
    a = list(map(int, input().split()))
    list.sort(a,reverse=True)
    ans = a[0]+a[1]*(n-2)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [6]

temp = 3
for i in range(1,30):
    temp *= 2
    x.append(temp)
    
a.sort(reverse = True)
sepa = []
un = []
j,k = 0,0
for i in range(n):
    if j == x[k]:
        sepa.append(un)
        un = []
        un.append(a[i])
        k += 1
        j = 0
        
    else:
        un.append(a[i])
        j += 1
        
sepa.append(un)

if len(sepa) != 1:
    ans = sepa[0][0] + (sepa[0][1] + sepa[0][2]) * 2
    for i in range(len(sepa)-1):
        for j in range(len(sepa[i+1])):
            ans += sepa[i][j//2]
            
else:
    p = [0,1,1,2,2]
    ans = 0
    for i in range(n-1):
        ans += sepa[0][p[i]]
            
print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
print(sum(A[1:]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
b = list(map(int,input().split()))

b.sort(reverse=True)
ret = 0
from collections import deque
stack_deque = deque([])
if n == 1:
    print(0)
    import sys
    sys.exit()
if n == 2:
    print(b[1])
    import sys
    sys.exit()

stack_deque.append(b[1])
stack_deque.append(b[1])
ret = b[0]
for bi in b[2::]:
    ret += stack_deque.popleft()
    stack_deque.append(bi)
    stack_deque.append(bi)
print(ret)

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

l.sort(reverse=True)

print(sum(l[:(n-1)]))

Submission status: Wrong Answer

Solution code:
"""
AtCoder :: Beginner Contest 173 :: Chat in a Circle
https://atcoder.jp/contests/abc173/tasks/abc173_d
"""
import sys


def solve(players):
    """Solve puzzle."""
    circle = sorted((f, i) for i, f in enumerate(players))
    comfort = sum(c[0] for c  in circle[1:])
    return comfort


def main():
    """Main program."""
    player_count = int(sys.stdin.readline())
    players = [int(i) for i in sys.stdin.readline().split()]
    print(solve(players))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(sum(Asrt[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = sorted([int(x) for x in input().split()])
print(sum(arr[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int, input().split()))
l.sort()
l.reverse()
s = l[0]
if N%2==0:
  c = N//2-1
  for i in range(c):
    s = s + l[i+1]*2
  
else:
  d = (N-3)//2
  for i in range(d):
    s = s + l[i+1]*2
    s = s+l[(N-1)//2]
print(s)

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
	cnt = 0
	yo = 2
	nexts = 0

	for i,val in enumerate(A):
		if i == 0:
			maxs = val
			continue
		if i == 1:
			ans += maxs
			maxs = val
		else:
			ans += maxs
			if val == maxs:
				yo += 1
			else:
				cnt += 1
				if nexts < val:
					nexts = val
			if cnt == yo:
				cnt = 0
				if nexts > val:
					maxs = nexts
				else:
					maxs = val
				nexts = 0

	print(ans)




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

Submission status: Wrong Answer

Solution code:

N = int(input())
A = sorted(map(int, input().split()))[::-1]

before = 0
comfort = 0
for i in range(1,N):
    if i == 1:
        comfort += A[0]
    if i == 2:
        comfort += A[1]
        before = A[1]
    if i>2:
        if A[i] == A[i-1]:
            comfort += before
        else:
            comfort += A[i-1]
            before = A[i]

print(comfort)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
sumA = 0
for x in range(N):
    if x == 0:
        sumA += 0
    elif x == 1:
        sumA += A[0]
    elif x == 2:
        sumA += A[1]
    else:
        sumA += A[x - 2]
print(sumA)

Submission status: Wrong Answer

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

print(sum(a_list) - min(a_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
sett = set(lst)
min_num = min(lst)

res = 0
while len(sett) != 0:
    max_num = max(sett)
    max_num_count = lst.count(max_num)
    res += max_num * (max_num_count - 1)
    res += max_num
    sett.remove(max_num)

res -= min_num
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def bubble_sort(arr):
    change = True
    while change:
        change = False
        for i in range(len(arr) - 1):
            if arr[i] > arr[i + 1]:
                arr[i], arr[i + 1] = arr[i + 1], arr[i]
                change = True
    return arr
  
N=input()
N=int(N)

A=input().strip().split()
A=[int(s) for s in A]
A_arr=bubble_sort(A)
print(sum(A_arr[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
4
2 2 1 3
'''

def solve(l):
	n = len(l)
	l.sort(reverse=True)
	ans = 0
	ans = 0
	hp = [[-l[0],-l[0]]]
	for i in range(1,n):
		curr = l[i]
		p = heappop(hp)
		minn = max(p)
		ans -= minn
		heappush(hp,[max(p),-curr])
		heappush(hp,[min(p),-curr])
	return ans
	

N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

A.sort(reverse=True)

q = A[:2][:]
ans = A[0]

ans += q[-1]*(n-2)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
lst = []
for i in range(len(a)):
    lst.append(sum(a)-a[i])
print(max(lst))

Submission status: Wrong Answer

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

ans = 0
mn = A[0]
for i, a in enumerate(A[1:]):
    ans += mn
    if a < mn:
        mn = a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]

n = int(input())
a_li = list(map(int, input().split()))
a_li.sort(reverse=True)
print(2*sum(a_li[:int((n+1)/2)])-a_li[0])

Submission status: Wrong Answer

Solution code:
N=int(input())
Alist=list(map(int,input().split()))
Alist.sort(reverse=True)
kokochiyosa=0
for i in range(N-1):
    kokochiyosa+=Alist[i]

print(kokochiyosa)

Submission status: Wrong Answer

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

score = a[0]
score += a[1]

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

print(score)

Submission status: Wrong Answer

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

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

A.sort(reverse=True)

if N == 2:
    print(A[0])
    sys.exit()

if N == 3:
    print(A[0]+A[1])
    sys.exit()

B = []
B.append(A[1])
B.append(A[2])
B.append(A[2])
ans = A[0]+A[1]

print(B)

for i in range(3,N):
    ans += max(B)
    index = B.index(max(B))
    B.pop(index)
    B.append(A[i])
    B.append(A[i])
    
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit

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

point = a[0]

one = a[0]
two = a[1]

for i in a[2:]:
    point += two
    one = two
    two = i

print(point)

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):
		ans+=a[i-2]
	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)
ans = 0
before = A[0]
for a in A[1:]:
    ans += before
    before = a
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a.sort()
a1 = int(a[-1])
a2 = int(a[-2])
m = n-2
c = a1 + a2*m
print(c)

Submission status: Wrong Answer

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

b=[a[0],a[1]]
ans=a[0]
for i in range(2,n):
    cnt=0
    d=1
    for l in range(len(b)-1):
        if min(b[l],b[l+1])>cnt:
            d=l+1
            cnt=min(b[l],b[l+1])
    if min(b[0],b[-1])>cnt:
        b.append(a[i])    
        ans+=min(b[0],b[-1])
    else:
        b.insert(d,a[i])
        ans+=cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
from collections import deque
A = sorted(A,reverse=True)
Q = deque(A[0:2])
ans = 0
ans += A[0]
turn = False
for a in A[2:]:
    add = 0
    if turn:
        Q.append(a)
        turn = False
        add = min(Q[-2],Q[0])
    else:
        Q.appendleft(a)
        turn = True
        add = min(Q[-1],Q[1])
    ans += add
print(ans)

Submission status: Wrong Answer

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

ans=sum(A)-min(A)

print(ans)

Submission status: Wrong Answer

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
a = intl()
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())
# = str(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

A = list(sorted(A))
del A[0]

print(sum(A))

Submission status: Wrong Answer

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

answer = sum(A) - min(A)
print(answer)

Submission status: Wrong Answer

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

if N == 2:
    ans = A[0]
elif N == 3:
    ans = sum(A[:2])
elif N == 4:
    ans = sum(A[:2])+A[1]
elif N == 5:
    ans = sum(A[:2])+A[1]*2
elif N == 6:
    ans = sum(A[:2])+A[1]*2+A[2]
else:
    ans = sum(A[:2])+A[1]*2+A[2]
    ind = N-6
    if ind%2 == 0:
        ans += sum(A[3:3+ind//2])*2
    else:
        ans += sum(A[3:3+ind//2])*2+A[3+ind//2+1]


print(ans)

Submission status: Wrong Answer

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

A.sort()

print(sum(A[-(N-1):]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(sum(A)-A[N-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

res = 0
mi = A[0]
for a in A[1:]:
    res += mi
    mi = min(mi, a)

print(res)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
aa = tuple(sorted(map(int, input().split())))

ans = 0
c = Counter(aa)
pk = None
pv = None
for k in reversed(sorted(c)):
    if pk is None:
        nv = 0
        ans = k * (c[k] - 1)
    else:
        nv = min(pv, c[k])
        ans += pk * nv + k * max(0, c[k] - nv)
    pk = k
    pv = c[k]
print(ans)

Submission status: Wrong Answer

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

ans = ls[0]

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

Submission status: Wrong Answer

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

if n % 2 == 0:
    print(a[0] + sum(a[1:n//2]) * 2)
else:
    print(a[0] + sum(a[1:n//2]) * 2 + a[n//2 + 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:
import math
n=int(input())
lst=list(map(int,input().strip().split()))
lst.sort()
print(sum(lst[1:n]))

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())
numbers = sorted(list(map(int, input().split())), reverse=True)

result = []
max = 0
for i, number in enumerate(numbers):
    if i == 0:
        result.append(number)
        continue
    max += min(result)
    result.append(number)

print(max)

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)
        elif i == 1:
            ans += cnt_a[i - 1][0] + max(0, c - 1) * v
        else:
            ans += cnt_a[i - 1][0] * min(c, 3) + max(0, c - 3) * 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:
n=int(input())
a=[int(i) for i in input().split()]
f=0
s=0
r=0
a=sorted(a)[::-1]
for i in range(len(a)):
    r+=s
    if i==0:
        f=a[i]
        s=a[i]
    else:
        s=a[i]
        if f < s:
            f,s=s,f
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())

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

B=sorted(A,reverse=True)

ans=sum(B[:-1])
print(ans)

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

A.sort(reverse=True)

comfort = list()
for i in range(1, N):
    if A[i-1] == A[i]:
        comfort.append(A[i])
    else:
        comfort.append(A[i])
        comfort.append(A[i])

ans = sum(comfort[:N])
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n  = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse = True)
    seki = [a[0],a[0]]
    ans = 0
    for i in range(1,n):
        if seki[0]<seki[1]:
            index = 0
        else:
            index = 1
        ans += seki[index]
        seki[abs(index-1)] = a[i]
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[-1]
del a[-1]
if n%2==0:
  for _ in range(n//2-1):
    m+=2*a.pop(-1)
else:
  for _ in range((n-3)//2):
    m+=2*a.pop(-1)
  m+=a[-1]
  print(m)

Submission status: Wrong Answer

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


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:
a=int(input())
b=list(map(int,input().split()))
b.sort()
c=0
j=-1
for i in range(a-1):
    c+=b[j]
    j-=1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
_A = []
for i, a in enumerate(A):
    if i==0:
        _A.append(a)
    else:
        ans += min(_A)
        _A.append(a)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 = ans + A[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a.sort()
a1 = [int(a[n-2]), int(a[n-1])]
c = int(a[n-1])
for i in range(2,n):
  j = n-i-1
  c += int(a1[-2])
  a1.append(int(a[j]))
  a1.sort()
print(c)

Submission status: Wrong Answer

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

a.sort()
a.reverse()
print(sum(a)-a[-1])

Submission status: Wrong Answer

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

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:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *A = map(int, read().split())

A = sorted(A)[::-1]
m_center = A[0]
m_left = A[1]
m_right = A[1]

ans = A[0]
for a in A[2:]:
    if m_left > m_right:
        ans += min(m_center, m_left)
        m_left = a
    else:
        ans += min(m_center, m_right)
        m_right = a

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = [int(s) for s in input().split()]

As = sorted(As)

ans = As[-1]

idx = (N-2) // 2
ans += sum(As[-2-idx:-2]) * 2
if (N-2)%2 == 1:
    ans += As[-2-idx]

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)

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:

import datetime
from decimal import Decimal, ROUND_DOWN
import heapq
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import statistics
# import numpy as np
# n = int(input())
# n, m, p = list(map(int, input().split()))
# a = list(map(int, input().split()))
#
#  abc = [int(input()) for i in range(5)]
n = int(input())
#h, w, k = list(map(int, input().split()))
#A = list(map(int, input().split()))
a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
#s = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#ab = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))

a.sort(reverse=True)
# print(a)
total = 0
for i in range(n-1):
    total += a[i]
print(total)

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

l.sort(reverse=True)

print(sum(l[:n-1]))

Submission status: Wrong Answer

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

s=sorted(set(a),reverse=True)
ans=0
for i in s:
    c=a.count(i)
    ans+=c*i

print(ans-a[-1])