Problem:
Exhaustive Search Write a program which reads a sequence A of n elements and an integer M , and outputs " yes " if you can make M by adding elements in A , otherwise " no ". You can use an element only once. You are given the sequence A and q questions where each question contains M i . Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers ( M i ) are given. Output For each question M i , print yes or no . Constraints  n ≤ 20  q ≤ 200  1 ≤ elements in A ≤ 2000  1 ≤ M i ≤ 2000  Sample Input 1 5
1 5 7 10 21
8
2 4 17 8 22 21 100 35 Sample Output 1 no
no
yes
yes
yes
yes
no
no Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2].

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
A = tuple(int(x) for x in input().split())
_ = int(input())
M = tuple(int(x) for x in input().split())

S = set()
def Check(i, s):
    if i == n:
        S.add(s)
        return
    Check(i + 1, s + A[i])
    Check(i + 1, s)

Check(0, 0)

for m in M:
    if m in S:
        print('yes')
    else:
        print('no')

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
m = list(map(int, input().split()))
memo = [[-1]*2000 for _ in range(20)]
def solve(i, m):
    if memo[i][m] != -1:
        return memo[i][m]
    if m == 0:
        memo[i][m] = 1
        return True
    if m < 0:
        memo[i][m] = 0
        return False
    if i >= N:
        memo[i][m] = 0
        return False
    if i == N-1:
        memo[i][m] = (A[N-1] == m)
        return (A[N-1] == m)
    res = solve(i+1, m) or solve(i+1, m-A[i])
    memo[i][m] = res
    return res
for mi in m:
    if solve(0, mi):
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
A = list(map(int, input().rstrip().split(" ")))

q = int(input())
M = list(map(int, input().rstrip().split(" ")))

existBits = 1

for a in A:
    existBits |= existBits << a
        
if(__name__ == '__main__'):
    
    for m in M:
        
        judge = (existBits << m)
        
        if(((existBits >> m) & 1) == 1):
            print("yes")
        else:
            print("no")

Solution (Python):

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

count_list = []
for i in range(1<<n):
    copy_A = A.copy()
    count = 0
    for j in range(n):
        mask = 1 << j
        if mask & i != 0:
            count += A[j]
    count_list.append(count)

for k in m:
    if k in count_list:
        print('yes')
    else:
        print('no')

Solution (Python):
from functools import lru_cache

n = int(input())
A = [int(n) for n in input().split()]
q = int(input())
M = [int(n) for n in input().split()]


@lru_cache(maxsize=2**12)
def makeCombination(i,key):
    if key == 0:
        return True
    if i == n:
        return False
    return makeCombination(i+1,key) or makeCombination(i+1,key-A[i])


for m in M:
    if makeCombination(0,m):
        print("yes")
    else:
        print("no")

Solution (Python):
from itertools import combinations


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


answer = ['no']*q
for i in range(1, n+1):
    for nums in combinations(a, i):
        val = sum(nums)
        if val in m:
            index = [i for i, num in enumerate(m) if val == num]
            for i in index:
                answer[i] = 'yes'

for i in answer:
    print(i)

Solution (Python):
def calc(s, i):
    global n
    global anslst
    global nlst
    if i == n:
        anslst[s] = 'yes'
        return

    calc(s, i+1)
    calc(s + nlst[i], i+1)


anslst = ['no']*2001
n = int(input())
nlst = list(map(int, input().split()))
q = int(input())
qlst = list(map(int, input().split()))

calc(0, 0)

for i in qlst:
    print(anslst[i])

Solution (Python):
import itertools

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

ANS = set()
for i in range(1,n+1):
    A_pairs = list(itertools.combinations(A, i))
    for j in range(len(A_pairs)):
        ANS.add(sum(A_pairs[j]))

for i in range(q):
    if m[i] in ANS:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))

S = set([])
for i in range(2<<n):
    num = 0
    for j in range(n):
        bit = (i>>j) & 1
        num += bit * A[j]
    S.add(num)

