Harryxun/stf_run huggingface dataset:
# ワ―シャルフロイドで解くよ
def main():
    import sys
    input = sys.stdin.readline  # 1行ごとの入力を繰り返し扱う場合の高速化
    N, M, L = map(int, input().split())
    # distanceを格納(未到達は無限遠として初期化)
    d = [[10 ** 12] * N for _ in range(N)]  
    # input-edges
    for i in range(M):
        a, b, c = map(int, input().split())
        if L >= c: # 距離がLより大きいのは無視
            d[a - 1][b - 1] = d[b - 1][a - 1] = c
    for i in range(N):
        d[i][i] = 0  # 自己ループ無
    
    # ワ―シャルフロイド法適用
    # 町間の最短距離を一度求める。
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][k] + d[k][j], d[i][j])
    
    # 先ほど求めた町間の内、最短距離がL以下のものを距離1で結ぶ。
    edge = [[10 ** 12] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                edge[i][j] = 1
    
    # もう一度ワ―シャルフロイド法適用
    for k in range(N):
        for i in range(N):
            for j in range(N):
                edge[i][j] = min(edge[i][k] + edge[k][j], edge[i][j])
    
    # input-query
    Q = int(input())
    for _ in range(N):
        s, t = map(int, input().split())
        if edge[s - 1][t - 1] >= 10 ** 12:
            print(-1)
        else:
            print(edge[s - 1][t - 1] - 1)  # 最初に燃料Lがある分、マイナス1をする。
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

# ワ―シャルフロイドで解くよ
def main():
    import sys
    input = sys.stdin.readline  # 1行ごとの入力を繰り返し扱う場合の高速化
    N, M, L = map(int, input().split())
    # distanceを格納(未到達は無限遠として初期化)
    d = [[10 ** 12] * N for _ in range(N)]  
    # input-edges
    for i in range(M):
        a, b, c = map(int, input().split())
        if L >= c: # 距離がLより大きいのは無視
            d[a - 1][b - 1] = d[b - 1][a - 1] = c
    for i in range(N):
        d[i][i] = 0  # 自己ループ無
    
    # ワ―シャルフロイド法適用
    # 町間の最短距離を一度求める。
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][k] + d[k][j], d[i][j])
    
    # 先ほど求めた町間の内、最短距離がL以下のものを距離1で結ぶ。
    edge = [[10 ** 12] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                edge[i][j] = 1
    
    # もう一度ワ―シャルフロイド法適用
    for k in range(N):
        for i in range(N):
            for j in range(N):
                edge[i][j] = min(edge[i][k] + edge[k][j], edge[i][j])
    
    # input-query
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        if edge[s - 1][t - 1] >= 10 ** 12:
            print(-1)
        else:
            print(edge[s - 1][t - 1] - 1)  # 最初に燃料Lがある分、マイナス1をする。
    
if __name__ == "__main__":
    main()
def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))


### FIXED CODE ###

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))
Week=["SAT","FRI","THU","WED","TUE","MON","SAN"]
Day=input()
print(Week.index(Day)+1)

### FIXED CODE ###

N = input()
if N == "SUN":
    print(7)
elif N == "MON":
    print(6)
elif N == "TUE":
    print(5)
elif N == "WED":
    print(4)
elif N == "THU":
    print(3)
elif N == "FRI":
    print(2)
elif N == "SAT":
    print(1)
n,m,x=map(int,input().split())
for i in range(m):
    a=list(map(int,input().split()))
count1=0
count2=0
for b in a:
    if b<x:
        count1+=1
    else:
        count2+=1
print(min(count1,count2))
        

### FIXED CODE ###

n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i]-=1

roop = []
pre = 0
for i in range(2*n):
    roop.append(pre)
    pre = a[pre]
cnt = [0]*n
s = ""
for i in range(len(roop)):
    cnt[roop[i]]+=1
    if cnt[roop[i]]>=2 and cnt[roop[i]]<3:
        s += str(roop[i])
ff = int(s[0])
s2 = s
for i in range(len(roop)):
    if roop[i]!=ff:
        s2  = str(roop[i]) + s2
    else:
        check = i
        break

if k<=len(s):
    print(a[k])
