Harryxun/stf_run huggingface dataset:
n = int(input())
A = list(map(int,input().split()))

def zenbu(m, B):
    dp = [-10**9]*m
    if dp[m-1] > -10**9:
        return dp[m-1]
    elif m == 1:
        dp[0] = B[0]
        return dp[0]
    elif m == 2:
        dp[1] = max(B[0],B[1])
        return dp[1]
    elif m == 3:
        dp[2] = max(B[0],B[1],B[2])
        return dp[2]
    elif m%2 == 0: #偶数の場合
        temp = 0
        for i in range(m//2-1):
            temp += B[i*2]
        dp[m-1] = max(temp+ max(B[m-2],B[m-1]), zenbu(m-2, B)+ B[m-1])
        return dp[m-1]
    else:#奇数の場合
        temp = 0
        for i in range((m-1)//2):
            temp += B[i*2]
        dp[m-1] = max(temp, zenbu(m-2,B)+ B[m-1], zenbu(m-3,B)+ max(B[m-2],B[m-1]))
        return dp[m-1]

ans = zenbu(n,A)

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
if N%2 == 0:
  dp = [[0]*2 for _ in range(N)] #0index
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  for i in range(2,N):
    dp[i][0] = dp[i-2][0]+A[i]
    if i-3>=0:
      dp[i][1] = max(dp[i-2][1],dp[i-3][0])+A[i]
    else:
      dp[i][1] = max(dp[i-2][1],0)+A[i]
  ans = max(dp[-2][0],dp[-1][1])
  print(ans)
#i個目を使ってj(0-2)回多く飛んでいる。
else: #N%2 == 1:
  dp = [[0]*3 for _ in range(N)] #0index
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  dp[2][2] = A[2]
  dp[2][0] = A[0]+A[2]
  #print(dp)
  for i in range(3,N):
    dp[i][0] = dp[i-2][0]+A[i]
    if i-3 >= 0:
      dp[i][1] = max(dp[i-2][1],dp[i-3][0])+A[i]
    else:
      dp[i][1] = max(dp[i-2][1],0)+A[i]
    if i-4 >= 0:
      dp[i][2] = max(dp[i-2][2],dp[i-3][1],dp[i-4][0])+A[i]
    elif i-3 >= 0:
      dp[i][2] = max(dp[i-2][2],dp[i-3][1],0)+A[i]
  #else:
  #  dp[i][2] = max(dp[i-2][2],0,0)+A[i]
  #print(dp[-1],dp[-2],dp[-3])

  ans = max(dp[-3][0],dp[-2][1],dp[-1][2])
  print(ans)
  exit()
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
from math import gcd
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a,b = iia()

print(int(a*b/gcd(a,b)))

### FIXED CODE ###

import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter

def gcd(a,b):
	if(b==0):
		return a
	return gcd(b,a%b)
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())

a,b = iia()

print(int((a*b)/gcd(a,b)))
a,b = map(int, input().split())
if a>b: print('GREATER')
elif a<b: print('LESS')
else: print('EQUAL')

### FIXED CODE ###

a = int(input())
b = int(input())
if a>b: print('GREATER')
elif a<b: print('LESS')
else: print('EQUAL')
x = raw_input()
y = raw_input()
z = raw_input()
print(x[0]+y[1]+z[2])

### FIXED CODE ###

x = input()
y = input()
z = input()
print(x[0]+y[1]+z[2])
from collections import defaultdict
dic = defaultdict(int)
N, X, M = map(int, input().split())
A = [X]
ans = X

temp = 1
dic[X]=temp
for i in range(2, N+1):
    a = A[-1]*A[-1]%M
    if dic[a]>0:
        
        fir = dic[a]
        break
    A.append(a)
    ans+=a
    temp+=1
    dic[a]=temp
T = temp-fir+1#周期
Tsum = 0 #周期の和
TempSum = 0 #後半あまりの和
M=N-fir+1 # 先頭のぞく 
amari = M%T # 後半あまり
for k in dic:
    if dic[k]>=fir and dic[k]<=temp:
        Tsum+=k
    if dic[k]>=fir and dic[k]<fir+amari:
        TempSum += k
ans+=TempSum
ans+=Tsum*(M//T-1)
print(ans)

### FIXED CODE ###

from collections import defaultdict
dic = defaultdict(int)
N, X, M = map(int, input().split())
A = [X]
ans = X
fir = -1
if N>1:
    temp = 1
    dic[X]=temp
    for i in range(2, N+1):
        a = A[-1]*A[-1]%M
        if dic[a]>0:
            fir = dic[a]
            break
        A.append(a)
        ans+=a
        temp+=1
        dic[a]=temp
    if fir!=-1:
        T = temp-fir+1#周期
        Tsum = 0 #周期の和
        TempSum = 0 #後半あまりの和
        M=N-fir+1 # 先頭のぞく 
        amari = M%T # 後半あまり
        for k in dic:
            if dic[k]>=fir and dic[k]<=temp:
                Tsum+=k
            if dic[k]>=fir and dic[k]<fir+amari:
                TempSum += k
        ans+=TempSum
        ans+=Tsum*(M//T-1)
    print(ans)
else:
    print(ans)
inp=raw_input().split()
a=int(inp[0])
b=int(inp[1])
c=int(inp[2])
if(c<=(a+b)):
	print(b+c)
else:
	print(a+b+b+1)


### FIXED CODE ###

inp=raw_input().split()
a=int(inp[0])
b=int(inp[1])
c=int(inp[2])
if(c<=(a+b)):
	print(b+c)
else:
	print(a+b+b+1)
lst = sorted(list(map(int, input().split)))
if lst[0] + lst[1] == lst[2]:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

lst = list(map(int, input().split()))
lst.sort()
if lst[0] + lst[1] == lst[2]:
  print("Yes")
else:
  print("No")
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main(){
  long int n, i = 1;
  cin >> n;
  for(long int j = 1; j <= n; j++){
    i *= j;
    i %= MOD;
  }
  cout << i << endl;
  return 0;
}


### FIXED CODE ###

p = 1
for i in range(int(input())):
    p = ((i + 1)*p) % (10**9 + 7)
print(p)
h = w = 0
slist =[]
list1=[]
def dfs(f):
    while True:
        if len(slist) == 0:
            return 1
        coordinate= slist.pop()
        #print(coordinate)
        x = coordinate[0]
        y = coordinate[1]

        list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]
        if x + 1 < w:
            if list1[y][x + 1] == f:
                slist.append([x + 1,y])
        if x - 1 >= 0:
            if list1[y][x-1] == f:
                slist.append([x - 1, y])
        if y + 1 < h:
            if list1[y + 1][x] == f:
                slist.append([x, y + 1])
        if y -1 >= 0:
            if list1[y -1][x] == f:
                slist.append([x, y - 1])

while True:
    h, w = list(map(lambda x: int(x),input().split(" ")))
    if 0 in (h, w):
        break
    n = 0
    for i in range(0, h):
        list1.append(input())
    for i in range(0, h):
        for j in range(0, w):
            if list1[i][j] != '1':
                slist.append([j,i])
                n += dfs(list1[i][j])
            #print(list1)
    print(n)

### FIXED CODE ###

h = w = 0
slist =[]
list1=[]
def dfs(f):
    while True:
        if len(slist) == 0:
            return 1
        coordinate= slist.pop()
        #print(coordinate)
        x = coordinate[0]
        y = coordinate[1]

        list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]
        if x + 1 < w:
            if list1[y][x + 1] == f:
                slist.append([x + 1,y])
        if x - 1 >= 0:
            if list1[y][x-1] == f:
                slist.append([x - 1, y])
        if y + 1 < h:
            if list1[y + 1][x] == f:
                slist.append([x, y + 1])
        if y -1 >= 0:
            if list1[y -1][x] == f:
                slist.append([x, y - 1])

while True:
    h, w = list(map(lambda x: int(x),input().split(" ")))
    if 0 in (h, w):
        break
    n = 0
    for i in range(0, h):
        list1.append(input())
    for i in range(0, h):
        for j in range(0, w):
            if list1[i][j] != '1':
                slist.append([j,i])
                n += dfs(list1[i][j])
            #print(list1)
    print(n)
    list1=[]
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
a = sorted(a)
bc = sorted(bc, key=lambda x: -x[1])
a_len = len(a)
i = 0
for one in bc:
    for j in range(one[0]):
        if i > a_len-1:
            break
        if a[i] > one[1]:
            break
        a[i] = one[1]
        i += 1
print(sum(a))

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]
a = sorted(a)
bc = sorted(bc, key=lambda x: -x[1])
a_len = len(a)
i = 0
for one in bc:
    for j in range(one[0]):
        if i > a_len-1:
            break
        if a[i] > one[1]:
            break
        a[i] = one[1]
        i += 1