for m in M:
    if m in S:
        print('yes')
        continue
    print('no')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
L = list(map(int, input().split()))
X = list()
for bit in range(1<<n):
  A2 = list()
  for i in range(n):
    if bit & (1<<i):
      A2.append(A[i])
  X.append(sum(A2))
for i in range(q):
  if L[i] in X:
    print('yes')
  else:
    print('no')

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

ans_map = {}

for i in range(1, n * 2000 + 1):
    ans_map[i] = 0

for i in range(2 ** n - 1):
    str_i = str(bin(i)[2:]).zfill(n)
    sum_a = 0
    for j, bit in enumerate(str_i):
        if bit == '1':
            sum_a += A[j]
    ans_map[sum_a] = 1

for m in M:
    if ans_map[m]:
        print('yes')
    else:
        print('no')

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

d={}
for i in range(2**n):
    c=0
    for j in range(n):
        if (i>>j)&1:
            c+=a[j]
    d[c]=1

for i in range(q):
    if m[i] in d:
        print("yes")
    else:
        print("no")

Solution (Python):
import itertools as it

n, A = int(input()), [*map(int, input().split())]
yes_nums = set()
for bools in it.product([True, False], repeat=n):
  yes_nums.add(sum(A[i] for i in range(n) if bools[i]))

_ = input()
for m in map(int, input().split()):
  print("yes" if m in yes_nums else "no")

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int, input().split()))

d = {}

def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    if (i, m) in d:
        return d[i, m]
    res = solve(i + 1,  m) or solve(i + 1, m - A[i])
    d[i,m] = res
    return res

for m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = list(map(int,input().split()))

sumn = {0}
for i in a:
    sumn |= {i + x for x in sumn}
for i in b:
    if i in sumn:
        print('yes')
    else:
        print('no')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

def solve(x,y):
    global n
    global A
    if y==0:
        return True
    if x>=n:
        return False
    if sum(A[x:])<y:
        return False
    return solve(x+1,y) or solve(x+1,y-A[x])
for i in m:
    if solve(0,i):
        print("yes")
    else:
        print("no")

Solution (Python):
from itertools import combinations
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

s=set()
for i in range(1,n+1):
    for j in combinations(a,i):
        s.add(sum(j))
for i in m:
    if i in s:
        print("yes")
    else:
        print("no")

Solution (Python):

n = int(input())
list_n = [int(x) for x in input().split(' ')]


q = int(input())
list_q = [int(x) for x in input().split(' ')]





def find_partial_sum(idx, M):
    if 0 > M or idx >= n:
        return False
    i = list_n[idx]
    if M == i:
        return True
    if find_partial_sum(idx+1, M-i) or find_partial_sum(idx+1, M):
        return True
    return False

for q_i in list_q:
    if sum(list_n) < q_i:
        print("no")
    elif find_partial_sum(0, q_i):
        print('yes')
    else:
        print('no')

Solution (Python):
N=int(input())
*A,=map(int,input().split())
Q=int(input())
*M,=map(int,input().split())
mf=['no']*Q
t=[]
for i in range(0,2**N):
    ans=0
    for j in range(N):
        if (i>>j&1):
            ans+=A[j]
    t.append(ans)
tset=set(t)

for i in range(Q):
    if M[i] in tset:
        mf[i] = 'yes'

for i in mf:
    print(i)

Solution (Python):


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


ans_list = ["no" for i in range(q)]
for bit in range(1 << n):
    s = 0
    for i in range(n):
        if bit & (1 << i):
            s += A[i]
    L = [i for i, x in enumerate(m) if x == s]
    for l in L:
        ans_list[l] = "yes"


for ans in ans_list:
    print(ans)

Solution (Python):
n = int(input())
*li, = map(int, input().split())
input()
*Q, = map(int, input().split())

bits = 1
for i in li:
    
    
    bits |= bits << i
    
    


for q in Q:
    
    print("yes"*((bits >> q) & 1) or "no")

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

