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())
a_list=list(map(int,input().split()))
a=a_list.count(max(a_list))
ans=sorted(set(a_list))[-1]*(2*a-1)
b_list=sorted(set(a_list))
count=2*a-1
#print(ans,count)
for i in range(1,N):
    if count<N:
        A=b_list[-i-1]
        B=a_list.count(A)
        #print(A,B)
        ans+=A*B*2
        count+=B*2
        #print(ans,count)
    else:
        A=b_list[-i]
        ans+=(N-count-1)*A
        #print(i)
        break
    
print(ans)

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n=I()
a=L()

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

if N == 2:
    print(A[0])
else:
    print(sum(A)-A[-1]-A[-2]+A[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)[::-1]
result = 0
if N == 1:
  result = 0
else:
  if N == 2:
    result = B[0]
  else:
    if N == 3:
      result = B[0] + B[1]
if N > 3:
    result = sum(B[:N-1])
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sort_a = sorted(a, reverse=True)
ans = 0
prev_min = 0
for i in sort_a:
    ans += prev_min
    if ans == 0 and prev_min == 0:
        prev_min = i
        continue
    else:
        if prev_min > i:
            prev_min = i
print(ans)

Submission status: Wrong Answer

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

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

    a_sort = sorted(a, reverse=True)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = sum(a[:2])
left, right = a[1], a[2]
for i in range(3, n):
    if left <= right:
        ans += right
        right = a[i]
    else:
        ans += left
        left = a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = sorted(a,reverse=True)
sort = []
ok = -1 * a[0]

for i, j in enumerate(a):
    if i % 2 == 0:
        sort.append(j)
        ok += min(sort[i-1],sort[0])
    if i % 2 == 1:
        sort.insert(0,j)
        ok += min(sort[-1], sort[1])

print(ok)

Submission status: Wrong Answer

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

a.sort()

ans = max(a)
o = 0
for i in range(n//2):
    if i != 0:
        o += a[i]
ans += o*2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
Mylist = input().split()
Mylist = [int(s) for s in Mylist]
Mydict = collections.Counter(Mylist)

ANS = 0
lastKey = 0
amari = 0

for keys in Mydict.keys():
    tukaukazu = amari-Mydict[keys]
    if tukaukazu > 0:
        ANS += lastKey*tukaukazu
        amari = tukaukazu
    else:
        ANS += lastKey*amari + keys*-1*tukaukazu
        amari = -1*tukaukazu
        lastKey = keys

print(ANS-min(Mylist))

Submission status: Wrong Answer

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


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 main():
    N = II()
    As = LI()
    As.sort()
    As.reverse()
    As_counter = collections.Counter(As)
    As_set = list(set(As))
    As_set.sort()
    As_set.reverse()

    As_set = collections.deque(As_set)

    ans = [As_set[0] for i in range(As_counter[As_set[0]])]
    joined_num = As_counter[As_set[0]]
    As_set.popleft()
    musts = []
    while len(As_set) > 0:
        target = As_set.popleft()

        target_num = As_counter[target]

        if (joined_num >= target_num):
            tmp = [target for i in range(2 * target_num)]
            ans.extend(tmp)
        else:
            tmp = [target for i in range(
                2 * joined_num + (target_num - joined_num))]
            tmp_must = [target for i in range(
                target_num - joined_num)]
            ans.extend(tmp)
            musts.extend(tmp_must)

        joined_num += target_num
    musts.extend(ans)

    print(sum(musts[:N-1]))


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Wrong Answer

Solution code:
# D
N = int(input())
A = list(map(int, input().split()))
sorted_lst = list(sorted(A, reverse=True))
ans = 0
ma = sorted_lst[0]
for i in range(1, N):
    if (i % 2 != 0):
        ans += ma
        ma = sorted_lst[i]
    else:
        ans += ma
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse= True)
sum1 = arr[0]
j = 1
i = n-2
while i > 0:
  sum1 += arr[j]*2
  i -= 2
  j += 1
if i == -1:
  sum1 -= arr[j]
print(sum1)

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    a = list(reversed(sorted(A)))
    ans = a[0]
    for i in range(N-2):
        ans += a[i+1]

    print(ans)
    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:
import sys
input = sys.stdin.readline

import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

n=ii()
a=ll()
a.sort()
a=a[::-1]
i=0
rem=n-1
ans=0
while(rem>0):
    k=min(rem,i+1)
    rem-=k
    ans+=k*a[i]
    #print(k,a[i],ans)
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import io,sys,copy
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    A = list(map(int,sys.stdin.readline().rstrip().split()))

    A.sort()
    print(sum(A[:-1]))
main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a.sort(reverse=True)

point = 0
num = a[0]
for i in range(1, n):
  if num >= a[i]:
    point += num
    num = a[i]

print(point)

Submission status: Wrong Answer

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

def fdly(l):
    res = 0
    if len(l) <= 1:
        return res
    if len(l) == 2:
        res = l[0]+l[1]
        return res

    for i in range(1,len(l)-1):
        res += min(l[i-1]     ,l[i+1])
    res += min(l[len(l)-2],l[0]  )
    return res

stda = sorted(a)

tt = 0
ccl = deque()
for e in stda:
    if tt == 0:
        ccl.append(e)
        tt = 1
    else:
        ccl.appendleft(e)

print(fdly(list(ccl)))

Submission status: Wrong Answer

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

players.sort(reverse=True)
total = 0
for i in range(1,N):
    j = int(i/2)
    print(players[j])
    total += players[j]
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

A.sort(reverse=True)

B = [A[i] for i in range(N) if i < N//2]

# 9 8 7 6 5
# 9 1 8 2 7 3 6 4 5
# 9+8+7+6+5+6+7+8

# 8 7 6 5
# 8 1 7 2 6 3 5 4
# 8+7+6+5+5+6+7

if N % 2 == 1:
    sm = B[0] + B[-1] + sum(B[i]*2 for i in range(len(B)) if 0 < i < N - 1)
    print(sm)
else:
    sm = B[0] + sum(B[i]*2 for i in range(len(B)) if 0 < i)
    print(sm)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
a = np.array(readline().split(), dtype=np.int64)
a.sort()
a = a[::-1]
print(a)
m = -(-n//2)
ans = np.sum(a[:m])*2 - a[0] if n % 2 == 0 else np.sum(a[:m])*2 - a[0] - a[m-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
kokoti=0
A.sort(reverse=True)
#print(A)
for i in range(1,N-1):
    if(i==1):
        kokoti+=A[0]
        #print(kokoti,A[0],1)
    elif(i==N-1):
        kokoti+=A[i-1]
        #print(kokoti,A[i-1],2)
    if(A[i-1]<=A[N-i-2]):
        kokoti+=A[i-1]
        #print(kokoti,A[i-1],3)
    elif(A[i-1]>=A[N-i-2]):
        kokoti+=A[N-i-2]
        #print(kokoti,A[N-i-2],4)
print(kokoti)

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int, input().split()))
x = sorted(x)[::-1]
ans = 0
if n%2 == 0:
    for i in range(int(n/2)):
        ans += x[i]*2
 #       print(ans)
    ans -= x[0]
else:
    for i in range(int((n-1)/2+1)):
        ans += x[i]*2
    ans = ans - x[i] - x[int((n-1)/2+1)]         
print(ans)

Submission status: Wrong Answer

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

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

ans = b[-1]
ans += b[-2] * min(2, n-1)
if n > 3:
    ans += b[-2] * (n-4)
print(ans)
# 10, 9, 9, ()

Submission status: Wrong Answer

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

N = int(input())

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

A_sort = sorted(A, reverse=True)

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=1)
    players = [A[0], float('inf'), float('inf'), A[0]]
    ans = 0
    for a in A[1:]:
        n1 = min(players[0], players[1], players[2])
        n2 = min(players[-1], players[-2], players[-3])
        if n1 > n2:
            ans += n1
            players[1] = a
        else:
            ans += n2
            players[-2] = a
    print(ans)


main()

Submission status: Wrong Answer

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

a.sort(reverse=True)

score=0

for i in range(len(a)):
  if i==0:
    score+=0
  else:
    score+=a[i-1]
print(score)

Submission status: Wrong Answer

Solution code:
import heapq


def get_tuple(a, b):
    if a > b:
        a, b = b, a
    return a, b


def main(a, N):
    a.sort(reverse=True)
    h = []
    comfort = a[0]
    heapq.heappush(h, get_tuple(a[0], a[1]))
    for i in range(N - 2):
        val = heapq.heappop(h)
        comfort += val[0]
        heapq.heappush(h, get_tuple(a[i], val[0]))
        heapq.heappush(h, get_tuple(a[i], val[1]))
    print(comfort)


if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    main(a, N)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import heapq
N = int(input())
A = sorted(list(map(int, input().split())))
if N >= 3 and A[-2] != A[-3]:
  ans = sum(A) + A[-2] - A[1] - A[0]
else:
  ans = sum(A) - A[0]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    A = input_number_list()
    A.sort(reverse=True)
    l = len(A)
    p = 0
    ans = sum(A[:l // 2])
    ans += sum(A[1:l // 2])
    if l % 2 == 1:
        ans += A[l // 2 + 1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

s = input().split()
A = []
for i in range(N):
  A.append(int(s[i]))
  
result = 0
A.sort(reverse=True)
result += A[0]
A.pop(0)
if N % 2 == 0:
  result += sum(A[:(int(N/2)-1)])*2
else:
  result += (sum(A[:(int((N-1)/2)-1)])*2 + A[int((N-1)/2)])
    
print(result)

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n=I()
a=L()

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

Submission status: Wrong Answer

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

import collections
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

C = collections.Counter(A)

if N == 2:
    print(A[0])
    exit()
ret = A[0]
cnt = 2

C = sorted(C.items())[::-1]

if len(C) == 1:
    print(C[0][0]*C[0][1]-1)
    exit()


for n, c in C[1:]:
    if cnt + c >= N:
        ret += n*(N-cnt)
        break
    else:
        ret += n*c*2
        cnt += c*2

print(ret)

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

print(ans)

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

b=merge_sort(a)
b.reverse()
c=[]
hap=0
for i in range(n):
    q=b.pop(0)
    if len(c)==0:
        c.append(q)
        hap+=0
    elif len(c)==1:
        c.append(q)
        hap+=c[0]
    else:
        c.insert(1,q)
        hap+=c[2]

print(hap)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
kokoti=0
A.sort(reverse=True)
#print(A)
for i in range(1,N-1):
    if(i==1):
        kokoti+=A[0]
        #print(kokoti,A[0],1)
    elif(i==N-1):
        kokoti+=A[N-1]
        #print(kokoti,A[i-1],2)
    if(A[N-1]<=A[N-i-2]):
        kokoti+=A[N-1]
        #print(kokoti,A[i-1],3)
    elif(A[N-1]>=A[N-i-2]):
        kokoti+=A[N-i-2]
        #print(kokoti,A[N-i-2],4)
print(kokoti)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
i = list(map(int, input().split()))
 
sorti = i
p = itertools.permutations(sorti, n)

ans = []
for pp in p:
    pp = list(pp)
  
    pp += [pp[0]]
    pp.insert(0, pp[-2])

    ans_m = 0
    for index, x in enumerate(pp):
        
        if index == 0:
            continue
        if index == n+1:
            break
    
        if pp[index-1] <= pp[index+1]:
            ans_m += pp[index+1]
        elif pp[index+1] <= pp[index-1]:
            ans_m += pp[index-1]

    ans.append(ans_m)
    
print(max(ans) - max(sorti))

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
print(sum(a)-min(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
Ns = [i for i in range(2 * (10 ** 5) + 1)]
As = list(map(int, input().split()))
As.sort(reverse=True)
if (len(As) % 2 == 0):
  ans = sum(As[:len(As) // 2] * 2)
else:
  ans = sum(As[:(len(As) + 1) // 2]) * 2 - As[-1]
print(ans - As[0])

Submission status: Wrong Answer

Solution code:
import copy

inp = input()
friends = input()
friendList = friends.split()
sortedFriends = sorted(friendList, reverse=True)
confs = [sortedFriends[0]]
copied = copy.deepcopy(sortedFriends)[1:]
sortedFriends.extend(copied)
sortedFriends = sorted(sortedFriends, reverse=True)

confFriends = ['0']
confFriends.extend(sortedFriends)
confSum = 0
for i in range(int(inp)):
    conf = int(confFriends[i])
    confSum += conf
print(str(confSum))

Submission status: Wrong Answer

Solution code:
n = int(input())
friendlies = [int(x) for x in input().split()]
comf_lvl = 0
table = []

print(friendlies)
print("----------")

def smaller_out(a,b):
      if a > b:
            return a
      else:
            return b
      

for i in range(n):
      if i%2 == 0:
            table.append(max(friendlies))
            friendlies[friendlies.index(max(friendlies))] = 0
      else:
            table.insert(0,max(friendlies))
            friendlies[friendlies.index(max(friendlies))] = 0
      
      print(table,end=" ")
      
      if i > 0:
            print(comf_lvl,table[i-1],table[0],end=":")
            print()
            comf_lvl += smaller_out(table[i-1],table[0])
      else:
            print("through")
            


print(comf_lvl)
print(friendlies)
print(table)

Submission status: Wrong Answer

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

print(sum(arr) - min(arr))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

arrival = sorted(l, reverse=True)
c = [arrival[0]]
com = 0
arrival.pop(0)

while arrival:
    com += min(c)
    c.append(arrival.pop(0))

print(com)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,25):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[insx_list[j-1]-1],reached_list[insx_list[j-1]])
    reached_list.insert(insx_list[j-1], A_list[j])
    mx_cmfrt += cmfrt
    cmfrt = 0
print(mx_cmfrt)

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
s=0
num=map(int,input().split())
for k in num:
    s=s+k
    l.append(k)
s=s-l[int((n+1)/2)]
print(s)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)[::-1]
    if n %2== 0:
        print(a[0]+sum(a[1:n//2]))
    else:
        print(a[0]+sum(a[1:n//2+1])*2)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
kokoti=0
A.sort(reverse=True)
#print(A)
for i in range(1,N-1):
    if(i==1):
        kokoti+=A[0]
        #print(kokoti,A[0],1)
    elif(i==N-i-1):
        kokoti+=A[N-i-1]
        #print(kokoti,A[i-1],2)
    if(A[N-i-1]<=A[N-i-2]):
        kokoti+=A[N-i-1]
        #print(kokoti,A[i-1],3)
    elif(A[N-i-1]>=A[N-i-2]):
        kokoti+=A[N-i-2]
        #print(kokoti,A[N-i-2],4)
print(kokoti)

Submission status: Wrong Answer

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

a.sort(reverse=True)
print(sum(a)-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:

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    
    Taku = []

    A.sort()
    A.reverse()
    flg = 0

    ans = 0

    for an in A:
        if flg == 0:
            Taku.append(an)
            flg = 1
        else:
            Takudiff = [min(Taku[i], Taku[i-1]) for i in range(len(Taku))]
            Taku.insert(Taku.index(max(Takudiff)), an)
            ans += max(Takudiff)

    print(ans)

solve()

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    a = list(reversed(sorted(A)))
    ans = a[0] + (N-2)*a[1]
    print(ans)
    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())
l=list(map(int,input().split()))
l.sort(reverse=True)
prev=l[0]
ans=0
for i in range(1,n):
  ans+=prev
  prev=min(prev,l[i])
l=l[::-1]
prev=l[0]
an=0
for i in range(1,n):
  an+=prev
  prev=min(prev,l[i])
print(max(ans,an))

Submission status: Wrong Answer

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


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 main():
    N = II()
    As = LI()
    As.sort()
    As.reverse()
    As_counter = collections.Counter(As)
    As_set = list(set(As))
    As_set.sort()
    As_set.reverse()

    As_set = collections.deque(As_set)

    ans = [As_set[0] for i in range(As_counter[As_set[0]])]
    joined_num = As_counter[As_set[0]]
    As_set.popleft()
    while len(As_set) > 0:
        target = As_set.popleft()

        target_num = As_counter[target]

        if (joined_num >= target_num):
            tmp = [target for i in range(2 * target_num)]
            ans.extend(tmp)
        else:
            tmp = [target for i in range(
                2 * joined_num + 2*(target_num - joined_num))]
            ans.extend(tmp)

        joined_num += target_num

    print(sum(ans[:N-1]))


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import numpy as np
import functools
import operator
import collections
import itertools
N=int(input())
A = list(map(int, input().split())) 
new_A=sorted(A)
print(sum(A)-new_A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
Ns = [i for i in range(2 * (10 ** 5) + 1)]
As = list(map(int, input().split()))
As.sort(reverse=True)
if (len(As) % 2 == 0):
  ans = sum(As[:len(As) // 2] * 2)
else:
  ans = sum(As[: (len(As) + 1) // 2]) * 2 - As[0]
print(ans - As[0])

Submission status: Wrong Answer

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

A.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
tmp=0
sukima=0
for i in A:
    if sukima>0:
        ans+=tmp
        sukima-=1
        if sukima==0:
            tmp=i
    else:
        if tmp==i:
            ans+=i
            sukima=A.index(i)+2
        else:    
            ans+=tmp
            tmp=i
            sukima=A.index(i)+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
b = a.copy()
a = Counter(a)
ans = 0
b = sorted(b,reverse=True)
kosuu = 0
num = 0
t = []
kosuu = a[b[0]]
if kosuu != 1:kosuu += 1
num = b[0]
t.append(b[0])
for i in range(1,n):
    if kosuu != 0:
        kosuu -= 1
        ans += num
        t.append(b[i])
    else:
        ans += min(t)
        t.append(b[i])
        kosuu = len(t)
        num = min(t)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(sum(m)-1)

Submission status: Wrong Answer

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

result = []
max = max(numbers)
mi = min(numbers)
numbers.remove(max)
numbers.remove(mi)
for number in range(n-2):
    m = min(numbers)
    max += m

print(max)

Submission status: Wrong Answer

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

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

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

print(score)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
a = sorted(a, reverse=True)

sum = a[0] + a[1]
for i in range(n-3):
    if i % 2 == 0:
        sum += a[int(i/2+1)]
    else:
        sum += a[int(i/2+2)]

print(sum)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    # Aiが大きいやつからいく
    ans = sum(A)-min(A)
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
#ABC174D - 絶対違う
n = int(input())
l = list(map(int,input().split()))
ans = 0
l2 = sorted(l)
l2.pop(0)
for i in l2:
  ans += i
print(ans)

Submission status: Wrong Answer

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

import collections
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

C = collections.Counter(A)

if N == 2:
    print(A[0])
    exit()
ret = A[0]
cnt = 2

C = sorted(C.items())[::-1]

if len(C) == 1:
    print(C[0][0]*C[0][1]-1)
    exit()


for n, c in C[1:]:
    if cnt + c >= N:
        ret += n*(N-cnt)
        break
    else:
        print('aaa',n*c*2)
        ret += n*c*2
        cnt += c*2

print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = input().split()
K = [int(n) for n in L]
print(sum(K)-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
l_sort = sorted(l,reverse=True)
l_len = len(l)
if(l_len%2==0):
    ans = sum(l_sort[:(l_len//2)-1]+l_sort[1:(l_len//2)+1])
else:
    ans = sum(l_sort[:(l_len//2)]*2)

print(ans)

Submission status: Wrong Answer

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

def main(n,a):
    #print(a)
    a.sort(reverse=True)
    #print(a)
    sum=a[0]
    j=1
    k=1
    for i in range(2,n):
        sum+=a[k]
        j+=1
        if j==2:
            j=0
            k+=1
    return sum

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
kokoti=0
A.sort(reverse=True)
print(A)
for i in range(1,N-1):
    if(i==1):
        kokoti+=A[0]
        #print(kokoti,A[0],1)
    elif(i==N-1):
        kokoti+=A[i-1]
        #print(kokoti,A[i-1],2)
    if(A[i-1]<=A[N-i-2]):
        kokoti+=A[i-1]
        #print(kokoti,A[i-1],3)
    elif(A[i-1]>=A[N-i-2]):
        kokoti+=A[N-i-2]
        #print(kokoti,A[N-i-2],4)
print(kokoti)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
s=0
num=map(int,input().split())
for k in num:
    s=s+k
    l.append(k)
s=s-l[(n+1)//2]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
c=1
ans=0
dic={}
for i in range(n):
    if i==0:
        num=a[i]
        dic[a[i]]=1
    else:
        if a[i]==a[i-1]:
            c+=1
            dic[a[i]]+=1
        else:
            num=a[i]
            dic[a[i]]=dic[a[i-1]]+1
#print(dic)
x=0
for k,v in dic.items():
    if x+v<=n-1:
        ans+=k*v
        x+=v
        #print(ans)
    else:
        ans+=k*(n-1-x)
        #print(ans)
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
B = []
ans = 0
i = 0
while A:
    a = A.pop()
    if i == 1:
        ans += B[0]
    elif i > 1:
        ans += min(B[-2], B[-1])
    B.append(a)
    i += 1
print(ans)