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:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
t=[A[0],A[1]]
ans=A[0]
for i in range(2,N):
    if t[1]>=t[-1]:
        ans+=t[1]
    else:
        t.append(A[i])
        ans+=t[-1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np


n = int(input())
ajs_str = input().split()
ajs = [int(aj) for aj in ajs_str]

ajs_sorted = np.sort(ajs)[::-1]

print(int(ajs_sorted[:-1].sum()))

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = sorted([int(x) for x in input().strip().split()], reverse=True)
    print(sum(A[:-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:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    A.sort()
    print(sum(A[1:]))

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys


def resolve(in_):
    n = int(in_.readline())
    a = list(map(int, in_.readline().split()))
    assert len(a) == n
    a.sort(reverse=True)
    return sum(a[:-1])


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


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[:-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

As.sort(reverse=True)
rlt = As[0]

if N == 2:
  print(rlt)
else:
  n = N // 2
  if N % 2 == 1:
    for i in range(1,n):
      rlt += 2*As[i]
    rlt += As[n]
  else:
    for i in range(1,n):
      rlt += 2*As[i]
    
print(rlt)

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

print(ans + a[-2])

Submission status: Wrong Answer

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


def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse = True)
    niko = (len(A) - 2) // 2
    conft = A[0] + sum(A[1:niko + 1]) * 2
    if (len(A) - 2) % 2 == 1:
        conft += A[niko + 2]
    print(conft)
    
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

A.pop(n-1)
print(sum(A))

Submission status: Wrong Answer

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

A_sorted = sorted(A,reverse = True)

import heapq

circle = []
heapq.heappush(circle, -A_sorted[1])
heapq.heappush(circle, -A_sorted[1])
answer = A_sorted[0]

for i in range(2,N):
    target = A[i]
    popped = heapq.heappop(circle)
    answer -= popped
    heapq.heappush(circle, -target)
    heapq.heappush(circle, -target)

print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A_arr = list(map(int, input().split()))
A_arr = sorted(A_arr, reverse=True)
comfort = 0
for i in range(len(A_arr)):
    if i == 0:
        pass
    else:
        comfort += A_arr[i - 1]
print(comfort)

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()
B = A[::-1]
ans = 0
print(sum(B) - B[-1] - B[-2] + B[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(reverse=True)
P=A[0]
for i in range(2,N):
  P+=min(A[i-1],A[i-2])
print(P)

Submission status: Wrong Answer

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

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())
A=[int(_) for _ in input().split(" ")]

ans=0
for i in range(N):
  ans+=A[i]

mi=min(A)

ans=ans-mi

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort(reverse=True)

    ans = 0
    m = 10 ** 10
    for i in range(1, N):
        if i == 1:
            ans += A[0]
            m = min(m, A[i])
        else:
            ans += m
            m = min(m, A[i])

    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys  import stdin,stdout

import bisect
import math
def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
            n=n-1
        else:
            a=(a*a)
            n=n>>1
    return r

m=(10**9 +7) 
def solve():
    n=inp()
    l=li()
    s=sum(l)
    k=set(l)
    print(s-n+len(k))
    
            
        
    

solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import heapq
def resolve():
    N,=pin()
    A=[*pin()]
    A.sort(reverse=True)

    ans=0
    h=[]
    heapq.heappush(h,0)
    for i in range(1,N):
        temp=heapq.heappop(h)
        print(temp)
        ans+=A[temp]
        heapq.heappush(h,i)
        heapq.heappush(h,i)
    print(ans)

#%%submit!
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(l) == 1:
  print(0)
else:
  ans = l[0]
  num = 1
  for i in range(1, n):
    ans += l[i]
    num += 1
    if num == n-1:
      break
    ans += l[i]
    num += 1
    if num == n-1:
      break
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
sum_ = sum(x)
min_ = min(x)
flag = 0
x = sorted(x)

for i in range(n-1):
  if x[i] == x[i+1]:
    flag = 1
    break

if flag == 0:
  print(sum_)
else:
  print(sum_-min_)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse = True)
som = 0
minm = arr[0]
for i in range(1,n):
    som+=minm
    minm = min(minm,arr[i])

print(som)

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 heapq
N = int(input())
*A, = map(int, input().split())
A.sort()
A.reverse()

ans = 0
hq = [(A[0], A[0], A[0])]
for a in A[1:]:
    s, n, m = heapq.heappop(hq)
    ans += s
    heapq.heappush(hq, (a, n, a))
    heapq.heappush(hq, (a, m, a))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


import bisect

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

a.sort(reverse=True)

ans = 0
que = []
diff = []
for i, e in enumerate(a):
  if len(que) == 0:
    que.append(e)
    diff.append((e, 0))
  else:
    ii = diff[-1][1]
    que.insert(ii, e)
    diff.insert(bisect.bisect(diff, (e, i)), (e, i))
    ans += min(que[ii - 1], que[(ii + 1) % len(que)])
  dprint(que)
  dprint(diff)
  dprint(ans)


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)):
    if i % 2 == 0:
        ans += A[i-1]
    else:
        ans += A[i-2]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    #隙間には2個入る
    res = a[0]
    tmp = a[1]
    k = 1
    cnt = 0
    for i in range(2,n):
        res += tmp
        cnt+=1
        if(cnt == 2):
            k+=1
            tmp = a[k]
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys  import stdin,stdout

import bisect
import math
def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
            n=n-1
        else:
            a=(a*a)
            n=n>>1
    return r

m=(10**9 +7) 
def solve():
    n=inp()
    l=li()
    s=sum(l)
    k=set(l)
    print(s-len(k))
    
            
        
    

solve()

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:
n = int(input())

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

a.sort()

ans = 0

for i in range(len(a) - 2):
    ans += a[i]

print(ans + a[-2])

Submission status: Wrong Answer

Solution code:
import numpy as np
import heapq

N = int(input())
A =  np.sort([int(x) for x in input().split(" ")])[::-1]

q = [(-A[1], (0, 1))]
confort = A[0]
heapq.heapify(q)

i = 2
while N > i:
    m = heapq.heappop(q)
    # print(f"{m[1][0]}と{m[1][1]}の間に割り込む. 気持ち良さ {-m[0]}")
    confort -= m[0]
    heapq.heappush(q, (-A[i], (i, m[1][0])))
    heapq.heappush(q, (-A[i], (i, m[1][1])))
    i += 1
print(confort)

Submission status: Wrong Answer

Solution code:
from collections import deque, defaultdict

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

A.sort(reverse=True)

d = defaultdict(int)
d[A[0]] += 1
x = deque([A[0]])
ans = 0
for a in A[1:]:
    d[x[0]] -= 1
    ans += x[0]
    if d[a] == 0:
        x.append(a)
    d[a] += 2
    if d[x[0]] == 0:
        x.popleft()
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)
forret = sorted(A_i)[1:]
print(sum(forret))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

a.sort()
print(sum(a[2:])+a[n-2])

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input().strip())
L = list(map(int, input().strip().split()))

