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:
from heapq import heapify, heappop, heappush


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

A.sort(reverse=True)

heap = []
heapify(heap)

val = 0
heappush(heap, -A[1])
val += A[0]


for a in A[2:]:
    n = heappop(heap)
    val += -n

    heappush(heap, -a)
    heappush(heap, -a)


print(val)

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()))
#print(a)
a.sort(reverse=True)
#print(a)
sum = a[0]
for i in range(1, len(a)-1):
    sum += a[1]
print(sum)

Submission status: Wrong Answer

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

a.sort(reverse=True)

migi = a[1]
hidari = a[1]
point = a[0]

for i in a[2:]:
    if migi >= hidari:
        point += migi
        migi = i
    else:
        point += hidari
        hidari = i

print(point)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
n=int(input())
a=sorted(list(map(int,input().split())))
b=[]
c=[]
for i in list(Counter(a).values()):
  b.append(i)
for i in list(Counter(a).keys()):
  c.append(i)
ans=c.pop()*((b[-1])-1)
m=a[-1]
f=len(b)
for i in range(f-2,-1,-1):
  if b[-1]>b[i]:
    b[-1]-=b[i]
    b.pop(i)
    c.pop(i)    
    ans+=b[i]*m
  else:
    ans+=m*b[-1]
    b[i]-=b[-1]
    m=c.pop()
    ans+=m*b[i]
    b.pop()
  print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#4問目
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
result = 0
print(sum(A) - A[-1])

Submission status: Wrong Answer

Solution code:
# Q4
import sys
from collections import Counter
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N = I()
A_list = LI()
count_A_list = Counter(A_list)
s_count_A_list = sorted(count_A_list.items(), reverse=True)


score = s_count_A_list[0][0] * (s_count_A_list[0][1]-1)
left_nums = len(A_list) - s_count_A_list[0][1]
if left_nums == 0:
    print(score)
    sys.exit()

index = 0
for num, count in s_count_A_list:
    for i in range(count):
        score += num
        index += 1

        if index == left_nums:
            print(score)
            sys.exit()

Submission status: Wrong Answer

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

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

a.sort(reverse=True)

left = 0
right = 0

s = 0

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

print(s)

Submission status: Wrong Answer

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

a.sort(reverse = True)

ans = 0
ans += a[0]
i = 1
j = 1
while i < n-1 :
    if i+2 < n-1 :
        ans += 2*a[j]
        j += 1
        i += 2
    else :
        ans += a[j]
        j += 1
        i += 1

print(ans)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

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

comfort = 0
min = a[0]
for ai in a:
    comfort += ai
    if min > ai:
        min = ai

print(comfort-min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A_sorted = sorted(A, reverse=True)
ans = 0
queue = deque([A_sorted[0]])
for a in A[1:]:
    ans += queue.popleft()
    queue.append(a)
    queue.append(a)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

sum=l[-1]
for i in range(1,n//2):
  sum+=2*l[-1-i]
if n%2!=0:
  sum+=l[n//2-1]
print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    n  = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse = True)
    """
    seki = [a[0],a[0]]
    ans = 0
    for i in range(1,n):
        if seki[0]<seki[1]:
            index = 0
        else:
            index = 1
        ans += seki[index]
        seki[abs(index-1)] = a[i]
    print(ans)
    """
    print(sum(a[:n-1]))

main()

Submission status: Wrong Answer

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

list2=[]

c=0
for i in range(n):
    if i ==0:
        list2.append(alist[i])
        c+=0
    elif i==1:
        list2.append(alist[i])
        c+=alist[0]
    else:
        a1 = list2[0]
        a2 = list2[-1]
        if a1 > a2:
            list2.insert(0,alist[i])
            c+=a2
        else:
            list2.append(alist[i])
            c+=a1
print(c)

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline().rstrip("\n"))
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
a.sort(reverse=True)
sat = 0
for i in range(n):
    if i != 0:
        sat += a[i-1]
print(sat)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())

As = list(map(int, input().split()))
As = sorted(As, reverse=True)

num = len(As)
As = As[:num-1]
print(sum(As))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

ARR = np.sort(ARR)

print(ARR[1:].sum() - 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
	fst = True

	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)

	print(sum(ansans))


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

Submission status: Wrong Answer

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

lst = sorted(lst, reverse=True)

print(sum(lst[0:n-1]))

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)
kl = tuple(reversed(sorted(c)))
si = 0

