Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
HW = input().split()
H = int(HW[0])
W = int(HW[1])
 
tmp = H // 2
tmp2 = H - tmp
wt = W // 2
wt2 = W - wt
ans = tmp * wt + tmp2 * wt2

if H % 2 == 0:
  h1 = H // 2
  h2 = H // 2
else:
  h1 = H//2 + 1
  h2 = H//2
if W % 2 == 0:
  w1 = W//2
  w2 = W//2
else:
  w1 = W//2+1
  w2 = w//2
  
ans = h1*w1+h2*w2  
print(ans)


Fixed submission:
HW = input().split()
H = int(HW[0])
W = int(HW[1])


tmp = H // 2
tmp2 = H - tmp
wt = W // 2
wt2 = W - wt
ans = tmp * wt + tmp2 * wt2

if H == 1:
  ans = 1
elif W == 1:
  ans = 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
turnover = False

for i in range(Q):
  TFC = input().split()
  T = int(TFC[0])
  if T == 1:
    # turn over
    turnover = not turnover
  elif T == 2:
    F = int(TFC[1])
    C = TFC[2]
    if turnover:
      if F == 1:
        F = 2
      else:
        F = 1
    if F == 1:
      S = C + S
      # put C before S
    elif F == 2:
      S = S + C
      # put C after S
if turnover:
  S = S[-1::-1]

print(S)

Fixed submission:
S = input()
Q = int(input())
turnover = False
suffix = ""
prefix = ""

for i in range(Q):
  TFC = input().split()
  T = int(TFC[0])
  if T == 1:
    # turn over
    turnover = not turnover
  elif T == 2:
    F = int(TFC[1])
    C = TFC[2]
    if turnover:
      if F == 1:
        F = 2
      else:
        F = 1
    if F == 1:
      prefix = prefix + C
      # put C before S
    elif F == 2:
      suffix = suffix + C
      # put C after S
S = prefix[-1::-1]+S+suffix
if turnover:
  S = S[-1::-1]

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for i in range(Q):
  TFC = input().split()
  T = int(TFC[0])
  if T == 1:
    # turn over
    S = S[-1::-1]
  elif T == 2:
    F = int(TFC[1])
    C = TFC[2]
    if F == 1:
      S = C + S
      # put C before S
    elif F == 2:
      S = S + C
      # put C after S

print(S)

Fixed submission:
S = input()
Q = int(input())
turnover = False
suffix = ""
prefix = ""

for i in range(Q):
  TFC = input().split()
  T = int(TFC[0])
  if T == 1:
    # turn over
    turnover = not turnover
  elif T == 2:
    F = int(TFC[1])
    C = TFC[2]
    if turnover:
      if F == 1:
        F = 2
      else:
        F = 1
    if F == 1:
      prefix = prefix + C
      # put C before S
    elif F == 2:
      suffix = suffix + C
      # put C after S
S = prefix[-1::-1]+S+suffix
if turnover:
  S = S[-1::-1]

print(S)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*n
    self.rank = [0]*n
    
  def find_root(self, e):
    if self.root[e] < 0:
      return e
    else:
      r = self.find_root(self.root[e])
      self.root[e] = r
      return r
    
  def combine(self, e1, e2):
    root1 = self.find_root(e1)
    root2 = self.find_root(e2)
    if root1 == root2:
      pass
    elif self.rank[root1] < self.rank[root2]:
      self.root[root1] += self.root[root2]
      self.root[root2] = root1
      self.rank[root1] = self.rank[root2] + 1
    elif self.rank[root2] < self.rank[root1]:
      self.root[root2] += self.root[root1]
      self.root[root1] = root2
      self.rank[root2] = self.rank[root1] + 1
    else:
      self.root[root2] += self.root[root1]
      self.root[root1] = root2
      self.rank[root2] += 1
      
  def in_the_same_group(self, e1, e2):
      r1 = self.find_root(e1)
      r2 = self.find_root(e2)
      if r1 == r2:
        return True
      return False
  

NMK = input().split()
N = int(NMK[0])
M = int(NMK[1])
K = int(NMK[2])
uf = UnionFind(N)
from collections import defaultdict
friend_list = [0]*N
for _ in range(M):
  AB = input().split()
  A = int(AB[0])-1
  B = int(AB[1])-1
  uf.combine(A,B)
  friend_list[A] += 1
  friend_list[B] += 1

block_list = [0]*N
for _ in range(K):
  CD = input().split()
  C = int(CD[0])-1
  D = int(CD[1])-1
  if uf.in_the_same_group(C, D):
    block_list[C] += 1
    block_list[D] += 1

