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 math

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(1, N):
	ans += A[math.ceil(i / 2)]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num=int(input())
s=[int(i) for i in input().split()]
array=[0 for _ in range(num)]
if 2<=num<=2*10**5 and max(s)<=10**9 and min(s)>=1:
    s.sort(reverse=True)
    point=0
    for (i,j) in enumerate(s):
        if len(array)==0:
            array.append(j)
            point+=0
        elif len(array)==1:
            array.append(j)
            point+=array[0]
        elif len(array)==2:
            array.append(j)
            point+=array[0]
        else:
            if array[i-1]>=array[i]:
                point+=array[i-1]
                array.insert(i,j)
            else:
                point+=array[i]
                array.insert(i,j)
    print(point)

Submission status: Wrong Answer

Solution code:
num=int(input())
s=[int(i) for i in input().split()]
if 2<=num<=2*10**5 and max(s)<=10**9 and min(s)>=1:
    s.sort(reverse=True)
    point=0
    for (i,j) in enumerate(s):
        if i+1==len(s):
            break
        point+=j
    print(point)

Submission status: Wrong Answer

Solution code:
num=input()
s=[int(i) for i in input().split()]
s.sort(reverse=True)
point=0
for (i,j) in enumerate(s):
    if i+1==len(s):
        break
    point+=j
print(point)

Submission status: Wrong Answer

Solution code:
import copy
 
inp = input()
friends = input()
friendList = friends.split()
sortedFriends = sorted(friendList, reverse=True)
confs = [sortedFriends[0]]
# copied = copy.deepcopy(sortedFriends)[1:]
sortedFriends.extend(sortedFriends[1:])

sortedFriends = sorted(sortedFriends, reverse=True)
 
#for i in sortedFriends:
    # print(int(i))
confSum = 0
for i in range(int(inp)-1):
    conf = int(sortedFriends[i])
    confSum += conf
print(str(confSum))

Submission status: Wrong Answer

