Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

newlist = []

for i in range(a):
  newlist.append(1)
for i in range(b):
  newlist.append(0)
for i in range(c):
  newlist.append(-1)
  
ans = 0
for i in range(k):
  ans = ans + newlist[i]
  
print(ans)

### FIXED CODE ###

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

ans = 0

if k > a:
  ans = a * 1
  k = k - a
  if k > b:
    ans += b * 0
    k = k - b
    ans += k * -1
    print(ans)
  elif k <= b:
    ans += k * 0
    print(ans)
elif k <= a:
  ans = k * 1
  print(ans)
### BUGGY CODE ###

# 配るDP
N, A = map(int, input().split())
X = list(map(int, input().split()))

dp = [[[0 for _ in range(3010)] for __ in range(N+1)] for ___ in range(N+1)]

dp[0][0][0] = 1

for i in range(N):
    for j in range(N):
        for k in range(2500+1):
            dp[i+1][j][k] += dp[i][j][k]
            dp[i+1][j+1][k+X[i]] += dp[i][j][k]

ans = 0
for n in range(1, N+1):
    ans += dp[N][n][n*A]

print(ans)


### FIXED CODE ###

# 配るDP
N, A = map(int, input().split())
X = list(map(int, input().split()))

dp = [[[0 for _ in range(3010)] for __ in range(N+1)] for ___ in range(N+1)]

dp[0][0][0] = 1

for i in range(N):
    for j in range(N):
        for k in range(2500+1):
            if dp[i][j][k]:
                dp[i+1][j][k] += dp[i][j][k]
                dp[i+1][j+1][k+X[i]] += dp[i][j][k]

ans = 0
for n in range(1, N+1):
    ans += dp[N][n][n*A]

print(ans)
### BUGGY CODE ###

n,k,q = map(int,input().split())
a = []
for i in range(q):
    a.append(int(input()))
for i in range(1,n+1):
    point = a.count(i)
    if k - q + point > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k,q = map(int,input().split())
a = [0 for i in range(n)]
for i in range(q):
    aa = int(input()) - 1
    a[aa] = a[aa] + 1
for i in a:
    if k - q + i > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

#!/usr/bin/env python3

import numpy as np

def main():
    a, b, q = map(int, input().split())
    huge = 10 ** 18
    s = np.array([-huge] + [int(input()) for i in range(a)] + [huge])
    t = np.array([-huge] + [int(input()) for i in range(b)] + [huge])
    for i in range(q):
        x = int(input())
        b = np.searchsorted(s, x, "right")
        d = np.searchsorted(t, x, "right")
        res = huge
        for sh in s[b - 1:b + 1]:
            for te in t[d - 1:d + 1]:
                d1 = abs(sh - x) + abs(sh - te)
                d2 = abs(te - x) + abs(sh - te)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3

import bisect

def main():
    a, b, q = map(int, input().split())
    huge = 10 ** 18
    s = [-huge] + [int(input()) for i in range(a)] + [huge]
    t = [-huge] + [int(input()) for i in range(b)] + [huge]
    for i in range(q):
        x = int(input())
        b = bisect.bisect_right(s, x)
        d = bisect.bisect_right(t, x)
        res = huge
        for sh in s[b - 1:b + 1]:
            for te in t[d - 1:d + 1]:
                d1 = abs(sh - x) + abs(sh - te)
                d2 = abs(te - x) + abs(sh - te)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

N, M = map(int, input().split())
income = [[] for _ in range(M+1)] # income[i]はi日後に報酬が得られる全ての仕事についての報酬のリスト
for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        income[a].append(b)

# 後ろから考える。残りi日のときに終了までに報酬が得られる仕事のうち報酬最大のものを選ぶ
ans = 0
for rest_days in range(1, M+1):
    if income[rest_days]:
        m = max(income[rest_days])
        ans += m
        if rest_days < M:
            income[rest_days].remove(m)
            income[rest_days+1] += income[rest_days]
            income[rest_days+1].sort()