values = set({})
for num in range(1 << n):
    count = 0
    for k in range(n):
        if num & (1 << k) == 1 << k:
            count += A[k]
    
    values.add(count)

m = int(input())
Q = list(map(int, input().split()))
for q in Q:
    if q in values:
        print("yes")
    else:
        print("no")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
b=[0]*2**n
for i in range(2**n):
  tr=bin(i)[2:].zfill(n)
  cnt=0
  for j in range(n):
    if tr[j]=='1':
      cnt+=a[j]
  b[i]=cnt
for i in m:
  if i in b:
      print('yes')
  else:
      print('no')

Solution (Python):
from functools import lru_cache

num = int(input())
arr = list(map(int, input().split()))
question_nums = int(input())
questions = list(map(int, input().split()))

@lru_cache(maxsize=2**12)
def solve(index, total):
    if total == 0:
        return True
    if index == num:
        return False
    return solve(index+1, total - arr[index]) or solve(index+1, total)

for q in questions:
    if solve(0, q):
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]
m = int(input())
b = [int(_) for _ in input().split()]

dp = [[False for i in range(4300)]for i in range(2)]
dp[0][0] = True
dp[1][0] = True
c = False
for i in a:
    for j in range(4000):
        if dp[c][j]:
            dp[not(c)][j+i] = True
            dp[not(c)][j] = True
    c = not(c)

for i in b:
    if dp[c][i]:
        print("yes")
    else:
        print("no")

Solution (Python):
def exhaustiveSearch(A:list, m:int) -> str:
    if m == 0:
        return True
    if len(A) == 0 or sum(A) < m:
        return False
    return exhaustiveSearch(A[1:], m) or exhaustiveSearch(A[1:], m - A[0])
    


if __name__ == '__main__':
    n = int(input())
    A = list(map(int, input().rstrip().split()))
    q = int(input())
    M = list(map(int, input().rstrip().split()))
    for m in M:
        if exhaustiveSearch(A, m):
            print('yes')
        else:
            print('no')

Solution (Python):
import sys, os, math \
    






sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    Q = ii()
    M = il()

    num_set = set()
    for i in range(1 << N):
        num = 0
        for n in range(N):
            if i >> n & 1:
                num += A[n]
        num_set.add(num)

    for m in M:
        if m in num_set:
            print('yes')
        else:
            print('no')


if __name__ == '__main__':
    main()

Solution (Python):

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

MAX = 2000
check = [False]*(MAX+1)

def recursive(index,tmp_sum):
    global N

    if index == N:
        check[tmp_sum] = True
        return

    recursive(index+1,tmp_sum)
    if tmp_sum+table[index] <= MAX:
        recursive(index+1,tmp_sum+table[index])

recursive(0,0)

num_query = int(input())
for num in list(map(int,input().split())):
    if check[num]:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
n_li = list(map(int, input().split()))

q = int(input())
q_li = list(map(int, input().split()))

ans = [0]*q
tmp_li = []

for i in range(2**n):
    check = [0]*n
    
    for j in range(n):
        if ((i >> j) & 1):
            check[n - 1 - j] = 1
    
    tmp = 0
    for a in range(n):
        if check[a] == 1:
            tmp += n_li[a]
    tmp_li.append(tmp)

for k in range(q):
    if q_li[k] in tmp_li:
        ans[k] = 1
        
for x in ans:
    if x == 1:
        print('yes')
    else:
        print('no')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

sumlist=[]

for i in range(2**n):
    sumA=0
    for j in range(n):
        if ((i>>j) & 1):
            sumA+=A[j]
    sumlist.append(sumA)

for k in range(q):
    if m[k] in sumlist:
        print("yes")
    else:
        print("no")

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
q=int(input())

st=set()
for i in range(1<<n):
  sm=0
  for j in range(n):
    if (i & (1<<j)):
      sm+=a[j]
  st.add(sm)
