Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

# for this we will use binary search.
import bisect as bis

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

# for this we will use binary search.
import bisect as bis

BSC = [0]*N
ASB = [0]*N

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

for i in range (0, N):
	ASB[i] = bis.bisect_right(B, A[i])
    
for i in range (1, N):
	BSC[N-1-i] += BSC[N-i]

count = 0
for i in range (0, N):
	if ASB[i] ==N:
		continue
	else:
		count+=BSC[ASB[i]]

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

# consider for each entry in B how many entries in C 
# exists which are larger than the entry...
BSC = [0]*N

# for this we will use binary search.
import bisect as bis

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

count = 0
# now we will loop over a...
for i in range (0, N):
	Upperpart = bis.bisect_right(B, A[i])
	count+=sum(BSC[Upperpart:])
    
print(count)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)

# for this we will use binary search.
import bisect as bis

BSC = [0]*N
ASB = [0]*N

for i in range (0, N):
	BSC[i] = N-bis.bisect_right(C, B[i])

for i in range (0, N):
	ASB[i] = bis.bisect_right(B, A[i])
    
for i in range (1, N):
	BSC[N-1-i] += BSC[N-i]

count = 0
for i in range (0, N):
	if ASB[i] ==N:
		continue
	else:
		count+=BSC[ASB[i]]

print(count)
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())

if B< A:
	print(0)
elif B = A:
	print(1)
elif B-A+1 > N:
	print(0)
else:
	print((N-2)*B-(N-2)*A+1)

Fixed submission:
N, A, B = map(int, input().split())

if A == B :
	print(1)
	exit()

print(max(B*(N-1)+A-(A*(N-1)+B)+1,0))
Buggy python submission (verdict: Time Limit Exceeded):
X = str(input())

for i in range (0, int(len(X)/2)+1):
	X = X.replace("ST", '')
	if X == X.replace("ST", ''):
		print(len(X))
		exit() 

print(len(X))

Fixed submission:
X = str(input())

Tn = 0
Sn = 0
Nagasa = len(X)

for i in range (0, Nagasa):
	if X[i] == 'T':
		if Sn == 0:
			Tn+=1
		else:
			Sn-=1
	else:
		Sn+=1

print(2*Tn)

Buggy python submission (verdict: Time Limit Exceeded):
X = str(input())

for i in range (0, int(len(X)/2)+1):
	X = X.replace("ST", '')
	if X == X.replace("ST", ''):
		print(len(X))
		exit() 

print(len(X))

Fixed submission:
X = str(input())

Tn = 0
Sn = 0
Nagasa = len(X)

for i in range (0, Nagasa):
	if X[i] == 'T':
		if Sn == 0:
			Tn+=1
		else:
			Sn-=1
	else:
		Sn+=1

print(2*Tn)

Buggy python submission (verdict: Time Limit Exceeded):
X = input()

for i in range (0, 100001):
	X = X.replace("ST", '')
	if X == X.replace("ST", ''):
		print(len(X))
		exit() 

print(len(X))


Fixed submission:
X = str(input())

Tn = 0
Sn = 0
Nagasa = len(X)

for i in range (0, Nagasa):
	if X[i] == 'T':
		if Sn == 0:
			Tn+=1
		else:
			Sn-=1
	else:
		Sn+=1

print(2*Tn)

Buggy python submission (verdict: Time Limit Exceeded):
X = input()

for i in range (0, 100001):
	X = X.replace("ST", '')

print(len(X))

Fixed submission:
X = str(input())

Tn = 0
Sn = 0
Nagasa = len(X)

for i in range (0, Nagasa):
	if X[i] == 'T':
		if Sn == 0:
			Tn+=1
		else:
			Sn-=1
	else:
		Sn+=1

print(2*Tn)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
D = list(map(int, input().split()))
D = np.array(D)
D = np.sort(D)

if D[0] != 0:
    print(0)
elif sum(D == 0) != 1:
    print(0)
elif sum(np.diff(np.array(list(set(D)))) != 1):
    print(0)
else:
    print(np.prod(D[1:]) % 998244353)

Fixed submission:
N = int(input())

