Harryxun/stf_run huggingface dataset:
n = int(input())
if n%500 > A:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

n = int(input())
a = int(input())
if n%500 > a:
    print("No")
else:
    print("Yes")
m=10**9+7
i=s=r=0
f=1
input()
a=map(int,input().split())
for x in a:i+=1;s+=pow(i,m-2,m);r+=x*~-s+a[-i]*s;f=f*i%m
print(r*f%m)


### FIXED CODE ###

m=10**9+7
i=s=r=0
f=1
_,*a=open(0).read().split()
for x in a:i+=1;s+=pow(i,m-2,m);r+=int(x)*~-s+int(a[-i])*s;f=f*i%m
print(r*f%m)
import numpy as np
S = input()
mod = 10 ** 9 + 7

n = len(S)
dp = np.zeros((n, 13))
a = S[-1]
now, pre = 10, 1
x_ = dp[0]
if a == "?":
    x_[0:10] = 1
else:
    x_[int(a)] = 1
for s, x in zip(S[-2::-1], dp[1:]):
    if s == "?":
        for v in range(10):
            w = v * now % 13
            x[w:13] += x_[:13 - w]
            x[:w] += x_[13 - w:]
    else:
        v = int(s) * now % 13
        x[w:13] = x_[:13 - w]
        x[:w] = x_[13 - w:]
    x %= mod
    now, pre = (now - pre) % 13, now
    x_ = x
print(int(dp[-1][5]))

### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
S = input()

MOD = 10 ** 9 + 7


def main():
    n = len(S)
    m = 5
    w = []
    p = 1
    for i in range(n):
        s = S[-1 - i]
        if s == "?":
            w.append(p)
        else:
            m = (m - int(s) * p) % 13
        p = p * 10 % 13

    n = len(w)
    l1 = [0] * 13
    l1[0] = 1
    for i in range(1, n + 1):
        l2 = [0] * 13
        for j in range(10):
            x = w[i - 1] * j % 13
            for k in range(13):
                t = (x + k) % 13
                l2[t] += l1[k]
        l1 = [y % MOD for y in l2]
    
    ans = l1[m]
    print(ans)


if __name__ == "__main__":
    main()
a=int(input())
print(700+a.count("o")*100)

### FIXED CODE ###

a=input()
print(700+a.count("o")*100)
n,m=map(int,input().split())
sw=[[]*m]
for _ in range(m):
    temp=list(map(int,input().split()))
    sw[_]=temp[1:]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    temp=[0]*n
    for j in range(n):
        if i&1: temp[j]=1
        i>>=1
    flag=1
    for l,s in enumerate(sw):
        cnt=0
        for k in s:
            if temp[k-1]==1: cnt+=1
        if p[l]!=cnt%2:
            flag=0
            break
    if flag: ans+=1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
sw=[[] for _ in range(m)]
for _ in range(m):
    temp=list(map(int,input().split()))
    sw[_]=temp[1:temp[0]+1]
p=list(map(int,input().split()))

ans=0
for i in range(2**n):
    temp=[0]*n
    for j in range(n):
        if i&1: temp[j]=1
        i>>=1
    flag=1
    for l,s in enumerate(sw):
        cnt=0
        for k in s:
            if temp[k-1]==1: cnt+=1
        if p[l]!=cnt%2:
            flag=0
            break
    if flag: ans+=1
print(ans)
k = int(input())
a, b = map(int, input().split())
ans = 0
for i in range(1000):
  j = k*i - a
  if a <= j and j <= b:
    print('OK')
    break
  elif:
    print('NG')

### FIXED CODE ###

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

for i in range(b+1):
    s = k*i
    if a <= s and s <= b:
        print('OK')
        break
    elif s > b:
        print('NG')
        break
input_str = str(input()).split()
a, b, k = int(input_str[0]), int(input_str[1]), int(input_str[2])

self = a
partner = b