Q=list(map(int,input().split()))
for i in Q:
  if i in st:
    print("yes")
  else:
    print("no")

Solution (Python):
from typing import List


def rec(i: int, tmp_sum: int, A_list: List[int], sum_list: List[bool]):
    if tmp_sum > 2000:
        return
    elif i == len(A_list):
        sum_list[tmp_sum] = True
        return

    rec(i + 1, tmp_sum + A_list[i], A_list, sum_list)
    rec(i + 1, tmp_sum, A_list, sum_list)


def main():
    n = int(input())
    A_list = list(map(int, input().split()))
    q = int(input())
    m_list = list(map(int, input().split()))

    sum_list = [False for _ in range(2001)]

    rec(0, 0, A_list, sum_list)

    for m in m_list:
        if sum_list[m]:
            print("yes")
        else:
            print("no")


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

cand = []
for i in range(2**n):
    tmp = 0
    for j in range(n):
        if (i>>j)&1:
            tmp += A[j]
    cand.append(tmp)

for i in m:
    if i in cand:
        print("yes")
    else:
        print("no")

Solution (Python):
import sys
from itertools import product


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    m = list(map(int, input().split()))
    ans = [False] * q
    for e in product((0, 1), repeat=n):
        s = 0
        for i in range(n):
            s += e[i] * a[i]
        for i in range(q):
            if m[i] == s:
                ans[i] = True
    for a in ans:
        print("yes" if a else "no")


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
se = set()
for i in range(1<<N):
    tot = 0
    for j in range(N):
        if i&(1<<j): tot += A[j]
    se.add(tot)
_ = int(input())
Q = list(map(int, input().split()))
for q in Q:
    if q in se:
        print("yes")
    else:
        print("no")

Solution (Python):
from itertools import product

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

A = [0]*(2**n)
c = 0
for x in product([0,1], repeat=n):
    summ = 0
    for j in range(n):
        if x[j] == 1:
            summ += a[j]
    A[c] = summ
    c+=1

for i in range(q):
    if m[i] in A:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = [int(x) for x in input().split()]
q = int(input())
M = [int(x) for x in input().split()]

ans = ["no"]*2000

for i in range(1<<n):
    a = 0
    for j in range(n):
        if (i>>j)&1 == 1:
            a += A[j]
    ans[a] = "yes"

for j in M:
    print(ans[j])

Solution (Python):
n = int(input())                                                                                                                                                                                                                              
A = list(map(int, input().split()))                                                                                                                                                                                      
q = int(input())                                                                                                                                                                                                                              
M = list(map(int, input().split()))                                                                                                                                                                                      
                                                                                                                                                                                                                                              
possible = set()                                                                                                                                                                                                         
                                                                                                                                                                                                                                              
for i in range(2**n):                                                                                                                                                                                                    
    s = 0                                                                                                                                                                                                                                     
    for j in range(n):                                                                                                                                                                                                   
        if i & (1 << j):                                                                                                                                                                                                                      
            s += A[j]                                                                                                                                                                                                    
    possible.add(s)                                                                                                                                                                                                                           
                                                                                                                                                                                                                         
for m in M:                                                                                                                                                                                                                                   
    if m in possible:                                                                                                                                                                                                    
        print("yes")                                                                                                                                                                                                                          
    else:                                                                                                                                                                                                                
        print("no")

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
A = [int(i) for i in input().strip().split()]
q = int(input())
M = [int(i) for i in input().strip().split()]

comb = set()

for i in range(2 ** n):
    _tmp = 0
    for j in range(n):
        if (i >> j) & 1:
            _tmp += A[j]
    comb.add(_tmp)

for m in M:
    if m in comb:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
(*a, ) = map(int, input().split())
q = int(input())
(*m, ) = map(int, input().split())
s = set()
for j in range(2 << n):
    c = 0
    for k in range(n):
        if j >> k & 1:
            c += a[k]
    s.add(c)

for i in m:
    print("yneos"[i not in s::2])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