cnt = defaultdict(int)
ans = []
for i in range(N):
  cnt[i] = -uf.root[uf.find_root(i)] - 1 - friend_list[i] - block_list[i]
  ans.append(str(cnt[i]))

print(" ".join(ans))

Fixed submission:
N = int(input())

if N % 2 == 0:
  print(N//2)
else:
  print(N//2+1)
Buggy python submission (verdict: Runtime Error):
NM = input().split()
N = int(NM[0])
M = int(NM[1])

sc = []
flg = False
for i in range(M):
  scc = input().split()
  sc.append([int(scc[0]), int(scc[1])])
  if int(scc[0]) == 1 and int(scc[1]) == 0:
    flg = True
else:
  string = ["0"]*N
  sc.sort(key=lambda x: x[0])
  s = []
  for i in range(M):
    if flg:
      break
    if i != M-1:
      if s and sc[i][0] == s[0][0]:
        s.append(sc[i])
      elif not s:
        s.append(sc[i])
      else:
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
        s = []
        s.append(sc[i])
    else:
      if sc[i][0] == s[0][0]:
        s.append(sc[i])
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
      else:
        tmp = s[0][1]
        string[int(s[0][0])-1] = str(tmp)
        for sss in s:
          if sss[1] != tmp:
            flg = True
        string[int(sc[i][0])-1] = str(sc[i][1])


if flg:
  print(-1)
else:
  string = "".join(string)
  if string == "0"*N:
    print('-1')
  else:
    print("".join(string))

Fixed submission:
NM = input().split()
N = int(NM[0])
M = int(NM[1])

from collections import defaultdict
sc = defaultdict(lambda: -1)
flg = False
for i in range(M):
  scc = input().split()
  if sc[scc[0]] == -1:
    sc[scc[0]] = scc[1]
  else:
    if scc[0] == "1" and scc[1] == 0 and N != 1:
      flg = True
      break
    elif sc[scc[0]] != scc[1]:
      flg = True
      break
if not flg:
  if N == 1:
    string = ["0"]
    for key, value in sc.items():
      string[int(key)-1] = value
    string = "".join(string)
    print(string)
  else:
    string = ["0"]*N
    string[0] = "1"
    for key, value in sc.items():
      string[int(key)-1] = value
    string = "".join(string)
    if string == "0"*N:
      print(-1)
    else:
      print(string)

else:
  print("-1")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = str(input()).split(' ')
a_s = [int(a) for a in As]

sum = 0
index = 0
for Ai in a_s:
  for Aj in a_s[index+1:]:
    sum += Ai ^ Aj
  index += 1

  
print(sum%(10**9+7))

Fixed submission:
N = int(input())
As = str(input()).split(' ')
a_s = [int(a) for a in As]

import numpy as np
a_s = np.array(a_s)
sum = 0
index = 0
for n in range(60):
  b = (a_s >> n) & 1
  x = np.count_nonzero(b)
  y = N - x
  ans = x * y
  for _ in range(n):
    ans *= 2
  sum += ans
  
print(sum%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
import queue

N = int(input())
ab = []
deg = [0 for i in range(N)]
child = [[] for _ in range(N)]
edge = {}
color = [0 for _ in range(N-1)]
for i in range(N-1):
  tmp = list(map(int, input().split()))
  deg[tmp[0]-1] += 1
  deg[tmp[1]-1] += 1
 
  child[tmp[0]-1].append(tmp[1]-1)
  child[tmp[1]-1].append(tmp[0]-1)
  tmp = [tmp[0]-1, tmp[1]-1]
  edge[tuple(tmp)] = i
  
q = queue.Queue()
q.put([None, 0, None])
used = [0]
# parent, self, color
while not q.empty():
  current = q.get()
  if current[0] is not None:
    cnt = 1
    for c in child[current[1]]:
      if c in used:
        continue
      used.append(c)
      if cnt == current[2]:
        cnt += 1
      q.put([current[1], c, cnt])
      ind = [current[1], c] if current[1] < c else [c, current[1]]
      
      color[edge[tuple(ind)]] = cnt
      
      cnt += 1
  else:
    for i, c in enumerate(child[current[1]]):
      used.append(c)
      q.put([current[1], c, i+1])
      ind = [current[1], c] if current[1] < c else [c, current[1]]
      #print(edge[tuple(ind)], i+1)
      color[edge[tuple(ind)]] = i+1
print(max(deg))
for c in color:
  print(c)

Fixed submission:
import queue

N = int(input())
ab = []
deg = [0 for i in range(N)]
child = [[] for _ in range(N)]
edge = {}
color = [0 for _ in range(N-1)]
for i in range(N-1):
  tmp = list(map(int, input().split()))
  deg[tmp[0]-1] += 1
  deg[tmp[1]-1] += 1
 
  child[tmp[0]-1].append(tmp[1]-1)
  child[tmp[1]-1].append(tmp[0]-1)
  tmp = [tmp[0]-1, tmp[1]-1]
  edge[tuple(tmp)] = i
  
q = queue.Queue()
q.put([None, 0, None])
used = [0]
# parent, self, color
while not q.empty():
  current = q.get()
  if current[0] is not None:
    cnt = 1
    for c in child[current[1]]:
  #    if c in used:
  #      continue
      used.append(c)
      if cnt == current[2]:
        cnt += 1
      q.put([current[1], c, cnt])
      ind = [current[1], c] if current[1] < c else [c, current[1]]
      
      color[edge[tuple(ind)]] = cnt
      child[c].remove(current[1])
      cnt += 1
  else:
    for i, c in enumerate(child[current[1]]):
      used.append(c)
      q.put([current[1], c, i+1])
      ind = [current[1], c] if current[1] < c else [c, current[1]]
      #print(edge[tuple(ind)], i+1)
      color[edge[tuple(ind)]] = i+1
      child[c].remove(current[1])

print(max(deg))
for c in color:
  print(c)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
if n % 2 == 0:
  end = n//
  start = end
else:
  end = n//2+1
  start = n//2
if s[:end] == s[start:]:
  print('Yes')
else:
  print('No')

Fixed submission:
n = int(input())
s = input()
if n % 2 == 0:
  end = n//2
  start = end
  if s[:end] == s[start:]:
    print('Yes')
  else:
    print('No')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):

from operator import mul
from functools import reduce
def combination_count(n, r):
  r = min(n-r, r)
  num = reduce(modmul, range(n, n-r, -1), 1)
  denom = reduce(modmul, range(r, 1, -1), 1)
  return num*pow(denom, 10**9+5, 10**9+7)

def modmul(a, b):
  return mul(a,b)%(10**9+7)

def modinv(a, b):
  d, x, y = extgcd(a, b)
  return (d + x%b) % b

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

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]


if (x+y)%3 != 0:
  print('0')
else:
  m = (2*x - y)//3
  n = x - 2*m
  c = combination_count(m+n, m)
  print(c%(10**9+7))

Fixed submission:
x, y = map(int, input().split())

from operator import mul
from functools import reduce
def combination_count(n, r):
  r = min(n-r, r)
  num = reduce(modmul, range(n, n-r, -1), 1)
  denom = reduce(modmul, range(r, 1, -1), 1)
  return num*mod_inv(denom,10**9+7)

def modmul(a, b):
  return mul(a,b)%(10**9+7)

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

if (x+y)%3 != 0:
  print('0')
else:
  m = (2*x - y)//3
  n = x - 2*m
  if m < 0 or n < 0:
    print('0')
  else:
    c = combination_count(m+n, m)
    print(c%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = []
for i in range(n):
  t = [int(inp) for inp in input().split()]
  if t[0] <= m:
    ab.append(t)

ab.sort(key = lambda x: x[0])
ans = 0
for i in range(1, m+1):
  ma = [0,0]
  for t in ab:
    if t[0] > i:
      break
    if t[1] > ma[1]:
      ma = t
  if ma != [0, 0]:
    ans += ma[1]
    ab.remove(ma)
print(ans)

Fixed submission:
n, m = map(int, input().split())
ab = [[] for _ in range(m+1)]
for i in range(n):
  t = [int(inp) for inp in input().split()]
  if t[0] <= m:
    ab[t[0]].append(-t[1])
ans = 0
import heapq
h = ab[1]
heapq.heapify(h)
for i in range(1, m+1):
  if len(h) > 0:
    ans += heapq.heappop(h)
  if i != m:
    for t in ab[i+1]:
      heapq.heappush(h, t)
print(-ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = []
for i in range(n):
  t = [int(inp) for inp in input().split()]
  if t[0] <= m:
    ab.append(t)

ab.sort(key = lambda x: -x[1])
ans = 0
slot = [False for i in range(m+1)]
for t in ab:
  b = t[0]
  a = t[1]
  if b > m:
    continue
  if False not in slot[b:m+1]:
    m = b-1
    continue
  ans += a
  ind = slot[b:m+1].index(False)
  slot[b+ind] = True
  if b+ind == m:
    m = m-1
print(ans)

Fixed submission:
n, m = map(int, input().split())
ab = [[] for _ in range(m+1)]
for i in range(n):
  t = [int(inp) for inp in input().split()]
  if t[0] <= m:
    ab[t[0]].append(-t[1])
ans = 0
import heapq
h = ab[1]
heapq.heapify(h)
for i in range(1, m+1):
  if len(h) > 0:
    ans += heapq.heappop(h)
  if i != m:
    for t in ab[i+1]:
      heapq.heappush(h, t)
print(-ans)
Buggy python submission (verdict: Runtime Error):
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

s = ri()
dp = [1]*(s+1)
for i in range(3):
    dp[i]=0
dp[3]=1
#[0,0,1,1,1,2,3,]
#a[i] = a[i-3]+...+a[0]
#     = a[i-3]+a[i-1]
for i in range(4,s+1):#3-7
    dp[i] = dp[i-3]+dp[i-1]

print(dp[s]%MOD)

Fixed submission:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

s = ri()
dp = [1]*max(4,(s+1))
for i in range(3):
    dp[i]=0
dp[3]=1
#[0,0,1,1,1,2,3,]
#a[i] = a[i-3]+...+a[0]
#     = a[i-3]+a[i-1]
for i in range(4,s+1):#3-7
    dp[i] = dp[i-3]+dp[i-1]

print(dp[s]%MOD)

Buggy python submission (verdict: Runtime Error):
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

s = ri()
dp = [1]*(s+1)
for i in range(3):
    dp[i]=0
#[0,0,1,1,1,2,3,]
for i in range(3,s+1):#3-7
    for j in range(3,i+1):#3-i-1
        if j==i-j:
            dp[i]+=dp[j]*dp[i-j]
        else:
            dp[i]+=dp[j]*dp[i-j]
print(dp[s]%MOD)
        
       

Fixed submission:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

s = ri()
dp = [1]*max(4,(s+1))
for i in range(3):
    dp[i]=0
dp[3]=1
#[0,0,1,1,1,2,3,]
#a[i] = a[i-3]+...+a[0]
#     = a[i-3]+a[i-1]
for i in range(4,s+1):#3-7
    dp[i] = dp[i-3]+dp[i-1]

print(dp[s]%MOD)
Buggy python submission (verdict: Runtime Error):
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()
a = []
b = []
for i in range(n):
    x,y = rl()
    a.append(x+y)
    b.append(x-y)
a.sort()
b.sort()
print(max(a[-1]-a[0], b[-1]-[0]))

Fixed submission:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()
a = []
b = []
for i in range(n):
    x,y = rl()
    a.append(x+y)
    b.append(x-y)
a.sort()
b.sort()
print(max(a[-1]-a[0], b[-1]-b[0]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

k = ri()
reses=[]
cnt = 1
tmp = 7
while True:
    res = tmp % k
    if res==0:
        print(cnt)
        break
        sys.exit()
    else:
        if res not in reses:
            reses.append(res)
        else:
            print("-1")
            break
            sys.exit()
    tmp = res * 10 + 7
    cnt += 1

Fixed submission:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

k = ri()
reses=[]
cnt = 1
tmp = 7
for i in range(k+1):
    res = tmp % k
    if res==0:
        print(cnt)
        sys.exit(0)
    tmp = res * 10 + 7
    cnt += 1
print(-1)
Buggy python submission (verdict: Runtime Error):
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
import numpy as np

h, w, k = rl()
a=[list(rs()) for _ in range(h)]
ans=0
for i in range(1<<h+w):
    c = np.array(a[:])
    for n in range(h+w):
        if i>>n&1:
            if n>=h:
                c[:,n-h-1]="*"
            else:
                c[n-1,:]="*"
    cnt=0
    for y in range(h):
        for x in range(w):
            if c[y][x]=="#":
                cnt+=1
    if cnt==k:
        ans+=1
print(ans)

Fixed submission:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
import numpy as np

h, w, k = rl()
a=[list(rs()) for _ in range(h)]
ans=0
for i in range(1<<h+w):
    c = np.array(a[:])
    for n in range(h+w):
        if i>>n&1:
            if n>=h:
                c[:,n-h-1]="*"
            else:
                c[n-1,:]="*"
    cnt=0
    for y in range(h):
        for x in range(w):
            if c[y][x]=="#":
                cnt+=1
    if cnt==k:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

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

Fixed submission:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

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

Buggy python submission (verdict: Runtime Error):
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()

n = ri()
a = rl()
a=a+a
a.sort()

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

Fixed submission:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

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

Buggy python submission (verdict: Runtime Error):
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
import numpy as np

n = ri()
a = rl()
a=a+a
a.sort()

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

Fixed submission:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

a.pop()
ans=0
for i in range(n-1):
    ans+=a[-i-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()  
    
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
ans=0

for i in range(n): 
    ans+=(i+1)*len(make_divisors(i+1))
print(ans)

Fixed submission:
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

n = ri()  
ans=0    
for i in range(1,n+1):
    ans+=(n//i)*(n//i+1)*i//2
print(ans)