print(ans)

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
income = [[] for _ in range(M+1)]  # income[i]はi日後に報酬が得られる全ての仕事についての報酬のリスト
for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        income[a].append(-b)

# 後ろから考える。残りi日のときに終了までに報酬が得られる仕事のうち報酬最大のものを選ぶ
ans = 0
tmp = []
heapq.heapify(tmp)

for rest_days in range(1, M+1):
    for x in income[rest_days]:
        heapq.heappush(tmp, x)
    if tmp:
        ans += heapq.heappop(tmp)

print(-ans)
### BUGGY CODE ###

a,b,k = map(int,input().split())
list = list(l for l in range(a,b+1))
if b-a+1 < k*2:
  print(*list,sep="\n")
else:
  print(*list[:k],sep="\n")
  print(*list[-k:],sep="\n")

### FIXED CODE ###

a,b,k = map(int,input().split())
x = range(a,b+1) 
if b-a+1 < k*2:
  print(*x,sep="\n")
else:
  print(*x[:k],sep="\n")
  print(*x[-k:],sep="\n")
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
  n, m = map(int, input().split())
  U = 2**n
  dp = [ [float("inf")]*(2**n) for _ in range(m) ]
  dp[0][0] = 0
  for i in range(1, m):
    a, b = map(int, input().split())
    k = map(int, input().split())
    c = 0
    for l in k:
      c |= 1<<(l-1)
    for j in range(U):
      dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

  if dp[m-1][2**n-1] == float("inf"):
    print(-1)
  else:
    print(dp[m-1][2**n-1])
    
if __name__ == "__main__":
  main()

### FIXED CODE ###

n, m = map(int, input().split())
dp = [ [float("inf")]*(2**n) for _ in range(m) ]
dp[0][0] = 0
for i in range(1, m):
  a, b = map(int, input().split())
  k = set(map(int, input().split()))
  c = 0
  for l in k:
    c += 2**(l-1)
  for j in range(2**n):
    dp[i][j] = min(dp[i-1][j&(~c)]+a, dp[i-1][j])

if dp[m-1][2**n-1] == float("inf"):
  print(-1)
else:
  print(dp[m-1][2**n-1])
### BUGGY CODE ###

from numba import njit
import numpy as np


MOD = 10**9 + 7

@njit
def fact_table(N, MOD):
    N += 1
    inv = np.empty(N, np.int64)
    inv[0] = 0
    inv[1] = 1
    for n in range(2, N):
        q, r = divmod(MOD, n)
        inv[n] = inv[r] * (-q) % MOD
    fact = np.empty(N, np.int64)
    fact[0] = 1
    for n in range(1, N):
        fact[n] = n * fact[n - 1] % MOD
    fact_inv = np.empty(N, np.int64)
    fact_inv[0] = 1
    for n in range(1, N):
        fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD
    return fact, fact_inv, inv

@njit
def main(k,n,fact,inv):
    ans = 0
    for i in range(k+1):
        c25 = 1
        for j in range(i):
            c25 *= 25
            c25 %= MOD
        f = fact[i+n-1] * inv[i] % MOD * inv[n-1] % MOD
        c25 *= f
        c25 %= MOD

        c26 = 1
        for h in range(k-i):
            c26 *= 26
            c26 %= MOD
            
        ans += (c25 * c26 % MOD)
        ans %= MOD
    return ans



k = int(input())
s = input()
'''
k = 37564
s = 'whydidyoudesertme'
'''
n = len(s)

fact, fact_inv, inv = fact_table(k+n, MOD)
print(main(k,n,fact,fact_inv))

### FIXED CODE ###

MOD = 10**9 + 7

def prepare(n, MOD):
 
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs


k = int(input())
s = input()
n = len(s)
ans = 0

l = k+n + 3
 
a25 = [1]
for i in range(l):
    a25.append((a25[-1] * 25) % MOD)
a26 = [1]
for i in range(l):
    a26.append((a26[-1] * 26) % MOD)