for i in range(k):
    if self % 2 == 1:
        self += -1

    partner += int(self / 2)
    self = int(self / 2)

    self, partner = partner, self
    i -= 1

if i % 2 == 1:
    a = partner
    b = self
else:
    b = partner
    a = self

print(a, b)


### FIXED CODE ###

s = input()

if s.__len__() == 3:
    print(s[::-1])
else:
    print(s)
A,B,C = map(int,input().split())
if C-A+B>0:print(C=A+B)
else:print(0)


### FIXED CODE ###

A,B,C = map(int,input().split())
if C-A+B>0:
    print(C-A+B)
else:
    print(0)
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from math import gcd

def main():
    n = int(input())
    if n == 1:
        print('Hello World')
    else:
        a = int(input())
        b = int(input())
        print(a + b)
if __name__ =='__main__':
    main()   


### FIXED CODE ###

MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    n = int(input())
    if n == 1:
        print('Hello World')
    else:
        a = int(input())
        b = int(input())
        print(a + b)
if __name__ =='__main__':
    main()
a, b = int(input().split())
if a <= 9 and b <= 9:
	c = a * b
	print(c)
else:
	print('-1')	
	

### FIXED CODE ###

a, b = map(int, input().split())
if a <= 9 and b <= 9:
	c = a * b
	print(c)
else:
	print('-1')
def make_tree(node):
    for i in tree_list[node]:
        if i != tree_dic[node]["p"]:
            tree_dic[node]["c"].append(i)
            tree_dic[i]["p"] = node
            make_tree(i)

n, q = map(int, input().split())
tree_list = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    tree_list[a-1].append(b-1)
    tree_list[b-1].append(a-1)

tree_dic = {} #tree_dic = {i:{p:j, c:[k, l]}}
for i in range(n):
    tree_dic[i] = {"p": None, "c": [], "x": 0}

make_tree(0)

for i in range(q):
    p, x = map(int, input().split())
    tree_dic[p-1]["x"] += x
# print(tree_dic)
x_list = [0 for _ in range(n)]
for i in range(n):
    tmp = 0
    p = i
    while True:
        tmp += tree_dic[p]["x"]
        if p == 0:
            break
        p = tree_dic[p]["p"]
    x_list[i] = tmp

print(x_list)

### FIXED CODE ###

n, q = map(int, input().split())
tree_candidate = [[] for _ in range(n)]

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

tree = [[] for _ in range(n)]

app = set([0])

import queue
next = queue.Queue()
next.put(0)
# print(tree_candidate)
while not next.empty():
    i = next.get()
    for j in tree_candidate[i]:
        if not j in app:
            tree[i].append(j)
            app.add(j)
            next.put(j)

cnts = [0 for _ in range(n)]
for i in range(q):
    p, x = map(int, input().split())
    cnts[p-1] += x
    # print(x, p, tree[p-1], cnts)

next = queue.Queue()
next.put(0)

while not next.empty():
    i = next.get()
    for j in tree[i]:
        cnts[j] += cnts[i]
        next.put(j)

for i in cnts:
    print(i, end=' ')
a,b,c,d,e,f = map(int, input().split())
wvs = []
va = 0
while va <= f:
    va += 100*a
    vab = va
    while vab <= f:
        wvs.append(vab)
        vab += 100*b

svs = []
vc = 0
while vc+100*a <= f:
    vc += c
    vcd = vc
    while vcd+100*a <= f:
        svs.append(vcd)
        vcd += d

n = []
for w in wvs:
    for s in svs:
        if w+s > f:
            break
        if s/w > e/100:
            break
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])


### FIXED CODE ###