b=[0]*2**n
for i in range(2**n):
  tr=bin(i)[2:].zfill(n)
  cnt=0
  for j in range(n):
    if tr[j]=='1':
      cnt+=a[j]
  b[i]=cnt
for i in m:
  if i in b:print('yes')
  else:print('no')

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
B=1
for i in range(N):
    B=B|B<<L[i]
BI=list(str(bin(B)))
BI=BI[2:]
SB=BI[::-1]

Q=int(input())
A=list(map(int,input().split()))
for i in range(Q):
    if A[i]>=len(SB):
        print("no")
    elif SB[A[i]]=="1":
        print("yes")
    else:
        print("no")

Solution (Python):
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    M = list(map(int, input().split()))

    num = set()
    for pattern in product([0, 1], repeat=n):
        total = 0
        for idx, p in enumerate(pattern):
            if p == 1:
                total += A[idx]
        num.add(total)

    for m in M:
        print("yes" if m in num else "no")


if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
m = int(input())
q = list(map(int,input().split()))

S = set()
for i in range(1<<n):
  s = 0
  for j in range(n):
    if (i>>j)&1:
      s += A[j]
  S.add(s)


for j in q:
  if j in S:
    print("yes")
  else:
    print("no")

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

result = set()
for i in range(2**n):
    tmp = 0
    for j in range(n):
        if i >> j & 1:
            tmp += arr[j]
    result.add(tmp)

for x in m:
    print("yes" if x in result else "no")

Solution (Python):
def main():
    n = int(input())
    A = list(map(int,input().split()))
    q = int(input())
    m = list(map(int,input().split()))

    sum_list = []
    back = []
    
    for i in range(1,2**n):
        for j in range(n):
            if ( (i>>j)&1 ):
                back.append(A[j])

        

        sum = 0
        for k in back:
            sum += k

        sum_list.append(sum)

        back = []

    for h in range(q):
        if m[h] in sum_list:
            print('yes')
        else:
            print('no')

main()

Solution (Python):
N = int(input().rstrip())
A = [int(_) for _ in input().rstrip().split(" ")]
Q = int(input().rstrip())
M = [int(_) for _ in input().rstrip().split(" ")]

import itertools

from functools import lru_cache

@lru_cache(maxsize=2**12)
def solve(i, m):
    if m == 0:
        return True
    elif i >= N:
        return False
    res = solve(i+1, m) or solve(i+1, m - A[i])
    return res
        
        
for m in M:
    if solve(0, m):
        print("yes")
    else:
        print("no")

Solution (Python):
from itertools import combinations as comb

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

numlst=[]
for i in range(1,n+1):
    for x in comb(lst,i):
        y=sum(x)
        if not y in numlst:
            numlst.append(y)

q=int(input())
lst2=list(map(int,input().split()))
for x in lst2:
    if x in numlst : print("yes")
    else : print("no")

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


pattern = []
for i in range(2 ** n):
    bit_set = []
    for j in range(n):
        if ((i >> j) & 1):
            bit_set.append(A[j])    
    pattern.append(sum(bit_set))



for m in m:
    if m in pattern:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

cand_list = []
for i in range(1, 2**n):
    cum_num=0
    for j in range(n):
        if i&1<<j:
            cum_num += A[j]
    cand_list.append(cum_num)
    
for m in M:
    if m in set(cand_list):
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))

flag = [0]*(2000+1)
for status in range(2**n):
    tmp = 0
    for mask in range(n):
        if status&(1<<mask):
            tmp += A[mask]
    flag[tmp] = True

for m in M:
    print('yes' if flag[m] else 'no')

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

k = 2**N
totallist = [0]*k
for b in range(k):
    total = 0
    for i in range(N):
        if b >> i & 1 == 1:
            total += A[i]
    totallist[b] = total

for m in M:
    print('yes') if m in totallist else print('no')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