fact, inv = prepare(n+k, MOD)
for i in range(k+1):
    c25 = a25[i]
    f = fact[i+n-1] * inv[i] % MOD * inv[n-1] % MOD
    c25 *= f
    c25 %= MOD

    c26 = a26[k-i]
    ans += (c25 * c26 % MOD)
    ans %= MOD
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

R = [i for i, x in enumerate(S) if x == 'R']
G = [j for j, y in enumerate(S) if y == 'G']
B = [k for k, z in enumerate(S) if z == 'B']

cnt=0
for r in R:
    for g in G:
        for b in B:
            if abs(g-r) != abs(b-g) and \
                abs(b-r) != abs(g-b) and \
                abs(r-b) != abs(g-r):
                cnt+=1

print(cnt)

### FIXED CODE ###

N = int(input())
S = input()

R = [X for X, x in enumerate(S) if x == 'R']
G = [Y for Y, y in enumerate(S) if y == 'G']
B = [Z for Z, z in enumerate(S) if z == 'B']

mae = len(R)*len(G)*len(B)

cnt=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k >=N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            cnt+=1

print(mae-cnt)
### BUGGY CODE ###

#!python
# -*- coding: utf-8 -*-


S = input() + '_'
T_s = ["dream", "dreamer", "erase", "eraser"]

while True:
    S_ = S
    for T in T_s:
        S = S.replace(T + "_", "_")
    if S_ == S:
        break

if S == "_":
    print("YES")
else:
    print("NO")


### FIXED CODE ###

#!python
# -*- coding: utf-8 -*-


S = input()
T_s = ["dream", "dreamer", "erase", "eraser"]

while len(S):
    for T in T_s:
        if T == S[-len(T):]:
            S = S[:-len(T)]
            break
    else:
        print("NO")
        break
else:
    print("YES")
### BUGGY CODE ###

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
dp = [[0 for i in range(W)] for j in range(H)]

for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    dp[hh - 1][ww - 1] += 1
    

hhh = max(h)
www = max(w)
keep_h = []
keep_w = []

for i in range(H):
    if h[i] == hhh:
        keep_h.append(i)
for i in range(W):
    if w[i] == www:
        keep_w.append(i)

check = 0
for i in keep_h:
    for j in keep_w:
        if dp[i][j] == 0:
            check = 1
print(hhh + www - (1-check))


### FIXED CODE ###

H, W, M = map(int, input().split())
h = [0 for i in range(H)]
w = [0 for i in range(W)]
DP = set()
for i in range(M):
    hh, ww = map(int, input().split())
    h[hh - 1] += 1
    w[ww - 1] += 1
    DP.add((hh - 1, ww - 1))

hhh = max(h)
www = max(w)
hhhh = [i for i, x in enumerate(h) if x == hhh]
wwww = [i for i, x in enumerate(w) if x == www]
check = 0

for i in hhhh:
    for j in wwww:
        if (i, j) not in DP:
            print(hhh + www)
            exit()
print(hhh + www - 1)
### BUGGY CODE ###

import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
# Written by NoKnowledgeGG @YlePhan
 
#import math
#mod = 10**9+7
 
 
 
def main():
  s = input()
  t = input()
  
  s_l = len(s)
  t_l = len(t)
  
  for a in itertools.permutations(s,s_l):
    for b in itertools.permutations(t,t_l):
      if a < b:
        print('Yes')
        exit()
  print('No')
  
  
if __name__ == '__main__':
  main()

### FIXED CODE ###

#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
# Written by NoKnowledgeGG @YlePhan
 
#import math
#mod = 10**9+7
 
 
 
def main():
  s = input()
  t = input()
  
  s = sorted(list(s))
  t = sorted(list(t),reverse=True)
  #print(s,t)
  if s < t:
    print('Yes')
  else:
    print('No')
  
  
if __name__ == '__main__':
  main()
### BUGGY CODE ###

M = 10**9+7
N = int(input())
A = list(map(int,input().split()))