if N % 2 == 0:
    print(N//2 -1)
else:
    print(N//2)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
import numpy as np


N = int(input())
D = list(map(int, input().split()))
D = np.array(D)
D = np.sort(D)


if D[0] != 0:
    print(0)
elif sum(D == 0) != 1:
    print(0)
else:
    D_counter = Counter(D)
    count = 1
    next = 1
    for i in range(1, max(D)+1):
        if i != next:
            print(0)
            break
        i = int(i)
        count = count * i**list(D_counter.values())[i]
        next += 1

print(count % 998244353)


Fixed submission:
N = int(input())

if N % 2 == 0:
    print(N//2 -1)
else:
    print(N//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
d = [int(input()) for i in range(N)]

point_sum = 0

for n in range(N):
    head = d.pop(0)
    point_sum += sum(list(map(lambda x : x * head, d)))
    
print(point_sum)

Fixed submission:
N = int(input())
d = list(map(int, input().split()))

point_sum = 0

for n in range(N):
    head = d.pop(0)
    point_sum += sum(list(map(lambda x : x * head, d)))
    
print(point_sum)

Buggy python submission (verdict: Runtime Error):
N = int(input())

d = [int(input()) for i in range(N)]

point_sum = 0

for n in range(N):
    head = d.pop(0)
    point_sum += sum(list(map(lambda x : x * head, d)))

Fixed submission:
N = int(input())
d = list(map(int, input().split()))

point_sum = 0

for n in range(N):
    head = d.pop(0)
    point_sum += sum(list(map(lambda x : x * head, d)))
    
print(point_sum)
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import array, zeros
IN_RANGE = 5


# 入力受け取り
N = int(input())
a_e = array([int(input()) for i in range(IN_RANGE)])


# どこに人がいるか
a_e_num = zeros(IN_RANGE+1)
a_e_num[0] = N


# 1分ずつの処理
minute = 0
while a_e_num[IN_RANGE] < N:
    minute += 1
    move_index = (a_e_num[:IN_RANGE] - a_e) >= 0
    move_num = a_e_num[:IN_RANGE].copy()
    move_num[move_index] = a_e[move_index]
    a_e_num[:IN_RANGE] = a_e_num[:IN_RANGE] - move_num
    a_e_num[1:] = a_e_num[1:] + move_num

print(minute)

Fixed submission:
# 2019/04/07

from numpy import array, zeros
IN_RANGE = 5


# 入力受け取り
N = int(input())
a_e = array([int(input()) for i in range(IN_RANGE)])


minute = 4 + -(- N // a_e.min())
print(minute)

Buggy python submission (verdict: Runtime Error):
# 2019/04/07

from numpy import array, zeros
IN_RANGE = 5


# 入力受け取り
N = int(input())
a_e = array([int(input()) for i in range(IN_RANGE)])


# どこに人がいるか
a_e_num = zeros(IN_RANGE+1)
a_e_num[0] = N


# 1分ずつの処理
minute = 0
while a_e_num[N] < N:
    minute += 1
    move_index = (a_e_num[:N] - a_e) >= 0
    move_num = a_e_num[:N].copy()
    move_num[move_index] = a_e[move_index]
    a_e_num[:N] = a_e_num[:N] - move_num
    a_e_num[1:] = a_e_num[1:] + move_num

print(minute)

Fixed submission:
# 2019/04/07

from numpy import array, zeros
IN_RANGE = 5


# 入力受け取り
N = int(input())
a_e = array([int(input()) for i in range(IN_RANGE)])


minute = 4 + -(- N // a_e.min())
print(minute)
Buggy python submission (verdict: Runtime Error):
import numpy
import math
 
L, R, d = input().split()
 
N = R/d
 
n = 0  # 切り捨てしたい桁
y = math.floor(L * 10 ** n) / (10 ** n)
 
print(math.floor(y))

Fixed submission:
l,r,d = map(int,input().split())
     
print( r//d -(l-1)//d )

Buggy python submission (verdict: Runtime Error):
import numpy
 
L, R, d = input().split()
 
N = R/d

n = 0  # 切り捨てしたい桁
y = math.floor(L * 10 ** n) / (10 ** n)

print(math.floor(y))

Fixed submission:
l,r,d = map(int,input().split())
     
print( r//d -(l-1)//d )

Buggy python submission (verdict: Runtime Error):
import numpy
 
L, R, d = input().split()
 
N = R/d
 
print(math.floor(N))

Fixed submission:
l,r,d = map(int,input().split())
     
print( r//d -(l-1)//d )

Buggy python submission (verdict: Runtime Error):
import numpy
 
a = input().split()
L = a(0)
R = a(1)
d = a(2)
 
N = R/d
 
print(math.floor(N))

Fixed submission:
l,r,d = map(int,input().split())
     
print( r//d -(l-1)//d )

Buggy python submission (verdict: Runtime Error):
import numpy

a = input().split()
L = a[0]
R = a[1]
d = a[2]

N = R/d

print(math.floor(N))


Fixed submission:
l,r,d = map(int,input().split())
     
print( r//d -(l-1)//d )
Buggy python submission (verdict: Runtime Error):
N = int(input())

ac = 0
wa = 0
tle = 0
re = 0

for i in range(1,N+1):
  S = str(input())
  if S == "AC":
    ac += 1
  elif S == "WA":
    wa += 1
  elif S == "TLE":
    tle += 1
  elif S == "RE":
    re += 1

print("AC ×" + str(ac))
print("WA ×" + str(wa))
print("TLE ×" + str(tle))
print("AC ×" + str(re))

Fixed submission:
N = int(input())
a = N//1000
b = ((a+1)*1000)-N
if b%1000 == 0:
	b = 0
    
print(b)
Buggy python submission (verdict: Time Limit Exceeded):
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]
N = int(input())
count = 0
for C in range(1, N):
    AB = N - C
    count = count + len(make_divisors(AB))
print(count)



Fixed submission:
N = int(input())
count = 0
for i in range(1, N):
    count += (N-1) // i
print(count)

Buggy python submission (verdict: Runtime Error):
import sympy
N = int(input())
count = 0
for C in range(1, N):
    AB = N - C
    count = count + len(sympy.divisors(AB))
print(count)

Fixed submission:
N = int(input())
count = 0
for i in range(1, N):
    count += (N-1) // i
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = reduce(mul, L)
if O < M:
    M = -1
print(M)

Fixed submission:
import sys
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = 1

if 0 in L:
    print(0)
    sys.exit()

for i in range(N):
    M = M * L[i]
    if O < M:
        print(-1)
        sys.exit()
    else:
        continue
print(M)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

N = int(input())
L = list(map(int, input().split()))
M = reduce(mul, L)
if 10 ** 18 < M:
    M = -1
print(M)

Fixed submission:
import sys
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = 1

if 0 in L:
    print(0)
    sys.exit()

for i in range(N):
    M = M * L[i]
    if O < M:
        print(-1)
        sys.exit()
    else:
        continue
print(M)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
N = int(input())
L = list(map(int, input().split()))
M = reduce(mul, L)
if 1000000000000000000 < M:
    M = -1
print(M)

Fixed submission:
import sys
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = 1

if 0 in L:
    print(0)
    sys.exit()

for i in range(N):
    M = M * L[i]
    if O < M:
        print(-1)
        sys.exit()
    else:
        continue
print(M)
Buggy python submission (verdict: Runtime Error):
input_data = input()
data = split(int(input_data))
d = data[0]
t = data[1]
s = data[2]
print("Yes") if d / s > t else print("No")

Fixed submission:
data = input()
data = data.split()
print("Yes") if int(data[0]) / int(data[2]) <= int(data[1]) else print("No")
Buggy python submission (verdict: Runtime Error):
K = int(input())
if K==7 or K==1:
  print(1)
else:
  count = 1
  for i in range(K):
    x = (x % K) * 10 + 7
    count += 1
    if x==0:
      print(count)
  if x!=0:
    print(-1)

Fixed submission:
K = int(input())
if K==7 or K==1:
  print(1)
else:
  count = 1
  x = 7%K
  for i in range(K):
    x = (x*10+7)%K
    count += 1
    if x==0:
      print(count)
      break
  if x!=0:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
count = 1
a='7'
if K%2==0:
  print('-1')
else:
  while int(a)%K!=0:
    count += 1
    a = a + '7'
  print(count)

Fixed submission:
K = int(input())
if K==7 or K==1:
  print(1)
else:
  count = 1
  x = 7%K
  for i in range(K):
    x = (x*10+7)%K
    count += 1
    if x==0:
      print(count)
      break
  if x!=0:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = [0]*N

for j in range(1,101):
  for k in range(1,101):
    for l in range(1,101):
      if (j**2+k**2+l**2+j*k+k*l+l*j)<i:
        l[j**2+k**2+l**2+j*k+k*l+l*j-1]+=1
        
for i in range(N):
  print(l[i])

Fixed submission:
L, R, d = input().split()
L, R, d = int(L), int(R), int(d)

count = 0
for i in range(L,R+1):
  if i%d==0:
    count += 1
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
 
for i in range(1,N+1):
  count = 0
  if i < 6:
    print('0')
  elif i == 6:
    print('1')
  else:
    for j in range(1,101):
      for k in range(1,101):
        for l in range(1,101):
          if (j**2+k**2+l**2+j*k+k*l+l*j)==i:
            count += 1
        
    print(count)

Fixed submission:
N = int(input())
l = [0]*N

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if (x**2+y**2+z**2+x*y+y*z+z*x)<=N:
        l[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1

for i in l:
  print(i)

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

for i in range(1,N+1):
  count = 0
  if i < 6:
    print('0')
  elif i == 6:
    print('1')
  else:
    for j in range(1,i):
      if (6*(j**2))==i:
        count += 1
      else:
        for k in range(1,i):
          if (3*(j**2)+2*j*k+k**2)==i:
            count += 1
          else:
            for l in range(1,i):
              if (j**2+k**2+l**2+j*k+k*l+l*j)==i:
                count += 1
        
    print(count)
    

Fixed submission:
N = int(input())
l = [0]*N

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if (x**2+y**2+z**2+x*y+y*z+z*x)<=N:
        l[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1

for i in l:
  print(i)

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


for i in range(1,N+1):
  count = 0
  if i < 6:
    print('0')
  elif i == 6:
    print('1')
  else:
    for j in range(1,i):
      for k in range(1,i):
        for l in range(1,i):
          if (j**2+k**2+l**2+j*k+k*l+l*j)==i:
            count+=1
    print(count)

Fixed submission:
N = int(input())
l = [0]*N

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if (x**2+y**2+z**2+x*y+y*z+z*x)<=N:
        l[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1

for i in l:
  print(i)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def resolve():
    import sys

    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    uf = UnionFind(n)

    for i in range(m):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        uf.union(a, b)

    print(len(uf.roots()) - 1)



if __name__ == "__main__":
    resolve()


Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def resolve():
    import sys

    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    uf = UnionFind(n)

    for i in range(m):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        uf.union(a-1, b-1)

    print(len(uf.roots()) - 1)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip())
    data = []
    ans = 0
    for i in range(n):
        row = [int(x) for x in input().rstrip().split(" ")]
        for (x, y) in data:
            dist = abs(x - row[0]) + abs(y - row[1])
            if ans < dist:
                ans = dist
        data.append(row)

    print(ans)


if __name__ == "__main__":
    resolve()

Fixed submission:

def dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])

def resolve():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip())
    ru = None
    rd = None
    lu = None
    ld = None

    for i in range(n):
        row = [int(x) for x in input().rstrip().split(" ")]
        if i == 0:
            ru = row
            rd = row
            lu = row
            ld = row
            continue

        if ru[0] + ru[1] < row[0] + row[1]:
            ru = row
        if rd[0] - rd[1] < row[0] - row[1]:
            rd = row
        if -lu[0] + lu[1] < -row[0] + row[1]:
            lu = row
        if -ld[0] - ld[1] < -row[0] - row[1]:
            ld = row

    ans = 0
    points = [ru, rd, lu, ld]
    for i in range(4):
        for j in range(i+1, 4):
            tmp = dist(points[i], points[j])
            if ans < tmp:
                ans = tmp

    print(ans)


if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    a_list = []

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        for past_a in a_list:
            ans += a * past_a
        a_list.append(a)
    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    past_a = 0

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        ans += a * past_a
        past_a += a

    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    a_list = [int(x) for x in input().rstrip().split(" ")]

    import itertools

    c = itertools.combinations(a_list, 2)

    x = 1000000007

    ans = sum([v[0] * v[1] for v in c]) % x

    print(ans)

if __name__ == "__main__":
    resolve()

Fixed submission:
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    past_a = 0

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        ans += a * past_a
        past_a += a

    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    a_list = [int(x) for x in input().rstrip().split(" ")]

    import itertools

    c = itertools.combinations(a_list, 2)

    x = 1000000007

    ans = 0
    for v in c:
        ans += v[0] * v[1]
        ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()


Fixed submission:
def resolve():
    import sys
    input = sys.stdin.readline

    n = input().rstrip()
    past_a = 0

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        ans += a * past_a
        past_a += a

    x = 1000000007

    ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()
Buggy python submission (verdict: Runtime Error):


def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    a_list = [int(x) for x in input().rstrip().split(" ")]
    a_list.sort(reverse=True)
        
    from heapq import heappush, heappop

    hq = []
    joined = set()
    joined.add(0)
    heappush(hq, (-a_list[0], 0, 0))
    result = 0
            
    for i in range(1, n):
        next_one = a_list[i]
        comfort, left, right = heappop(hq)
        comfort = -comfort

        result += comfort

        heappush(hq, (-(a_list[left] if a_list[left] < a_list[next_one] else a_list[next_one]),left, next_one))
        heappush(hq, (-(a_list[right] if a_list[right] < a_list[next_one] else a_list[next_one]),next_one,right))
    
    print(result)


if __name__ == "__main__":
    resolve()


# を理解する。そうすると、明らかに制限時間内に実行が終わらないソースコードを出さなくなる。ちなみに、競プロでは 108108 ～ 109109 回程度のループが回せるといわれている。

Fixed submission:


def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip())
    a_list = [int(x) for x in input().rstrip().split(" ")]
    a_list.sort(reverse=True)
        
    from heapq import heappush, heappop

    hq = []
    joined = set()
    joined.add(0)
    heappush(hq, (-a_list[0], 0, 0))
    result = 0
            
    for i in range(1, n):

        comfort, left, right = heappop(hq)
        comfort = -comfort

        result += comfort

        heappush(hq, (-(a_list[left] if a_list[left] < a_list[i] else a_list[i]),left, i))
        heappush(hq, (-(a_list[right] if a_list[right] < a_list[i] else a_list[i]),i,right))
    
    print(result)


if __name__ == "__main__":
    resolve()


# を理解する。そうすると、明らかに制限時間内に実行が終わらないソースコードを出さなくなる。ちなみに、競プロでは 108108 ～ 109109 回程度のループが回せるといわれている。
Buggy python submission (verdict: Runtime Error):
import numpy as np

def resolve():
    import sys
    input = sys.stdin.readline
    xn = [int(x) for x in input().rstrip().split()]
    x = xn[0]
    n = xn[1]
	
    if n == 0:
      print(x)
      exit()
    
    p = [int(x) for x in input().rstrip().split()]
    num_list = [i for i in range(1, 101) if not i in p]

    idx = np.abs(np.asarray(num_list) - x).argmin()
    print(num_list[idx])



# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()


Fixed submission:
import numpy as np

def resolve():
    import sys
    input = sys.stdin.readline
    xn = [int(x) for x in input().rstrip().split()]
    x = xn[0]
    n = xn[1]
	
    if n == 0:
      print(x)
      exit()
    
    p = [int(x) for x in input().rstrip().split()]
    num_list = [i for i in range(0, 102) if not i in p]

    idx = np.abs(np.asarray(num_list) - x).argmin()
    print(num_list[idx])



# x = list(map(int, input().split()))

if __name__ == "__main__":
    resolve()