for i in range(len(kl)):
    k = kl[i]
    if k == mk:
        nv = 0
        ans = k * (c[k] - 1)
    else:
        v = c[k]
        for j in range(si, i + 1):
            kk = kl[j]
            if c[kk] == 0:
                continue
            if kk == k:
                break
            nd = min(v, c[kk])
            ans += kk * nd
            v -= nd
            c[kk] -= nd
            if c[kk] == 0:
                si += 1
            if v <= 0:
                break
        if v > 0:
            ans += v * k
            
print(ans)

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

Submission status: Wrong Answer

Solution code:
""" D
    https://atcoder.jp/contests/abc173/tasks/abc173_d
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def main(N, A):
    A.sort(reverse=True)

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

    return sum

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [input() for l in range(1)]

m = m[0].split()
for i in range(0,len(m)):
    m[i] = int(m[i])

p = sorted(m, reverse=True)

t = p[0]
r = len(p)%2
if r == 0:
    s = len(p)//2
if r == 1:
    s = len(p)//2 + 1

if n == 1:
    print(0)
if n == 2:
    print(p[0])
if n >= 3:
    if r == 0:
        for i in range(1,s):
            t = t + m[i] * 2
    if r == 1:
        for i in range(1,s):
            t = t + m[i] *2
        t = t - m[s]
print(t)

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

a_sort = sorted(a,reverse=True)
total = 0
for i in a_sort:
    total += i
print(total - a_sort[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[*map(int,input().split())]
print((n-2)*max(m)+min(m))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ARR = np.sort(ARR)

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

Submission status: Wrong Answer

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

A_cnt = collections.Counter(A)
A_key = list(A_cnt.keys())[::-1]
A_val = list(A_cnt.values())[::-1]
total = 0
for i in range(len(A_val)):
    a_val = A_val[i]
    j = 0
    while a_val>0:
        if A_val[j]==0:
            j +=1
        else:
            if a_val > A_val[j]:
                total += (a_val - A_val[j])*A_key[j]
                a_val = a_val - A_val[j]
                A_val[j] = 0
            else:
                if i == j:
                    total += (A_val[j] - 1) * A_key[j]

                else:
                    total += (A_val[j] - a_val)*A_key[j]

                A_val[j] = A_val[j]-a_val+1
                a_val = 0
            j +=1

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
if n%2==0:
    s=0
    s=2*(sum(a[0:(n//2)]))-a[0]
    print(s)
else:
    s=0
    s=2*(sum(a[0:(n//2)+1]))-a[0]-a[(n+1)//2]
    print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.remove(min(A))
print(sum(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+=A[(i>>1)<<1]
print(P)

Submission status: Wrong Answer

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

s = sum(a)-a[-1]
print(s)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
K = list(sorted(map(int, input().split()), reverse=True))

max1 = K[0]
max2 = K[1]
if N == 2:
    print(max1)
else:
    max3 = K[2]
    count = max1 + max2
    cands = deque([(max1, max2), (max2, max3)])
    for k in K[3:]:
        cand = cands.popleft()
        hi, lo = cand
        count += lo
        cands.append((hi, k))
        cands.append((lo, k))
    print(count)

Submission status: Wrong Answer

Solution code:
import math
import collections

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

li = sorted(li, reverse=True)

ans = 0
d = collections.deque([])
for i, l in enumerate(li):
    if i == 0:
        d.append(l)
        continue
    if d[0] > d[-1]:
        bef = d[0]
        d.appendleft(l)
        aft = d[-1]
        ans += min(bef, aft)
    else:
        bef = d[-1]
        d.append(l)
        aft = d[0]
        ans += min(bef, aft)

print(ans)

Submission status: Wrong Answer

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

ans = 0
n = 1
l = [a_list[0]]
for i in range(1, N):
    if i % 2 == 1:
        ans += l[-1]
        l = [a_list[i]] + l
    else:
        ans += l[0]
        l = l + [a_list[i]]
print(ans)

Submission status: Wrong Answer

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

A.sort()
import collections
col= collections.Counter(A)

setA = set(A)

ans = 0
for i in reversed(list(setA)):
    ans += col[i] * i * 2
    N -= col[i] * 2
    if N < 0:
        ans += N * i
        break
print(ans-list(setA)[-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)
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()))
b=sorted(a,reverse=True)
s=b[0]
t=2
for i in range(1,n):
    for _ in range(2):
        s+=b[i]
        t+=1
        if t==n:
            break
    else:
        continue
    break
print(s)

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()
ans=0
mi=arr[0]
for i in range(1,n):
    ans+=mi
    mi=min(mi,arr[i])
print(ans)

Submission status: Wrong Answer

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

A_list.sort(reverse=True)
#print(A_list)

score = 0
for i in range(1, N):
    if i > 3:
        score += A_list[i-2]
    else:
        score += A_list[i-1]

print(score)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
Aset = list(set(A))
Aset.sort(reverse=True)
c = A.count(Aset[0])
capa = c*2
if n <= capa :
    igokochi = Aset[0]*(n-1)
    print(igokochi)
    exit()
igokochi = Aset[0]*(capa-1)
people = capa

i = 1
while(1) :
    c = A.count(Aset[i])
    capa += c*2
    if n <= capa :
        igokochi += Aset[i]*(n-people)
        print(igokochi)
        exit()
    igokochi += Aset[i]*capa
    people += capa
    i += 1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
list.sort(a, 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[i+1]
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-1):
  ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import os
import heapq

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n = int(input())
    a_s = list(map(int, input().split()))

    a_s.sort(reverse=True)

    que = []
    heapq.heapify(que)

    ans = 0
    for cnt, a in enumerate(a_s):
        if cnt == 0:
            heapq.heappush(que, a)
        else:
            # キューから値の取り出し
            target = heapq.heappop(que)
            ans += target
            heapq.heappush(que, a)
            heapq.heappush(que, a)

    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4
2 2 1 3"""
        output = """7"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """7