ans = 0
for k in range(60):
    N1 = 0
    N1 = sum(1 for a in A if ( (a >> k) & 1))
    N0 = N-N1
    ans += (((1<<k)) *N0 *N1)
    ans %= M    

print(int(ans))

### FIXED CODE ###

M = 10**9+7
N = int(input())
A = list(map(int,input().split()))

ans = 0
for k in range(61):
    N1 = 0
    N1 = sum([1 for a in A if ( (a >> k) & 1)])
    ans += (((1<<k)) *(N-N1) *N1)
    ans %= M    

print(ans)
### BUGGY CODE ###

n, _ = map(int, input().split())
CST = {} # {c:[max_t, [s,t],...[,]]}
for i in range(n):
    s, t, c = map(int, input().split())
    if c in CST: CST[c] += [[s,t]]
    else: CST[c] = [t, [s,t]]
    CST[c][0] = max(CST[c][0], t)
ans = 0
R = [0]*200002
for c, ST in CST.items():
    mx_t = ST[0]*2+2
    TZ = [0]*mx_t
    for s,t in ST[1:]:
        TZ[2*s - 1] += 1
        TZ[2*t] -= 1
    for i in range(mx_t - 1):
        TZ[i+1] += TZ[i]
        if TZ[i+1] > 0:
            R[i+1] += 1
            if ans < R[i+1]: ans = R[i+1]
print(ans)


### FIXED CODE ###

N, C = map(int, input().split())
STC = [[*map(int, input().split())] for _ in range(N)]
mx_t = 200002
R = [0]*mx_t
for cc in range(1, C+1):
    TZ = [0]*mx_t
    for s,t,c in STC:
        if c == cc:
            TZ[2*s - 1] += 1
            TZ[2*t] -= 1
    for i in range(mx_t - 1):
        TZ[i+1] += TZ[i]
        if TZ[i+1] > 0: R[i+1] += 1
print(max(R))
### BUGGY CODE ###

from heapq import heapify, heappushpop

n, m = map(int, input().split())
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
heapify(aa)
for b, c in bcbc :
    for _ in range(min(n, b)) :
        heappushpop(aa, c)
print(sum(aa))

### FIXED CODE ###

from operator import itemgetter

n, m = map(int, input().split())
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
bcbc.extend([[1, a] for a in aa])
bcbc.sort(key=itemgetter(1), reverse=True)

count = 0
s = 0
for b, c in bcbc :
    if count + b >= n :
        b = n - count
    count += b
    s += b*c
    if count == n :
        break
print(s)
### BUGGY CODE ###

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

for i in que:
    for j in range(N):
        if arr[j] == i[0]:
            arr[j] = i[1]
    print(sum(arr))


### FIXED CODE ###

N = int(input())
arr = list(map(int, input().split()))
Q = int(input())
que = [list(map(int, input().split())) for _ in range(Q)]

count_list=[0]*(10**5+1)

for i in range(N):
    count_list[arr[i]] +=1

ans = sum(arr)

for i in que:
    keep = count_list[i[0]]
    c_ans = ans+keep*(i[1]-i[0])
    print(c_ans)
    ans =c_ans
    if count_list[i[0]] == 0:
        continue
    if count_list[i[0]] != 0:
        count_list[i[1]] += count_list[i[0]]
        count_list[i[0]] = 0
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxcomb = 0
x=0
y=0
def comb(n,r):
    npr = 1
    rp1 = 1
    for i in range(n-r+1,n+1):
        npr *= i
    for j in range(1,r+1):
        rp1 *= j
    return npr // rp1

comb(10,2)

for i in range(1,n):
    for j in range(0,i):
        if maxcomb < comb(b[i],b[j]):
            maxcomb = comb(b[i],b[j])
            x=b[i]
            y=b[j]
print(x,y)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
maxb = max(b)
mini = b[0]
for i in b:
    if abs(maxb/2 - i) < abs(maxb/2 - mini):
        mini = i
