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()

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

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST(), reverse=True)

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

print(ans)

Submission status: Wrong Answer

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

ans = 0
circled = []
while len(AN) != 0:
    tmp = AN.pop(0)
    if len(circled) != 0:
        ans += circled[-1]
    circled.append(tmp)
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.sort(reverse = True)
print(sum(a) - min(a))

Submission status: Wrong Answer

Solution code:
# @author 

import sys

class DChatInACircle:
    def solve(self, tc=0):
        n = int(input())
        a = [int(_) for _ in input().split()]
        a.sort()
        it = [a[-1], a[-2], a[-2]] + list(reversed(a[:-2]))
        print(sum(it[:n - 1]))


solver = DChatInACircle()
input = sys.stdin.readline

solver.solve()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000) #use "python" instead of "pypy" to avoid MLE
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heapreplace, heappushpop
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['YES', 'NO']





test_case=1
while test_case:
    test_case-=1

    n=ii()
    a=li()
    a.sort()
    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[:-1]))

Submission status: Wrong Answer

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

ans = sum(aa[1:])
print(ans)

Submission status: Wrong Answer

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

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

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)
    conft = 0
    for i in range(len(A)):
        if i == 0:
            conft += 0
        else:
            conft += A[i - 1]

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

Submission status: Wrong Answer

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

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

