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 sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

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


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
#DEBUG=True
DEBUG=False
if DEBUG:
    f=open("202007_1st/D_input.txt")
else:
    f=sys.stdin
N=int(f.readline().strip())
A=list(map(int,f.readline().split()))
A.sort(reverse=True)
ans=0
for _ in range(N-1):
    ans+=A[_]
print(ans)
f.close()

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

ans = int(ans +a[0])
print(ans)

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

ans /= 2
ans = int(ans +a[0])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
i=len(A)
i//=2
print(sum(A[-i-2:-2])*2+A[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
i=len(A)
i//=2
print(sum(A[-i-1:-2])*2+A[-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
i=len(A)
i//=2
print(sum(A[-i-1:-1])*2+A[-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=list(reversed(sorted(A)))
i=len(A)
i//=2
print(sum(A[-i-1:-1])*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
a = deque(sorted(list(map(int, input().split())), reverse=True))
count = 0
ans = 0
while n > count + 1:
    ans += a.popleft()
    count += 1
print(ans)

Submission status: Wrong Answer

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


if n % 2 == 0:
    print(l[0] + sum(l[1:2+(n-2)//2]))
else:
    print(l[0] + sum(l[1:2+(n-2)//2+2]))

Submission status: Wrong Answer

Solution code:
from collections import deque

n = int(input())
a = deque(sorted(list(map(int, input().split())), reverse=True))
print(a)
count = 0
ans = 0
while n > count + 1:
    ans += a.popleft()
    count += 1
print(ans)

Submission status: Wrong Answer

Solution code:
count = int(input())
people=input().split(" ")
people1=[]
 
for i in range(count):
    people1.append(int(people[i]))
 
people1.sort(reverse=True)
#print(people1)

ans_list=[]
k = 0
ans = 0
ans_list.append(people1[0])
for i in range(len(people1)-1):
    ans_list.insert(k,people1[i+1])
    if k == 0:
        ans=ans + ans_list[-1]
    elif k == len(ans_list)-1:
        ans = ans + min(ans_list[0],ans_list[-2])
    else:
        ans = ans + min(ans_list[k-1],ans_list[k+1])
    k = k + 2
    if k > len(ans_list):
        if len(ans_list)%2==0:
            k=len(ans_list)//2-1
        else:
            k=len(ans_list)//2
    #print(ans_list)
    #print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())),key=lambda x: -x)
T = A.pop(0)
LEFT = A.pop(0)
RIGHT = LEFT
ans = T
for a in A:
    if LEFT >= RIGHT:
        ans += LEFT
        LEFT = a
    else:
        ans += RIGHT
        RIGHT = a
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=list(reversed(sorted(A)))
i=len(A)
i//=2
if i%2==0:
    print(sum(A[-i-1:-1])*2+1)
else:
  print(sum(A[-i-1:-1])*2)

Submission status: Wrong Answer

Solution code:
n = int(input())
sum(sorted([int(x) for x in input().split()] * 2, reverse = True)[1:n])

Submission status: Wrong Answer

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

cnt = 0
for i in range(N):
    if i==0: continue
    if i==1:
        cnt += A[0]
    else:
        cnt += min(A[i-1], A[i-2])

print(cnt)

Submission status: Wrong Answer

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

if len(A) <= 2:
    print(sum(A[1:]))
else:
    ans = A[0] + 2*sum(A[1:math.floor(n/2)]) + (n%2)*A[math.floor(n/2)]
    print(ans)

Submission status: Wrong Answer

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

if len(A) <= 2:
    print(sum(A))
else:
    ans = A[0] + 2*sum(A[1:math.floor(n/2)]) + (n%2)*A[math.floor(n/2)]
    print(ans)

Submission status: Wrong Answer

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

com_list = sorted(l,reverse = True)
com_total = 0

for i in range(1,member):
    com_total += com_list[i-1]

print(com_total)

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=[int(i) for i in input().split()]
a.sort()
ans=0
ans+=max(a)
a.pop()
w=[a.pop()]*2
for i in range(n-2):
    ans+=max(w)
    if i==0: continue
    if w[0]>=w[1]: w[0]=a.pop()
    else: w[1]=a.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=0
ans+=max(a)
a.pop()
w=[a.pop()]*2
for i in range(n-2):
    ans+=max(w)
    if w[0]>=w[1]: w[0]=a.pop()
    else: w[1]=a.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=0
ans+=max(a)
w=[a.pop()]*2
for i in range(n-2):
    ans+=max(w)
    if w[0]>=w[1]: w[0]=a.pop()
    else: w[1]=a.pop()
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=0
ans+=max(a)
a.pop()
x=a.pop()
for i in range(n-2):
    ans+=x
    x=a.pop()
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = LI()

A = sorted(A)[1:]
print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
N-=1
a=list(map(int,input().split()))
a.sort
a.reverse()
b=0
c=0
if N % 2==1:
  b+=a[0]
  c+=1
  i=0
  while True:
    if c==N:
      print(b)
      break
    else:
      i+=1
      c+=2
      b+=2*a[i]
  
if N % 2==0:
  b+=a[0]
  c+=1
  i=0
  while True:
    i+=1
    c+=2
    b+=2*a[i]
    m=N-c
    if m==1:
      b+=a[i]
      print(b)
      break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

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

if N%2 != 0:
    ans += A[(N-2)//2]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

l = sorted(l,reverse=True)

print(sum(l[:len(l)-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
print(A)
limit = 0
ans = 0
count = 0
lim = 0
t = N - 1
for i in range(N):
    lim = 2
    if i == 0:
        lim = 1
    
    for j in range(lim):
        # print(j)
    
        if t > 0:
            ans += A[i]
        
            t -= 1
            # print(t)

# for i,a in enumerate(A):
#     limit = 2
#     if i == 0:
#         limit = 1
#     for j in range(limit, 1, -1):
#         # print(j)
#         if j > 0: 
#             ans += a
#             count += 1
#             # print(count)
#             print(ans)
#             if count > N - 1:
#                 # print(ans)
#                 # exit(1)
#                 break
#     if count > N - 1:
#         break
    # # print(N - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
# print(A)
limit = 0
ans = 0
count = 0
for i,a in enumerate(A):
    limit = 2
    if i == 0:
        limit = 1
    for j in range(limit, 1, -1):
        # print(j)
        if j > 0: 
            ans += a
            count += 1
            # print(count)
            if count > N - 1:
                break
# print(N - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

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

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_sorted = sorted(A, reverse=True)
    ans = 0
    for i in range(N-1):
        ans += A_sorted[i]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)
result = 0

for iter in range(len(A)):
    if iter == 0:
        continue
    if iter == 1:
        result += A[0]
        continue
    result += A[iter-1] if A[iter-1] < A[iter-2] else A[iter-2]


print(result)

Submission status: Wrong Answer

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

A = sorted(A, reverse=True)
result = 0

for iter in range(len(A)):
    if iter == 0:
        continue
    result += A[iter-1]


print(result)

Submission status: Wrong Answer

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

ans_list = list()
ans = 0


for num in range(n):
    flag = 0
    #print(ans)
    #print(a_list)
    person = a_list.pop(a_list.index(max(a_list)))
    if num == 0:
        ans_list.append(person)
    elif num == 1:
        ans_list.append(person)
        ans += ans_list[0]
    else:
        for ans_index in range(num):
            #print(ans_index)
            if person == ans_list[ans_index]:
                #print("pepepe")
                ans_list.insert(ans_index, person)
                ans += ans_list[ans_index]
                flag = 1
                break
                
            elif person < ans_list[ans_index] and ans_list[ans_index] >= ans_list[ans_index + 1]:
                #print("kekeke")
                ans += ans_list[ans_index+1]
                ans_list.insert(ans_index+1, person)
                #print(ans_list[ans_index])
                
                flag = 1
                break
                
        if flag == 0:
            #print("kokoko")
            ans += ans_list[len(ans_list)]
            ans_list.append(person)
    #print(ans_list)
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect, insort

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

sa = sorted(A)

count = 0
rs = sorted(sa[1:], reverse=True)
for i in rs:
    ba = bisect(sa, i)
    count += sa[ba-1]

print(count)

Submission status: Wrong Answer

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

count = 0
point = b[0]
ans = 0
before_count = 0
while count < n:
    ans += point*(len(b[:count+1])-len(b[:before_count+1]))
    before_count = count
    point = b[:count+1][-1]
    count += len(b[:count+1])
print(ans)

Submission status: Wrong Answer

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

sa = sorted(A, reverse=True)

store = [max(A)]

count = 0
for i in sa[1:]:
    count += min(store)
    store.append(i)

print(count)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
ans = 0
A.sort(reverse=True)
temp = 0
for i in range(N-1):
    temp += min(A[i-1], A[i+1])
ans = max(ans, temp)
print(ans)

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
ans = 0
for L in itertools.permutations(A):
    temp = 0
    for i in range(N-1):
        temp += min(L[i-1], L[i+1])
    ans = max(ans, temp)
print(ans)

Submission status: Wrong Answer

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

list.sort(reverse=True)

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

Submission status: Wrong Answer

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

list.sort(reverse=True)

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

Submission status: Wrong Answer

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

list.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A.sort(reverse=True)
A = deque(A)
res = 0
C = A.popleft()

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A.sort(reverse=True)
A = deque(A)
res = 0
C = A.popleft()

for n in range(N-1):
    res += C
    C = A.popleft()
print(res)

Submission status: Wrong Answer

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

Ai.sort()
print(sum(Ai[1:]))

Submission status: Wrong Answer

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

Ai.sort()
print(Ai)
print(sum(Ai[1:]))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

if len(players) == 1:
    total = 0
else:
    players.sort(reverse=True)
    total = players[0] + players[1] * (len(players) - 2)

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

players.sort()

print(sum(players[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())
que = [x*-1 for x in list(map(int,input().split()))]

import heapq
#from collections import deque
heapq.heapify(que)
#m = heapq.heappop(que)
ans = 0
que = list(que)
for i in range(1,n):
  ans -= que[i//2]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
que = [x*-1 for x in list(map(int,input().split()))]

import heapq
from collections import deque
heapq.heapify(que)
ans = heapq.heappop(que)*-1
que = deque(que)
que.pop()
while que:
  m = que.popleft()
  ans += m*-1
  if len(que)>0:
    que.pop()
    ans += m*-1
  

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
que = [x*-1 for x in list(map(int,input().split()))]

import heapq
heapq.heapify(que)

ans = 0
for _ in range(n-1):
  ans += heapq.heappop(que)*-1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
que = [x*-1 for x in list(map(int,input().split()))]

import heapq
heapq.heapify(que)

def gen(roop,i):
  return min(roop[i-1],roop[i])

m = heapq.heappop(que)
roop = [m*-1, m*-1]

ans = 0
while que:
  a = 0
  for i in range(1,len(roop)):
    h = gen(roop, i)
    if a < h:
      point = i
      a = h
  roop = roop[:point-1] + [heapq.heappop(que)*-1] + roop[point:]
  ans += a

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time

readline = sys.stdin.readline
 
IPS = lambda: readline().rstrip()
IP = lambda: int(readline().rstrip())
MP = lambda: map(int, readline().split())
LS = lambda: list(map(int, readline().split()))

def solve():
    for _ in range(1):
        n = IP()
        arr = LS()
        print(sum(arr) - min(arr))
       
       
if __name__ == "__main__":
    solve()

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

ans = A[0]

for i in range(2,N):
  I = (i+2)//2
  ans += A[I]
  
print(ans)

Submission status: Wrong Answer

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


def main():
    import sys
    input = sys.stdin.readline

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

    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:
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(sum(A)-min(A))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,*A = map(int,open(0).read().split())
a = sorted(A,reverse=True)

arr = np.array(a)
bai = arr * 2
ruisekiwa = np.cumsum(bai[1:])
#print(ruisekiwa)
if N % 2 == 0:
    print(ruisekiwa[(N-1)//2 - 1] + a[0])
else:
    print(ruisekiwa[(N-1)//2 - 2] + a[(N-1)//2] + a[0])

Submission status: Wrong Answer

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

ans += a[0]

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
if N == 3:
  print(a[0] + a[1])
ans1 = 2*sum(a[0:N//2]) - a[0]
if N%2 == 0:
  print(ans1)
if N%2 == 1 and N != 3:
  print(ans1 + a[(N+1)//2])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse = True)
ans1 = 2*sum(a[0:N//2]) - a[0]
if N%2 == 0:
  print(ans1)
if N%2 == 1:
  print(ans1 + a[(N+1)//2])

Submission status: Wrong Answer

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

a.sort(reverse=True)
a = deque(a)
circle = []
circle.append(a.popleft())
ans = 0

if a:
    ans += circle[0]
    circle.append(a.popleft())

while a:
    ans += circle[1]
    circle.append(a.popleft())
    circle.sort(reverse=True)

print(ans)

Submission status: Wrong Answer

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

result = 0
spots = [a.pop()]

while a:
	next = a.pop()
	result += spots.pop()
	spots.append(next)
	spots.append(next)
	
print(result)

Submission status: Wrong Answer

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

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(sum(a) - min(a))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

Submission status: Wrong Answer

Solution code:
conf = 0
num_char = int(input())
char = list(map(int, input().split()))
char.sort(reverse=True)
count = 0
conf_int = 0
for i in range(num_char):
  if count == 0:
    count = 1
  elif count == 1:
    count = 2
    conf = char[conf_int]
    count_int = 0
    conf_int = 1
  else:
    if count_int == 0 :
      conf += char[conf_int]
      count_int = 1
    else:
      conf += char[conf_int]
      conf_int += 1
      count_int = 0
print(conf_int)

Submission status: Wrong Answer

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

if N==2:
    print(max(A))
    exit()
else:
    ans += A[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = [int(i) for i in input().split()]
alist.sort()
print(sum(alist)-alist[0])

Submission status: Wrong Answer

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

t=sum(arr)
print(t-arr[0])

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
h = [A[0]]
ans = 0
for i in range(1,N):
    ans += heapq.heappop(h)
    heapq.heappush(h, A[i])
    heapq.heappush(h, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
_ = 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)
com = 0;
for k in range(n-1):
    kk = n - (k+1) // 2 - 1
    com += a[kk]
print(com);

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

Submission status: Wrong Answer

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

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

a.sort(reverse=True)

cnt = 1
ans = a[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
num=int(input())
s=[int(i) for i in input().split()]
s.sort(reverse=True)
point=0
for i in range(num-1):
    if i==0:
        point+=s[i]
    else:
        t=2
        if t>0:
            point+=s[i-t]
            t-=1
print(point)

Submission status: Wrong Answer

Solution code:
N=int(input())
array=list(map(int,input().split()))
array.sort()
array.pop(0)
print(sum(array))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

a.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

a.sort(reverse=True)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = list(map(int, input().split()))
alist.sort(reverse=True)
sumscore=alist[0]
for n in range(1,int(N/2)):
  sumscore = sumscore + alist[n]*2
if N%2==1:
  sumscore += alist[n]

print(sumscore)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n=int(input())
alist=list(map(int,input().split()))
blist=sorted(alist,reverse=True)
total=0
total+=blist[0]
for i in range(1,int(n/2)):
  total+=blist[i]*2
if n%2:
  total+=blist[int(n/2)+1]
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num=int(input())
s=[int(i) for i in input().split()]
s.sort(reverse=True)
point=0
for i in range(num-1):
    if i==0:
        point+=s[i]
    elif i%2==0:
        point+=s[i-1]
    else:
        point+=s[i]
print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num=int(input())
s=[int(i) for i in input().split()]
s.sort(reverse=True)
point=0
for i in range(num-1):
    if i==0:
        point+=s[i]
    else:
        point+=s[i]
print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

n = int(input())
a = list(map(int, input().split()))
a.sort()
c = int(a[-1])
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = int(a[n-2-i])
    c += a1*2
else:
  n2 = n//2-1
  a3 = int(a[n-n2-1])
  c += a3
  for i in range(n2):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a.sort()
c = int(a[-1])
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = int(a[n-2-i])
    c += a1*2
else:
  n2 = n//2
  a3 = int(a[n-n2-1])
  c += a3
  for i in range(n2-1):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
a.sort()
c = int(a[-1])
if n%2 == 0:
  n1 = n//2-1
  for i in range(n1):
    a1 = int(a[n-2-i])
    c += a1*2
else:
  c += int(a[n - 2])
  n2 = n//2 - 1
  for i in range(n2):
    a2 = int(a[n-2-i])
    c += a2*2
print(c)

Submission status: Wrong Answer

Solution code:
import math

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