print(maxb,mini)
### BUGGY CODE ###

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

count = 0
prev = 1
ans = 1
for i in range(0, K):
  prev *= A[i]

for i in range(K, N):
  ans = prev
  ans //= A[count]
  ans *= A[i]
  if ans > prev:
    print("Yes")
  else:
    print("No")
  prev = ans
  count += 1



### FIXED CODE ###

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

for i in range(N-K):
    print('Yes' if A[i] < A[i+K] else 'No')
### BUGGY CODE ###

import sys

N = int(input())
P = [int(v) for v in input().split()]
cnt = 0
for i in range(N):
    flg = True
    for j in range(i):
        if P[i] > P[j]:
            flg = False
            break
    if flg:
        cnt += 1
print(cnt)




### FIXED CODE ###

import sys

N = int(input())
P = [int(v) for v in input().split()]
cnt = 0
M = 3 * 10 ** 5
for i in range(N):
    if M > P[i]:
        cnt += 1
    M = min(M,P[i])
print(cnt)
### BUGGY CODE ###

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

for i in range(n):
  print(a.count(int(i)+1))

### FIXED CODE ###

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

A = [0]*n
for i in range(n-1):
  A[a[i]-1] += 1
for j in range(n):
  print(A[j])
### BUGGY CODE ###

n = int(input())
possible = [1]
i=1
while i <= 100000:
  i = i*6
  possible+=[i]
i=1
while i <= 100000:
  i = i*9
  possible+=[i]
possible.sort(reverse =1)
ans = 1
table = set(possible)
while True:
  if n in table:
    print(ans)
    break
  ans+=1
  nexttable = set()
  for num in table:
    for p in possible:
      nexttable.add(num+p)
  table = table | nexttable

### FIXED CODE ###

n = int(input())
possible = [1]
i=1
while i <= 100000:
  i = i*6
  possible+=[i]
i=1
while i <= 100000:
  i = i*9
  possible+=[i]
possible.sort(reverse =1)
ans = 0
table = set([n])
while True:
  if 0 in table:
    print(ans)
    break
  ans+=1
  nexttable = set()
  for num in table:
    for p in possible:
      if num - p >= 0:
        nexttable.add(num-p)
  table =nexttable
### BUGGY CODE ###

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

ans = A
for i in range(B-A):
    ans = ans ^ (A + i + 1)

print(ans)


### FIXED CODE ###

def func(a):
    if(0 == a % 4):
        return(a)
    if(1 == a % 4):
        return(1)
    if(2 == a % 4):
        return(a + 1)
    if(3 == a % 4):
        return(0)

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

print(func(A - 1) ^ func(B))
### BUGGY CODE ###

class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def get_top(self):
        return self.top
    
    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top
 
dice = Dice(*map(int,input().split()))
n = int(input())
for i in range(n):
    a, b = input().split()
    if dice.east == b or dice.west == b:
        dice.rotate("W")
    while a != dice.top:
        dice.rotate("N")
    while b != dice.south:
        dice.rotate("W")
    print(dice.east)

### FIXED CODE ###

class Dice:
 
    def __init__(self, faces):
        self.faces = tuple(faces)
 
    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])
 
    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])
 
    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])
 
    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])
 
    def number(self, face_id):
        return self.faces[face_id - 1]
 
dice = Dice(list(map(int, input().split())))
n = int(input())
for i in range(n):
    (face1, face2) = map(int, input().split())
    if face2 == dice.number(3) or face2 == dice.number(4):
        dice.roll_west()
    while dice.number(2) != face2:
        dice.roll_north()
    while dice.number(1) != face1:
        dice.roll_west()
    print(dice.number(3))
### BUGGY CODE ###

from itertools import permutations
n_node, n_edge, R = map(int,input().split())
r_ls = list(map(int,input().split()))
for i in range(R):
    r_ls[i] -= 1
ad_mat = [[float('inf')]*n_node for _ in range(n_node)]
for i in range(n_node):
    ad_mat[i][i] = 0
