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:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


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

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    N = intinput()
    a_arr = list(mulinputs())
    l = len(a_arr)
    is_odd = l % 2
    a_arr.sort(reverse=True)

    # ans = a_arr.pop(0)
    # for _ in range(int(l//2)-1):
    #     ans += (a_arr.pop(0) * 2)
    # if is_odd:
    #     ans += a_arr.pop(0)
    # print(ans)
    idx = 0
    ans = a_arr[idx]
    idx += 1
    for i in range(int(l//2)-1): ans += (a_arr[idx+i])*2
    if is_odd:
        idx += int(l//2)
        ans += a_arr[idx]
    print(ans)

Submission status: Wrong Answer

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

A.sort()

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

Submission status: Wrong Answer

Solution code:
import copy

# a = get_int()
def get_int():
    return int(input())

# a = get_string()
def get_string():
    return input()

# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]

# a_list = get_string_list():
def get_string_list():
    return input().split()

# a, b = get_int_multi()
def get_int_multi():  # a, b = get_int_multi()
    return map(int, input().split())

# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():

    n = get_int()
    a_list = get_int_list()

    a_list.sort(reverse=True)

    ans = 0
    for idx in range(n-1):
        ans += a_list[idx]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a.sort()
ans = int(a[-1])
zzz = int(a[-2])

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)[::-1]
if N==1:
  print(0)
  exit()
if N==2:
  print(A[-1])
  exit()
  
A.append(0)
d=A[0]
D=[]
cnt=1
for i in range(N):
  if d==A[i+1]:
    cnt+=1
  else:
    D.append((d,cnt))
    cnt=1
    d=A[i+1]
ans=0
nokori=N
for a,b in D:
  if b*2<=nokori:
    ans+=a*b*2
    nokori-=b*2
  else:
    ans+=nokori*a
    nokori=0
print(ans-A[0])

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
mini = A[0]
print(A)
for i in range(1, N):
    print(ans ,mini)
    ans += mini
    mini = min(mini, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
print(sum(a[:-1]))

Submission status: Wrong Answer

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

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

print(sum(A[0:-2])+A[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

import math
import itertools
import random
n = int(input())
a = list(map(int, input().split()))
minimum = 999999999
ans=0
for i in a:
    minimum = min(minimum, i)
    ans += i
print(ans-minimum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort()

print(sum(A[2:])+A[-2])

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

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


place=[A_list.pop(A_list.index(max(A_list)))]
place.append(A_list.index(max(A_list)))
comfort=place[0]
edge=[place[1],place[1]]
for i in range(len(A_list)):
    now=A_list.pop(A_list.index(max(A_list)))
    ins=edge.index(max(edge))
    comfort+=max(edge)
    place.insert(ins,now)
    
    edge[ins]=min(place[ins],now)
    edge.insert(ins+1,min(place[ins+1],now))
print(comfort)

Submission status: Wrong Answer

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


a.sort()

ans = 0
c = 0
s = a[-1]
while len(a)>=2 and s == a[-1]:
	s = a.pop()
	ans += s

a = a[::-1]

for i in range(len(a)-1):
	ans += a[i//2]

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
_ = input()
li = sorted(list(map(int, input().split())))
score = 0
status = []

tmp_1 = li.pop()
status.append(tmp_1)
tmp_2 = li.pop()
score+=tmp_1
status.append(tmp_2)

for _ in range(len(li)):
  tmp = li.pop()
  max_status = []
  max_score = score
  for i in range(len(status)):
    if min(status[i-1], status[i])+score > max_score:
      left = status.copy()
      right = status.copy()
      max_score = min(status[i-1], status[i])+score
      max_status = (left[:i] + [tmp] + right[i:]).copy()
      
  score = max_score
  status = max_status.copy()

print(status)
print(score)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
read = sys.stdin.read
def main():
    n, *a = map(int, read().split())
    a.sort()
    r = sum(a[1:])
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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


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

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

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

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

    return arr


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


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


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

n = ir()
a = lr()
a.sort()
print(a[-1]+a[-2]*(n-2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_li = list(map(int,input().split()))
a_li.sort(reverse=1)
if n == 2:
    print(a_li[0])
    exit()
if n == 3:
    print(a_li[0]+a_li[1])
    exit()

m = a_li[0]
l = a_li[1]
r = a_li[2]
ans = 0
ans += a_li[0]+a_li[1]
for i in range(3,n):
    if l > r:
        ans += l
        l = a_li[i]
    else:
        ans += r
        r = a_li[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())), reverse=True)
ans = -a[0]
#print(ans)
cnt = 0
while True:
    if cnt>=n:
        break
    ans += a[0]*2
    cnt += 2
    del a[0]
if n%2==0:
    print(ans)
elif n%2==1:
    print(ans-a[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[int(x) for x in input().split()]
m=sorted(m, reverse=True)
u=sorted(list(set(m)), reverse=True)
d={}
for i in m:
  if i in d:
    d[i]+=1
  else:
    d[i]=1
pos=0
c=u[pos]*(d[u[pos]]-1)
posm=d[u[pos]]
while posm < len(m):
  if d[u[pos]] > d[m[posm]]:
    c+=u[pos]*d[m[posm]]
    d[u[pos]]-=d[m[posm]]
    posm+=d[m[posm]]
  elif d[u[pos]] == d[m[posm]]:
    c+=u[pos]*d[m[posm]]
    d[u[pos]]-=d[m[posm]]
    posm+=d[m[posm]]
    pos+=1
  else:
    f=t=d[m[posm]]
    while t > 0:
      if d[u[pos]] <= t:
        c+=u[pos]*d[u[pos]]
        t-=d[u[pos]]
        d[u[pos]]=0
        pos+=1
      else:
        c+=u[pos]*t
        d[u[pos]]-=t
        t=0
    posm+=f
print(c)

Submission status: Wrong Answer

Solution code:
import heapq
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
  b.append(-i)
b.sort()
heapq.heapify(b)
ans=0
for i in range(n-1):
  tmp=heapq.heappop(b)
  ans+=(-tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def resolve(in_):
    n = int(in_.readline())
    a = list(map(int, in_.readline().split()))
    assert len(a) == n
    a.sort(reverse=True)
    i = 0
    b = a[0]
    s = a[0]
    c = 0
    for v in a[1:]:
        i += s
        if b == v:
            s = v
            c += 1
        elif c > 0:
            c -= 1
        else:
            s = v

    return i


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split(" ")]
sortedA = sorted(A)
result = 0
for x in sortedA[1:]:
  result += x

print(result)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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



if __name__ == "__main__":
    run()

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 *

input = sys.stdin.readline

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

inf = float('inf')
mod = 1000000007

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

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

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

	ansans = []
	pgt = deque()
	for i,val in enumerate(A):
		if i == 0:
			pgt.append(val)
		else:
			tmp = pgt.pop()
			ansans.append(tmp)

			pgt.append(val)

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

	print(sum(ansans))


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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
"""
AtCoder :: Beginner Contest 173 :: Chat in a Circle
https://atcoder.jp/contests/abc173/tasks/abc173_d
"""
import sys
import heapq

def solve(players):
    """Solve puzzle."""
    players.sort(reverse=True)
    circle = [-players[1]]
    comfort = players[0]
    for player in players[2:]:
        spot = -heapq.heappop(circle)
        comfort += spot
        heapq.heappush(circle, -player)
        heapq.heappush(circle, -player)
    return comfort


def main():
    """Main program."""
    player_count = int(sys.stdin.readline())
    players = [int(i) for i in sys.stdin.readline().split()]
    print(solve(players))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(len(a)-1):
    ans += nxt
    nxt = a[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    a.sort()
    print(sum(a[1:]))
    return


#main
if __name__ == '__main__':
    solve()

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(N-2):
    index = i // 2
    print(index)
    ANS += A[index+1]
print(ANS)

Submission status: Wrong Answer

Solution code:
N = int(input())
n = list(map(int, input().split()))
min_num = min(n)
n.remove(min_num)
print(sum(n))

Submission status: Wrong Answer

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

circle = [max(A_LIST)]
pts = 0
for a in sorted(A_LIST)[::-1][1:]:
    pts += min(circle[0], circle[-1])
    if len(circle) // 2:
        circle += [a]
    else:
        circle = [a] + circle
        
print(pts)

Submission status: Wrong Answer

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

if n % 3 == 0:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2 + 1])
elif n % 3 == 2:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])
else:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])

Submission status: Wrong Answer

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

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[index] = a[i]
    print(ans)

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

conf=0
for i in A:
  conf+=i
  
print(conf)

Submission status: Wrong Answer

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


FRI = sorted(FRI, reverse=True)

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

ARR = ARR[:-1]


print(ARR.sum())

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = (map(int, raw_input().split()))
A.sort(reverse=True)
ans = 0
for i, x in enumerate(A):
  if i:
    ans += A[i-1]
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def judge():
    ans = True
    return ans

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

sum = 0
val = False
d_min = 0
for d in a:
    sum += d
    if not val:
        val = True
        d_min = d
    else:
        if d < d_min:
            d_min = d
print (sum - d_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse = True)
k=0
som=0
for i in range(n):
    if k>=n:
        break
    if i%2==0 and k<n:
        som+=arr[i]
        k+=1
    else:
        if k+2<n:
            som+=2*arr[i]
            k+=2
            if k==n-1:
                break
        elif k+1==n-1:
            som+=arr[i]
            break
        else:
            break
print(som)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a).most_common()
for i in c:
    a += [i[0] for j in range(i[1] // 2)]
a.sort(reverse=True)
print(sum(a[:n-1]))

Submission status: Wrong Answer

Solution code:
n=int(input(""))
l=input("").split(" ")
a=[]
c=[]
for i in range(n):
    a+=[int(l[i])]
a.sort()
for i in range(n):
    c+=[a[n-i-1]]
cnt=2
nzyou=2
s=c[1]+c[0]
print(s)
print(c)
num=2
while(n>cnt):
    cnt+=1
    if (num==2**nzyou):
        s+=c[num-1]*2
        if (cnt==n-1):
            break
        cnt+=1
        nzyou+=1
        num=2
    else:
        s+=c[num-1]
        num+=1

print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

print(res)

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N == 2:
    ans = A[0]
elif N == 3:
    ans = sum(A[:2])
elif N == 4:
    ans = sum(A[:2])+A[1]
elif N == 5:
    ans = sum(A[:2])+A[1]+A[2]
elif N == 6:
    ans = sum(A[:2])+A[1]+A[2]*2
else:
    ans = sum(A[:2])+A[1]+A[2]*2
    # print(ans)
    ind = N-6
    if ind%2 == 0:
        ans += sum(A[3:3+ind//2])*2
    else:
        ans += sum(A[3:3+ind//2])*2+A[3+ind//2+1]


print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
#print(a)
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)

ans = 0
for i in range(n):
    if i == 1:
        ans += a[0]
    if i >= 2:
        ans += min(a[0], a[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_i = list(map(int, input().split()))

forret = sorted(A_i)
ret = A_i[-1]
for i in range(N-1):
    ret = ret + A_i[-1-1-(i//2)]
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

check = [l[0],l[1]]
ans = l[0]

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

Submission status: Wrong Answer

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

print(sum(A)-min(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    sl = list(reversed(sorted(A)))
    score = 0
    circle = []
    for i in range(len(sl)):
        if i > 0:
            score += min(circle[0], circle[len(circle)-1])
        circle.append(sl[i])

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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    if i == 0:
        m = A[i]
    else:
        ans += m
        m = A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())

a.sort(reverse=True)

if n == 2:
    print(a[0])
    exit()
ans = a[0]
ans += a[1] * (n - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]

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