Problem:


Score: 400 points

Problem Statement

Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.

The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere.

When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0.

What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

By arriving at the place in the order Player 4, 2, 1, 3, and cutting into the circle as shown in the figure, they can get the total comfort of 7.

They cannot get the total comfort greater than 7, so the answer is 7.

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6



Sample input:
4
2 2 1 3


Sample output:
7

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
import string
def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    print(sum(a) - min(a))
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A.sort()

ans = 0
for k, i in enumerate(A):
  if k == 0:
    continue
  ans += i
print(ans)

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

Submission status: Wrong Answer

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

sorti = i

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
input1=list(map(int,input().split()))
max1=0
for  i in input1:
	if sum(input1)-i >=max1:
		max1=i 
print(max1)

Submission status: Wrong Answer

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

sorti = i

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a.count(a[0]) == 1:
    print(sum(a)-a[0])
elif a.count(a[0]) == n:
    print(a[0]*(n-1))
else:
    cnt = a.count(a[0])
    print(sum(a)-a[0]*cnt+(cnt-1)*a[cnt])

Submission status: Wrong Answer

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    A = input_number_list()
    A.sort(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()))

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque


def solve(N: int, A: "List[int]"):
    sl = list(reversed(sorted(A)))
    score = 0
    circle = []

    queue = deque()
    for i in range(len(sl)):
        if i > 0:
            score += queue[0]
            if sl[i] < queue[0]:
                queue.popleft()
        queue.append(sl[i])

        # circle.append(sl[i])

    # for i in range(len(sl)):
    #     if i > 0:
    #         score += min(circle[0], circle[len(circle)-1])
    #     circle.append(sl[i])

    # print(sl)
    # print(circle)
    print(score)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a.sort(reverse=True)
ans = a[0]
if n%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-2)//2]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, 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 = 0
for i in range(N):
  ans += a[i]
ans-=a[1]
print(ans)

Submission status: Wrong Answer

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

import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
a.sort()
print(sum(a[1:])-a[1]+a[n-2])

Submission status: Wrong Answer

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

a.sort(reverse=True)
ans = sum(a[0:n-1])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

cnt = 0
for i in range(len(a)):
    if i == 0:
        cnt += 0
    elif i == 1:
        cnt += a[i-1]
    else:
        cnt += min(a[i-2], a[i-1])

print(cnt)

Submission status: Wrong Answer

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

N=int(input().rstrip('\n'))
As=[int(x) for x in input().rstrip('\n').split()]
As_s=sorted(As,reverse=True)
res = As_s[0]
num = 2
for i in As_s[1:]:
  res += i
  num += 1
  if num ==N:
    break
  res += i
  num += 1
  if num==N:
    break
print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())

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

A=sorted(A)
A.reverse()

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
ans = 0
flg = 0
for i in range(n-1):
    if i == 0:
        ans += A[i]
        continue
    if flg == 0:
        ans += A[i]
        flg = 1
    elif flg == 1:
        ans += A[i - 1]
        flg = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from functools import reduce

def main():

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
players = list(map(int, input().strip().split(" ")))

players.sort(reverse=True)
total = 0
for i in range(N-1):
    j = int((i+1)/2)
    total += players[i]
print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
ARR = list(map(int, input().split()))
ARR = sorted(ARR, key=lambda x: -x)

arr = np.array(ARR)

result = np.sum(arr[:-1])
print(result)

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 = sorted(map(int, input().split(" ")), reverse=True)
result = A[0]
current_comfortest = A[1]
for i in range(2, N):
    if i == 2:
        result += current_comfortest
        continue
    elif i == 4:
        current_comfortest = A[i - 2]
        result += current_comfortest
        continue
    elif i % 2 != 0:
        result += current_comfortest
        continue
    else:
        current_comfortest = A[i - 3]
        result += current_comfortest
        continue
print(result)

Submission status: Wrong Answer

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

