ZhenlongDai/ACPR huggingface dataset:
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())


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



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

Failing test case input:
7
1 110 -5 2 8 1 -1

Expected output:
131


Actual output:
121


Fixed submission (verdict: Accepted):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())


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



A.sort(reverse = True)
h = [-A[0]]

answer = 0
for a in A[1:]:
    answer -= heappop(h)
    heappush(h, -a)
    heappush(h, -a)

print(answer)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]

ans=0

last=0
for i in range(n):
  ans+=last
  last=a[i]

print(ans)


Failing test case input:
7
1 110 -5 4 8 1 -2

Expected output:
135


Actual output:
122


Fixed submission (verdict: Accepted):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
a=sorted(nl())[::-1]
 
ans=0

cur=0
now=1
for i in range(n-1):
  ans+=a[cur]
  if now==1:
    now=0
    cur+=1
  elif now==0:
    now=1


print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=1)
ans = 0 + a[0] + (n-2) * a[1]
print(ans)

Failing test case input:
7
2 101 -1 1 -2 -1 3

Expected output:
112


Actual output:
116


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=1)
ans = 0 + a[0]
for i in range(n-2):
    ans += a[i
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)

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

Failing test case input:
7
-1 100 0 0 0 -3 1

Expected output:
102


Actual output:
100


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
a.sort(reverse=True)

ans=max(a)
cnt=0
for i in range(1,n):
  now=a[i]
  for s in range(2):
    if cnt+1<=n-2:
      ans+=now
      cnt+=1
print(ans)
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))

A.sort(reverse=True)

ans=0

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

print(ans)

Failing test case input:
4
1 5 1 10

Expected output:
20


Actual output:
16


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))

A.sort(reverse=True)

ans=0

for i in range(N-1):
    ans += A[(i+1)
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
ans = sum(A[:N-1])
print(ans)

Failing test case input:
4
0 10 1 2

Expected output:
14


Actual output:
13


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(1, N):
    ans += A[N - i
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from math import floor
n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10000000000

m=floor((n-1)/2)

a=sorted(a,reverse=True)

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

    comfort+=a[m+2]

print(comfort)


Failing test case input:
7
-1 100 -4 1 -1 -2 2

Expected output:
105


Actual output:
103


Fixed submission (verdict: Accepted):

n=int(input())
b=input().split()
a=[0 for i in range(n+1)]
for i in range(1,n+1):
  a[i]=int(b[i-1])

a[0]=10**10

m=int((n-2)/2)

a=sorted(a,reverse=True)

comfort=a[1]
if(n==2):
  print(comfort)
else:
  
  for i in range(2,m+2):
    comfort+=(2*a[i])

  if(n%2 ==0):
    print(comfort)
  else:
    print(comfort+a[m+2])

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort(reverse=True)

ans=a[0]
left=a[1]
right=a[1]

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

print(ans)

Failing test case input:
7
1 110 -8 2 16 2 -2

Expected output:
148


Actual output:
147


Fixed submission (verdict: Accepted):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort(reverse=True)

ans=a[0]

inx=1
i=2
while i<n:
  ans+=a[inx]

  if i%2==1:
    inx+=1

  i+=1

print(ans)
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]




from collections import deque

N = ii()
A = sorted(li(), reverse=True)

l = deque([A[1]])

ans = A[0]
for num in A[2:]:
    
    ans += l.popleft()
    l.append(num)
    l.append(num)

print(ans)

Failing test case input:
7
-1 81 -2 -2 1 1 -2

Expected output:
84


Actual output:
82


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]




from collections import deque

N = ii()
A = sorted(li(), reverse=True)

l = deque([A[1], A[1]])

ans = A[0]
for num in A[2:]:
    
    ans += l.popleft()
    l.append(num)
    l.append(num)

print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import queue

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

ans = A[0]
q.put( (A[0], A[1]) )
for i in range(2, len(A)):
  t = q.get()
  ans += min(t[0], t[1])
  q.put((t[0], A[i]))
  q.put((t[1], A[i]))
  
