Buggy python submission (verdict: Runtime Error):
import sys
from collections import namedtuple

import numpy as np

sys.setrecursionlimit(10**6)

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
print(total_score)

Fixed submission:
import sys
import math

price = int(sys.stdin.readline().strip())

if price % 1000 == 0:
  print(0)
else:
	print(1000 * (price // 1000 + 1) - price)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import namedtuple

import numpy as np

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
print(total_score)

Fixed submission:
import sys
import math

price = int(sys.stdin.readline().strip())

if price % 1000 == 0:
  print(0)
else:
	print(1000 * (price // 1000 + 1) - price)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import namedtuple

import numpy as np

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  #print('----------')
  #print("ADDING {}".format(values[index]))
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  #print("CHOOSE: {}({})-{}({})-{}({}): {}".format(
  #  values[best_index], 
  #  best_index,
  #  values[index],
  #  index,
  #  values[next_ptr[best_index]], 
  #  next_ptr[best_index],
  #  best_score))
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
  #print('----- TEST -----')
  #index = 0
  #while True:
  #  print(values[index])
  #  index = next_ptr[index]
  #  if index == 0:
  #    break

#print("ANSWER")
print(total_score)

Fixed submission:
import sys
import math

price = int(sys.stdin.readline().strip())

if price % 1000 == 0:
  print(0)
else:
	print(1000 * (price // 1000 + 1) - price)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import namedtuple

import numpy as np

length = int(sys.stdin.readline())

values = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)
values = np.sort(values)[::-1]

next_ptr = np.zeros(shape=values.shape, dtype=np.int32)-1
next_ptr[0] = 0

total_score = 0
for index in range(1, len(values)):
  #print('----------')
  #print("ADDING {}".format(values[index]))
  best_index = 0
  best_score = 0
  i = np.where(next_ptr>=0)[0]
  next_i = next_ptr[i]
  values_i = values[i]
  next_values_i = values[next_i]
  scores = np.min([values_i, next_values_i], axis=0)
  best_index = np.argmax(scores)
  #print("CHOOSE: {}({})-{}({})-{}({}): {}".format(
  #  values[best_index], 
  #  best_index,
  #  values[index],
  #  index,
  #  values[next_ptr[best_index]], 
  #  next_ptr[best_index],
  #  best_score))
  
  total_score += scores[best_index]
  
  next_ptr[index] = next_ptr[best_index]
  next_ptr[best_index] = index
  
  #print('----- TEST -----')
  #index = 0
  #while True:
  #  print(values[index])
  #  index = next_ptr[index]
  #  if index == 0:
  #    break

#print("ANSWER")
print(total_score)

Fixed submission:
import sys
import math

price = int(sys.stdin.readline().strip())

if price % 1000 == 0:
  print(0)
else:
	print(1000 * (price // 1000 + 1) - price)

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

length = int(sys.stdin.readline())

array = np.array([int(i) for i in sys.stdin.readline().split()], dtype=np.int32)

array[::-1].sort()

array = list(array)

added = array[0:1]
to_add = array[1:]

score = 0
while to_add:
  inst = to_add.pop(0)
  scores = [min(added[i-1], added[i]) for i in range(len(added))]
  index = np.argmax(scores)
  max_score = scores[index]
  score += max_score
  added.insert(index, inst)

print(score)


Fixed submission:
import sys
import math

price = int(sys.stdin.readline().strip())

if price % 1000 == 0:
  print(0)
else:
	print(1000 * (price // 1000 + 1) - price)