print(sum(S)-min(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sorti = sorted(i, reverse=True)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

class ErasableHeapq:
    def __init__(self):
        self.p = list()
        self.q = list()
        self.len = 0

    def insert(self, x):
        heapq.heappush(self.p, x)
        self.len += 1
        return

    def erase(self, x):
        heapq.heappush(self.q, x)
        self.len -= 1
        return

    def minimum(self):
        while self.q and self.p[0] == self.q[0]:
            heapq.heappop(self.p)
            heapq.heappop(self.q)
        return self.p[0]

    def __len__(self):
        return self.len

    def empty(self):
        return self.len == 0

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

    # 大きい順
    A.sort()
    sA = A[::-1]

    ans = sA[0]

    eq = ErasableHeapq()
    eq.insert((-sA[1], -sA[0]))
    eq.insert((-sA[1], -sA[0]))

    for a in A[2:]:
        best_pair = eq.minimum()
        ans += -best_pair[0]
        eq.insert((-a, best_pair[0]))
        eq.insert((-a, best_pair[1]))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
alist =sorted( list(map(int,input().split())))
alist.reverse()
#print(n)
#print(alist)

c=0
for i in range(n):
    if i==0:
        #1個目の親切さは無視
#        print("[{}] is {}".format(i,alist[i]))
        c+=alist[i]
    elif i==n-1:
#        print("[{}] is 0(last)".format(i,alist[i]))
        #最後の親切さは影響しない
        c+=0
    else:
#        print("[{}] is {}".format(i,alist[i]))
        c+=alist[i]
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input().split()
A = []
for s in S:
    A.append(int(s))
A.sort(reverse=True)

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

Submission status: Wrong Answer

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

print(sum(S)-1)

Submission status: Wrong Answer

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

a.sort(reverse=True)

point = 0
max_point = queue.Queue()
max_point.put(a[0])
for i in range(1, n):
    point += max_point.get()
    if max_point.qsize() < 10**5:
        for j in range(2**(i+1)):
            max_point.put(a[i])

print(point)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

li.sort(reverse=True)

d = deque()
ans = 0

for i in range(n):
    if i == 0:
        d.append(li[i])
    elif i == 1:
        d.append(li[i])
        ans += d.popleft()
    else:
        d.append(li[i])
        d.append(li[i])
        ans += d.popleft()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = 0
c = Counter(aa)
mk = max(c)

for k in reversed(sorted(c)):
    if k == mk:
        nv = 0
        ans = k * (c[k] - 1)
    else:
        v = c[k]
        for kk in reversed(sorted(c)):
            if c[kk] == 0:
                continue
            if kk == k:
                break
            nd = min(v, c[kk])
            ans += kk * nd
            v -= nd
            c[kk] -= nd
            if v <= 0:
                break
        if v > 0:
            ans += v * k
            
print(ans)

Submission status: Wrong Answer

Solution code:

def resolver(N, A):
    A.sort(reverse=True)
    ans = 0
    for i, _ in enumerate(A):
        if i == 0:
            continue
        elif i == 1:
            ans += A[0]
        else:
            j = (i // 2) +1
            ans += A[j]
    
    return ans



def _resolver(N, A):
    A.sort(reverse=True)
    circle = []
    ans = 0

    for a in A:
        if len(circle) == 0:
            circle.append(a)
        elif len(circle) == 1:
            ans += circle[0]
            circle.append(a)
        else:
            idx = max(range(len(circle)), key=lambda i: min(circle[i-1], circle[i]))
            ans += min(circle[idx-1], circle[idx])
            circle.insert(idx, a)

    return ans

def main():

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n = int(input())
r = list(map(int, input().split(' ')))

r.sort(reverse=True)
r.pop(-1)

print(sum(r))

Submission status: Wrong Answer

Solution code:
num = (int)(input())
a = sorted(list(map(int, input().split(" "))), reverse=True)
b = [a[0]]
total = 0
for i in range(1, num):
  if i >= 4:
    total += min(b[:-1])
  else:
    total += min(b)
  b.append(a[i])
print(total)

Submission status: Wrong Answer

Solution code:
from collections import deque
cou = 0
d = deque([])
n = int(input())
a = sorted(list(map(int,input().split())))
a1 = a.pop()
d.append(a1)

while len(a)!=0:
  t = a.pop()
  if d[-1]<=d[0]:
    cou += d[-1]
    d.appendleft(t)
  else:
    cou += d[0]
    d.append(t)
print(cou)

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

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


main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

A=sorted(A)[::-1]
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()))

A.sort(reverse=True)

ans=0

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

Submission status: Wrong Answer

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

A.sort(reverse = True)

ans = 0
re = [A[0]]
n = 0
for num in A[1:]:
     re.append(num)
     if num < re[0]:
          n += 1
     ans += re[0]
     if n == 1:
         re.pop(0)
         n = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
import string
def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    print(sum(a)-1)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

A = list(map(int,input().split()))
A_counter = collections.Counter(A)
A_set = list(set(A))
A_set.sort(reverse = True)

ans_ = 0
space = 0
counter_ =1 
sort_index = 0

if A_counter[A_set[0]] > 1:
    ans_ += (A_counter[A_set[0]] - 1) * A_set[0]
    counter_ += (A_counter[A_set[0]] - 1)


while True:
    space += A_counter[A_set[sort_index]]

    if space + counter_ < N:
        ans_ += (space * A_set[sort_index])
        counter_ += space
    elif space + counter_ == N:
        ans_ += (space * A_set[sort_index])
        break
    else:
        ans_ += ((N - counter_) * A_set[sort_index])
        
        break
        
    sort_index += 1
print(ans_)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())