a,b,c,d,e,f = map(int, input().split())
ws = []
for i in range(f//100//a+1):
    for j in range(f//100//b+1):
        w = 100*(a*i+b*j)
        if 0 < w <= f:
            ws.append(w)
        if w >= f:
            break
ss = []
for i in range(f*e//(100+e)//c+1):
    for j in range(f*e//(100+e)//d+1):
        s = c*i+d*j
        if 0 <= s <= f*e//(100+e):
            ss.append(s)
n = []
for w in ws:
    for s in ss:
        if w+s > f:
            continue
        if s > e*w//100:
            continue
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])
n,m=map(int,input().split())#正方形
a= [list(input()) for n in range(n)] #大
b= [list(input()) for m in range(m)] #小
m1=0
for i in range(n-m+1): #行
    for j in range(n-m+1): #左からの位置
      if b[i][j+k]==a[i][j] for k in range(n-m+1):m1+=1
        if m1==m:print('Yes') and exit()
        else:pass
      else:print('No')

### FIXED CODE ###

n,m = map(int,input().split()) #要復習
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
 
for i in range(n-m+1):
    for j in range(n-m+1):
        a1 = [a[k][j:j+m] for k in range(i,i+m)]
        if a1 == b:
            print('Yes')
            exit()

print('No')
s = input()
s1 = s[0:1]
s2 = s[2:3]

i1 = int(s1)
i2 = int(s2)

if i1 = 0 or i2 = 0: res =NA
if i1 <=12:
	if i2 <= 12:
		res = "AMBIGUOUS"
    else:
      	res = "MMYY"
elif 12 < i1:
  	if i2 <= 12:
      	res = "YYMM"
    else:
      	res = NA
        
print(res)

### FIXED CODE ###

s = input()
s1 = s[0:2]
s2 = s[2:4]

i1 = int(s1)
i2 = int(s2)
 
if 1 <= i1 <=12 and 1 <= i2 <= 12:
    res = "AMBIGUOUS"
elif 1 <= i1 <= 12:
    res = "MMYY"
elif 1 <= i2 <= 12:
    res = "YYMM"
else:
    res = "NA"

print(res)
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort()

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]

  ans_list.sort(reverse=True)
  # print(ans_list)
  i=0
  for _ in range(c):
    if len(lc)==0:
      break
    if x+y<len(lc):
      lc.pop()
    else:
      while True:
        if len(ans_list)<=i:
          break
        _c=lc.pop()
        if ans_list[i]<_c:
          ans_list[i]=_c
        else:
          lc.append(_c)
        i+=1

  # print(ans_list)
  return sum(ans_list)

# main()
print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort(reverse=True)

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]
  ans_list+=lc[:(x+y)]

  ans_list.sort(reverse=True)


  # print(ans_list)
  return sum(ans_list[:x+y])

# main()
print(main())
N = int(input())
LR = [tuple(map(int,input().split()))for i in [None] * N]
Lmin = sorted(LR,key=lambda x:x[0])
Rmax = sorted(LR,key=lambda x:x[1],reverse=True)

T = 0
def t_len(lr):
    a = lr[1] - T
    b = T - lr[0]
    return  a if a > b else b

def select(l):
    return sorted(l,key=t_len,reverse=True)[0]

def select2(l):
    a = abs(Lmin[0][0] - T)
    b = abs(Rmax[0][1] - T)
    return Lmin[0] if a > b else Rmax[0]

def selectT(lr):
    if lr[0] <= T <= lr[1]:
        return T
    a = lr[1] - T
    b = T - lr[0]
    return  lr[0] if a > b else lr[1]
K = 0
for i in [None]*N:
    s = select2(LR)
    nextT = selectT(s)
    K += abs(nextT-T)
    T = nextT
    LR.remove(s)
    Lmin.remove(s)
    Rmax.remove(s)
K += abs(T)
print(K)

### FIXED CODE ###

N = sum([int(i) for i in input()])
print('10' if N == 1 else N)
S = input()[::-1]

## 余りを0~2018で総数保持
counts = [0]*2019
## 0桁の余りは0
counts[0] = 1

num, d = 0, 1

for c in s:
  ## 右から~桁の数字
  num += int(c) * d
  num %= 2019
  
  ## 次の桁
  d *= 10
  #d %= 2019
  
  counts[num] += 1
  