Solution code:
N,*As=map(int,open(0).read().split());As.sort();print(As[-1]+sum(As[-2-i//2]for i in range(N-1)))

Submission status: Wrong Answer

Solution code:
N,*As = map(int, open(0).read().split());As.sort();print(As[0]+sum(As[1+i//2]for i in range(N-1)))

Submission status: Wrong Answer

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

A.sort()
A.reverse()
ans = 0
ans += A[0]

if len(A) % 2 == 0:
  tmp = 0
  for i in range(1, int((N-2)/2)+1):
    tmp += A[i] * 2
else:
  tmp = 0
  for i in range(1, int((N-1)/2)+1):
    tmp += A[i] * 2
  tmp -= A[int((N-3)/2)]

ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline 

N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)[::-1] # 降順ソート

count = 0
limit = 1
t = 1
for i in range(N - 1):
    if i == 0:
        count += A_sort[0]
    else:
        count += A_sort[limit]
        t += 1
        if t % 2 == 0:
            limit += 1
        

print(count)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline 

N = int(input())
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)[1:][::-1] # 降順ソート

count = 0
limit = 1
t = 1
for i in range(N - 1):
    if i == 0:
        count += A_sort[0]
    else:
        count += A_sort[limit]
        t += 1
        if t % 2 == 0:
            limit += 1
        

print(count)

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())
A.sort()
print(sum(A[-(k // 2)] for k in range(1, N)))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
#多分下から2番目の値を取り続ける
A.sort(reverse=True)
print(sum(A[:-1]))

Submission status: Wrong Answer

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

in_list.sort(reverse=True)
result = 0
if len(in_list) == 2:
    result = in_list[1]
else:
    if n % 2 == 1:
        #print(sum(in_list[2:((n+1)//2)])*2)
        #print(len(in_list))
        #print(in_list[n-1])
        #print(in_list[2:((n+1)//2)+1])
        result += sum(in_list[2:((n+1)//2)+1]) * 2 - in_list[n-1] +in_list[1]
    elif n % 2 == 0:
        result += sum(in_list[2:(n+1//2)+1]) * 2 +in_list[1]

print(result)

Submission status: Wrong Answer

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

in_list.sort(reverse=True)
result = 0
if len(in_list) == 2:
    result = in_list[1]
else:
    if n % 2 == 1:
        print(sum(in_list[2:((n+1)//2)])*2)
        print(len(in_list))
        print(in_list[n-1])
        print(in_list[2:((n+1)//2)+1])
        result += sum(in_list[2:((n+1)//2)+1]) * 2 - in_list[n-1] +in_list[1]
    elif n % 2 == 0:
        result += sum(in_list[2:(n+1//2)+1]) * 2 +in_list[1]

print(result)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il(), reverse=True)

    ret = 0
    for k in range(1, N):
        ret += A[N - (k // 2) - 1]
    print(ret)


if __name__ == '__main__':
    main()

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:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
a = li()

a.sort()

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

Submission status: Wrong Answer

Solution code:
N = 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()))

A.sort()
res = 0

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

print(res)

Submission status: Wrong Answer

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

A.sort()
A.reverse()

res = A[0]
x = A[:2]

for a in A[2:]:
    res += min(x[-2:])
    x.append(a)

print(res)

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

Submission status: Wrong Answer

Solution code:
import heapq


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


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


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

Submission status: Wrong Answer

Solution code:
import heapq


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


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


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

Submission status: Wrong Answer

Solution code:
import heapq


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


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


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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
A = [int(x) for x in input().split()]
A.sort()
A.reverse()

point = 0
h = []
tmp = (A[0], A[0])
heapq.heappush(h, tmp)
for i in range(1, N):
    joiner = A[i]
    item = h.pop()
    if len(item) == 2:
        point += item[0]
        heapq.heappush(h, (min([item[1], joiner]), item[1], joiner))
        heapq.heappush(h, (min([item[1], joiner]), item[1], joiner))
    else:
        point += item[0]
        heapq.heappush(h, (min([item[1], joiner]), item[1], joiner))
        heapq.heappush(h, (min([item[2], joiner]), item[2], joiner))
print(point)

Submission status: Wrong Answer

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

A.sort(reverse = True)
ans = A[0]
count = 1
flg = False
for i in range(1,N):
    for j in range(2):
        ans += A[i]
        count += 1
        if count >= N-1:
            flg = True
            break
    if flg == True:
            break
        
print(ans)

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:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
print(sum(a[0:-1]))

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:
import heapq

N = int(input())
A = [int(x) for x in input().split()]
A.sort()
A.reverse()

point = 0
h = []
tmp = (A[0], A[0])
heapq.heappush(h, tmp)
for i in range(1, N):
    joiner = A[i]
    item = h.pop()
    if len(item) == 2:
        point += item[0]
        heapq.heappush(h, (min([item[1], joiner]), item[1], joiner))
    else:
        point += item[0]
        heapq.heappush(h, (min([item[1], joiner]), item[1], joiner))
        heapq.heappush(h, (min([item[2], joiner]), item[2], joiner))
print(point)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=1)
    d, m = divmod(N, 2)
    n = [2] * (d + m)
    n[0], n[-1] = 1, n[-1] - m
    ans = 0
    for i, k in enumerate(n):
        ans += A[i] * k
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

read = sys.stdin.buffer.read

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

deq = deque([A[0]])
ans = 0

for x in A[1:]:
    deq.append(x)
    deq.append(x)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


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


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())

        A = int_input()

        A.sort(reverse=True)

        res = sum(A[:-1])

        print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix
# CreatedDate:  2020-07-06 21:04:46 +0900
# LastModified: 2020-07-06 21:13:15 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    s = a.pop()
    t = a.pop()
    confortable = s
    while a:
        target = a.pop()
        confortable += min(s, t)
        tmp = t
        t = target
        s = tmp
    print(confortable)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import queue
N = int(input())
U = input().split()
l = [0 for i in range(N)]
for i in range(N):
    l[i]= int(U[i])
ans = 0
l.sort()
l.reverse()
q = queue.LifoQueue()
q.put(l[0])
for i in range(1,N):
    ans += q.get()
    for j in range(2):
        q.put(l[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline 

N = input()
A = np.array(readline().split(), np.int64)
A_sort = np.sort(A)[1:]
Acum = np.cumsum(A_sort)

print(Acum[-1])

Submission status: Wrong Answer

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

#print(A)

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

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()
ans=a[-1]
for i in range(N-2):
  ans+=a[-i//2-2]
print(ans)

Submission status: Wrong Answer

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

ans = li_a[0]
if n % 2 == 0:
    for i in range(1,n//2):
        ans += 2*li_a[i]
else:
    for i in range(1,n//2):
        ans += 2*li_a[i]
    ans += li_a[n//2+1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N==2:
  print(A[-1])
  exit()
  
ans=0
for i in range(N-1):
  ans+=A[(i-2)//2]
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
ans = 0
L = []
for i in range(N):
    if i == 0:
        L.append(A[i])
    elif i % 2 == 0:
        L.append(A[i])
        ans += min(L[0],L[-2])
    else:
        L.insert(0,A[i])
        ans += min(L[1],L[-1])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()
A.sort(reverse=True)

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

ans = A[0] + sum(A[:(n-1)//2]) * 2 - A[(n-1)//2+1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int( input() )
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
    arr.append(int(i))
left = []
right = []
ans = 0 
#print(arr)
arr = sorted(arr)
arr = arr[::-1]
for j, i in enumerate(arr):
    if j == 0 :
        left.append(int(i))
    elif j == 1 :
        right.append(int(i))
        ans += left[-1]
        
    elif len(left) == len(right):
        mins = min(left[-1], right[-1])
        ans += mins
        left.append(i)
    else:
        mins = min(left[-1], right[-1])
        ans += mins
        right.append(i)
    #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input());
A = [int(x) for x in input().split()];
A.sort(reverse=True);
#print(A);
c =[];
c.append(A[1]);
confort = 0;
c.append(A[1]);
confort = A[0];
for i in range(2,N) :
    minv = min(c);
    idx = c.index(minv);
    c[idx] = A[i];
    c.insert(idx,A[i]);
    confort += minv;
    #print(c,confort)
    
print(confort);
#print(sum(A)-min(A));

Submission status: Wrong Answer

Solution code:
def nth_element(array, will):
    will -= 1
    n = len(array)
    left = 0
    right = n-1
    while right > left:
        i = left-1
        j = right
        v = array[right]
        while True:
            i += 1
            j -= 1
            while array[i]<v:i+=1
            while array[j]>v:j-=1
            if i>=j:break
            array[i],array[j] = array[j],array[i]
        array[i],array[right] = array[right],array[i]
        if i == will:break
        if i > will:
            right = i-1
        else:
            left = i+1
    return array

# from random import randrange
# for i in range(100):

n = int(input())
A = list(map(int,input().split()))
# n = randrange(2,10)
# A = [0]*n
# for j in range(n):
#     A[j] = randrange(1,1000)
k = 1 + (n-1)//2

nth_element(A,n-k+1)
# B = sorted(A)
ans = 0
M = 0
# m = B[-1]
for i in range(-1,n-1):
    ans += A[n - (i+1)//2 - 1]
    M = max(M, A[n- (i+1)//2 - 1])
    # ans -= B[n-(i+1)//2 - 1]
ans -= M
# ans += m
# if ans != 0:
#     print(n,A)

Submission status: Wrong Answer

Solution code:
def nth_element(array, will):
    will -= 1
    n = len(array)
    left = 0
    right = n-1
    while right > left:
        i = left-1
        j = right
        v = array[right]
        while True:
            i += 1
            j -= 1
            while array[i]<v:i+=1
            while array[j]>v:j-=1
            if i>=j:break
            array[i],array[j] = array[j],array[i]
        array[i],array[right] = array[right],array[i]
        if i == will:break
        if i > will:
            right = i-1
        else:
            left = i+1
    return array

from random import randrange
for i in range(100):
    # n = int(input())
    # A = list(map(int,input().split()))
    n = randrange(2,10)
    A = [0]*n
    for j in range(n):
        A[j] = randrange(1,1000)
    k = 1 + (n-1)//2

    nth_element(A,n-k+1)
    B = sorted(A)
    ans = 0
    M = 0
    m = B[-1]
    for i in range(-1,n-1):
        ans += A[n - (i+1)//2 - 1]
        M = max(M, A[n- (i+1)//2 - 1])
        ans -= B[n-(i+1)//2 - 1]
    ans -= M
    ans += m
    if ans != 0:
        print(n,A)

Submission status: Wrong Answer

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

# check
sort_A = sorted(A, reverse=True)
print(sum(sort_A[:-1]))

Submission status: Wrong Answer

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

# check
sort_A = sorted(A, reverse=True)
print(sum(A[:-1]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
X = int(input())
x_list = list(map(int, input().split()))
sum = sum(x_list)
print(sum - min(x_list))

Submission status: Wrong Answer

Solution code:

N = int(input())
data =  [int(x) for x in input().split()]
data.sort(reverse=False)

point_list = [data.pop(),]
result = 0
while N > 2:
    point_list.append(data.pop()*2)
    N -= 2
if N == 1:
    point_list.append(data.pop())
if N == 2:
    point_list.append(data.pop()*2)

print(sum(point_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
data =  [int(x) for x in input().split()]
data.sort(reverse=False)

point_list = [data.pop(),]
N = N - 1
result = 0
while N > 2:
    point_list.append(data.pop()*2)
    N -= 2
if N == 1:
    point_list.append(data.pop())

print(sum(point_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
data =  [int(x) for x in input().split()]
data.sort(reverse=False)

point_list = [data.pop(),]

result = 0
while N > 1:
    point_list.append(data.pop()*2)
    N -= 2
if N == 1:
    point_list.append(data.pop())

print(sum(point_list))

Submission status: Wrong Answer

Solution code:
def nth_element(array, will):
    will -= 1
    n = len(array)
    left = 0
    right = n-1
    while right > left:
        i = left-1
        j = right
        v = array[right]
        while True:
            i += 1
            j -= 1
            while array[i]<v:i+=1
            while array[j]>v:j-=1
            if i>=j:break
            array[i],array[j] = array[j],array[i]
        array[i],array[right] = array[right],array[i]
        if i == will:break
        if i > will:
            right = i-1
        else:
            left = i+1
    return array

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

k = 1 + (n-1)//2

nth_element(A,n-k+1)

ans = 0
for i in range(n-1):
    ans += A[n - (i+1)//2 - 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)
print(sum(arr[:-1]))

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	A = list(rli())
	A.sort(reverse = True)
	comfort = 0
	H = []
	for f in A:
		L = [] 
		for _ in range(2):
			if not H: break
			L.append(-heappop(H))
		for oldf in L:
			heappush(H, -oldf)
		comfort += min(L) if L else 0
		heappush(H, -f)
	print(comfort)
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))[::-1]
ans = 0
temp = a[0]
lim = 1
cnt = 1
for v in a[1:]:
  if lim==0:
    temp = pre
    lim = cnt
    cnt += 1
  ans += temp
  cnt += 1
  lim -= 1
  pre = v
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)*(1)
    ans += tmp
    heapq.heappush(q, arr[i])
    heapq.heappush(q, arr[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
d = deque()
c = 0
count = 2
ans = 0

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

Submission status: Wrong Answer

Solution code:
import copy
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
d = deque()
c = 0
count = 2
ans = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque


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

circle = deque([A.pop()])
while True:
    try:
        circle.append(A.pop())
        ans += min(circle[0], circle[-2])
        circle.appendleft(A.pop())
        ans += min(circle[0], circle[-2])
    except IndexError:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
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())
data =  [int(x) for x in input().split()]
data.sort(reverse=False)

point_list = [data.pop(),]

result = 0
while N > 2:
    point_list.append(data.pop()*2)
    N -= 2
if N == 1:
    point_list.append(data.pop())

print(sum(point_list))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A.sort(reverse=True)

dp=deque([A[1]])
point=A[0]
for n in range(2,len(A)):
    p=dp.popleft()
    cnt=0
    if cnt==0:
        cnt+=1
        dp.append(A[n])
        point+=p
    else:
        cnt=0
        dp.append(A[n])
        point+=p

print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

B = [0 for _ in range(3)]

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

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

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