for i in range(n_edge):
    a,b,c = map(int,input().split())
    ad_mat[a-1][b-1] = c
    ad_mat[b-1][a-1] = c

# ワーシャルフロイド
for start in range(n_node):
    for end in range(n_node):
        for stop in range(n_node):
            ad_mat[start][end] = min(ad_mat[start][end],ad_mat[start][stop]+ad_mat[stop][end])

ans = float('inf')
for path in permutations(r_ls):
    cost = 0
    for i in range(R-1):
        cost += ad_mat[path[i]][path[i+1]]
    ans = min(ans,cost)
print(ans)


### FIXED CODE ###

from itertools import permutations
n_node, n_edge, R = map(int,input().split())
r_ls = list(map(int,input().split()))
for i in range(R):
    r_ls[i] -= 1
ad_mat = [[float('inf')]*n_node for _ in range(n_node)]
for i in range(n_node):
    ad_mat[i][i] = 0
for i in range(n_edge):
    a,b,c = map(int,input().split())
    ad_mat[a-1][b-1] = c
    ad_mat[b-1][a-1] = c

# ワーシャルフロイド
for stop in range(n_node):
    for start in range(n_node):
        for end in range(n_node):
            ad_mat[start][end] = min(ad_mat[start][end],ad_mat[start][stop]+ad_mat[stop][end])

ans = float('inf')
for path in permutations(r_ls):
    cost = 0
    for i in range(R-1):
        cost += ad_mat[path[i]][path[i+1]]
    ans = min(ans,cost)
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A_cum = A.cumsum()
beauties = []
for i, j in itertools.combinations(range(N+1), 2):
    beauties.append(A_cum[j] - A_cum[i])

beauties.sort(reverse=True)
j = 0
def check(x):
    return sum([x&y == x for y in beauties]) >= K

answer = 0
for i in range(40, -1, -1):
    if check(answer + (1 << i)):
        answer += 1 << i

print(answer)
# 00


### FIXED CODE ###

import sys
import numpy as np
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = np.array([0] + lr())
A_cum = A.cumsum()
beauties = []
for i, j in itertools.combinations(range(N+1), 2):
    beauties.append(A_cum[j] - A_cum[i])

beauties = np.array(beauties)
j = 0
def check(x):
    return np.sum(beauties&x == x) >= K

answer = 0
for i in range(40, -1, -1):
    if check(answer + (1 << i)):
        answer += 1 << i

print(answer)
# 00
### BUGGY CODE ###

def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False


n = int(input())
d = []
for i in range(n):
    cmd, string = input().split()
    if cmd == "insert":
        d.append(string)
    else:
        if binarySearch(sorted(d), string):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

n = int(input())
d = {}
for i in range(n):
    cmd, string = input().split()
    if cmd == "insert":
        d[string] = True
    else:
        try:
            if d[string]:
                print("yes")
        except:
            print("no")
### BUGGY CODE ###

H, N = map(int, input().split())
A = []
max_A = 0
for i in range(N):
    A.append(tuple(map(int, input().split())))
    max_A = max(max_A, A[i][0])

INF = 10**9
dp = [INF] * (2 * 10 ** 4 + 1)
dp[0] = 0

for i in range(2 * 10 ** 4):
    for a, b in A:
        if i + a <= 2 * 10 ** 4:
            dp[i+a] = min(dp[i]+b, dp[i+a])

print(min(dp[H:]))

### FIXED CODE ###

H, N = map(int, input().split())
A = []
max_A = 0
for i in range(N):
    A.append(tuple(map(int, input().split())))
    max_A = max(max_A, A[i][0])

INF = 10**9
dp = [INF] * (2 * 10 ** 4 + 1)
dp[0] = 0

for i in range(2 * 10 ** 4):
    for a, b in A:
        if i + a <= 2 * 10 ** 4:
            dp[i+a] = min(dp[i]+b, dp[i+a])

print(min(dp[H:]))