ans = 0
for cnt in counts:
  ## nC2の計算
  ans += cnt * (cnt-1) //2
  
print(ans)

### FIXED CODE ###

S = input()[::-1]
 
## 余りを0~2018で総数保持
counts = [0]*2019
## 0桁の余りは0
counts[0] = 1
 
num, d = 0, 1
 
for c in S:
  ## 右から~桁の数字
  num += int(c) * d
  num %= 2019
  
  ## 次の桁
  d *= 10
  d %= 2019
  
  counts[num] += 1
  
ans = 0
for cnt in counts:
  ## nC2の計算
  ans += cnt * (cnt-1) //2
  
print(ans)
import sys

def fill(s): return '0' * (6 - len(s)) + s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(*[iter(py)] * 2, range(m)))

def main():
    res = [None] * m
    prev = j = None
    for p, y, i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()

### FIXED CODE ###

# 2019-11-11 14:35:02(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 
from copy import deepcopy

def main():
    n, m = (int(x) for x in sys.stdin.readline().split())
    PY = [[int(x) for x in sys.stdin.readline().split()] for _ in range(m)]
    py = sorted(deepcopy(PY))

    ids = dict()
    for i in range(m):
        p, y = py[i][0], py[i][1]
        if not p in ids:
            ids[p] = dict()
            x = 0
        x += 1
        id_i = '0' * (6 - (math.floor(math.log10(p)) + 1)) + str(p) + '0' * (6 - (math.floor(math.log10(x)) + 1)) + str(x)
        ids[p][y] = id_i
    
    for i in range(m):
        p, y = PY[i][0], PY[i][1]
        print(ids[p][y])


if __name__ == "__main__":
    main()
class BufInput:
  def __init__(self):
    self.save = False
    self.buf = None
  def read(self, save=False):
    if self.save:
      ret = self.buf
    else:
      try:
        ret = input()
      except EOFError as e:
      	ret = None
    self.save = save
    self.buf = ret
    return ret
    
  
bi = BufInput()
while bi.read(True):
  n, k = map(int, bi.read().split())
  s = bi.read().rstrip()

  def findEx(s, f, pos, notfound):
    pos = s.find(f, pos)
    if pos == -1:
      pos = notfound
    return pos

  ans = 0
  left = 0
  right = 0
  while right < n:
      if k > 0:
          right = findEx(s, '01', right, n-1) + 1
          k = k - 1
          right = findEx(s, '10', right, n-1) + 1
          ans = max(ans, right - left)
      else:
          left = findEx(s, '01', left, n-1) + 1
          k = k + 1

  print(ans)


### FIXED CODE ###

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

AB = []
AB += [A, B]

def push(AB):
  if AB[0] >= AB[1]:
    i = 0
  else:
    i = 1
  ret = AB[i]
  AB[i] -= 1
  return ret

s = 0
for _ in range(2):
	s += push(AB)

print(s)
n=int(input())
a=list(map(int,input().split()))
x=[0,0,0]
count=1
mod=10**9+7
for i in range(n):
  if x[0]==0 and a[i]==0:
    x[0]+=1
    count=count*3
  elif x[1]==0 and a[i]==0:
    x[1]+=1
    count=count*2
  elif x[2]==0 and a[i]==0:
    x[2]+=1
    count=count*1
  else:
    count=count*x.count(a[i])
    x[x.index(a[i])]+=1
print(count%mod)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
x=[0,0,0]
count=1
mod=10**9+7
for i in range(n):
  if x[0]==0 and a[i]==0:
    x[0]+=1
    count=count*3
  elif x[1]==0 and a[i]==0:
    x[1]+=1
    count=count*2
  elif x[2]==0 and a[i]==0:
    x[2]+=1
    count=count*1
  else:
    if x.count(a[i])==0:
      count=0
      break
    else:
      count=count*x.count(a[i])
      x[x.index(a[i])]+=1
print(count%mod)
A, B = map(int, input().split())
if int(A/0.08*0.1) == B :
    print(int(A/0.08))