L.sort(reverse=True)
hq=[L[0]]
ans=0

for i in range(1,n):
    ans+=heapq.heappop(hq)
    heapq.heappush(hq, L[i])
    heapq.heappush(hq, L[i])
    
print(ans)

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
for i in range(n):
    y += x
    if i == 0:
        x = b[0]
    elif i < 3:
        if b[i] < x:
            x = b[i]
print(y)

Submission status: Wrong Answer

Solution code:
from collections import deque

d= deque()

N = int(input())
L = map(int,input().split())
L = sorted(list(L))[::-1]
import heapq
ans = 0
ideal = []
ans += L[0]
del L[0]
heapq.heappush(ideal, L[0])
heapq.heappush(ideal, L[0])
del L[0]

for x in L:
    ans += heapq.heappop(ideal)
    heapq.heappush(ideal, x)
    heapq.heappush(ideal, x)

print(ans)

Submission status: Wrong Answer

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    A=list(mi())

    A.sort(reverse=True)
    dp = [0] * N
    ck = [A[0]]
    for i in range(1,N):
        a = A[i]
        dp[i] = min(ck[0],ck[-1]) + dp[i-1]
        ck.append(a)

    print(dp[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)

left = a[0]
right=a[0]
conft=0
for i in range(1,n):
    now = a[i]
    if left>=right:
        conft += right
        right=now
    else:
        conft += left
        left=now
print(conft)

Submission status: Wrong Answer

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

ans = l[0]
num = 1
for i in range(1, n):
  ans += l[i]
  num += 1
  if num == n-1:
    break
  ans += l[i]
  num += 1
  if num == n-1:
    break
  
  
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort(reverse=True)

ans=a[0]
left=a[1]
right=a[1]

for i in range(2,n):
  if i%2==0:
    ans+=left
    left=a[i]
  else:
    ans+=right
    right=a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())
    a = [int(ai) for ai in input().split()]

    print(sum(a) - min(a))


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

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