n = int(input())
a = lmp()
a.sort(reverse=True)
print(sum(a[:-1]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from collections import deque

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

l = deque([A[1]])

ans = A[0]
for num in A[2:]:
    #print(l)
    ans += l.popleft()
    l.append(num)
    l.append(num)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
# print(f'{A=}')
ans = sum(A) - A[-1]
print(ans)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
A = getList()
A.sort(reverse = True)
print(sum(A[:-1]))

Submission status: Wrong Answer

Solution code:
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import collections
from heapq import *
import json
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    A[i]=-A[i]
heapify(A)
l=[]
ans=0
for i in range(N):
    num=heappop(A)
    ans=ans+min(l,default=0)
    if len(l)>1:
        if l[0]>=l[1]:
            l.pop(0)
        elif l[0]<l[1]:
            l.pop(1)
    l.append(-num)
    #print(l,ans)
    #input()
print(ans)

Submission status: Wrong Answer

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

print(sum(c)-min(c))

Submission status: Wrong Answer

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans =A[1:]
print(sum(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ct = 0
j=n-1
a=0
for i in range(n-1):
  if((j==n-1 and ct==1) or (ct==2)):
    j-=1
  a+=l[j]
  ct+=1
print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
Arr = list(map(int,input().split()))
Arr.sort()
for i in range(N-2,-1,-1):
    Arr[i] += Arr[i+1]
print(Arr[1])

Submission status: Wrong Answer

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

A.sort(reverse=True)

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

Submission status: Wrong Answer

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

A.sort()

ans = sum(A[1:])

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 = A[0]
left = A[1]
right = A[1]
for i in range(2, len(A)):
    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 python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

center = A[0]
l, r = center, center

ct = 0

ret = 0
for i in A[1:]:
    
    if ct % 2 == 0:
        l = i
    else:
        r = i
    ct += 1
    ret += max(l, r)
print(ret)

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = sorted(map(int, args[1].split()), reverse=True)
    return str(sum(A[:-1]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

A.sort(reverse=True)
result = 0
for i in range(N):
    result += A[(i + 1) // 2]
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort(reverse=True)

ans = 0
que = []
for e in a:
  if len(que) != 0:
    ans += min(que[-1], que[0])
  que.append(e)

print(ans)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    print(sum(arr)-min(arr))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis = sorted(lis,reverse=True)
ans = 0
fir=0
sec=0
if n == 2:
    print(lis[1])
elif n == 3:
    print(lis[1]+lis[2])
else:
    ans += lis[0]+lis[1]
    fir= lis[2]
    sec = lis[1]
    for i in range(3,n):
        ans += sec
        sec = fir
        fir = lis[i]
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

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

    A.sort(reverse = True)
    return A[0] + (N-2) * A[1]

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
go=0
for x in a:
    go+=x
print(go-min(a))

Submission status: Wrong Answer

Solution code:
n = int(input())

a = list(map(int, input().split()))
s = sum(a) - min(a)
print(s)

Submission status: Wrong Answer

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

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

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

if len(A)==2:
    ans = A[0]
else:
    ans = sum(A[:-1])

print(ans)

Submission status: Wrong Answer

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

result = a[0]
if n > 2:
	for i in range(2, n - 1):
		result += min(a[i - 1], a[i - 2])

result += a[1]

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(lst)-min(lst))

Submission status: Wrong Answer

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

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]
ans = max(L)
prev = max(L)
del L[0]
prev2 = max(L)
del L[0]


for x in L:
    ans += min(prev,prev2)
    prev = prev2
    prev2 = x

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

A.sort(reverse=True)

ans=0

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

print(ans)

Submission status: Wrong Answer

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

d  = sorted(a, reverse = True)
e = []
ans = 0
for i in range(n):
    if(len(e) >= 1):
        ans += min(e[i-1], e[-1])
    e.append(d[i])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

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

A.sort(reverse=True)

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

Submission status: Wrong Answer

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

ans, cnt = 0, a[0]
for i in a[1:]:
    ans += cnt
    cnt = min(cnt, i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')


import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = a[0]

    h = [(a[1], a[0], a[1]), (a[1], a[0], a[1])]
    heapq.heapify(h)

    for i in range(2, n):
        p = heapq.heappop(h)
        ans += p[0]
        heapq.heappush(h, (a[i], a[i], p[1]))
        heapq.heappush(h, (a[i], a[i], p[2]))

    return ans


def main():
    n = ri()
    a = ria()
    wi(solve(n, a))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=0
min=a[-1]
for i in range(len(a)-2,-1,-1):
    if a[i]<min:
        ans+=min
        min=a[i]
    else:
        ans+=min
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
if n==1:
    print(0)
    sys.exit()
a=input()
al=[int(i) for i in a.split()]
al.sort(reverse=True)
ans=al[0]
for i in range(round((len(al)-2)/2)):
    ans+=al[i+1]*2
if round((len(al)-2)/2)-(len(al)-2)/2!=0:
    ans+=al[round((len(al)-2)/2)+1]
print(ans)

Submission status: Wrong Answer

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

    A.sort(reverse = True)

    # print(A)

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


main()

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(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = A[0]
cnt = 2
for i in range(1,N):
    ans += A[i]
    cnt += 1
    if cnt==N:
        break
    ans += A[i]
    cnt += 1
    if cnt==N:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
print(sum(sorted(arr)) - sorted(arr)[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
s = sum(A)
print(s-A[-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappop, heappush
N,*A=map(int, open(0).read().split())
A=sorted(A, reverse=True)
L=[0]*N
R=[0]*N
ans=0
L[0]=0
R[0]=0
H=[(A[0],0,0)]
heapify(H)
for i in range(1,N):
    a=A[i]
    p,pl,pr=heappop(H)
    ans+=p
    L[pr]=i
    R[pl]=i
    L[i]=pl
    R[i]=pr
    heappush(H,(min(A[pl],a),pl,i))
    heappush(H,(min(A[pr],a),i,pr))
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(sum(fr)-min(fr))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(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)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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])

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(j)for j in input().split()]
print(sum(a)-min(a))

Submission status: Wrong Answer

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

import sys
stdin = sys.stdin

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

def main():
    n = ni()
    a = na()
    a.sort(reverse=True)
    ans = a[0]
    for i in range(n-2):
        j = i % 2 + 1
        ans += a[j]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
a.sort()
print(sum(a) - a[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    a = list(IL())
    a.sort(reverse=True)
    a.pop()
    print(sum(a))
    return

if __name__=='__main__':
    Main()

Submission status: Wrong Answer

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

# A.sort()
print(sum(A) - min(A))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=input()
al=[int(i) for i in a.split()]
al.sort(reverse=True)
ans=al[0]
for i in range(round((len(al)-2)/2)):
    ans+=al[i+1]*2
if round((len(al)-2)/2)-(len(al)-2)/2!=0:
    ans+=al[round((len(al)-2)/2)+1]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = sum(A[:N // 2]) * 2 - A[0]

print(ans)
if N % 2 == 1:
    ans += A[N // 2]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A.sort()

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


    
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n = Li()
a = sorted(Li())
a.pop(0)
print(sum(a))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(N, As):
    As.sort(reverse=True)
    return sum(As[:-1])


if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[int(x) for x in input().split()]
m=sorted(m, reverse=True)
c=0
mini=m[0]
for i in range(1, len(m)):
  c+=mini
  if mini > m[i]:
    mini=m[i]
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s = 0

for i in range(1, n):
    s += min(arr[0], arr[i - 1])




print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

a = l()
a.sort()

ans = 0

print(sum(a[1:]))

Submission status: Wrong Answer

Solution code:


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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N=ii()
    A=lmis()
    ans = sum(A) - min(A)
    print(ans)






main()

Submission status: Wrong Answer

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

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 = list(map(int,input().split()))
a.sort(reverse = True)
t = [a[0]]
p = 0

for i in range(1,n):
    if i % 2 == 0:
        p += t[0]
        t.append(a[i])
    else:
        p += t[-1]
        t.insert(0,a[i])

print(p)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    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 = sorted(list(map(int, input().split())), reverse=True)

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

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

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

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=sum(a)
c=min(a)
print(b-c)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
sum=0

for i in range(1,n):
  sum+=l[i]
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

n = int(input())
a = [0 for _ in range(n)]
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()

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