print(ans)

Failing test case input:
4
2 4 1 10

Expected output:
18


Actual output:
16


Fixed submission (verdict: Accepted):
import queue

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

ans = A[0]
q.put( (A[0], A[1]) )
q.put( (A[0], A[1]) )
for i in range(2, len(A)):
  t = q.get()
  ans += min(t[0], t[1])
  q.put((t[0], A[i]))
  q.put((t[1], A[i]))
  
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)

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

Failing test case input:
7
-1 111 -1 0 1 0 2

Expected output:
117


Actual output:
113


Fixed submission (verdict: Accepted):
N=int(input())
L=list(map(int,input().split()))
L.sort(reverse=True)

ans=0
for i in range(1,N):
    ans+=L[i
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

d  = sorted(a, reverse = True)
print(sum(d) - d[n-1])


Failing test case input:
4
1 10 1 3

Expected output:
16


Actual output:
14


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
b = sorted(a, reverse=True)
ans = 0
for i in range(n-1):
    ans += b[(i+1)
print(ans)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):





import sys
import heapq

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

    nums.sort()
    temp1 = None
    temp2 = None
    ans = 0

    
    temp1 = nums.pop()
    temp2 = nums.pop()
    ans += temp1
    while nums:
        ans += temp2
        temp1 = temp2
        temp2 = nums.pop()

    print(ans)

    return

if __name__ == "__main__":
    main()

Failing test case input:
4
1 3 1 3

Expected output:
9


Actual output:
7


Fixed submission (verdict: Accepted):





import sys
import heapq

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

    nums.sort()
    ans = 0

    
    temp = nums.pop()
    ans += temp
    n -= 2

    for i in range(n 
        ans += nums[-i - 1] * 2

    if n % 2:
        ans += nums[-(n 
    
    
    print(ans)

    return

if __name__ == "__main__":
    main()

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
a = input().split()
a = list(map(int,a))
sa = sorted(a,reverse=True)
count = 0
count += sa[0]

f = 0
t = 1
for i in range(N-2):
    f += 1
    if f == 3:
        t += 1
        count += sa[t]

        f = 0
    else:
        count += sa[t]

print(count)

Failing test case input:
7
1 110 -5 2 4 0 -1

Expected output:
123


Actual output:
124


Fixed submission (verdict: Accepted):
N = int(input())
a = input().split()
a = list(map(int,a))
sa = sorted(a,reverse=True)
count = 0
count += sa[0]
f = 0
t = 1
for _ in range(N-2):
    if f == 2:
        t += 1
        count += sa[t]
        f = 0
    else:
        count += sa[t]
    f += 1
print(count)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

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

ans = 0
cur = 0
for i in range(N - 1):
    ans += A[cur]
    if i < 2:
        cur += 1
    elif i % 2 == 1:
        cur += 1

print(ans)

Failing test case input:
7
0 111 -3 1 4 0 0

Expected output:
121


Actual output:
117


Fixed submission (verdict: Accepted):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

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

ans = 0
cur = 0
for i in range(N - 1):
    ans += A[cur]
    if i < 1:
        cur += 1
    elif i % 2 == 0:
        cur += 1

print(ans)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
P=A[0]
for i in range(2,N):
  P+=A[((i>>1)<<1)-1]
  print((i>>1)<<1)
print(P)


Failing test case input:
7
-1 81 -2 -2 1 1 -2

Expected output:
84


Actual output:
2
2
4
4
6
79


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
P=A[0]
for i in range(2,N):
  P+=A[i
print(P)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
C = A[0]
for i in range(2,N):
  C = C+min(A[i-1],A[i-2])
print(C)

Failing test case input:
7
-3 000 1 -1 -2 -3 -1

Expected output:
-2


Actual output:
-6


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
C = A[0]
j=0
for i in range(1,N-1):
  if i%2 == 0:
    C = C+A[j]
  elif i%2 != 0:
    j=j+1
    C = C+A[j]
print(C)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

ans = A[0]
idx = 1                 
for i in range(2, N):
    ans += A[idx]
    if i % 2 == 0:
        idx += 1

print(ans)


Failing test case input:
4
1 4 1 3

Expected output:
10


Actual output:
8


Fixed submission (verdict: Accepted):

import math

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

ans = 0
for i in range(1, N):
    idx = math.floor(i/2)           
    ans += A[idx]

print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A.sort()
p = 0
ans = 0
for i in range(len(A)):
    if i == 2 or not i % 2 == 0:
        p = A.pop()
    ans += p
print(ans)

Failing test case input:
4
2 4 1 10

Expected output:
18


Actual output:
16


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A.sort()
p = 0
ans = 0
for i in range(len(A)):
    if i == 0:
        continue
    if i == 1 or i % 2 == 0:
        p = A.pop()
    ans += p
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
7
-2 81 -2 -2 0 1 -2

Expected output:
81


Actual output:
76


Fixed submission (verdict: Accepted):
import math
 
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans = 0
for i in range(1, N):
	ans += A[math.floor(i / 2)]
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a)-a[-1])


Failing test case input:
7
-1 100 0 1 -1 -3 3

Expected output:
108


Actual output:
102


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
if n%2:
    print(sum(a[:(n+1)
else:
    print(sum(a[:n
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N=int(input())
Alist=list(map(int,input().split()))
Alist.sort(reverse=True)
kokochiyosa=0
for i in range(N-1):
    kokochiyosa+=Alist[i]

print(kokochiyosa)



Failing test case input:
7
1 110 -1 0 2 -1 2

Expected output:
119


Actual output:
114


Fixed submission (verdict: Accepted):



N=int(input())
Alist=list(map(int,input().split()))
Alist.sort(reverse=True)
kokochiyosa=Alist[0]
for i in range(1,N-1):
    kokochiyosa+=Alist[(i+1)

print(kokochiyosa)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
7
0 101 -8 3 18 3 -2

Expected output:
146


Actual output:
123


Fixed submission (verdict: Accepted):
n = int(input())
A = input()
A = A.split()
A = [int(i) for i in A]
A = sorted(A, reverse = True)

ans = 0

for i in range(int(n/2)):
	ans += A[i]*2

ans -= A[0]

if n&1:
  ans += A[int(n/2)]


print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
lst = list(map(int, input().split()))

lst = sorted(lst, reverse=True)

print(sum(lst[0:n-1]))

Failing test case input:
7
-1 101 -2 0 -1 0 4

Expected output:
109


Actual output:
103


Fixed submission (verdict: Accepted):
n = int(input())
lst = list(map(int, input().split()))

lst = sorted(lst, reverse=True)

print(sum(lst[0:n

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

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

print(ans)

Failing test case input:
7
-1 0 3 -2 -1 1 -1

Expected output:
4


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

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

if n % 2 == 1:
  ans += a[(n - 1) 

print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
conf = 0
num_char = int(input())
char = list(map(int, input().split()))
char.sort(reverse=True)
count = 0
conf_int = 0
for i in range(num_char):
  if count == 0:
    count = 1
  elif count == 1:
    count = 2
    conf = char[conf_int]
    count_int = 0
    conf_int = 1
  else:
    if count_int == 0 :
      conf += char[conf_int]
      count_int = 1
    else:
      conf += char[conf_int]
      conf_int += 1
      count_int = 0
print(conf_int)

      
  

Failing test case input:
4
1 0 1 13

Expected output:
15


Actual output:
2


Fixed submission (verdict: Accepted):
conf = 0
num_char = int(input())
char = list(map(int, input().split()))
char.sort(reverse=True)
count = 0
conf_int = 0
for i in range(num_char):
  if count == 0:
    count = 1
  elif count == 1:
    count = 2
    conf = char[conf_int]
    count_int = 0
    conf_int = 1
  else:
    if count_int == 0 :
      conf += char[conf_int]
      count_int = 1
    else:
      conf += char[conf_int]
      conf_int += 1
      count_int = 0
print(conf)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
a = list(reversed(sorted(a)))

result = a[0]
if n > 2:
	for i in range(2, n):
		result += min(a[i - 1], a[i - 2])

print(result)



Failing test case input:
4
2 4 1 10

Expected output:
18


Actual output:
16


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
a = list(reversed(sorted(a)))

result = a[0]
n -= 2

i = 1

while n > 0:
	result += a[i]
	n -= 1
	if n > 0:
		result += a[i]
		n -= 1

	i += 1

print(result)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A.sort()

    ans = sum(A[1:])
    ans -= A[1]
    ans += A[-2]
    print(ans)


    
    

if __name__ == '__main__':
    main()



Failing test case input:
7
-2 81 -2 -2 0 1 -2

Expected output:
81


Actual output:
79


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    A.sort(reverse=True)

    c = 0
    ans = A[0]

    for i in range(2, N):
        if i % 2 == 0:
            c += 1
        ans += A[c]

    print(ans)

    
    

if __name__ == '__main__':
    main()

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from heapq import heapify, heappop, heappush


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

A.sort(reverse=True)

heap = []
heapify(heap)

val = 0
heappush(heap, -A[1])
val += A[0]


for a in A[2:]:
    n = heappop(heap)
    val += -n

    heappush(heap, -a)
    heappush(heap, -a)


print(val)



Failing test case input:
7
-1 38 -2 -2 -2 1 -2

Expected output:
36


Actual output:
33


Fixed submission (verdict: Accepted):
from heapq import heapify, heappop, heappush


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

A.sort(reverse=True)

heap = []
heapify(heap)

val = 0
heappush(heap, -A[1])
val += A[0]

for i, a in enumerate(A[2:]):
    n = heappop(heap)
    val += -n

    if i == 0:
        heappush(heap, n)

    heappush(heap, -a)
    heappush(heap, -a)


print(val)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from collections import deque
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]

if n==2:
    print(a[0])
else:
    b=deque([a[1],a[2]])
    ans=a[0]+a[1]
    minlist=[min(b)]
    j=1
    for i in range(n-3):
        if j==0:
            j+=1
            ans+=b[0]
            b+=[a[i+2]]
        else:
            j=0
            ans+=b[0]
            b.popleft()
            b+=[a[i+2]]
    print(ans)

Failing test case input:
7
-1 101 -2 1 -1 0 18

Expected output:
139


Actual output:
140


Fixed submission (verdict: Accepted):
from collections import deque
n=int(input())
a=sorted([int(i) for i in input().split()])[::-1]

if n==2:
    print(a[0])
else:
    b=deque([a[1],a[2]])
    ans=a[0]+a[1]
    minlist=[min(b)]
    j=1
    for i in range(n-3):
        if j==0:
            j+=1
            ans+=b[0]
            b+=[a[i+3]]
        else:
            j=0
            ans+=b[0]
            b.popleft()
            b+=[a[i+3]]

    print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

n = k()
a = l()

a.sort()
a.reverse()

b = list(itertools.accumulate(a))
print(b[-1]-a[-1])


Failing test case input:
7
1 100 0 1 -2 -5 0

Expected output:
104


Actual output:
100


Fixed submission (verdict: Accepted):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 1
ans = 0
inf = float("inf")

n = k()
a = l()

a.sort(reverse = True)

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

print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))  
A.sort(reverse=True)
print(sum(A)-A[-1])

Failing test case input:
7
-1 111 -2 2 -1 -24 4

Expected output:
122


Actual output:
113


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))  
A.sort(reverse=True)
ans = 0
for i in range(1,N):
    ans += A[i
print(ans)
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
tmp=A[0]
next=0
for i in range(1,N):
  ans+=tmp
  tmp=A[i]
print(ans)

Failing test case input:
7
1 110 -8 2 31 2 -2

Expected output:
178


Actual output:
144


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
li=[A[0]]
for i in range(1,N):
  ans+=li[i-1]
  li.append(A[i])
  li.append(A[i])
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = list(it)

    A.sort()
    if N ==2:
        print(A[-1])
        return

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

if __name__ == "__main__":
    resolve()


Failing test case input:
7
1 110 -5 4 8 1 -2

Expected output:
135


Actual output:
132


Fixed submission (verdict: Accepted):


import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = list(it)

    A.sort(reverse=True)
    ans = A[0] + 2*sum(A[1:(N-1)
    if N % 2:
        ans -= A[(N-1)

    print(ans)

if __name__ == "__main__":
    resolve()

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

import heapq
def resolve():
    N,=pin()
    A=[*pin()]
    A.sort(reverse=True)

    ans=0
    h=[]
    heapq.heappush(h,0)
    for i in range(1,N):
        temp=heapq.heappop(h)
        print(temp)
        ans+=A[temp]
        heapq.heappush(h,i)
        heapq.heappush(h,i)
    print(ans)


resolve()

Failing test case input:
4
-11 -96 -2 -1

Expected output:
-5


Actual output:
0
1
1
-5


Fixed submission (verdict: Accepted):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

import heapq
def resolve():
    N,=pin()
    A=[*pin()]
    A.sort(reverse=True)

    ans=0
    h=[]
    heapq.heappush(h,0)
    for i in range(1,N):
        temp=heapq.heappop(h)
    
        ans+=A[temp]
        heapq.heappush(h,i)
        heapq.heappush(h,i)
    print(ans)


resolve()
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
a = LI()
a.sort(reverse=True)
ans = sum(a[:2])
if n<=3:
	print(ans)
else:
	ans = sum(a[:3])
	for i in range(3,n-1):
		ans+=a[i-2]
	print(ans)

Failing test case input:
4
1 5 1 10

Expected output:
20


Actual output:
16


Fixed submission (verdict: Accepted):
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
n = II()
a = LI()
a.sort(reverse=True)
ans = 0
for i in range(1,n):
	ans+=a[i-math.ceil(i/2)]
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import math


from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
a=sum(arr)
b=min(arr)
print(a-arr[0])


Failing test case input:
7
-1 100 -4 1 -1 -2 2

Expected output:
105


Actual output:
96


Fixed submission (verdict: Accepted):
import sys
import math


from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
ans=0
arr.sort(reverse=True)
for i in range(1,n):
    ans+=arr[i
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

ans = 0
if n >= len(A):
  ans = sum(A)-1
  
else:
  ans += A[1]
  t = n-1
  for i in range(1, n):
    lim = 2
    for j in range(0, lim):
      if t > 0: ans += A[i]
      t -= 1
      
print(ans)


Failing test case input:
4
0 10 1 2

Expected output:
14


Actual output:
12


Fixed submission (verdict: Accepted):
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

ans = A[0]
t = n-2
for a in A[1:n]:
  lim = 2
  for _ in range(lim):
    if t > 0: ans += a
    t -= 1
      
print(ans)
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = sum(a[:1])
    que = [(-a[1], -a[0])]
    heapq.heapify(que)
    for i in range(2, n):
        x, y = heapq.heappop(que)
        ans += min(-x, -y)
        heapq.heappush(que, (-a[i], x))
        heapq.heappush(que, (-a[i], y))
    return ans

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

Failing test case input:
7
-1 100 -4 1 -1 -2 2

Expected output:
105


Actual output:
102


Fixed submission (verdict: Accepted):
import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = a[0]
    que = [(-a[1], -a[0]), (-a[1], -a[0])]
    heapq.heapify(que)
    for i in range(2, n):
        x, y = heapq.heappop(que)
        ans += min(-x, -y)
        heapq.heappush(que, (-a[i], x))
        heapq.heappush(que, (-a[i], y))
    return ans

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

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = sum(A) - min(A)
    print(ans)

if __name__ == "__main__":
    main()


Failing test case input:
4
1 3 1 3

Expected output:
9


Actual output:
7


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)
    A = A[::-1]

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

    print(ans)


if __name__ == "__main__":
    main()

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math

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

Failing test case input:
7
-1 100 -2 1 -1 -1 18

Expected output:
137


Actual output:
238


Fixed submission (verdict: Accepted):
import math
 
N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
ans = 0
for i in range(1, N):
	ans += A[math.floor(i / 2)]
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
  N=int(input())
  A=list(map(int,input().split()))
  A.sort(reverse=True)
  ans=sum(A)-A[-1]
  print(ans)
  pass
if __name__ == '__main__':
  main()




Failing test case input:
7
1 2 4 -3 2 0 0

Expected output:
13


Actual output:
9


Fixed submission (verdict: Accepted):
def main():
  N=int(input())
  A=list(map(int,input().split()))
  A.sort(reverse=True)
  ans=0
  for i in range(1,len(A)):
    ans+=A[i
  print(ans)
  pass
if __name__ == '__main__':
  main()
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import math


from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
ans=0
mi=arr[0]
for i in range(1,n):
    ans+=mi
    mi=min(mi,arr[i])
print(ans)


Failing test case input:
7
-2 59 -2 -2 -1 1 -2

Expected output:
57


Actual output:
-12


Fixed submission (verdict: Accepted):
import sys
import math


from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
ans=0
arr.sort(reverse=True)
for i in range(1,n):
    ans+=arr[i
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

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


Failing test case input:
7
-3 000 1 -1 -2 -3 -1

Expected output:
-2


Actual output:
-3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

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

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

pq = []
res = 0
heapq.heapify(pq)

for i in range(n):
  if len(pq) < 1:
    heapq.heappush(pq, a[i])
    continue

  res += pq[0]
  heapq.heappush(pq, a[i])

print(res)



Failing test case input:
7
1 2 2 -1 2 0 2

Expected output:
12


Actual output:
9


Fixed submission (verdict: Accepted):
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

pq = []
res = 0
heapq.heapify(pq)

for i in range(n):
  if len(pq) == 0:
    heapq.heappush(pq, -a[i])
  else:
    score = -heapq.heappop(pq)
    res += score
    for _ in range(2):
      heapq.heappush(pq, -a[i])

print(res)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)

ans = 0
for i in range(N-1):
  a = math.floor(i/2)
  ans += A[a]
    
print(ans)

Failing test case input:
7
-1 101 -2 0 -1 0 4

Expected output:
109


Actual output:
210


Fixed submission (verdict: Accepted):
import math
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)

ans = 0
for i in range(1,N):
  a = math.floor(i/2)
  ans += A[a]
    
print(ans)
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
AList = list(map(int, input().split()))
sList = sorted(AList, reverse=True)
ans = sum(sList) - sList[-1]
print(ans)

Failing test case input:
7
-2 81 -2 -2 0 1 -2

Expected output:
81


Actual output:
76


Fixed submission (verdict: Accepted):
N = int(input())
AList = list(map(int, input().split()))
sList = sorted(AList, reverse=True)
ans = sList[0]
idx = 1
for i in range(1, N-1):
  ans += sList[idx]
  if i%2 == 0:
    idx += 1

print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import itertools
import sys
input = sys.stdin.readline

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

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

print(ans)


Failing test case input:
7
-1 81 -2 -2 0 1 -2

Expected output:
82


Actual output:
77


Fixed submission (verdict: Accepted):
import itertools
import sys
input = sys.stdin.readline

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

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

print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
A=[]
A=list(map(int, input().split()))


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

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




print(sum-mina)


Failing test case input:
7
0 100 -8 3 31 3 -2

Expected output:
171


Actual output:
135


Fixed submission (verdict: Accepted):
n=int(input())
A=[]
A=list(map(int, input().split()))


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

A.sort()
A.reverse()

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




print(sum)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


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


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


n = I()
a = list(MI())

a.sort()
a.reverse()

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

print(ans)


Failing test case input:
7
-1 111 -2 2 -1 -24 4

Expected output:
122


Actual output:
113


Fixed submission (verdict: Accepted):

import sys
from collections import deque

input = sys.stdin.readline


def S():
    return input().rstrip()


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


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


n = I()
al = list(MI())

al.sort()
al.reverse()

ans = 0
q = deque()
for a in al:
    if q:
        ans += q.popleft()
        q.append(a)
        q.append(a)
    else:
        q.append(a)

print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=0
ans+=max(a)
a.pop()
w=[a.pop()]*2
for i in range(n-2):
    ans+=max(w)
    if w[0]>=w[1]: w[0]=a.pop()
    else: w[1]=a.pop()
print(ans)


Failing test case input:
7
0 101 -2 4 -1 -16 10

Expected output:
129


Actual output:
124


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=0
ans+=max(a)
a.pop()
n-=2
while n:

    if n>=2:
        ans+=a.pop()*2
        n-=2
    else:
        ans+=a.pop()
        n-=1
print(ans)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from heapq import heapify, heappop, heappush
N,*A=map(int, open(0).read().split())
A=sorted(A, reverse=True)
L=[0]*N
R=[0]*N
ans=0
L[0]=0
R[0]=0
H=[(A[0],0,0)]
heapify(H)
for i in range(1,N):
    a=A[i]
    p,pl,pr=heappop(H)
    ans+=p
    L[pr]=i
    R[pl]=i
    L[i]=pl
    R[i]=pr
    heappush(H,(min(A[pl],a),pl,i))
    heappush(H,(min(A[pr],a),i,pr))
print(ans)

Failing test case input:
7
0 100 -8 2 31 3 -2

Expected output:
170


Actual output:
134


Fixed submission (verdict: Accepted):
from heapq import heapify, heappop, heappush
N,*A=map(int, open(0).read().split())
A=sorted(A, reverse=True)
L=[0]*N
R=[0]*N
ans=0
L[0]=0
R[0]=0
H=[(-A[0],0,0)]
heapify(H)
for i in range(1,N):
    a=A[i]
    p,pl,pr=heappop(H)
    ans+=-p
    L[pr]=i
    R[pl]=i
    L[i]=pl
    R[i]=pr
    heappush(H,(-min(A[pl],a),pl,i))
    heappush(H,(-min(A[pr],a),i,pr))
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import itertools
import sys
input = sys.stdin.readline

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


Failing test case input:
7
1 1 1 0 1 0 2

Expected output:
7


Actual output:
3


Fixed submission (verdict: Accepted):
import itertools
import sys
input = sys.stdin.readline

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

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

print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys

import math
import itertools
import random
def next(index, lis):
    for i in range(index, 0):
        if (i != 0):
            return i

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
isLeftSide = True
leftval=a[1]
rightval = a[1]
ans=a[0]
for i in range(2, n):
    if (isLeftSide):
        ans += leftval
        leftval = a[i]
        isLeftSide=False
    else:
        ans += rightval
        rightval = a[i]
        isLeftSide = True
print(ans)


        
                        



Failing test case input:
7
1 110 -5 4 8 1 -2

Expected output:
135


Actual output:
132


Fixed submission (verdict: Accepted):
import sys

import math
import itertools
import random
def next(index, lis):
    for i in range(index, 0):
        if (i != 0):
            return i

n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
cnt = 1
tmp=1
while (True):
    if (cnt == n-1):
        break
    ans += a[tmp]
    cnt+=1
    if (cnt == n-1):
        break
    ans += a[tmp]
    cnt+=1
    tmp+=1
print(ans)
Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
lis = list(map(int, input().split()))

lis = sorted(lis, reverse=True)

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

print(ans)

Failing test case input:
7
-1 81 0 -3 0 1 0

Expected output:
83


Actual output:
81


Fixed submission (verdict: Accepted):
n = int(input())
lis = list(map(int, input().split()))

lis = sorted(lis, reverse=True)

ans = lis[0]
t = 0
for i in range(1,n-1):
    if i % 2 != 0:
        t += 1
    ans += lis[t]
        

print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)


Failing test case input:
7
-2 59 -2 -2 -1 1 -2

Expected output:
57


Actual output:
53


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

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
sum(sorted([int(x) for x in input().split()] * 2, reverse = True)[1:n])

Failing test case input:
7
1 1 1 1 1 0 1

Expected output:
6


Actual output:

Fixed submission (verdict: Accepted):
n = int(input())
print(sum(sorted([int(x) for x in input().split()] * 2, reverse = True)[1:n]))

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from heapq import heappop, heappush
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
gaps = [-A[0]]
ans = 0
for a in A[1:]:
    x = heappop(gaps)
    ans += -x
    heappush(gaps, -a)
print(ans)
    

Failing test case input:
4
0 10 1 2

Expected output:
14


Actual output:
13


Fixed submission (verdict: Accepted):
from heapq import heappop, heappush
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
gaps = [-A[0]]
ans = 0
for a in A[1:]:
    x = heappop(gaps)
    ans += -x
    heappush(gaps, -a)
    heappush(gaps, -a)
print(ans)

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    
    a.sort(reverse=True)
    
    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)


Failing test case input:
7
1 2 4 -3 2 0 0

Expected output:
13


Actual output:
12


Fixed submission (verdict: Accepted):
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    
    a.sort(reverse=True)
    
    sum=a[0]
    j=0
    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)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from math import ceil
from collections import defaultdict as dd
import sys
input=sys.stdin.readline


n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=l[0]
ii=1
cou=0
for i in range(2,n):
    if(cou==2):
        ii+=1
        cou=0
    ans+=l[ii]
print(ans)


Failing test case input:
7
-1 111 -2 2 -1 -16 3

Expected output:
120


Actual output:
126


Fixed submission (verdict: Accepted):
from math import ceil
from collections import defaultdict as dd
import sys
input=sys.stdin.readline


n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
ans=l[0]
ii=1
cou=0
for i in range(2,n):
    if(cou==2):
        ii+=1
        cou=0
    ans+=l[ii]
    cou+=1
print(ans)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import collections
from heapq import *
import json
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    A[i]=-A[i]
heapify(A)
l=[]
ans=0
for i in range(N):
    num=heappop(A)
    ans=ans+min(l,default=0)
    if len(l)>1:
        if l[0]>=l[1]:
            l.pop(0)
        elif l[0]<l[1]:
            l.pop(1)
    l.append(-num)
    
    
print(ans)

Failing test case input:
7
-1 38 -2 -2 -2 1 -2

Expected output:
36


Actual output:
32


Fixed submission (verdict: Accepted):
from math import floor,ceil,sqrt
import fractions
from collections import deque
import itertools
from collections import deque
import collections
from heapq import *
import json
l=[]
N=int(input())
A=list(map(int,input().split()))
c=collections.Counter(A)
values=list(c.values())	
key=list(c.keys())	
for i in range(len(key)):
    l.append([key[i],values[i]])
l.sort(key=lambda x:x[0],reverse=True)
ans=0
num=N-1
for i in range(len(l)):
    if i==0:
        ans=ans+l[i][0]*min(2*l[i][1]-1,num)
        num=num-min(2*l[i][1]-1,num)
    else:
        ans=ans+l[i][0]*min(2*l[i][1],num)
        num=num-min(2*l[i][1],num)
print(ans)
Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

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

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

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

print(cnt)



Failing test case input:
4
1 0 13 5

Expected output:
23


Actual output:
19


Fixed submission (verdict: Accepted):

import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

res = [A[0]]
for a in A[1:]:
    res.append(a)
    res.append(a)
print(sum(res[: N - 1]))

Problem: p02615
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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)

Failing test case input:
7
0 100 -8 3 31 3 -2

Expected output:
171


Actual output:
168


Fixed submission (verdict: Accepted):
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)-1])
    
print(result)

Problem: p02615
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

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

print(cnt)


Failing test case input:
4
2 4 1 10

Expected output:
18


Actual output:
16


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)

cnt = 0
for i in range(1,n):
    cnt += a[i

print(cnt)