Problem:


Score: 400 points

Problem Statement

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

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

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

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

Constraints

All values in input are integers.

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

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N

Output

Print the maximum total comfort the N players can get.

Sample Input 1

4
2 2 1 3

Sample Output 1

7

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

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

Sample Input 2

7
1 1 1 1 1 1 1

Sample Output 2

6



Sample input:
4
2 2 1 3


Sample output:
7

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N == 2:
    print(max(A))

A.sort(reverse=True)

max_num, *p = A

node_num = N-1

q = [(2*i <= node_num) + (2*i+1 <= node_num) for i in range(1, node_num+1)]

# print(q)
# print(max_1, max_2, sum(p_i*q_i for p_i, q_i in zip(p, q)))
r = max_num + sum(p_i*q_i for p_i, q_i in zip(p, q))
print(r)

Submission status: Wrong Answer

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

if N == 2:
    print(max(A))

A.sort(reverse=True)

max_1, max_2, *p = A

q = [(2*i <= N-2) + (2*i+1 <= N-2) for i in range(1, N-1)]

# print(q)
# print(max_1, max_2, sum(p_i*q_i for p_i, q_i in zip(p, q)))
r = max_1 + max_2 + sum(p_i*q_i for p_i, q_i in zip(p, q))
print(r)

Submission status: Wrong Answer

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

if N == 2:
    print(max(A))

A.sort(reverse=True)

max_1, max_2, *p = A

q = [(2*i <= N-2) + (2*i+1 <= N-2) for i in range(1, N-1)]

# print(q)
print(max_1, max_2, sum(p_i*q_i for p_i, q_i in zip(p, q)))
r = max_1 + max_2 + sum(p_i*q_i for p_i, q_i in zip(p, q))
print(r)

Submission status: Wrong Answer

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

A.sort()

print(sum(A[1:]))

Submission status: Wrong Answer

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

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

    A = sorted(A)
    ans = 0
    B = []
    while A:
        tmp = A.pop()
        if len (B) > 0:
            ans += B[-1]
            N -= 1
        B.append(tmp)

    
    print(ans)

main()

Submission status: Wrong Answer

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

lis = sorted(lis, reverse=True)

ans = 0
for i in range(n-1):
    ans += lis[i]

print(ans)

Submission status: Wrong Answer

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

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(A, reverse=True)
    A.pop()
    ans = 0
    for a in A:
        ans += a
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
score = A[0]
for i in range(1, math.ceil(N*0.5)):
    score += 2 * A[i]
print(score)

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
q=[A[0],A[0]]
heapq.heapify(q)

ans=0
for a in A[1:]:
    one=heapq.heappop(q)
    two=heapq.heappop(q)
    ans+=max(one,two)
    heapq.heappush(q,a)
    heapq.heappush(q,a)
    heapq.heappush(q,one)
    heapq.heappush(q,two)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