else:
    print(-1)


### FIXED CODE ###

S = input()
if S.find("A") == -1 or S.find("B") == -1:
    print("No")
else:
    print("Yes")
n=int(input())
a=(list(map(int,input().split()))
b=list()
for i in range(n):
  b.append(1+a.index(1+i))
print(*b)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[[a[i],i] for i in range(n)]
b.sort()
for i in b:
  print(i[1]+1,end=" ")
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)))


### FIXED CODE ###

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


def solve():
    n, k = map(int, input().split())
    hl = [int(input()) for _ in range(n)]
    hl.sort()
    diff = hl[k - 1] - hl[0]
    for i in range(0, n - k + 1):
        td = hl[k - 1 + i] - hl[i]
        diff = min(td, diff)
    print(diff)


if __name__ == "__main__":
    solve()
n = int(input())
x = [int(i) for i in input().split()]

for i in x:
    if i > statistics.median(sorted(x)[0:len(x)-1]):
        print(statistics.median(sorted(x)[0:len(x)-1]))
    else:
        print(statistics.median(sorted(x)[1:len(x)]))

### FIXED CODE ###

n = int(input())
xm = list(map(int, input().split()))
xm_sort = sorted(xm)
a = n//2-1
for i in range(n):
    if xm[i]<=xm_sort[a]:
        print(xm_sort[a+1])
    else:
        print(xm_sort[a])
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    name_roop = []

    level = 1

    ans = ""
    n = 26
    for i in range(30):
        if N > n:
            n += 26**(i+2)
            level += 1
        else:
            break

    for i in range(level, 1, -1):
        count = 0
        a = 26**(i-1)
        for _ in range(27):
            if N-a > 0:
                N -= a
                count += 1
            if N <= a:
                name_roop.append(count)
                break

    for i in name_roop:
        ans += ascii_lowercase[i-1]
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    name_roop = []

    level = 1

    ans = ""
    while N > 0:
        N -= 1
        n = N % 26
        ans += ascii_lowercase[n]
        N //= 26
    print(ans[::-1])
    # for i in range(level, 1, -1):
    #     count = 0
    #     a = 26**(i-1)
    #     for j in range(26):
    #         if N-a > 26**(i-2):
    #             N -= a
    #             count += 1
    #     name_roop.append(count)

    # name_roop.append(N)
    # for i in name_roop:
    #     ans += ascii_lowercase[i-1]
    # print(ans)


if __name__ == '__main__':
    main()
from scipy.special import comb
N=[int(x) for x in input().split()]
if N[1]==1:
  sum1=0
else:
  sum1 = comb(N[1], 2, exact=True)
if N[0]==1:
  sum2=0
else:
    sum2 = comb(N[0], 2, exact=True)
print(sum1+sum2)

### FIXED CODE ###

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N=[int(x) for x in input().split()]
if N[1]==1 or N[1]==0:
  sum1=0
else:
  sum1 = comb(N[1], 2)
if N[0]==1 or N[0]==0:
  sum2=0
else:
    sum2 = comb(N[0], 2)
print(sum1+sum2)
import math


n = int(input())
a = [int(x) for x in input().split(" ")]
g = a.sort()[n - 1]


for i in range(1, n):
    g = math.gcd(g, a[i])


print(g)

### FIXED CODE ###

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