print(sum(a))
N=int(input())
  A=list(map(int,input().split()))
  if 0 in A:
    print(0)
  prod=1
  for a in A:
    prod*=a
    if prod>10**18:
      print(-1)
   
  print(prod)

### FIXED CODE ###

N = int(input())
L = input().split()
 
 
def mult():
    if "0" in L:
        return 0
    else:
        a = 1
        for i in L:
            a = a * int(i)
            if a > 1000000000000000000:
                return -1
        return a
 
print(mult())
import sys
def main():
    A,B,N=tuple(map(int,sys.stdin.readline().split()))
    L=min([B-1,N])
    print(max(list(map(lambda c:(A*c)//B,list(range(1,L+1))))))
if __name__=='__main__':main()

### FIXED CODE ###

import sys
def main():
    A,B,N=tuple(map(int,sys.stdin.readline().split()))
    L=max([1,min([B-1,N])])
    print((A*L)//B) if B!=1 else print(0)
if __name__=='__main__':main()
for i in xrange(input()):
	n = sorted(raw_input())
	x = int("".join(n[::-1]))
	for j in xrange(len(n)):
		if n[i] == "0": del n[i]
		else: break
	print x - int("".join(n))

### FIXED CODE ###

for i in xrange(input()):
	s = sorted([s for s in raw_input()])
	print int("".join(reversed(s))) - int("".join(s))
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
def moji(s):
    tmp = []
    for i in range(10):
        tmp.append(s[i])
    tmp.sort()
    new_s = ''
    for i in range(10):
        new_s += tmp[i]
    return new_s

N = int(input())
dic = {}
ans = 0
for i in range(N):
    tmp = moji(input())
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
for i in dic.values():
    ans += C(i,2)
print(ans)

### FIXED CODE ###

import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = {}
ans = 0
for _ in range(N):
    S = input()
    tmp_arr = []
    for i in range(10):
        tmp_arr.append(S[i])
    tmp_arr.sort()
    moji_sorted = ''
    for i in tmp_arr:
        moji_sorted += i
    if moji_sorted in arr:
        arr[moji_sorted] += 1
    else:
        arr[moji_sorted] = 1
# print(arr)

for i in arr.values():
    if i-2 >= 0:
        ans += C(i,2)

print(ans)
from math import gcd

X = int(input())

line = input()
numbers = [int(n) for n in line.split()]

num_factors = [factors(num) for num in numbers]
left_list = [0]*(X+1)
right_list = [0]*(X+1)
for i in range(X):
    left_list[i+1] = gcd(left_list[i], numbers[i])
    right_list[X-1-i] = gcd(right_list[X-i], numbers[X-1-i])
predicted_value = max([gcd(left_list[i], right_list[i+1]) for i in range(X)])


print(predicted_value)

### FIXED CODE ###

from fractions import gcd

X = int(input())

line = input()
numbers = [int(n) for n in line.split()]

left_list = [0]*(X+1)
right_list = [0]*(X+1)
for i in range(X):
    left_list[i+1] = gcd(left_list[i], numbers[i])
    right_list[X-1-i] = gcd(right_list[X-i], numbers[X-1-i])
predicted_value = max([gcd(left_list[i], right_list[i+1]) for i in range(X)])

print(predicted_value)
s = int(input())
a = [s]
z = set(s)
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)


### FIXED CODE ###

s = int(input())
a = [s]
z = set([s])
idx = 1
for i in range(10**8):
    idx += 1
    if a[i] % 2 == 0:
        ai = a[i] // 2
    else:
        ai = 3 * a[i] + 1
    if ai in z:
        print(idx)
        exit()
    a.append(ai)
    z.add(ai)
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if (a*b) >= 1:
    child = abs(b-a)
else:
    child = abs(a) + abs(b)

try:
    n = child/(v-w)
except ZeroDivisionError:
    n = -1
if n.is_integer() and n>=0 and n <= t:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())


if (a*b) < 0:
    child = max(a,b) - min(a,b)
else:
    child = abs(b-a)

mother = v-w
if mother <= 0:
    print('NO')
    exit()

n = child/mother
if n>0 and n<=t:
    print('YES')
else:
    print('NO')
N,M=map(int,input().split())
u=0
for i in range(M):
  a,b=list(map(int,input().split()))
for i in range(M):
  if a[i]==1:
    s=b[i]
    idxlist=[]
    for idx,val in enumerate(a):
      if val==s:
        idxlist.append(idx)
    for j in idxlist:
      if b[j]!=N:
        u+=1
if u==len(idxlist):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

### FIXED CODE ###

N,M=map(int,input().split())
x=[]
for i in range(M):
  a,b=map(int,input().split())
  if a==1:
    x.append(b)
  if b==N:
    x.append(a)
l=len(x)
if len(set(x))==l:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")
n,m=[int(i) for i in input().split()]
l=[]
c=[input() for i in range(n)]
l=sorted(c)
b=l[0:m]
maxs=max(b)-min(b)
for i in range(0,(n-m)):
    b.pop(0)
    b.append(l[i+m])
    f=(max(b)-min(b))
    if(f<maxs):
        maxs=f
print(maxs)

### FIXED CODE ###

N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])

hmax = 0
hmin = 0
ans = 10**10
for i in range(N - K + 1):
    hmax = h[i + K - 1]
    hmin = h[i]
    if hmax - hmin < ans:
        ans = hmax - hmin
print(ans)
x,n = map(int,input().split())
if n == 0:
  ans = x
else:
  p = [int(i.strip()) for i in input().split()]
  for i in range(n):
    ch_1 = x-i
    ch_2 = x+i
    if p.count(ch_1) == 0:
      ans = ch_1
      break
    elif p.count(ch_2) == 0:
      ans = ch_2
      break
print(ans)

### FIXED CODE ###

x,n = map(int,input().split())
if n == 0:
  ans = x
else:
  p = [int(i.strip()) for i in input().split()]
  for i in range(n+1):
    ch_1 = x-i
    ch_2 = x+i
    if p.count(ch_1) == 0:
      ans = ch_1
      break
    elif p.count(ch_2) == 0:
      ans = ch_2
      break
print(ans)
'''
Created on 2017/03/26

@author: Tomoya
'''
import math

# D - Maximum Average Sets
# 問題URL:http://abc057.contest.atcoder.jp/tasks/abc057_d

# N:商品の数　A個以上B個以下の範囲で選ぶ
N, A, B = map(int, input().split())
# C：最大価値組み合わせ総数
C = 0
# cnt:カウンター
cnt = 0

# 商品価値をリストに入れる
V = [int(value) for value in input().split()]
# 商品価値が高い順に並び替え
V.sort(reverse=True)

# 商品価値が高いものから出来るだけ少なく（＝A個）選ぶのが最も平均価値が高くなる
S = V[0:A]
ave = sum(S) / A
print(ave)

Vs = V.count(min(S)) # A個選んだ中で最も低い価値を持つ商品は、もともとの商品リストの中にいくつあるか
Ss = S.count(min(S)) # A個選んだ時中で最も低い価値を持つ商品はいくつあるか

if V[0]== V[A-1]: # もしもA個選んだ中の商品価値が全て同じだったら
    for i in range(N):
        
        # N個の商品の中に最大価値値を持つものがいくつあるか調べる
        if V[0] == V[i]:
            cnt += 1
    
    j = A
    while j <= B and V[-i] == min(S):
        C = C + math.factorial(Vs) / ( math.factorial(Vs - i) * math.factorial(i))
        j += 1
    

else: # 商品価値が均一でなかったのなら
    # nCk = n! /( (n-k)! * k! )に基づきCを計算
    C = math.factorial(Vs) / (math.factorial(Vs - Ss) * math.factorial(Ss) )

print(int(C))
    






    


### FIXED CODE ###

# 元ソースコード：http://abc057.contest.atcoder.jp/submissions/1183710
# 初心者の実験用です

import math
N,A,B = map(int,input().split())
V = list(map(int,input().split()))
V.sort()
S = V[-A:]
avgmax = sum(S) / A
print(avgmax)
 
Vs = V.count(min(S))
Ss = S.count(min(S))
if min(S) != max(S):
	C = math.factorial(Vs) // (math.factorial(Vs -Ss) * math.factorial(Ss))
	print(C)
else:
	i = A
	C = 0
	while i <= B and V[-i] == min(S):
		c = math.factorial(Vs) // (math.factorial(Vs -i) * math.factorial(i))
		C = C + c
		i = i + 1
	print(C)
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    pos = []
    for i, v in enumerate(s):
        if s[i] == 'A' and s[i+1] == 'C':
            pos.append(i+1)
            i += 1

    for _ in range(q):
        le, re = split_and_to_int(input().strip())
        n = len([v for v in pos if le <= v < re])
        res = res + "\n" + str(n)

    print(res.strip())


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n, q = map(int, input().split())
    s = input()

    # 累積出現数を格納: 指定される番号が1始まりなのでズラして格納
    p = [0] * (n+1)
    for i in range(n):
        p[i+1] = p[i] + (1 if s[i:i+2] == "AC" else 0)

    for i in range(q):
        l, r = map(int, input().split())
        # 終端(=l-1)から始端-1(=r-1)の累積出現数を引いた数が指定区間内での出現回数
        print(p[r-1] - p[l-1])


if __name__ == '__main__':
    main()
num = input().split()
  a = int(num[0])
  b = int(num[1])
  c = int(num[2]) 
if a < b < c :
    print("Yes")
else :
    print("No")

### FIXED CODE ###

num = input().split()
a = int(num[0])
b = int(num[1])
c = int(num[2]) 

if a < b < c :
    print("Yes")
else :
    print("No")
k, s = map(int, input().split())

count = 0
for x in range(0, k+1):
   for y in range(0, k+1):
         z = s - (x + y)
         if (z >= 0 and z <= k):
            count += 1
print(count)


### FIXED CODE ###

s = input()
print(s.replace(',', ' '))
while True:
  count = input()
  if count == 0: break
  previous_cube = [ 1, 2, 3, 4, 5, 6]
  operation = {'North':[1, 5, 2, 3, 0, 4], 'East':[3, 1, 0, 5, 4, 2], 'West': [2, 1, 5, 0, 4, 3], 'South':[4, 0, 2, 3, 5, 1], 'Right':[0, 2, 4, 1, 3, 5], 'Left':[0, 3, 1, 4, 2, 5]}
  sum = 1
  for i in xrange(count):
    new_cube = []
    for e in xrange(5):
      new_cube.append(previous_cube[operation[str(raw_input())][e]])
    sum += new_cube[0]
    previous_cube = new_cube
  print sum

### FIXED CODE ###

while 1:
  n = input()
  if n == 0:  break
  d = range(1, 7)
  ans = 1
  for i in range(n):
    c = raw_input()[0]
    if c == 'N': S = [1,5,2,3,0,4]
    elif c == "S": S = [4,0,2,3,5,1]
    elif c == "E": S = [3,1,0,5,4,2]
    elif c == "W": S = [2,1,5,0,4,3]
    elif c == "R": S = [0,2,4,1,3,5]
    elif c == "L": S = [0,3,1,4,2,5]
    d = [d[s] for s in S]
    ans += d[0]
  print ans
s = list(input())
t = list(input())


def check_context(a, b):
    ss = s.copy()
    if a <= b:
        return []
    if len(s[a:]) < len(t[b:]):
        return []
    ss[a-b:a-b+len(t)] = t[:]
    return ss



for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            x = check_context(i, j)
            if x:
                for k in range(len(x)):
                    if x[k] == '?':
                        x[k] = 'a'

if x:
    print(x, sep='')
else:
    print('UNRESTORABLE')



### FIXED CODE ###

s = list(input())
t = list(input())

length_1 = len(s)
length_2 = len(t)


def check_word(num1, length):
    a = s[num1:num1+length]
    b = t[:]
    flag = True
    for i in range(length):
        if a[i] == '?':
            continue
        elif a[i] == b[i]:
            continue
        else:
            flag = False
            break
    if flag is True:
        c = s.copy()
        c[num1:num1+length] = t[:]
        c = fill_a(c)
        return c
    elif flag is False:
        return []


def fill_a(li):
    for i in range(len(li)):
        if li[i] == '?':
            li[i] = 'a'
    return li


word_list = []
for i in range(length_1 - length_2 + 1):
    x = check_word(i, length_2)
    if x != []:
        word_list.append(x)

if word_list == []:
    print('UNRESTORABLE')
else:
    word_list.sort()
    while word_list[0] == []:
        x.pop(0)
    for i in word_list[0]:
        print(i, end='')
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,Q = map(int,input().split())
S = input().rstrip()
LR = [map(int,input().split()) for _ in range(Q)]

A = [0]*(N+1)
for i in range(N):
    if S[i]=="A" and S[i+1]=="C":
        A[i+1] = 1
for i in range(i):
    A[i+1] += A[i]

for l,r in LR:
    print(A[r-1]-A[l-1])

### FIXED CODE ###

# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,Q = map(int,input().split())
S = input().rstrip() + "Z"
LR = [map(int,input().split()) for _ in range(Q)]

A = [0]*(N+1)
for i in range(N):
    if S[i]=="A" and S[i+1]=="C":
        A[i+1] = 1
for i in range(i):
    A[i+1] += A[i]

for l,r in LR:
    print(A[r-1]-A[l-1])
N, W =map(int, input().split())
weight = [0] * 110
value = [0] * 110
dp = [[0] * (110) for _ in range(10010)]

for i in range(N):
    weight[i], value[i] = map(int, input().split())

for i in range(N):
    for w in range(W + 1):# <= を表現したいときは+1するとよいかも
        if(w >= weight[i]):
            dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w])
        else:
            dp[i + 1][w] = dp[i][w]