else:
    print(a[check +(k-check)%len(s)]+1)





### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i]-=1

roop = [0]
for i in range(3*n):
    roop.append(a[roop[i]])
cnt =[0]*n
d = []
for i in range(len(roop)):
    cnt[roop[i]]+=1
    if cnt[roop[i]]>=3 and cnt[roop[i]]<4:
        d.append(roop[i])
for i in range(len(roop)):
    if roop[i] == d[0]:
        check = i
        break
if check == 0:
    k%=len(d)
    print(d[k]+1)
else:
    if k<check + len(d):
        print(roop[k]+1)
    else:
        k-=check
        k%=len(d)
        print(d[k]+1)
N = int(input())
edges = [{}for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    edges[a][b] = c
    edges[b][a] = c

costDic = [0]*(N+1)
def f(cost,now,p):
    costDic[now] = cost
    for nx,c in edges[now].items():
        if nx != p:
            f(cost+c,nx,now)

Q,K = map(int,input().split())
f(0,K,0)
for _ in range(Q):
    x,y = map(int,input().split())
    print(costDic[x]+costDic[y])

### FIXED CODE ###

"""
--- アルゴリズム概要 ---
前計算で頂点Kから各ノードへの最短路を記録しておき、
各クエリに対しては、dp[a]+dp[b]を返せばよい。

頂点Kから各ノードへの最短ルートはdfsとかで記録していけばよい。
"""
def main():
    from collections import deque
    import sys
    sys.setrecursionlimit(20000000)
    input = sys.stdin.readline
    N = int(input())
    AB = [[]for _ in range(N+1)]
    for i in range(N-1):
        a,b,c = map(int,input().split())
        AB[a].append((b,c))
        AB[b].append((a,c))

    Q,K = map(int,input().split())

    path = {K:""}
    dp = [0]*(N+1)
    que = deque()
    for n,c in AB[K]:
        que.append((n,c))
    while que:
        now,cost = que.pop()
        path[now]=""
        dp[now]=cost
        for n,c in AB[now]:
            if n not in path:
                que.append((n,cost+c))
    for i in range(Q):
        x,y=map(int,input().split())
        print(dp[x]+dp[y])
main()
n, q = map(int, input().split())
s = input()
keep = [0]*(n)

for i in range(1, n):
    l, r = i-1, i+1
    if s[l:r] == "AC":
        keep[i] = 1

for j in range(q):
    l, r = map(int, input().split())
    print(sum(keep[l:r]))


### FIXED CODE ###

b=input()
lis=["A","G","T","C"]
print(lis[(int(lis.index(b))+2)%4])
N = int(input())
L = map(int, input().split())

ans = 0
for aix in range(N):
    for bix in range(aix, N):
        for cix in range(cix, N):
            if L[aix] < L[bix] + L[cix] and L[bix] < L[aix] + L[cix] and L[cix] < L[aix] + L[bix]:
                ans += 1

print(ans)


### FIXED CODE ###

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

import bisect

L.sort()
# print(L)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N-1):
        ix = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, ix - j - 1)

print(ans)
from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]
ans[ch-1][cw-1]=0

qu = deque([])
qu.append((cw-1,ch-1))
while qu:
  x,y=qu.popleft()

  for i in range(max(x-2,0),min(x+3,w)):
    for j in range(max(y-2,0),min(y+3,h)):
      if (x==i and y==j):
        continue
      if maze[j][i]=="." and (ans[j][i]>ans[y][x] or ans[j][i]==-1):
        if (x==i and y==j+1) or (x==i+1 and y==j) or (x==i-1 and y==j) or (x==i and y==j-1):
          qu.appendleft((i,j))
          ans[j][i] = ans[y][x]
        elif ans[j][i]>ans[y][x]+1 or ans[j][i]==-1:
          ans[j][i]=(ans[y][x]+1)
          qu.appendleft((i,j))

print(ans[dh-1][dw-1])

  




### FIXED CODE ###

n,x,t=map(int,input().split())