mans = set()
b = 0
for b in range(2**n):
    ans = 0
    for i in range(n):
        if 1&(b>>i):
            ans += A[i]
    mans.add(ans)
for m in M:
    if m in mans:
        print("yes")
    else:
        print("no")

Solution (Python):
def resolve():
    n=int(input())
    a=list(map(int,input().split()))
    q=int(input())
    m=list(map(int,input().split()))
    sa=[0]*100000
    for i in range(2**n):
        s=0
        for j in range(n):
            if i>>j&1:
                s+=a[j]
        sa[s]=1
    for i in m:
        if sa[i]==0:
            print('no')
        else:
            print('yes')

if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

ans = set()
for i in range(2**n):
    total = 0
    bits = bin(i)[2:].zfill(n)
    for j, b in enumerate(bits):
        if b == '1':
            total += A[j]
    ans.add(total)

for i in range(q):
    if M[i] in ans:
        print('yes')
    else:
        print('no')

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
M = int(input())
Q = list(map(int,input().split()))
SL = []
for bit in range(1<<N):
    SUM = 0
    for i in range(N):
        if bit & (1<<i):
            SUM += A[i]
    SL.append(SUM)
for q in Q:
    if q in SL:
        print('yes')
    else:
        print('no')

Solution (Python):
N=int(input())
U=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))


dp = [[-1 for j in range(400001)] for i in range(N+1)]


def func(i,X,U,dp):
    if i==0:
        if X==0:
            return True
        else:
            return False
    if X<0:
        return False
    
    if dp[i][X] !=-1:
        return dp[i][X]
    
    
    if func(i-1,X,U,dp):
        dp[i][X]=1
        return dp[i][X]
    if (func(i-1,X-U[i-1],U,dp)):
        dp[i][X]=1
        return dp[i][X]
    
    dp[i][X]=0
    return dp[i][X]

for i in range(M):
    if func(N,T[i],U,dp)==True:
        print("yes")
    else:
        print("no")

Solution (Python):
import sys
import itertools

import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

can_make = [False] * 2001
for bit in range(2 ** n):
    total = 0
    for i in range(n):
        if bit & 1 << i > 0:
            total += A[i]
    if total <= 2000:
        can_make[total] = True

for m in M:
    if can_make[m]:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
pos = set()


for i in range(1 << n):
    point = 0
    for j in range(n):
        
        if (i >> j)&1:
            point += a[j]
    pos.add(point)

q = int(input())
m = list(map(int,input().split()))

for i in m:
    if i in pos:
        print("yes")
    else:
        print("no")

Solution (Python):

from sys import stdin

n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().split()))
q = stdin.readline().rstrip()
M = list(map(int, stdin.readline().split()))

sum_results = set()

for i in range(2 ** n):
  sum_tmp = 0
  for j in range(n):
    

    if ((i >> j) & 1):  
      sum_tmp += A[j]
  else:
    sum_results.add(sum_tmp)

for m in M:
  if m in sum_results:
    print("yes")
  else:
    print("no")

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

ans = [0] * (2 ** n)
for i in range(2 ** n):
    p = 1
    for j in range(n):
        if i & p:
            ans[i] += A[j]
        p *= 2

for i in range(q):
    if m[i] in ans:
        print("yes")
    else:
        print("no")

Solution (Python):
n=int(input())
A=[int(x) for x in input().split()]
q=int(input())
m=[int(x) for x in input().split()]

A_sum = []
for bit in range(1,2**n):
    a_sum = 0
    for i in range(n):
        if bin((bit>>i) & 0b1) == '0b1':
            a_sum += A[i]
    A_sum.append(a_sum)
            
for mi in m:
    if mi in A_sum:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
nums = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

li = []
for i in range(2**n):
    an = format(i, 'b').zfill(n)
    li.append(an)

ans = []
for lis in li:
    num = 0
    for i in range(n):
        if lis[i] == '1':
            num += nums[i]
    ans.append(num)

for j in m:
    if j in ans:
        print('yes')
    else:
        print('no')