#print(weight[:N],value[:N])
print(dp[N][W])


### FIXED CODE ###

import numpy as np
N, W = map(int, input().split())
dp = np.zeros(W + 1, dtype = np.int64)

for _ in range(N):
    w,v = map(int, input().split())
    np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

print(dp[W])
n, r = int(input().split())
if n >= 10:
  print(r)
else:
  print(r + 100 * (10 - n))

### FIXED CODE ###

n, r = map(int, input().split())
if n >= 10:
  print(r)
else:
  print(r + 100 * (10 - n))
n=int(input())
s=list(int(input()) for i in range(n))
print('AC x',s.count('AC'))
print('WA x',s.count('WA'))
print('TLE x',s.count('TLE'))
print('RE x',s.count('RE'))


### FIXED CODE ###

n=int(input())
s=list(input() for i in range(n))
print('AC x ',s.count('AC'))
print('WA x ',s.count('WA'))
print('TLE x ',s.count('TLE'))
print('RE x ',s.count('RE'))
import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int,input().split())
G=[[] for i in range(n)] #隣接配列
P=[0]*n #親のポイント
Ga_append=G[a].append
Gb_append=G[b].append
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    Ga_append(b)
    Gb_append(a)
for i in range(q):
    p,x=map(int,input().split())
    p-=1
    P[p]+=x
    