# endregion

if __name__ == "__main__":
    main()

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(0, 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(reverse=True)
print (sum(a[:-1]))

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:
#! /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]

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

Submission status: Wrong Answer

Solution code:
# ABC173d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

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

    a.sort(reverse=True)
    ans = a[0]
    last1 = a[1]
    last2 = a[1]
    for i in range(2, n):
        if last1 < last2:
            ans += last2
            last2 = a[i]
        else:
            ans += last1
            last1 = a[i]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np


n = int(input())
ajs_str = input().split()
ajs = [int(aj) for aj in ajs_str]

#まず光順に並び替え

ajs_sorted = np.sort(ajs)[::-1]

print(ajs_sorted[:-1].sum())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
A = LI()

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import heapq
def main():
    n = int(input())
    a = [int(t)for t in input().split()]

    a = sorted(a)
    ans = 0

    paired = []

    prev = a.pop()
    temp = a.pop()
    heapq.heappush(paired,(-temp,-prev))
    ans += prev

    
    for _ in range(n-2):
        temp = a.pop()
        pair = heapq.heappop(paired)

        ans -= pair[0]
        heapq.heappush(paired,(-temp,pair[0]))
        heapq.heappush(paired,(-temp,pair[1]))

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

f = 0
t = 1
for i in range(N-2):
    f += 1
    if f == 3:
        t += 1
        count += sa[t]

        f = 0
    else:
        count += sa[t]

print(count)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
n=int(input())
a=get_array()
b=sorted(a)
ans1=b[n-1]
ans2=b[n-2]*(n-2)
print(ans1+ans2)

Submission status: Wrong Answer

Solution code:
def main():
    n, *a = map(int, open(0).read().split())
    b = sorted(a)
    ans = sum(b[1:])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    A = LIST()

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


if __name__ == '__main__':
    main()

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
			if val == maxs:
				pass
			else:
				counts += 1
			if counts == 2:
				maxs = val
				counts = 0

	print(ans)




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

Submission status: Wrong Answer

Solution code:
n = int(input())
al = list(map(int, input().split()))
al.sort(reverse=True)
ans = max(al[:2])
for i in range(n-2):
    # print(i, ans, al[i:i+2])
    ans += min(al[i:i+2])
print(ans)

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)

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=0

for i in range(N-1):
    ans += A[i]

print(ans)

Submission status: Wrong Answer

Solution code:
input = raw_input
n = int(input())
nums = map(int, input().split(" "))

out = sum(nums) - min(nums)
print(out)

Submission status: Wrong Answer

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

A.sort(reverse=True)
if n > 2:
  ans = sum(A) - A[-1] - A[-2] + A[1]
else:
  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)
cnt = 0
S = [A[0]]
for i in range(1,N) :
    cnt += min(S)
    S.append(A[i])
print(cnt)