res = A[0] + sum(A[1:(n//2)]) * 2
if n % 2 == 0:
    print(res)
else:
    res += A[n//2 + 1]
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if a[0] == a[1]:
  tmp = a[0]
else:
  tmp = a[1]
ind = 0
for i in range(n-2):
  ans += tmp
  ind += 1
  if a[ind] < tmp:
    tmp = a[ind]
    ind = 0
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]
ind = 0
for i in range(n-1):
  ans += tmp
  ind += 1
  if a[ind] < tmp:
    tmp = a[ind]
    ind = 0
print(ans)

Submission status: Wrong Answer

Solution code:
def abc173d_chat_in_the_circle():
    n = int(input())
    a = sorted(map(int, input().split()), reverse=True)
    if n <= 1:
        print(0)
        return
    val = 0
    for i in range(1, n):
        idx = i // 2 - 1
        val += a[idx]
    print(val)

abc173d_chat_in_the_circle()

Submission status: Wrong Answer

Solution code:
from collections import deque

def main():
    n = int(input())
    l = list(map(int, input().split()))

    comfort = 0
    q = deque(sorted(l, reverse=True))
    while len(q) > 1:
        comfort += q[0]
        q.popleft()
    print(comfort)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]


nums = sorted(nums, reverse=True)


a_sum = 0
for i in range(N-1):
    if i == 0:
        index = 0
    else:
        index = (i-1)//2 + 1
    print(index)
    a_sum += nums[index]

print(a_sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(i) for i in input().split()]


nums = sorted(nums, reverse=True)


a_sum = 0
for i in range(N-1):
    if i == 0:
        index = 0
    else:
        index = i//2 + 1
    a_sum += nums[index]

print(a_sum)

Submission status: Wrong Answer

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

s = sorted(a, reverse=True)
iterator = iter(s)
prev = next(iterator)
confort = prev
for curr in iterator:
    confort += min(prev, curr)
    prev = curr
print(confort-s[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
x=list(map(int,input().split()))
x=sorted(x)
y=[]
for _ in range(n):
 y.append(0)
for j in range(n):
 i=0
 if j<n-2:
  y[j]=x[i]
  i+=1
  j+=2
 elif j==n-2 and n%2==0:
  y[j]=x[i]
  i+=1
  j=1
 elif j==n-1 and n%2==0:
  y[j]=x[i]
 elif j==n-1 and n%2==1:
  y[j]=x[i]
  i+=1
  j=1
 elif j==n-2 and n%2==1:
  y[j]=x[i]
z=[]
for k in range(n):
 if k-1==-1:
  z.append(min(y[1],y[n-1]))
 elif k+1==n:
  z.append(min(y[0],y[n-2]))
 else:
  z.append(min(y[k-1],y[k+1]))
a=sum(z)
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

"""
N= 4
K = [2, 2, 1, 3]
"""

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





K = sorted(K,reverse=True)
#print(K)
before_data = 0
ans = 0 
for i in K :
    ans += before_data
    before_data = i

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
'''
参考
https://yamakasa.net/atcoder-abc-173-d/
図
https://github.com/ymo999/AtCoder/blob/master/2020/20200705_ABC173/ABC173_D.pdf
'''
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

ans = A[0]
idx = 1                 # 心地よさの和を算出するためのindex
for i in range(2, N):
    ans += A[idx]
    if i % 2 == 0:
        idx += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = input().split()
li.sort(reverse=True)
print(li)
print(type(li))
total = 0
l = -1
r = -1
c = 1
for i in range(0, n):
    item = li.pop(0)
    if l == -1 and r == -1:
        l = int(item)
        c = -1
    elif r == -1:
        r = int(item)
        c = 1
        total += l
    elif c == 1:
        l = int(item)
        total += r
        c = -1
    else:
        r = int(item)
        total += l
        c = 1
print(total)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    ans = sum(A) - min(A)
    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)
ans = sum(A[:-1])
print(ans)

Submission status: Wrong Answer

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

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


a = merge_sort(a)

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

print(ans)

Submission status: Wrong Answer

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

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


a = merge_sort(a)
print(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

s = list(sorted(a,reverse=True))
del s[n-1]
print(sum(s))

Submission status: Wrong Answer

Solution code:
n=int(input())
lst=list(map(int,input().split()))
lst=sorted(lst)
if(n>2):
    sm=lst[-1]+(n-2)*lst[-2]
elif(n==2):
    sm=lst[-1]
print(sm)

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
A=np.zeros(n)
A=np.array(input().split(),np.int64)
A.sort()
A=A[::-1]
ans=int(0)
for i in range(n-1):
    ans+=A[(i+1)%2]
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

def solve():
    N = int(input())
    A = list(sorted(map(int, input().split()), reverse=True))
    C = [(-A[1], A[0], A[1])]

    ans = A[0]
    for a in A[2:]:
        K,A0,A1 = heapq.heappop(C)
        ans += -K
        heapq.heappush(C, (-a, A0, a))
        heapq.heappush(C, (-a, A1, a))

    print(ans)



solve()

Submission status: Wrong Answer

Solution code:
n = input()
xs = [ int(x) for x in input().split() ]
xs.sort(reverse=True)
best, buf = 0, [xs[0]]
for x in xs[1:]:
  i, y = max([ (min(buf[i-1], y), i) for i,y in enumerate(buf) ])
  best += y
  buf.insert(i, x)
print(best)

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input())
A = [int(x) * (-1) for x in input().split()]
heapq.heapify(A)
now = 0
conf = heapq.heappop(A) * -1

for x in A:
    conf += now
    now = -x

print(conf)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 10**9 +5
ans = 0
for i in range(len(a)):
  ans += a[i]
  m = min(m, a[i])
ans -= m
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y

n = ini()
a = inl()
m = min(a)
ans = sum(a) - m
print(ans)

Submission status: Wrong Answer

Solution code:
import queue

ans = 0

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
q = queue.LifoQueue()
q.put(0)
for a in range(len(A)):
    ans += q.get()
    q.put(A[a])
    if a != 0:
        q.put(A[a])

print(ans)

Submission status: Wrong Answer

Solution code:
import queue

ans = 0

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
q = queue.LifoQueue()
q.put(0)
for a in A:
    ans += q.get()
    q.put(a)
    q.put(a)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0 + a[-1]
    for i in range(n-2):
        k = a[-(i+4)//2]
        ans += k
    print(ans)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = a[-1]
    for i in range(n-2):
        k = a[-(i+4)//2]
        ans += k
    print(ans)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

a.sort(reverse=True)
ans = a[0]
cnt = 1
for i in range(1, n):
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)
ans = a[0]
cnt = 1
for i in range(1, n):
    cnt += 1
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
    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 = a[0]
cnt = 1
for i in range(1, n):
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
    ans += a[i]
    cnt += 1
    if cnt == n - 1:
        break
print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)
ans = a[0]
i = 1
while True:
    if i == n - 1:
        break
    ans += a[i]
    i += 1
    if i == n - 1:
        break
    ans += a[i]
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
A = sorted([int(x) for x in input().split()])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)[::-1]
print(max(a) + 2*sum(sa[1:n//2]) + (n%2)*sa[-(-n//2)])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = [int(x) for x in input().split()]

arr = sorted(arr)
arr.reverse()

comfort = 0

for x in range(1, len(arr)):
	comfort += arr[x-1]

print(comfort)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
S = [A[0], A[1]]
for i in range(2, len(A)):
    m = min(A[0], A[-1])
    cnt = -1
    for j in range(len(A)-1):
        if min(A[j], A[j+1]) < m:
            m = min(A[j], A[j+1])
            cnt = j
    S = S[:cnt] + [A[i]] + S[cnt:]
    ans += m
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
sum_com = 0
distinct_a = sorted(list(set(a)), reverse=True)
comfort = {i: 0 for i in distinct_a}
comfort[a[0]] = 1
max_com = 0

for ai in a[1:]:
    sum_com += distinct_a[max_com]
    if distinct_a[max_com] == ai:
        comfort[distinct_a[max_com]]+= 1
    else:
        comfort[distinct_a[max_com]] -= 1
        max_com += 1
        comfort[distinct_a[max_com]] += 2

print(sum_com)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in range(n-1):
    ans += a[(i + 1) // 2]
#     print(ans)

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = A[0] + A[1]*(N-2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

conf = 0
from heapq import heapify, heappop, heappush
As.sort(reverse=True)
m = As.pop(0)
s = As.pop(0)
conf += m
Q = []
heappush(Q, s)
heappush(Q, s)
for a in As:
    s = heappop(Q)
    conf += s
    heappush(Q, a)
    heappush(Q, a)
print(conf)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a = sorted(a,reverse=True)[:N-1]
b = 0
b = int(b)
b = int(sum(a))
print(b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
score = nums[0] + sum(nums[1:N//2])
if N%2 != 0:
  score += nums[N//2]
print(score)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

n, *aaa = map(int, sys.stdin.buffer.read().split())
aaa.sort(reverse = True)   

for i in range(n):
  if i ==0:
    cnt=0
  else:
    cnt += aaa[i-1]

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a =LI()
a.sort(reverse=True)
ans = 0
for i in range(n):
  ans += a[i%2]
print(ans - a[0])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a =LI()
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[1:]))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
# 全部のパターンだとN**2
# 仕組み的に低い人ほどあとにきた方がうまくいきそうに見える
A.sort()
s = 0
for i in range(1, N):
    s += A[i]
print(s)

Submission status: Wrong Answer

Solution code:
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


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

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

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


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    #n, k = map(int, input().split())
    #a, b = map(int, input().split())
    #c, d = map(int, input().split())
    n = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)
    #b = 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()))

answer = sum(A) - min(A)

print(answer)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
result = []
result.append(a[0])
result.append(a[1])
count = a[0]
for i in range(2,len(a)):
    count += min(result[i-2],result[i-1])
    result.append(a[i])
print(count)

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:
import itertools
N = int(input())
A = list(map(int, input().split()))

A.sort()

cp = A[1:N]
print(sum(cp))

Submission status: Wrong Answer

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

dp = [0] * (n + 1)

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())
s=sorted((list(map(int, input().split()))), reverse = True)
 
total=0
for i in range(1,n):
	print(s[i//2])
print(total)

Submission status: Wrong Answer

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

total=0
for i in range(1,n):
  print(s[i//2])

print(total)

Submission status: Wrong Answer

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

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())
confort_list = list(map(int, input().split()))
confort_list.sort()
result = 0
for i in range(N-1):
    result += confort_list[i+1]
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

# print(A)
mina = min( A )
maxa = max( A )

A.sort()
A.reverse()

sum = 0
for i in range(n):
    sum +=A[(i+1)//2]
    # print(A[(i+1)//2])

# print(mina)
# print(maxa)
# print(sum)
print(sum)

Submission status: Wrong Answer

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

# print(A)
mina = min( A )
maxa = max( A )

sum = 0
for a in A:
    sum +=a

# print(mina)
# print(maxa)
# print(sum)
print(sum-mina)

Submission status: Wrong Answer

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

# print(A)
mina = min( A )
maxa = max( A )

sum = 0
for i in range(n):
    sum +=A[i]

# print(mina)
# print(maxa)
# print(sum)
print(sum-mina)

Submission status: Wrong Answer

Solution code:
n = input()
friendliness = [int(item) for item in input().split()]
friendliness.sort()
def of_ans():
    sum_ = 0
    for idx in range(len(friendliness) - 1):
      sum_ += friendliness[- (idx // 2) - 1]
    return sum_
print(of_ans())