Harryxun/stf_run huggingface dataset:
import numpy as np

import numpy as np
from numpy.linalg import solve
N = int(input())
A = np.array(list(map(int,input().split())))


x = np.roll(np.eye(N),1)
x[0,0]=0
x[N-1,0]=1
x += np.eye(N)
x /= 2


Q, R = linalg.qr(x)
t = np.dot(Q.T, A)
x = linalg.solve(R, t)

print(" ".join( list(map(str,list(map(int,x).tolist())))))


### FIXED CODE ###

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

# A[0]は0と1の間に振ったものなので、
a = 0
for i in range(N//2):
  a +=  A[2*i] - A[2*i+1]

a0 = (a + A[-1]) //2

for i in A:
  print(a0*2,end=" ")
  a0 = i - a0
def resolve():
  N = int(input())
  X = input()
  base_1_count = X.count("1")
  X_int = int(X, 2)
  X_int_p = X_int%(base_1_count + 1)
  X_int_m = X_int%(base_1_count - 1)

# 高速化バージョン
  print()
  for i in range(N):
    if X[i] == "1":
      Xi = X_int_m - 2**(N-i-1)%(base_1_count-1)
    else:
      Xi = X_int_p + 2**(N-i-1)%(base_1_count+1)
    count = 1
    while Xi != 0:
      # print(Xi)
      num_of_1 = bin(Xi).count("1")
      Xi %= num_of_1
      count += 1
    # print("~~~~~~~~~~~~~~~")
    print(count)

# 低速バージョン
  # for i in range(N):
  #   if X[i] == "1":
  #     Xi = X_int - 2**(N-i-1)
  #   else:
  #     Xi = X_int + 2**(N-i-1)
  #   count = 0
  #   while Xi != 0:
  #     # print(Xi)
  #     num_of_1 = bin(Xi).count("1")
  #     Xi %= num_of_1
  #     count += 1
  #   # print("~~~~~~~~~~~~~~~")
  #   print(count)

if __name__ == "__main__":
    resolve()

### FIXED CODE ###

def resolve():
  N = int(input())
  X = input()

  if N == 1:
    if X.count("1"):
      print(0)
    else:
      print(1)
    return True

  base_1_count = X.count("1")
  if base_1_count == 0:
    for _ in range(N):
      print(1)
    return True

  X_int = int(X, 2)
  X_int_p = X_int%(base_1_count + 1)

  # RE 対策
  if base_1_count == 1:
    for i in range(N):
      if X[i] == "1":
        print(0)
      else:
        if i == N - 1:
          Xi = X_int_p + 1
        else:
          Xi = X_int_p
        count = 1
        while Xi != 0:
          Xi %= bin(Xi).count("1")
          count += 1
        print(count)
    return True

  X_int_m = X_int%(base_1_count - 1)
  for i in range(N):
    # 初期値計算を高速にやる
    if X[i] == "1":
      temp_1_count = base_1_count-1
      pow_2 = pow(2, N-i-1, base_1_count-1)
      if X_int_m <= pow_2:
        Xi = X_int_m - pow_2 + base_1_count-1
      else:
        Xi = X_int_m - pow_2
    else:
      temp_1_count = base_1_count+1
      Xi = X_int_p + pow(2, N-i-1, base_1_count+1)
      while Xi >= base_1_count+1:
        Xi %= base_1_count+1

    # print("1_c={0}".format(temp_1_count))
    if temp_1_count == Xi:
      print(1)
      continue

    count = 1
    while Xi != 0:
      num_of_1 = bin(Xi).count("1")
      Xi %= num_of_1
      count += 1
    print(count)

if __name__ == "__main__":
    resolve()
a,b,c = map(int, input().split())
org_list =[a, b, c]　
org_list.sort()
print(org_list)


### FIXED CODE ###

a, b, c = map(int, input().split())
 
if a<b and a<c:
    if b<c :
        print(a, b, c)
    else :
        print(a, c, b)
elif b<a and b<c :
    if a<c :
        print(b, a, c)
    else :
        print(b, c, a)
else :
    if a<b :
        print(c, a, b)
    else :
        print(c, b, a)
import math

N, X = map(int, input().split())
xlist = list(map(int, input().split()))
gaplist = []
for i in range(N):
    tmp = abs(xlist[i] - X)
    if tmp==0:
        tmp = 1
    gaplist.append(tmp)

ans = gaplist[0]
for i in range(1,N):
    ans = math.gcd(ans, gaplist[i])
    #次のxとの最大公約数を動的計画法求めるメソッド O(logX)

print(ans)

### FIXED CODE ###

from fractions import gcd

N, X = map(int, input().split())
xlist = list(map(int, input().split()))
gaplist = []
for i in range(N):
    tmp = abs(xlist[i] - X)
    if tmp==0:
        tmp = 1
    gaplist.append(tmp)

ans = gaplist[0]
for i in range(1,N):
    ans = gcd(ans, gaplist[i])
    #次のxとの最大公約数を動的計画法求めるメソッド O(logX)

print(ans)
a, b, c = map(int, input().split())

if (a == b) and (b == c):
  print('No')
  return
elif (a == b) or (b == c):
  print('Yes')
  return
else:
  print('No')
  

### FIXED CODE ###

a, b, c = map(int, input().split())

if (a == b) and (b == c):
  print('No')
elif (a == b) or (b == c) or (a == c):
  print('Yes')
else:
  print('No')
S = input()
if S = Sunny:
  print("Cloudy")
elif S = Cloudy:
  print("Rainy")
else:
  print("Sunny")

### FIXED CODE ###

S = input()
if S == "Sunny":
    A = "Cloudy"
elif S == "Cloudy":
    A = "Rainy"
else:
    A = "Sunny"
print(A)
x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
r_rev = sorted(r, reverse=True)
#print(p_rev[:x])
#print(q_rev[:y])
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

num_r = len(r_rev)
start = len(pq_rev) - num_r
total = sum(pq_rev[:(-1)*num_r])
#print(total)
pq_cnt=0
r_cnt = 0
for i in range(num_r):
  if pq_rev[start + pq_cnt] > r_rev[r_cnt]:
    total += pq_rev[start + pq_cnt]
    pq_cnt += 1
  else:
    total += r_rev[r_cnt]
    r_cnt += 1
print(total)

### FIXED CODE ###

x,y,a,b,c = list(map(int, input().split()))

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p_rev = sorted(p, reverse=True)
q_rev = sorted(q, reverse=True)
pq_rev = sorted(p_rev[:x] + q_rev[:y] , reverse=True)

total = sum(sorted(pq_rev + r, reverse=True)[:x+y])
print(total)
N,M,X = map(int, input().split())
li = list(map(int, input().split()))
an1 = 0
an2 = 0
nu = 0
for i in range(1,X+1):
    if i == li[nu]:
        an1 += 1
        nu += 1
for i in range(X+1,N):
    if i == li[nu]:
        an2 += 1
        nu += 1
if an1 > an2:
    print(an2)
else:
    print(an1)

### FIXED CODE ###

N,M,X = map(int, input().split())
li = list(map(int, input().split()))
a = 0
nu = 0
for i in range(1,X):
    if i == li[nu]:
        a += 1
        nu += 1
    if nu == len(li):
        break
b = len(li) - a
if a > b:
    print(b)
else:
    print(a)
h,w = map(int,input().split)
print(h*w-(h*w//2))

### FIXED CODE ###

h,w = map(int,input().split())
if min(h,w) == 1:
	print(1)
else:
	print(h*w-(h*w//2))
def sample_code(N):

 #   print('Prime factor')
    fct = factorize(N)
 #   print(fct,num(fct))

 #   print('divisor')
    for div in divisorize(fct):
        b = num(div)


def divisorize(fct):
    b,e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b,k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def factorize(N):
    fct = []
    b,e = 2, 0
    while b * b <= N:
        while N % b == 0:
            N = N // b
            e = e + 1
        if e > 0:
            fct.append((b,e))
        b,e = b + 1,0
    if N > 1:
        fct.append((N,1))
    return fct

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
        divisor_list.append(a)
    return a

N = int(input())
sum_m = 0
divisor_list = []
sample_code(N)
divisor_list = list(set(divisor_list))

for c in divisor_list:
    if c != 1 and c!= 2:
        if N // (c-1) >= (c-1):
            continue
        else:
            sum_m += c - 1

print(sum_m)

### FIXED CODE ###

def sample_code(N):

 #   print('Prime factor')
    fct = factorize(N)
 #   print(fct,num(fct))

 #   print('divisor')
    for div in divisorize(fct):
        b = num(div)


def divisorize(fct):
    b,e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b,k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def factorize(N):
    fct = []
    b,e = 2, 0
    while b * b <= N:
        while N % b == 0:
            N = N // b
            e = e + 1
        if e > 0:
            fct.append((b,e))
        b,e = b + 1,0
    if N > 1:
        fct.append((N,1))
    return fct

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
        divisor_list.append(a)
    return a

N = int(input())
sum_m = 0
divisor_list = []
if N == 1:
    print(0)
else:
    sample_code(N)
    divisor_list = list(set(divisor_list))

    for c in divisor_list:
        if c != 1 and c!= 2:
            if N // (c-1) >= (c-1):
                continue
            else:
                sum_m += c - 1

    print(sum_m)
print(x * x * x)


### FIXED CODE ###

x = int(input())
x = x*x*x
print(x)
s=input()

if(s=="ABC")print("ARC")
else if(s=="ARC")print("ABC")




### FIXED CODE ###

s=input()

if(s=="ABC"):print("ARC")
if(s=="ARC"):print("ABC")
N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*100000000

for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
  num[1+i-a[i]]+=1
for i in range(N):
  count+=num[w[i]]
print(count)

### FIXED CODE ###

N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*N
maxi=max(a)
for i in range(N):
  s.append(1+i-a[i])
  if 1+i+a[i]<N:
    num[1+i+a[i]]+=1
for i in range(N):
  if s[i]>=0:
    count+=num[s[i]]
print(count)
import numpy as np
# def main():
#     N=input()
#     N=int(N)
#     A=input().split(" ")
#     A=np.array([int(i) for i in A]).astype(np.uint64)
#     # A=np.random.randint(0,100000,200000)
#     l=[]
#     A=np.sort(A)
#     A=np.flip(A).astype(np.uint64)
#     sum=0
#     for i,num in enumerate(A):
#         if i%2==0:
#             l=l+[num]
#             if i!=0:
#                 sum+=min(l[-2],l[0])
#         else:
#             l=[num]+l
#             sum+=min(l[1],l[-1])
#     print(int(sum))

# def main2():
#     N=input()
#     N=int(N)
#     A=input().split(" ")
#     A=np.array([int(i) for i in A]).astype(np.uint64)
#     # A=np.random.randint(0,100000,200000)
#     A=np.sort(A)
#     A=np.flip(A).astype(np.uint64)
#     sum=0
#     for i,num in enumerate(A):
#         if i==0:
#             l=A[0]
#             r=A[0]
#             continue
#         sum+=min(l,r)
#         if l<r:
#             r=num
#         else:
#             l=num
#     print(int(sum))

def main3():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    l=[]
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i,num in enumerate(A):
        if i==0:
            l.append(num)
            continue
        l1=np.array(l,dtype=np.uint64)
        l2=np.roll(l1,1)
        l1=l1.reshape(-1,1)
        l2=l2.reshape(-1,1)
        l1=np.concatenate([l1,l2],1)
        l2=l1.min(1)
        arg=l2.argmax()
        l=l[:arg+1]+[num]+l[arg+1:]
        sum+=l2[arg]

    print(int(sum))


def correct():
    N=input()
    N=int(N)
    A=input().split(" ")
    A=np.array([int(i) for i in A]).astype(np.uint64)
    l=[]
    A=np.sort(A)
    A=np.flip(A).astype(np.uint64)
    sum=0
    for i in range(N-1):
        i+=1
        sum+=A[N-int(i/2)]
    print(int(sum))

if __name__ == "__main__":
    # main3()
    correct()

### FIXED CODE ###

if __name__ == "__main__":
    N=input()
    N=int(N)
    x=N//1000
    if N%1000==0:
        print(0)
    else:
        print((x+1)*1000-N)
N = int(input())
dic = {}
for i in range(N):
  a = int(input())
  dic[i+1] = a
counter = 0
place = 1
while place != 2:
  if dic[place] in dic:
    temp = dic[place]
    dic.pop(place)
    place = temp
    counter += 1
  else:
    counter = -1
    break

print(counter)

### FIXED CODE ###

N = int(input())
dic = {}
for i in range(N):
  a = int(input())
  dic[i+1] = a
counter = 0
place = 1
while place != 2:
  if dic[place] in dic and dic[place] != place:
    temp = dic[place]
    dic.pop(place)
    place = temp
    counter += 1
  else:
    counter = -1
    break
print(counter)
n, m = map(int, input().split())
a = list(map(int, input().split()))

sumList = [0] * n
sumList[0] = a[0] % m
number = {}

for i in range(1, n):
    sumList[i] = (sumList[i - 1] + a[i]) % m
    number[sumList[i]] = 0

for i in range(n):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2
    if key == 0:
        ans += value

print(ans)


### FIXED CODE ###

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

sumList = [0] * n
sumList[0] = a[0] % m
number = {}
number[sumList[0]] = 0

for i in range(1, n):
    sumList[i] = (sumList[i - 1] + a[i]) % m
    number[sumList[i]] = 0

for i in range(n):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2
    if key == 0:
        ans += value

print(ans)
def solve(string):
    s, k = map(int, string.split())
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return str(s) if len(str(s)) == 1 else "1" if k < counter else str(s)[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


### FIXED CODE ###

def solve(string):
    s, k = string.split()
    if len(s) == 1:
        return s
    counter = 0
    for _s in str(s):
        if _s == "1":
            counter += 1
            continue
        break
    return "1" if len(k) < 4 and int(k) <= counter else s[counter]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = list(input().split())
    reslut = ''
    for s in S:
        if S == 'B':
            reslut.pop()
        else:
            reslut.append(s)
    print(reslut)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = list(input())
    reslut = []
    for s in S:
        if s == 'B' and len(reslut) == 0:
            continue
        elif s == 'B':
            reslut.pop()
        else:
            reslut.append(s)
    print(''.join(reslut))


if __name__ == "__main__":
    main()
S=map(int,input())
h=(int)S/3600
m=(int)S%3600/60
s=(int)S%3600%60
print(f"{h}:{m}:{s}")


### FIXED CODE ###

S=int(input())
h=S//3600
m=S%3600//60
s=S%3600%60
print(f"{h}:{m}:{s}")
s = input()
weather = ["Sunny","Cloudy","Rainy"]

a = weather[s]
print(weather[a+1])

### FIXED CODE ###

s = input()
weather = ["Sunny","Cloudy","Rainy"]

a = weather.index(s)
if a == 2:
    print("Sunny")
else:
    print(weather[a+1])
S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
length = len(l)
flag=0
i=0
ans = 0
while flag ==0:
    if l[i] == 1 or l[i]==0:
        i = i + 1
    else:
        flag=1
        ans = l[i]
if len(l)>=K:
    ans = l[K-1]
print(ans)


### FIXED CODE ###

S = int(input())
K = int(input())
l = [int(x) for x in list(str(S))]
flag=0
flag2=0
i=0
j=0
ans = 0
if K<=len(l):
    while j<K and flag2 == 0:
        if l[j] == 1 or l[j]==0:
            ans = l[j]
            j = j + 1
        else:
            flag2 =1
            ans = l[j]
else:
    while flag ==0:
        if l[i] == 1 or l[i]==0:
            i = i + 1
        else:
            flag=1
            ans = l[i]
print(ans)
s = str(input())
mae = s[:2]
usiro = s[2:]
if 0 < mae < 13:
    if 0 <usiro < 13:
        print("AMBIGUOUS")
    else:
         print("MMYY")
elif 0 < usiro < 13:
         print("YYMM")
else:
    print("NA")

### FIXED CODE ###

s = str(input())
mae = int(s[:2])
usiro = int(s[2:])
if 0 < mae < 13:
    if 0 <usiro < 13:
        print("AMBIGUOUS")
    else:
         print("MMYY")
elif 0 < usiro < 13:
         print("YYMM")
else:
    print("NA")
s=input()
ng=False
for i in range(n):
  if i%2=0:
    if s[i]=='R':
      ng=True
  else:
    if s[i]=='L':
      ng= True
if ng:
  print('No')
else:
  print('Yes')

### FIXED CODE ###

s=input()
ng=False
for i in range(len(s)):
  if i%2==0:
    if s[i]=='L':
      ng=True
  else:
    if s[i]=='R':
      ng= True
if ng:
  print('No')
else:
  print('Yes')
N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif a not in l and i > 0:
        b = list(a)
        print(b)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)
    elif a in l and i > 0:
        print("No")
        exit(1)

for h in range(0,len(l)-2,2):
    if l[h] == l[h+1]:
        flag = True
if all(l):
#if len(set(words))*2 - len(words) == 0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = int(input())
words = []
l = []
for i in range(N):
    a = input()
    if i == 0:
        l.append(a)
        b = list(a)
        words.append(b[len(b)-1])
    elif i > 0:
        b = list(a)
        if i == N-1:
            words.append(b[0])
        else:
            words.append(b[0])
            words.append(b[len(b)-1])
        l.append(a)

if len(set(l)) != len(l):
    print("No")
    exit()

for h in range(0,len(words),2):
    if words[h] != words[h+1]:
        print("No")
        exit()
print("Yes")
def function(ar):
  print((ar.index(0))+1)

if __name__==__"main"__:
  ar=list(map(int, input().rstrip().split()))
  function(ar)

### FIXED CODE ###

def function(ar):
    print(ar.index(0)+1)

if __name__ == '__main__':
    ar = list(map(int, input().rstrip().split()))
    function(ar)
N=int(input())
W = list(map(int,input().split()))
tmp = 10000000
for i in range(N):
  if tmp >= abs(sum(W[:i+1]) - sum(W[i:])):
    tmp = abs(sum(W[:i+1]) - sum(W[i:]))
    ans = i-1
print(ans)

### FIXED CODE ###

def resolve():
    P,Q,R = map(int,input().split())

    if P+Q <= Q+R and P+Q <= R+P:
        print(P+Q)
    elif Q+R <= R+P and Q+R <= P+Q:
        print(Q+R)
    elif R+P <= P+Q and R+P <= Q+R:
        print(R+P)

resolve()
N = int(input())

ans = 2 # N and N-1                                                                                                                                                                 
for K in range(2, N):
    if K*K>N: break
    n = N
    if n%K!=0: continu-e
    while n%K==0: n//=K
    if n%K==1: ans +=1

y = 0
N_ = N-1
for K in range(2, N):
    if K*K>=N_: break
    if N_%K==0: y +=2
if K*K==N_: y += 1

print(ans+y)

### FIXED CODE ###

N = int(input())

if N==2:
  print(1)
  exit()

ans = 2 # N and N-1
for K in range(2, N):
    if K*K>N: break
    n = N
    if n%K!=0: continue
    while n%K==0: n//=K
    if n%K==1: ans +=1

y = 0
N_ = N-1
for K in range(2, N):
    if K*K>=N_: break
    if N_%K==0: y +=2
if K*K==N_: y += 1

print(ans+y)
from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def main():
    def mincost(n,h):
    	dp=[-1 for i in range(n)]
    	dp[n-1]=0
    	dp[n-2]=abs(h[n-2]-h[n-1])
    	for i in range(n-3,-1,-1):
        	mn=min(i+k+1,n)
        	mnm=sys.maxsize
        	for j in range(i+1,mn):
            	mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
        	dp[i]=mnm    
    	return dp[0]
 
	n,k=map(int,input().split())
	h=[int(x) for x in input().split()]
	print(mincost(n,h))
 
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def mincost(n,h,k):
  dp=[-1 for i in range(n)]
  dp[n-1]=0
  dp[n-2]=abs(h[n-2]-h[n-1])
  for i in range(n-3,-1,-1):
    mn=min(i+k+1,n)
    mnm=sys.maxsize
    for j in range(i+1,mn):
      mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
    dp[i]=mnm    
  return dp[0]
 
def main():
  n,k=map(int,input().split())
  h=[int(x) for x in input().split()]
  print(mincost(n,h,k)) 
 
if __name__ == "__main__":
    main()
N = int(input())
ans = ["a"] * N


def next_chr(ch):
    res = []
    for i in range(-1, 2):
        if ord(ch) + i >= ord("a") and ord(ch) + i <= ord("z"):
            res.append(chr(ord(ch)+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(s[-1])
        for m in ch:
            print("".join([s, m]))
    else:
        i += 1
        ch = next_chr(s[-1])
        for m in ch:
            answer("".join([s, m]), i)


answer("a", 2)


### FIXED CODE ###

N = int(input())
ans = []


def next_chr(ch):
    res = []
    g = ord(ch) - ord("a") + 2
    for i in range(g):
        res.append(chr(ord("a")+i))
    return res


def answer(s, i):
    if i == N:
        ch = next_chr(max(s))
        for m in ch:
            ans.append("".join([s, m]))
    else:
        i += 1
        ch = next_chr(max(s))
        for m in ch:
            answer("".join([s, m]), i)


if N == 1:
    print("a")
else:
    answer("a", 2)
    ans = sorted(ans)
    for c in ans:
        print(c)
S=input()
u=S[7:8]
U=int(u)
if U<=4:
    print('Heisei')
else:
    print('TBD')


### FIXED CODE ###

y,m,d = map(int,input().split("/"))
if m<=4:
  print('Heisei')
else:
  print('TBD')
# Fast IO (only use in integer input)

# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from copy import copy

N = int(input())
Resident = []
for i in range(N):
    x,y,p = map(int,input().split())
    Resident.append((x,y,p))

minCost = [-1] * (N+1)

preCalRange = 1 << N

horizontalLineDistance = []
verticalLineDistance = []

for i in range(preCalRange):
    railRoad = []
    tmp = i
    for j in range(N):
        railRoad.append(tmp % 2)
        tmp //= 2
    minDistance = [-1] * N
    for j in range(N):
        minDistance[j] = min(abs(Resident[j][0]),abs(Resident[j][1]))
        for k in range(N):
            if railRoad[k] == 1 and abs(Resident[j][0] - Resident[k][0]) < minDistance[j]:
                minDistance[j] = abs(Resident[j][0] - Resident[k][0])
    horizontalLineDistance.append(copy(minDistance))
    minDistance = [-1] * N
    for j in range(N):
        minDistance[j] = min(abs(Resident[j][0]),abs(Resident[j][1]))
        for k in range(N):
            if railRoad[k] == 1 and abs(Resident[j][1] - Resident[k][1]) < minDistance[j]:
                minDistance[j] = abs(Resident[j][1] - Resident[k][1])
    verticalLineDistance.append(copy(minDistance))

totalCases = 3 ** N

for i in range(totalCases):
    railRoad = []
    tmp = i
    for j in range(N):
        railRoad.append(tmp % 3)
        tmp //= 3
    horizontalCount = 0
    verticalCount = 0
    numNewRailroad = 0
    for j in range(N):
        if railRoad[j] == 1:
            numNewRailroad += 1
            horizontalCount += 1 << j
        if railRoad[j] == 2:
            verticalCount += 1 << j
            numNewRailroad += 1
    minDistance = []
    for j in range(N):
        minDistance.append(min(horizontalLineDistance[horizontalCount][j], verticalLineDistance[verticalCount][j]))

    cost = 0
    for j in range(N):
        cost += Resident[j][2] * minDistance[j]
    if minCost[numNewRailroad] == -1 or minCost[numNewRailroad] > cost:
        minCost[numNewRailroad] = cost
for elem in minCost:
    print(elem)


### FIXED CODE ###

# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

X = int(input())
if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
elif X <= 1999:
    print(1)
IN = iter(Input.split('\n')).__next__
def input():
    return IN()


h,w = map(int,input().split())
for i in range(h):
    x = input()
    print(x)
    print(x)

### FIXED CODE ###

h,w = map(int,input().split())
for i in range(h):
    x = input()
    print(x)
    print(x)
N = input()
S = list(map(int, input().split()))
ans = 10000

for T in range(1, N):
    s1 = 0
    s2 = 0
    for i in range(len(S)):
        if S[i] <= T:
            s1 += S[i]
        else:
            s2 += S[i]
    if abs(s1 - s2) < ans:
        ans = abs(s1 - s2)
        
print (ans)


### FIXED CODE ###

N = int(input())
S = list(map(int, input().split()))
ans = 10000

for T in range(1, N):
    s1 = 0
    s2 = 0
    for i in range(len(S)):
        if i+1 <= T:
            s1 += S[i]
        if i+1 > T:
            s2 += S[i]
    if abs(s1 - s2) < ans:
        ans = abs(s1 - s2)
        
print (ans)
n,k=int(input().split())
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)

### FIXED CODE ###

n,k=input().split()
n=int(n)
k=int(k)
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)