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 itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline
import copy

# S=(input())
# N=int(input())
# N,K=map(int,input().split())
# ListA=list(map(int,input().split()))
# ListA.sort()#reverse=True)



def resolve():
    N=int(input())
    ListA=list(map(int,input().split()))
    ListA.sort()#reverse=True)

    ans=0
    for i in range(1,N):
        ans+=ListA[i]           

    print(ans) 



resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis = sorted(lis,reverse=True)
prev = lis[0]
count = 0
ans = 0

for i in range(1,n):
    if count<2:
        ans += prev
        count+=1
    else:
        ans+=lis[i]
        prev = lis[i]
        count = 0
print(ans)

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()
a.sort(reverse=True)
# print(a)
ans = a[0]
left = a[0]
right = a[1]
for i in range(2,len(a)):
    if left >= right:
        ans += right
        left = a[i]
    else:
        ans += left
        right = a[i]
        
print(ans)

Submission status: Wrong Answer

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

A_list.sort(reverse=True)

score = 0
for i in range(1, N):
    score += A_list[i-1]

print(score)

Submission status: Wrong Answer

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N = intinput()
    a_arr = list(mulinputs())
    l = len(a_arr)
    is_odd = l % 2
    a_arr.sort(reverse=True)

    # ans = a_arr.pop(0)
    # for _ in range(int(l//2)-1):
    #     ans += (a_arr.pop(0) * 2)
    # if is_odd:
    #     ans += a_arr.pop(0)
    # print(ans)
    idx = 0
    ans = a_arr[idx]
    idx += 1
    for i in range(int(l//2)-1): ans += (a_arr[idx+i])*2
    if is_odd:
        idx += int(l//2)-1
        print(a_arr[idx])
        ans += a_arr[idx]
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int,input().split())
A = sorted(A, reverse=True)
L = [A[0]]
R = [A[1]]
l = 1
r = 1
count = 0
for i in range(2,N):
    if L[-1] < R[-1]:
        count += L[-1]
        L.append(A[i])
        l += 1
    elif L[-1] > R[-1]:
        count += R[-1]
        R.append(A[i])
        r += 1
    else:
        if l <= r:
            count += L[-1]
            L.append(A[i])
            l += 1
        elif l > r:
            count += R[-1]
            R.append(A[i])
            r += 1
count += A[0]
print(count)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    A = sorted(A, reverse=True)
    max_a = max(A)
    ans = 0
    arr = []
    cnt = 0
    cur = 0
    v = max_a

    while cur < len(A) and v == A[cur]:
        cur += 1
        cnt += 1
        arr.append(v)

    while cur < len(A):
        while cur < len(A) and v == A[cur]:
            cur += 1
            cnt += 1

        ans += cnt * v
        # print(v, cnt)
        for i in range(cnt):
            arr.append(v)
        if cur < len(A):
            v = A[cur]
        if len(arr) >= 2 * N:
            break

    # print(arr)
    # print(arr[1:N])
    print(sum(arr[1:N]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

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


def step(lst, idx, a):
    new_lst = lst[:]  # type: list
    new_lst.insert(idx, a)

    if len(lst) == 0:
        conf = 0
    elif len(lst) == 1:
        conf = lst[0]
    else:
        conf = max(new_lst[idx - 1], new_lst[(idx + 1) % len(new_lst)])
    return new_lst, conf


cache = {}

max_conf = -1
for perm in itertools.permutations(range(1, N + 1)):
    cache = [([], 0)]
    for a in perm:
        new_cache = []
        for lst, conf in cache:
            for idx in range(len(lst) + 1):
                new_cache.append(step(lst, idx, a + conf))
        cache = new_cache
    max_conf = max(max_conf, max([conf for _, conf in cache]))

print(max_conf)

Submission status: Wrong Answer

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

#print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
M = 1
while M*2<=N:
    M*=2
C = sum(A[0:M-1])
for i in range(M,N):
	C+=A[i//2]
print(C)

Submission status: Wrong Answer

Solution code:
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
a=sum(arr)
b=min(arr)
print(a-b)

Submission status: Wrong Answer

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

c = 0
q = [a[0]]
for i in a[1:]:
    m = max(q)
    idx = q.index(m)
    c += m
    q.pop(idx)
    q.insert(idx,1)
    q.insert(idx,i)
print(c)

Submission status: Wrong Answer

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

forret = sorted(A_i)
ret = A_i[-1]
for i in range(N-2):
    ret = ret + forret[-1-1-(i//2)]
print(ret)

Submission status: Wrong Answer

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

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()))
print("{}".format(sum(a)-min(a)))

Submission status: Wrong Answer

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

forret = sorted(A_i)
ret = A_i[-1]
for i in range(N-2):
    print('A')
    print('ret', ret)
    ret = ret + forret[-1-1-(i//2)]
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse = True)

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

Submission status: Wrong Answer

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

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

    val_list = []
    heappush(val_list, (-min(A[0], A[1]), -A[0], -A[1], 1))
    ans = A[0]

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



if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
min1 = 1000000000
min2 = 0
result = 0
for sumNum in A:
    if min1 > min2:
        result += min2
        min2 = sumNum
    else:
        result += min1
        min1 = sumNum
print(result)

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 = [int (x) for x in input().split()]
comfort = 0
B = 0
#数字がでかい順に到着させる
B = sorted(A)
comfort = B[-1]
for x in reversed(range(len(sorted(B)))):
    #print(str(B[x]) + ' ' +str(B[x-1]))
    if B[x] >= B[x-1]:
        #print(str(B[x]) + ' ' + str(B[x - 1]))
        comfort += B[x-1]
    elif B[x] <= B[x-1]:
        #print(str(B[x]) + ' ' + str(B[x - 1]))
        comfort += B[x]
    if x == 2:
        break

print(comfort)

Submission status: Wrong Answer

Solution code:

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

sorti = sorted(i, reverse=True)
sorti.insert(0, sorti[-1])

ans = 0
for index, x in enumerate(sorti):

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

print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

pts = 0
for a in sorted(A_LIST)[::-1][:-1]:
    pts += a
print(pts)

Submission status: Wrong Answer

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

ans = 0
l = len(a)//2
if l % 2 == 0:
  b = a[:l]
  ans = 2 * sum(b) - b[0]
else:
  b = a[:l]
  ans = 2 * sum(b)

print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
A=input().strip().split()
A=[int(s) for s in A]
A.sort()
ans=sum(A[1:])
print(ans)

Submission status: Wrong Answer

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

import numpy as np
ARR = np.array(FRI)

ARR = np.sort(ARR)

print(ARR[1:].sum()) # 最後の一人はカウントされない

Submission status: Wrong Answer

Solution code:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import itertools as it

N=one_int()
A=many_int()

sort_A = sorted(A,reverse=True)

print(sum(sort_A) - sort_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:
#D
N = int(input())
an = list(map(int,input().split()))

an.sort()
bn = sorted(an,reverse = True)
long = int(len(an)/2)

Sum1 = 0
Sum2 = 0
Sum3 = 0

Sum1 = sum(an) - an[0]
Sum2 = sum(bn) - bn[0]
Sum3 = sum(an) - an[long]

Max = Sum1

if Max < Sum2:
    Max = Sum2

if Max < Sum3:
    Max = Sum3
    
print(Max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
ans = A[N//2:]
if N//2 == 0:
    print(sum(ans)*2 - max(ans))
else:
    print(sum(ans)*2 - max(ans) - min(ans))

Submission status: Wrong Answer

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

t=sum(a)-a[n-1]

print(t)

Submission status: Wrong Answer

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

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

a.sort(reverse=True)

left = 0
right = 0

s = 0

for i in range(n):
    if i == 0:
        left = a[i]
    elif i == 1:
        s += left
        right = a[i]
    else:
        s += min(left, right)
        right = max(right, a[i])

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split(" ")))
b=sorted(a,reverse=True)
g=0
f=0
c=[]

for i in range(n):
  if i==n-f:
    break
  else:
    num=b.count(b[i])
    if num>1:
      for j in range(num-1):
        b.remove(b[i])
    c.append(num)
    f=f+num-1
h=c[0]
l=0
for i in range(n):
  if i==0:
    g=0
  elif h<=i:
    g=g+b[l]
    l=l+1
    h=h+c[l]
  else:
    g=g+b[l]
    
    
print(g)

Submission status: Wrong Answer

Solution code:
n=int(input(""))
l=input("").split(" ")
a=[]
c=[]
for i in range(n):
    a+=[int(l[i])]
a.sort()
for i in range(n):
    c+=[a[n-i-1]]
cnt=2
nzyou=2
s=c[1]+c[0]

num=2
while(n-1>cnt):
    cnt+=1
    if (num==2**nzyou):
        s+=c[num-1]*2
        if (cnt==n-2):
            break
        cnt+=1
        nzyou+=1
        num=2
    else:
        s+=c[num-1]
        num+=1

print(s)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())

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

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

Submission status: Wrong Answer

Solution code:
N = input()
li = [int(s) for s in input().split(" ")]
Min = min(li)
print(sum(li)-Min)

Submission status: Wrong Answer

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

print(sum(a[:n]))

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
total = arr[0]
for i in range(1, n//2):
    total += 2*arr[i]
if n % 2 == 1:
    total += arr[n//2 + 1]
print(total)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sorti = sorted(i, reverse=True)


#sorti = sorti + [sorti[0]]
sorti.insert(0, sorti[-1])

print(sorti)
    
ans = 0
for index, x in enumerate(sorti):

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

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
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()))

a.sort()
ans = sum(a) - a[0]
print(ans)

Submission status: Wrong Answer

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

A.sort()
A.pop(0)

print(sum(A))

Submission status: Wrong Answer

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

A.sort(reverse = True)
ans = 0
for a in A:
  ans += a

ans -= A[-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input(""))
l=input("").split(" ")
a=[]
c=[]
for i in range(n):
    a+=[int(l[i])]
a.sort()
for i in range(n):
    c+=[a[n-i-1]]
cnt=2
nzyou=2
s=c[1]+c[0]
print(s)
print(c)
num=2
while(n-1>cnt):
    cnt+=1
    if (num==2**nzyou):
        s+=c[num-1]*2
        if (cnt==n-2):
            break
        cnt+=1
        nzyou+=1
        num=2
    else:
        s+=c[num-1]
        num+=1

print(s)

Submission status: Wrong Answer

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

ans = 0
A.sort()
arr = []

for _ in range(2):
    temp = A.pop()
    arr.append(temp)
    
ans += arr[0]

for i in range(N - 2):
    t = min(arr[-1], arr[-2])
    ans += t
    p = A.pop()
    arr.append(p)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    co_list = Counter(num_list)

    count = 0

    num_list = list(set(num_list))
    num_list.sort(reverse=True)

    ans_list = []

    for num in num_list:
        num_c = co_list[num]
        if num_c == 1:
            ans_list.append(num)
        else:
            for _ in range(num_c*2):
                ans_list.append(num)

    for i in range(n-1):
        count += ans_list[i]
        
    print(count)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq


def get_tuple(a, b):
    if a > b:
        a, b = b, a
    return a, -b, a, b


def main(a, N):
    a.sort(reverse=True)
    h = []
    comfort = a[0]
    heapq.heappush(h, get_tuple(a[0], a[1]))
    for i in range(N - 2):
        val = heapq.heappop(h)
        comfort += val[0]
        heapq.heappush(h, get_tuple(a[i], val[2]))
        heapq.heappush(h, get_tuple(a[i], val[3]))
    print(comfort)


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    main(a, N)

Submission status: Wrong Answer

Solution code:
def readInt():
    return list(map(int, input().split()))

n = int(input())
a = readInt()
a.sort(reverse=True)
# print(a)
ans = a[0]
left = a[0]
right = a[1]
for i in range(2,len(a)):
    if left >= right:
        ans += right
        right = a[i]
    else:
        ans += left
        lift = a[i]
        
print(ans)

Submission status: Wrong Answer

Solution code:
## coding: UTF-8
N = int(input())
A = list(map(int,input().split()))

A = sorted(A, reverse = True)
#print(N, A)

ans = 0

if(N == 2):
    print(A[0])
elif(N == 3):
    print(A[0] + A[1])
elif(N == 4):
    print(A[0] + A[1] + A[1])
elif(N == 5):
    print(A[0] + A[1] + A[1] + A[2])
else:
    ans += A[0]
    ans += A[1]
    for i in range(2, N-3):
        ans += A[i]
    ans += A[1]
    ans += A[2]
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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


sr = sorted(coms)

ans = 0
for i in range(n - 1):
    if i == 0:
        ans += sr[0]
    else:
        nth = (i + 1) // 2
        ans += sr[nth]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort(reverse=True)
ls = [0] * n
for i in range(1,n):
    ls[i] = nums[i-1]
print(sum(ls))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

n_sum = sum(n_list) - n_list[-1]
print(n_sum)