if n%x==0:
  print(t*(n//x))
else:
  print(((n//x)+1)*t)
import numpy as np
import itertools
 
H, W, K = list(map(int, input().split())) 
c = [input().split() for l in range(H)]
b=[]
d=[]
for m in range(len(c)):
  for item in c[m]:
    item_mod = item.replace("."  , "0")
    item_mod = item_mod.replace("#" , "1")
    b.append(item_mod)
  d.append(b)
  b=[]

C_arr = np.array(d , dtype = int)
 
In = np.array(list(itertools.product([0,1] , repeat=H)))
Out = np.array(list(itertools.product([0,1] , repeat=W)))
 
ans = 0
for i in range(len(In)):
  for j in range(len(Out)):
    In_matrix = np.diag(In[i])
    Out_matrix = np.diag(Out[j])
    
    In_C = np.dot(In_matrix , C_arr)
    In_C_Out = np.dot(In_C , Out_matrix)
    
    ICO = In_C_Out.flatten()
    ICO = ICO.tolist()
    
    if ICO.count(1) == K:
      ans += 1
      
print(ans)

### FIXED CODE ###

H, W, K = list(map(int, input().split()))
 
c = [list(input()) for i in range(H)]
 
cnt = 0
for i in range(2**H):
    for j in range(2**W):
        cnt_black = 0
        for k in range(H):
            if (i >> k) & 1:
                continue
            for l in range(W):
                if (j >> l) & 1:
                    continue
                if c[k][l] == '#':
                    cnt_black += 1
        if cnt_black == K:
            cnt += 1
 
print(cnt)
import sys
sys.setrecursionlimit(10 ** 6)

N, Q = map(int, input().split())

edges = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edges[a-1].append(b - 1)

counter = [0] * N

def process(root, value):
    counter[root] += value
    for next_root in edges[root]:
        process(next_root, value)

for _ in range(Q):
    p, x = map(int, input().split())
    process(p - 1, x)

print(" ".join(counter))

### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())

edges = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

counter = [0] * N
checked = [False] * N

for i in range(Q):
    p, x = map(int, input().split())
    counter[p - 1] += x

queue = deque()
queue.append(0)

while queue:
    root = queue.pop()
    checked[root] = True
    for e in edges[root]:
        if checked[e] == False:
            queue.append(e)
            counter[e] += counter[root]

print(" ".join(map(str, counter)))
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from copy import deepcopy
n,m = map(int,input().split())
inf = float("inf")
L = [[inf for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    L[a-1][b-1] = 1
    L[b-1][a-1] = 1
#print(L)
cnt = 0
for i in range(n):
    for j in range(n):
        LL = deepcopy(L)
        LL[i][j] = 0
        LL[j][i] = 0
        LL = floyd_warshall(LL)
        #print(LL)
        for k in LL:
            if inf in k:
                cnt +=1
                break
print(cnt//2) 

### FIXED CODE ###

n,m = map(int,input().split())
d = []
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    d.append((a,b))
#print(d)
pa = None

def root(a):
    if pa[a] == a:
        return a
    else:
        pa[a] = root(pa[a])
        return pa[a]
def is_same(a,b):
    return root(a) == root(b)
def unite(a,b):
    aa = root(a)
    bb = root(b)
    if aa == bb:
        return
    pa[aa] = bb

ans = 0
for i in range(m):
    pa = [x for x in range(n)]
    for j,v in enumerate(d):
        #(i,j,v)
        if i == j:continue
        a,b = v
        unite(a,b)
    a,b = d[i]
    if not is_same(a,b):
        ans +=1
print(ans)
import numpy as np
n,m=map(int,input().split())
nextmatrix=np.zeros((n,n))
for i in range(m):
    a,b=map(int,input().split())
    nextmatrix[a-1][b-1]=1
    nextmatrix[b-1][a-1]=1
nextmatrix2=nextmatrix.dot(nextmatrix)
if nextmatrix2[0][n-1]==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

### FIXED CODE ###

#068-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()

n,m=IL()
nl=[[] for i in range(n)]
for i in range(m):
    a,b=IL()
    nl[a-1].append(b-1)
for i in nl[0]:
    if n-1 in nl[i]:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")
#!/usr/bin/env python3


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



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

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))



### FIXED CODE ###

#!/usr/bin/env python3



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

dp = [float('inf') for i in range(N+1)]

dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b = [int(i) for i in input().split()]123 456
print(lcm(a, b))


### FIXED CODE ###

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

a, b = [int(i) for i in input().split()]
print(lcm(a, b))
import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
di = dict()
for k in li:
    word = sorted(list(k))
    if word in di.keys():
        ans += di[word]
        di[word] += 1
    else:
        di[word] = 1
print(ans)

### FIXED CODE ###

import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
di = dict()
for k in li:
    word = ''.join(sorted(list(k)))
    if word in di.keys():
        ans += di[word]
        di[word] += 1
    else:
        di[word] = 1
print(ans)
a,b,k = map(int,input().split(" "))
c = [1]
for i in range(1,max(a,b)):
  if a % i == 0 and b % i == 0 and i!=1:
    c.append(i)
c.sort(reverse=True)
print(c[k-1])

### FIXED CODE ###

a,b,k = map(int,input().split(" "))
c = [1]
for i in range(1,max(a,b)+1):
  if a % i == 0 and b % i == 0 and i!=1:
    c.append(i)
c.sort(reverse=True)
print(c[k-1])
L,R = map(int,input().split())

#区間の両端を除いた数=2017より長ければ2019の倍数が含まれているので0が解
if R - L >= 2018:
  print(0)
else:
  ans = 2018 ** 2
  for i in range(L,R):
    for j in range(L + 1,R):
      mod = (i * j) % 2019 
      if mod < ans:
        ans = mod
      elif mod == 0:
        ans = 0
        break
print(ans)



### FIXED CODE ###

L,R = map(int,input().split())

ans = 2019 ** 2

if R - L >= 2018:
  ans = 0
  print(ans)
else: 
  for i in range(L,R):
    for j in range(L + 1,R + 1):
      mod = (i * j) % 2019 
      if mod < ans:
        ans = mod
      elif mod == 0:
        ans = 0
        break
  print(ans)
# Python
user_input = input("Input in format A op B")
input_sep = user_input.split()
input_a = input_sep[0]
operator = input_sep[1]
input_b = input_sep[2]

if operator is '+':
    print(int(input_a + input_b))
elif operator is '-':
    print(int(input_a - input_b))

### FIXED CODE ###

# python
my_input = str(input())
print(str(eval(my_input)))
N, M=map(int, input().split())
ans=["-1"]*M
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  a="".join(ans)
  b=a.replace("-1", "1")
  print(b)
   

### FIXED CODE ###

N, M=map(int, input().split())
ans=["-1"]*N
f=0
for i in range(M):
  s, c=map(int, input().split())
  if s==1 and c==0 and N!=1:
    f=1
  if ans[s-1]!=str(c) and ans[s-1]!="-1":
    f=1
  ans[s-1]=str(c)

if f==1:
  print(-1)
else:
  if ans[0]=="-1" and N!=1:
    ans[0]="1"
  elif M==0 and N==1:
    ans[0]="0"
  a="".join(ans)
  b=a.replace("-1", "0")
  print(b)
def main():  
  N = int(input())
  VW = [list(map(int,input().split())) for _ in range(N)]
  Q = int(input())
  vL = [list(map(int,input().split())) for _ in range(Q)]
  M = 0
  import math
  from collections import deque
  for q in range(Q):
    x = vL[q][1]
    if x>M:
      M = x

  D = int(math.log2(N)) + 1
  K = D//2
  Ddp = deque([[0] * (M+1) for _ in range(2**K)])

  for q in range(Q):
    v,L = vL[q]
    if v<=2**K - 1:
      print(Ddp[v][L])
      continue
    
main()


### FIXED CODE ###

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

for i in range(1,K+1):
  B = [0]*N
  for j in range(N):
    l = max(0, j-A[j])
    r = min(N-1, j+A[j])
    B[l] += 1
    if r+1<N:
      B[r+1] -= 1
    
  if B[0]==N:
    x = 1
  else:
    x = 0
  for i in range(1,N):
    B[i] += B[i-1]
    if B[i]==N:
      x += 1
  A = B.copy()
  if (x==N)or(i==K):
    break
    
print(' '.join(list(map(str,A))))
n = int(input())
A = sorted(map(int, input().split()))
nux = A[-1]+1
ans = 0
table = [True]*nux
for i, s in enumerate(A):
    if table[s] == False:
        continue
    if i == n-1:
        ans += 1
    elif A[i+1] != s:
        ans += 1
    b = 1
    while b*s <= nux:
        table[b*s] = False
        b += 1
print(ans)


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
nux = max(A)
B = set(A)
A.sort()
ans = 0
table = [True]*(nux+1)
for ii, s in enumerate(A):
    if table[s] == False:
        continue
    if ii == n-1:
        ans += 1
    elif A[ii+1] != s:
        ans += 1
    i = 1
    while i*s <= nux:
        table[i*s] = False
        i += 1

print(ans)
N,X = map(int,input().split())
B = [-1 for i in range(51)]
P = [-1 for i in range(51)]

def buns(L):
    if L == 0:#再帰終了条件
        B[L] = 0
        return B[L]
    else:
        if B[L] == -1:
            B[L] = buns(L-1)*2 + 2
            return B[L]
        else:
            return B[L]

def patty(L):
    if L == 0:#再帰終了条件
        P[L] = 1        
        return P[L]
    else:
        if P[L] == -1:
            P[L] = patty(L-1)*2 + 1
            return P[L]
        else:
            return P[L]

buns(N)
patty(N)
memo = [B[i] + P[i] for i in range(51)]

def func(L,X):

    if L == 0:
        if X <= 0:
            return 0
        else:
            return 1
    elif X <= memo[L-1]+1:
        return func(L-1,X-1)
    else :
        return P[L-1] + 1 + func(L-1,X-2-memo[L-1])


print(func(N,X))

### FIXED CODE ###

D = input()

if D == "25":
  print("Christmas")
elif D == "24":
  print("Christmas Eve")
elif D == "23":
  print("Christmas Eve Eve")
elif D == "22":
  print("Christmas Eve Eve Eve")
else:
  pass
print(sum([x for i in range(int(input())+1)]))

### FIXED CODE ###

print(sum([int(i) for i in range(int(input())+1)]))
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

a = [[a[i][0], a[i][1], a[i][2]*(-1)] for i in range(m)]
point = [0] + ['inf']*(n-1)

for j in range(n):
  for i in range(m):
    
    if point[a[i][1]-1] == 'inf' or point[a[i][1]-1] > point[a[i][0]-1] + a[i][2]:
      point[a[i][1]-1] = point[a[i][0]-1] + a[i][2]
    
      if j == (n-1) and a[i][1]-1 == (n-1):
        point.append('inf')
        
        
if 'inf' in point:
  print('inf')
else:
  print(-point[n-1])
  

### FIXED CODE ###

import sys
INF=float('inf')
def Bellmanford(n,edges,r):
  d=[INF]*n
  d[r]=0    
  for i in range(n):
    for (u,v,c) in edges:
      if d[u]!=INF and d[u]+c<d[v]:
        d[v]=d[u]+c
        if i==n-1 and v==n-1:
          return 'inf'   
  return (-1)*d[n-1]

N,M=map(int, sys.stdin.readline().split())
Edges=[0]*M

for i in range(M):
  a,b,c=map(int, sys.stdin.readline().split())
  Edges[i]=(a-1,b-1,-c)
    
ans=Bellmanford(N,Edges,0)
print(ans)
ans = a * b
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())
print(a*b)
tgt_b = int(str_in[2])
tgt_c = int(str_in[3])

source = [int(input()) for i in range(num)]

mp = float('inf')

for i in range(1,2**num):

  sum_a = 0
  len_a = 0
  
  bin_i = format(i,'0256b')  
  for t in range(1,num+1):
    sum_a += int(bin_i[-t])
    len_a += int(bin_i[-t]) * source[t-1]
    
  for j in range(1,2**num):
 
    sum_b = 0
    len_b = 0

    if (i & j) > 0:
      continue
    
    bin_j = format(j,'0256b')
    for t in range(1,num+1):
      sum_b += int(bin_j[-t])
      len_b += int(bin_j[-t]) * source[t-1]

    for k in range(1,2**num):

      sum_c = 0
      len_c = 0
      
      if (i & k) > 0:
        continue
      elif(j & k) > 0:
        continue
        
      bin_k = format(k,'08b')        
      
      for t in range(1,num+1):
        sum_c += int(bin_k[-t])
        len_c += int(bin_k[-t]) * source[t-1]
        
      mp_try = abs(len_a - tgt_a) + abs(len_b - tgt_b) + abs(len_c - tgt_c) + (sum_a + sum_b + sum_c - 3) * 10 
      if(mp > mp_try):
        mp = mp_try

print (mp)


### FIXED CODE ###

str_in = input().split()
num   = int(str_in[0])
tgt_a = int(str_in[1])
tgt_b = int(str_in[2])
tgt_c = int(str_in[3])

source = [int(input()) for i in range(num)]

mp = float('inf')

for i in range(1,2**num):

  sum_a = 0
  len_a = 0
  
  bin_i = format(i,'08b')  
  for t in range(1,num+1):
    sum_a += int(bin_i[-t])
    len_a += int(bin_i[-t]) * source[t-1]
    
  for j in range(1,2**num):
 
    sum_b = 0
    len_b = 0

    if (i & j) > 0:
      continue
    
    bin_j = format(j,'08b')
    for t in range(1,num+1):
      sum_b += int(bin_j[-t])
      len_b += int(bin_j[-t]) * source[t-1]

    for k in range(1,2**num):

      sum_c = 0
      len_c = 0
      
      if (i & k) > 0:
        continue
      elif(j & k) > 0:
        continue
        
      bin_k = format(k,'08b')        
      
      for t in range(1,num+1):
        sum_c += int(bin_k[-t])
        len_c += int(bin_k[-t]) * source[t-1]
        
      mp_try = abs(len_a - tgt_a) + abs(len_b - tgt_b) + abs(len_c - tgt_c) + (sum_a + sum_b + sum_c - 3) * 10 
      if(mp > mp_try):
        mp = mp_try

print (mp)
s=input()
k=int(input())
ans=1
for i in range(len(s)):
    if s[i]!="1":
        num=i
        ans=s[i]
        break
if k<=num:
    print(1)
else:
    print(ans)


### FIXED CODE ###

s=input()
k=int(input())
ans=1
num=1000
for i in range(len(s)):
    if s[i]!="1":
        num=i
        ans=s[i]
        break
if k<=num:
    print(1)
else:
    print(ans)
n=int(input())
l=list(input())
m=int(input())
time=0
for i in l:
  time+=i
for i in range(m):
  p,x=map(int,input().split())
  print(time-l(p-1)+x)

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
m=int(input())
time=0
for i in l:
  time+=int(i)
for i in range(m):
  p,x=map(int,input().split())
  print(time-l[p-1]+x)
a, b, x = map(int, input().split())
ls = list(range(a, b+1))
count = [i % x for i in ls].count(0)

print(count)


### FIXED CODE ###

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

count = b//x - (a-1)//x if a > 0 else b//x + 1

print(count)
s = input()
n = len(s)

res = 0

def part_sum(cur, i):
  if i != n:
    part_sum(cur+s[i], i+1)
    part_sum(cur+s[i]+"+", i+1)
  else:
    cur += s[i]
    res += sum(list(map(int, cur.split("+")))) 
  
part_sum([], 0)
print(res)

### FIXED CODE ###

s = input()
n = len(s)

def part_sum(cur, i, res):
    if i < n-1:
        part_sum(cur+s[i], i+1, res)
        part_sum(cur+s[i]+"+", i+1, res)
    else:
        cur += s[i]
        res.append(sum(list(map(int, cur.split("+")))) )
    return res
  
res = part_sum("", 0, [])
print(sum(res))
import math

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

if x<=a^2*b/2
  y=x/a*2/b
  print(math.atan(b/y))
else:
  z=b*2-2x/a^2
  print(math.atan(z/a))


### FIXED CODE ###

import math

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

if x<=(a**2)*b/2:
  y=x/a*2/b
  print(' {:.10f}'.format(math.atan(b/y)/math.pi*180))
else:
  z=b*2-2*x/(a**2)
  print(' {:.10f}'.format(math.atan(z/a)/math.pi*180))