1 1 1 1 1 1 1"""
        output = """6"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
A = sorted(A, reverse=True)
c = []
ans = 0
for a in A:
  if len(c)==0:
    pass
  else:
  	ans += min(c)
  c.append(a)

print(ans)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
m = 0
n = 3
for i in range(N):
    if i == 0:
        m = A[i]
    elif i < n:
        ans += m
        m = A[i]
        if i == n-1:
            n = n*2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, reverse=True)
    # Aiが大きいやつからいく
    if A[0]>A[1]:
        max1,max2 = A[0],A[1]
    else:
        max1,max2 = A[1],A[0]
    ans = max1
    for i in range(2,N):
        ans += max2
        if A[i]>max1:
            max2 = max1
            max1 = A[i]
        elif A[i]>max2:
            max2 = A[i]
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

ans = 0
friendly = []

for i in range(1,n):
    # print(friendly)
    point = a.pop()
    friendly.extend([a[-1], a[-1]])

    if i != 1:
        friendly.pop(0)
    ans += point

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
A_int = []
con = 0
for i in range(N):
  A_int.append(int(A[i]))
for i in range(N):
  con += A_int[i]
print(con-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split( )))
A.sort()
A = A[::-1]
a = A[:3].copy()
ans = a[0] + a[1]
for plus in A[3:]:
    b = [min(a[-1],a[0]),min(a[0],a[1]),min(a[1],a[2])]
    flag = np.argmax(b)
    ans += max(b)
    a.insert(flag,plus)
    flag = np.argmax(a)
    del a[flag]
print(ans)

Submission status: Wrong Answer

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

def li():
    return [int(x) for x in input().split()]

N = int(input())
A = li()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
F_list = list(map(int, input().split()))
# print(F_list)
New_list = sorted(F_list, reverse=True)
# print(New_list)
ans = 0
for i in range(N):
    if i > 1:
        ans += New_list[1]
    elif i == 0:
        ans += 0
    elif i == 1:
        ans += New_list[0]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

nums = []
nums = list(map(int, input().split()))
nums = sorted(nums, reverse=True)

cf = nums[0]

for i in range(2, n):
    nums_min = min(nums[i-1], nums[i-2])
    cf += nums_min

print(cf)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    a.sort(reverse=True)
    ans = 0
    dict = {}
    count = 0
    for i in a:
        if ans ==0:
            ans+=i
            count+=1
        else:
            if count == n-2:
                ans+=i
                break
            elif count == n-3:
                ans+=i*2
                break
            else:
                ans+=i*2
                count+=2

    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
AS=sorted(A,reverse=True)
answers=[]
answers.append(AS[0])
del AS[0]
answer=0
for a in AS:
    answer+=answers[-1]
    answers.append(a)
print(answer)

Submission status: Wrong Answer

Solution code:
def main():

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

Submission status: Wrong Answer

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

print(sum(A_list) - A_list[-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
	fst = True

	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:
				if fst == True:
					pgt.put(val)
			else:
				pgt.put(val)
			fst = False

	#print(ansans)
	print(sum(ansans))


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))

a.sort()
a.pop(0)
print(sum(a))

Submission status: Wrong Answer

Solution code:
def main():

    N = int(input())
    lst = sorted([int(i) for i in input().split()], reverse=True)
    ans = lst[0]

    n, m = divmod(N - 2, 2)
    ans += sum(lst[1:n + 1]) * 2
    if m:
        ans += lst[n + 2]

    print(ans)


if __name__ == '__main__':
    main()