def m(a):
    a.sort()
    l = len(a)
    b = []
    for i in range(l // 2):
        b.append(gcd(a[i], a[l - i - 1]))
    if l % 2 == 1:
        b.append(a[l // 2])
    return list(set(b))

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

while len(a) > 1:
    a = m(a)

print(a[0])
# 新ステージでは、一度全部どんぐりに直してから換金を始めるとしてよい

def F(N, A, B):
  # N個のどんぐりを、Aで換金してからBに持っていく
  # Bでどんぐりに直す
  A,B = zip(*[(x,y) for x,y in zip(A,B) if x < y])
  dp = [0] * (N+1)
  for n in range(N+1):
    x = n
    for j in range(3):
      if n >= A[j]:
        y = dp[n-A[j]] + B[j]
        if x < y:
          x = y
    dp[n] = x
  return dp[N]

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

answer = F(F(N,A,B),B,A)
print(answer)


### FIXED CODE ###

# 新ステージでは、一度全部どんぐりに直してから換金を始めるとしてよい

def F(N, A, B):
  # N個のどんぐりを、Aで換金してからBに持っていく
  # Bでどんぐりに直す
  dp = [0] * (N+1)
  for n in range(N+1):
    x = n
    for j in range(3):
      if n >= A[j]:
        y = dp[n-A[j]] + B[j]
        if x < y:
          x = y
    dp[n] = x
  return dp[N]

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

answer = F(F(N,A,B),B,A)
print(answer)
from typing import List, Dict

INF = 10**9+1


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

def remove_if_gt(a, b):
    if a >= b:
        return a-b
    return a

def solve() -> int:
    N, K = read_ints()
    A = read_ints()
    S = []
    for i in range(N):
        prefix = 0
        for j in range(i, N):
            prefix += A[j]
            S.append(prefix)
    S.sort(reverse=True)
    highest_bit = 40
    answer = 0
    while highest_bit >= 0:
        while 1<<highest_bit > S[0]:
            highest_bit -= 1
            if highest_bit < 0:
                return answer
        highest_bit_val = 1<<highest_bit
        count = 0
        for i in range(N):
            if S[i]&highest_bit_val != 0:
                count += 1
            else:
                break
        if count < K:
            S = [remove_if_gt(s, highest_bit_val) for s in S]
        else:
            answer += highest_bit_val
            S = [remove_if_gt(s, highest_bit_val) for s in S if s >= highest_bit_val]
        S.sort(reverse=True)
    return answer


if __name__ == '__main__':
    print(solve())


### FIXED CODE ###

from typing import List, Dict

INF = 10**9+1


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

def remove_if_gt(a, b):
    if a >= b:
        return a-b
    return a

def solve() -> int:
    N, K = read_ints()
    A = read_ints()
    S = []
    for i in range(N):
        prefix = 0
        for j in range(i, N):
            prefix += A[j]
            S.append(prefix)
    S.sort(reverse=True)
    highest_bit = 40
    answer = 0
    while highest_bit >= 0:
        while 1<<highest_bit > S[0]:
            highest_bit -= 1
            if highest_bit < 0:
                return answer
        highest_bit_val = 1<<highest_bit
        count = 0
        for i in range(len(S)):
            if S[i] >= highest_bit_val:
                count += 1
            else:
                break
        if count < K:
            S = [remove_if_gt(s, highest_bit_val) for s in S]
        else:
            answer += highest_bit_val
            S = [remove_if_gt(s, highest_bit_val) for s in S if s >= highest_bit_val]
        S.sort(reverse=True)
    return answer


if __name__ == '__main__':
    print(solve())
n = input()
s = map(int, raw_input().split())
ans = s[-1]
dp = [[0] * 21 for i in range(n)]
dp[0][s[0]] = 1
for i in range(1, n-1):
    for j in range(21):
        if dp[i-1][j] == 0: continue
        vp = j + s[i]
        vm = j - s[i]
        if vp <= 20:
            dp[i][vp] += dp[i-1][j]
        if 0 <= vm:
            dp[i][vm] += dp[i-1][j]
print dp[n-2][ans

### FIXED CODE ###

n = input()
s = map(int, raw_input().split())
ans = s[-1]
dp = [[0] * 21 for i in range(n)]
dp[0][s[0]] = 1
for i in range(1, n-1):
    for j in range(21):
        if dp[i-1][j] == 0: continue
        vp = j + s[i]
        vm = j - s[i]
        if vp <= 20:
            dp[i][vp] += dp[i-1][j]
        if 0 <= vm:
            dp[i][vm] += dp[i-1][j]
print dp[n-2][ans]