def dfs(s,p=-1):        
    for i in G[s]:
        if i!=p:
            P[i]+=P[s]
            dfs(i,s)

dfs(0)
print(*P)

### FIXED CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque

def main():
    n,q=map(int,input().split())
    G=[[] for i in range(n)] #隣接配列
    P=[0]*n #親のポイント
    for i in range(n-1):
        a,b=map(int,input().split())
        a-=1
        b-=1
        G[a].append(b)
        G[b].append(a)
    for i in range(q):
        p,x=map(int,input().split())
        p-=1
        P[p]+=x
    
    Chk=[0]*n #訪問済みチェック
    q=deque([0])
    while q: #qが空になるまで(BFS:幅優先探索)
        now=q.popleft() #取り出す
        Chk[now]=1 #訪問済みにする
        for i in G[now]: #子に対し
            if Chk[i]==0: #未訪問のとき
                P[i]+=P[now] #ポイント加算
                q.append(i) #親としてqに入れる

    print(*P)

if __name__ == '__main__':
    main()
from sys import exit
n, m = map(int, input().split())
s1 = " ".join([input() for _ in range(n)])
s2 = [input() for _ in range(m)]
flag = True

i = 0
while i < m:
    #try:
        if s1.count(s2[i]) == 0:
            print("No")
            exit()
        ind = s1.index(s2[i])
        s1 = list(s1)
        del s1[ind]
        s1 = "".join(s1)
        if s1[ind+n+1:ind+n+m+1:] == s2[i+1]:
            i += 1
    #except:
        """print("No")
        exit()"""
print("Yes")

### FIXED CODE ###

n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j] == b[0][0]:
            cnt = 0
            for k in range(m):
                if a[i+k][j:j+m] == b[k]: cnt+=1
            if cnt == m:
                print("Yes")
                exit()
print("No")