l=input().split()

li = [int(s) for s in l]
li.sort(reverse=True)
leng=len(li)
li.pop(leng-1)


ans=0

for i in li:
    ans=ans+i

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()

	A.sort()
	A = A[::-1]
	ans = 0
	maxs = 0
	cnt = 0

	ansans = []
	pgt = queue.Queue()
	for i,val in enumerate(A):
		if i == 0:
			pgt.put(val)
		else:
			tmp = pgt.get()
			ansans.append(tmp)

			pgt.put(val)

			if tmp == val:
				pass
			else:
				pgt.put(val)

	print(sum(ansans))


class Queue:
    def __init__(self, queue = None):
        if type(queue) is type([]):
            self.queue = queue
        else:
            self.queue = []

    def enqueue(self, e):
        self.queue.append(e)
        return self.queue

    def dequeue(self):
        try:
            qEl = self.queue[0]
            del self.queue[0]
            return qEl
        except IndexError:
            return None


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

Submission status: Wrong Answer

Solution code:
n = input()
a = [int(x) for x in input().strip().split()]
count = {}
for x in a:
    if x not in count:
        count[x] = 0
    count[x] += 1
sort_keys = sorted(list(count.keys()), reverse=True)

result = 0
position = []
for idx, current in enumerate(sort_keys):
    value = count[current]
    if idx == 0:
        result += current * (value - 1)
        position.append([current, value])
    else:
        new_pos = 0
        while len(position) > 0 and value > 0:
            if position[0][1] > value:
                result += position[0][0] * value
                new_pos += value * 2
                position[0][1] -= value
                value = 0
            else:
                value -= position[0][1]
                result += position[0][1] * position[0][0]
                new_pos += value * 2
                position.remove(position[0])
        if value > 0:
            new_pos += value
            result += current * value
        position.append([current, new_pos])
print(result)

Submission status: Wrong Answer

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

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

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

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



if __name__ == "__main__":
    run()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())

a=list(map(int,input().split()))
res=0
b=a.sort()
for i in range(1,n):
    res=res+a[i]

print(res)

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

res = 0

m1 = A[0]
m2 = A[0]

del A[0]

for a in A:
    res += min(m1, m2)
    m2 = m1
    m1 = a

print(res)

Submission status: Wrong Answer

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

flist = []
for i, ai in enumerate(a):
    flist.append([i+1, ai])
flist.sort(key = lambda x: x[1], reverse=True)

circle = []
circle.append(flist[0][1])
circle.append(flist[1][1])
comfort = circle[0]
for i in range(2, n):
    circle.insert(1, flist[i][1])
    comfort += circle[2]

print(comfort)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
a = np.array(readline().split(), dtype=np.int64)
a.sort()
a = a[::-1]
m = -(-n//2)
ans = np.sum(a[:m])*2 - a[0] if n % 2 == 0 else np.sum(a[:m])*2 - a[0] - a[m]
print(ans)

Submission status: Wrong Answer

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

import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
a.sort()
print(sum(a[1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
p = a[0]
c = 1
ans = 0
for i in range(n-1):
    ans += p
    if c == 0:
        c += 1
    else:
        c = 0
        p = a[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
left, right = a[0], a[0]
for i in range(1, n):
    if left <= right:
        ans += left
        left = a[i]
    else:
        ans += right
        right = a[i]
print(ans)