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 = input()
friendliness = [int(item) for item in input().split()]
friendliness.sort()
def of_ans():
    sum_ = 0
    for idx in range(len(friendliness)):
      sum_ += friendliness[- (idx // 2) - 1]
    return sum_
print(of_ans())

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(1, len(friendliness)):
  	sum_ += friendliness[- (idx // 2)]
  return sum_
print(of_ans())

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)):
  	sum_ += friendliness[- (idx // 2)]
  return sum_
print(of_ans())

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = sorted(list(map(int, input().split())),reverse=True)
s = A[0]
print(A)

for i in range(1,N-1):
    s += A[math.ceil(i/2)]

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = sorted(list(map(int, input().split())),reverse=True)
s = A[0]

for i in range(1,N):
    s += A[math.ceil(i/2)]

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
friendliness = [int(item) for item in input().split()]
friendliness.sort(reverse=True)
comfort = 0
table = []


def sit(person, table):
    table.append(person)
    if len(table) == 1:
        return 0
    return min(table[-2], table[0])


for person in friendliness:
    comfort += sit(person, table)
print(comfort)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import deque

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

A = deque(A)
L = deque()

# print(A, L)
ans = A.popleft()
L.append(A.popleft())
F = True
for i in range(2, N):
    if F:
        ans += L[0]
        F = not F
    else:
        t = A.popleft()
        ans += t
        L.append(t)
        F = not F
print(ans)

Submission status: Wrong Answer

Solution code:
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
result=0
for i in range(2,num+1):
        result+=sample[round(i/2)-1]
print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

# https://www.youtube.com/watch?v=GXZZB5vO78c
n = I()
a = RI()
b = deepcopy(a)
b.sort(reverse=True)
print(a)
print(b)

ans = 0
j = 0
for i in range(n):
    if i==0:
        ans += 0
    elif i==1:
        ans += b[j]
    else:
        if i%2==0:
            j += 1
            ans += b[j]
        else:
            ans += b[j]
print(ans)

Submission status: Wrong Answer

Solution code:
num=int(input().rstrip())
m=input().rstrip().split()
main=[]
for i in m:
    main.append(int(i))
sample=sorted(main,reverse=True)
new=[]
plusold=0
result=0
for i in range(num):
    if len(new)==0:
        new.append(sample[i])
    elif len(new)<=2:
        new.append(sample[i])
        result+=sample[i-1]
    else:
        plus=new[len(new)-1]
        point=len(new)
        for j in range(len(new)-1):
            if plus<new[j] and plus<new[j+1]:
                plus=min([new[j],new[j+1]])
                point=j+1
                if plus==plusold:
                    break
        result+=plus
        plusold=plus
        if point==len(new):
            new.append(sample[i])
        else:
            new.insert(point,sample[i])
print(result)
print(plusold)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from math import ceil
from collections import defaultdict as D

def S(): return sys.stdin.readline().rstrip().split(' ')
def Ss(): return list(S())
def I(): return _I(Ss())
def Is(): return list(I())
def _I(ss): return map(int, ss) if len(ss) > 1 else int(ss[0])

_ = S()
xs = Is()

xs = sorted(xs, reverse=True)
print(np.sum(xs[:-1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
comfort = list(map(int,input().split()))
comfort_reverse = np.sort(comfort)[::-1]

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
comfort = list(map(int,input().split()))
comfort_reverse = np.sort(comfort)[::-1]
print(comfort_reverse)

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

print(ans)

Submission status: Wrong Answer

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

a.sort()
arr = [a.pop(-1)]
ans = 0
while True:
    if len(a) >= 1:
        arr.insert(0, a.pop(-1))
        #print(arr)
        ans += min(arr[-1],arr[1])
    else:
        break
    if len(a) >= 1:
        arr.append(a.pop(-1))
        #print(arr)
        ans += min(arr[-2],arr[0])
    else:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
print(sum(a) - min(a))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
# print(N,a)

a_sort = sorted(a, reverse=True)

a_sum = a_sort[0]

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
# print(N,a)

a_sort = sorted(a, reverse=True)

a_sum = a_sort[0]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())

t=[]
for l in s:
	if l!=" ":
		t.append(l)

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

total=int(t[0])+int(t[1])*int((len(t)-2))
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(item) for item in input().split()]
A = sorted(A, reverse=True)
print(sum(A)- A[-1])

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
A.sort()
print(sum(A)-A[0])

Submission status: Wrong Answer

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

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())
values = list(map(int, input().split(' ')))

print(sum(values) - min(values))

Submission status: Wrong Answer

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

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


A.sort(reverse=True)
print(A)
B = A[:-1]

print(sum(B))

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]
print(sum(A) - min(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    N = i2n()
    A = i2nn()
    A.sort()
    A.reverse()
    n = 0
    for i in range(N-1):
        n += A[i]
    print(n)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
print(sum(sorted(A)[1:]))

Submission status: Wrong Answer

Solution code:
def main():
    N = II()
    A = LI()
    A.sort(reverse=True)
    ans = -A[0]
    hq=[]
    heapq.heapify(hq)
    heapq.heappush(hq,A[0]*-1)
    for i,a in enumerate(A):
        ans+=heapq.heappop(hq)*-1
        if(a!=0):
            heapq.heappush(hq,a*-1)
            heapq.heappush(hq,a*-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import heapq

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    N = II()
    A = LI()
    A.sort(reverse=True)
    ans = -A[0]
    hq=[]
    heapq.heapify(hq)
    heapq.heappush(hq,A[0]*-1)
    for i,a in enumerate(A):
        ans+=heapq.heappop(hq)*-1
        if(a!=0):
            heapq.heappush(hq,a*-1)
    print(ans)

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
a, *an = map(int, input().split())
A.append(a)
A += an
A.sort()

Node = []
score = 0
Node.append(A.pop())

#print(A)

for n in range(N - 1):
    score += Node[0]
    num = A.pop()
    #Node = Node[1:]
    Node.append(num)
    Node.append(num)

#print(Node)
print(score)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
a, *an = map(int, input().split())
A.append(a)
A += an
A.sort()

Node = []
score = 0
Node.append(A.pop())

#print(A)

for n in range(N - 1):
    #score += Node.pop(0)
    num = A.pop()
    Node.append(num)
    Node.append(num)

#print(Node)
print(score)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
a, *an = map(int, input().split())
A.append(a)
A += an
#A.sort()

Node = []
score = 0
Node.append(A.pop())

#print(A)

for n in range(N - 1):
    score += Node.pop(0)
    num = A.pop()
    Node.append(num)
    Node.append(num)

#print(Node)
print(score)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
a, *an = map(int, input().split())
A.append(a)
A += an
A.sort()

Node = []
score = 0
Node.append(A.pop())

print(A)

for n in range(N - 1):
    score += Node.pop(0)
    num = A.pop()
    Node.append(num)
    Node.append(num)

#print(Node)
print(score)

Submission status: Wrong Answer

Solution code:
from collections import deque

N = input()
A = sorted(list(map(int, input().split())), reverse=True)
s,d = 0,deque()

d.append(0)
for a in A:
	s += d.popleft()
	d.append(a)
	d.append(a)
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque

N = input()
A = sorted(list(map(int, input().split())), reverse=True)
s,d = 0,deque()

d.append(0)
for a in A:
	s += d.pop()
	d.append(a)
	d.append(a)
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = input()
A = A.split()
A = [int(i) for i in A]
A = sorted(A, reverse = True)
ans = 0

for x in A:
	ans += x

ans -= A[n-1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
 
list.sort(lst, reverse=True)
#print(lst)
lst2 = []
total = 0
for i in range(n):
  num = lst[i]
  if len(lst2) == 2:
    total += lst2[1]
    lst2.pop(1)
    lst2.append(num)
  if len(lst2) == 1:
    total += lst2[0]
    lst2.append(num)
  if not lst2:
    lst2.append(num)
  #print(total)
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
 
list.sort(lst)
#print(lst)
lst2 = []
total = 0
for i in range(n):
  num = lst[i]
  if len(lst2) == 2:
    total += lst2[1]
    lst2.pop(1)
    lst2.append(num)
  if len(lst2) == 1:
    total += lst2[0]
    lst2.append(num)
  if not lst2:
    lst2.append(num)
  #print(total)
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

list.sort(lst)
print(lst)
lst2 = []
total = 0
for i in range(n):
  num = lst[i]
  if len(lst2) == 2:
    total += lst2[1]
    lst2.pop(1)
    lst2.append(num)
  if len(lst2) == 1:
    total += lst2[0]
    lst2.append(num)
  if not lst2:
    lst2.append(num)
  #print(total)
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]

list.sort(lst)
lst2 = []
total = 0
for i in range(n):
  num = lst[i]
  if not lst2:
    lst2.append(num)
  if len(lst2) == 1:
    total += lst2[0]
    lst2.append(num)
  if len(lst2) == 2:
    total += lst2[1]
    lst2.pop(1)
    lst2.append(num)
print(total)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

A = np.array([int(i) for i in input().split()])
A_sort = np.sort(A)

print(A_sort)
score = 0
score += A_sort[-1]
for i in range(0, (N-2)//2):
    score += A_sort[-2-i] * 2
    
if (N-2) % 2 == 1:
    score += A_sort[-3-i]
    
print(score)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))

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

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
import collections
import bisect
import math
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    print(sum(A) - min(A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
print(sum(x) - min(x))

Submission status: Wrong Answer

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

# import copy


# 引数が一つだけのやつ
n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

# 引数が複数あるやつ（そうじゃないの）
# target = [int(x) for x in input().split()]

# number = int(input())
# 複数行を受け取って処理するやつ
# target = [list(input()) for i in range(H)]

# 関数
def count_sharp(target):
    return sum([x.count("#") for x in target])


def bin_code(value, keta):
    return list(("{:0" + str(keta) + "b}").format(value))


# 初期
target_1.sort()
point = 0
for idx, ins in enumerate(target_1):
    if idx != len(target_1) - 1:
        point += target_1[-(1 + math.floor(idx))]

# 出力
print(point)

Submission status: Wrong Answer

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

# import copy


# 引数が一つだけのやつ
n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

# 引数が複数あるやつ（そうじゃないの）
# target = [int(x) for x in input().split()]

# number = int(input())
# 複数行を受け取って処理するやつ
# target = [list(input()) for i in range(H)]

# 関数
def count_sharp(target):
    return sum([x.count("#") for x in target])


def bin_code(value, keta):
    return list(("{:0" + str(keta) + "b}").format(value))


# 初期
target_1.sort()
point = 0
for idx, ins in enumerate(target_1):
    if idx != len(target_1) - 1:
        point += target_1[-(1 + math.ceil(idx))]

# 出力
print(point)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# import math
# import copy


# 引数が一つだけのやつ
n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

# 引数が複数あるやつ（そうじゃないの）
# target = [int(x) for x in input().split()]

# number = int(input())
# 複数行を受け取って処理するやつ
# target = [list(input()) for i in range(H)]

# 関数
def count_sharp(target):
    return sum([x.count("#") for x in target])


def bin_code(value, keta):
    return list(("{:0" + str(keta) + "b}").format(value))


# 初期
target_1.sort()
target_1.reverse()
ring = []
point = []
for ins in target_1:
    ring.append(ins)
    print(ins)
    # point計算
    if len(ring) == 1:
        point.append(0)
    else:
        point.append(min(ring[0], ring[-2]))

# 出力
print(sum(point))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# import math
# import copy


# 引数が一つだけのやつ
n = int(input())
# 引数が複数あるやつ（全部数字）
target_1 = [int(x) for x in input().split()]

# 引数が複数あるやつ（そうじゃないの）
# target = [int(x) for x in input().split()]

# number = int(input())
# 複数行を受け取って処理するやつ
# target = [list(input()) for i in range(H)]

# 関数
def count_sharp(target):
    return sum([x.count("#") for x in target])


def bin_code(value, keta):
    return list(("{:0" + str(keta) + "b}").format(value))


# 初期
target_1.sort()
target_1.pop(0)
# 出力
print(sum(target_1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
for i in range(len(A)-1):
    if i == 0:
        ans += A[0]
    elif i % 2 == 0:
        ans += A[i-1]
    else:
        ans+= A[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

added   = 1
mins    = [ ai[0] ]
comfort = 0

while added < len(ai):
    comfort += sum(mins[ : len(ai) - added ]) * (2 if added != 1 else 1)
    mins = ai[ added : added + 2 ** added ]
    added += len(mins)

print(comfort)

# 7 6 5 4 3 2 1 0

# (0) 7
# (_ + 7 * 1) 7 6
# (_ + 6 * 2) 7 5 6 4
# (_ + 5 * 2 + 4 * 2) 7 3 5 2 6 1 4 0

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

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

Submission status: Wrong Answer

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

ans = A[0]
n-=2
loop = [A.pop(0)]
for i in A[1:]:
    if n==0:
        break
    if n==1:
        ans+=i
        break
    ans+=i*2
    n-=2
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
from heapq import heappop
n = int(input())
A = list(map(lambda x:-int(x),input().split()))
A.sort()

ans = 0
loop = [A.pop(0)]
heapq.heapify(loop)
heapq.heapify(A)
#二番目に小さい値を加算していく
for i in range(n-1):
    if len(loop)==1:
        a = loop[0]
    else:
        a = loop[1]
    ans+=a
    heapq.heappush(loop,heapq.heappop(A))
    
print(-ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import heapq
n = int(input())
A = list(map(lambda x:-int(x),input().split()))
A.sort()

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 = list(map(int,input().split()))
ans = 0
a.sort()
a = a[::-1]
r = []
for i in range(n):
    r.append(a[i])
    if i != 0:
        ans += min(r[0],r[-2])
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())
lst = list(map(int, input().split()))
lst = sorted(lst, reverse=True)
print(sum(lst[:-1]))

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in raw_input().split()]
a.sort()
s=a[n-1]
for i in range(n/2,n):
  s+=a[i]*2
if(n%2==1):
  s-=a[n/2]
print s

Submission status: Wrong Answer

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

A.sort(reverse=True)
max_value = A.pop(0)
diff = [max_value]
ans = 0
for i in A:
    n = diff.pop(0)
    ans = ans + n
    diff = diff + [n, n]

print(ans)

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in raw_input().split()]
a.sort()
s=0
for i in range(1,n):
  s+=a[i]
print s

Submission status: Wrong Answer

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

A.sort(reverse=True)
ring = []
max_value = A.pop(0)
ring.append(max_value)
ring.append(max_value)
ans = 0
for i in A:
    buf = [x for x in ring]
    print(ring)
    n = []
    for j in range(0, len(ring) - 1):
        n.append(min(ring[j:j+2]))
    ans = ans + max(n)
    ring.insert(n.index(max(n)) + 1, i)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline())
lst = list(map(int, sys.stdin.readline().split()))
put = [0]*n

first_arrival = max(lst)
first_idx = lst.index(first_arrival)

put[first_idx] = first_arrival
lst[first_idx] = 0

ans = 0

for i in range(1, len(lst)):
    arrival = max(lst)
    idx = lst.index(arrival)

    put[idx] = arrival
    lst[idx] = 0

    #find comfort num
    l, r = 0, 0

    for i in range(1, len(put)):
        if l == 0 and put[(idx-i+len(put))%len(put)] != 0:
            l = put[(idx-i+len(put))%len(put)]
        if r == 0 and put[(idx+i)%len(put)] != 0:
            r = put[(idx+i)%len(put)]
        
        if r != 0 and l != 0:
            break
    
    
    ans += min(l, r)

print(ans)

Submission status: Wrong Answer

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

comfort = 0
circle = []

flag = False

for index, tmp in enumerate(data):
  circle.append(tmp)
  if flag:
    comfort += circle[index-1]
    
  flag = True
    

print(comfort)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    l=[]
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(int(sum))

def main2():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i,num in enumerate(A):
        if i==0:
            l=A[0]
            r=A[0]
            continue
        sum+=min(l,r)
        if l<r:
            r=num
        else:
            l=num
    print(int(sum))


if __name__ == "__main__":
    # main()
    main2()

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    l=[]
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(int(sum))

def main2():
    # N=input()
    # N=int(N)
    # A=input().split(" ")
    # A=np.array([int(i) for i in A]).astype(np.uint64)
    A=np.random.randint(0,100000,200000)
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    l=A[0]
    r=A[0]
    for i,num in enumerate(A,start=0):
        sum+=min(l,r)
        if l<r:
            r=num
        else:
            l=num
    print(int(sum))


if __name__ == "__main__":
    # main()
    main2()

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    l=[]
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(int(sum))

# def main2():

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    # A=np.random.randint(0,100000,200000)
    l=[]
    A=np.sort(A)
    A=np.flip(A)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(sum)

# def main2():

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
if __name__ == "__main__":
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint32)
    l=[]
    A=np.sort(A)
    A=np.flip(A)
    sum=0
    for i,num in enumerate(A):
        if i%2==0:
            l=l+[num]
            if i!=0:
                sum+=min(l[-2],l[0])
        else:
            l=[num]+l
            sum+=min(l[1],l[-1])
    print(sum)