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 Mi.

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 (Mi) are given.

Output

For each question Mi, print yes or no.

Constraints

n ≤ 20

 q ≤ 200 

1 ≤ elements in A ≤ 2000

1 ≤ Mi ≤ 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].

Template in C
-->



Sample input:
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35


Sample output:
no
no
yes
yes
yes
yes
no
no

Submission status: Runtime Error

Solution code:
n=(raw_input())
A=map(int, raw_input().split())
q=(raw_input())
m=map(int, raw_input().split())

def solve(c, m):
  if m == 0:
    return 1
  if c >= n or sum(A)<m:
    return 0
  res = solve(c + 1, m) or solve(c + 1, m - A[c])
  return res

for i range(0,q):
  if solve(0,m[i])==1:
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n=int(raw_input())
A=map(int, raw_input().split())
q=int(raw_input())
m=map(int, raw_input().split())

def solve(c, m):
  if m == 0:
    return 1
  if c >= n or sum(A)<m:
    return 0
  res = solve(c + 1, m) or solve(c + 1, m - A[c])
  return res

for i range(0,q):
  if solve(0,m[i])==1:
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n=int(raw_input())
A=map(int, raw_input().split())
q=int(raw_input())
m=map(int, raw_input().split())

def solve(c, m):
  if m == 0:
    return 1
  if c >= n or sum(A)<m:
    return 0
  res = solve(c + 1, m) or solve(c + 1, m - A[c])
  return res

for i range(0,q):
  if solve(0,m[i]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n=int(raw_input())
A=map(int, raw_input().split())
q=int(raw_input())
m=map(int, raw_input().split())

def solve(c, m):
  if m == 0:
    return 1
  if c >= n or sum(A)<m:
    return 0
  res = solve(c + 1, m) or solve(c + 1, m - A[c])
  return res

for i range(0,q):
  if solve(0, m[i]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n=int(raw_input())
A=map(int, raw_input().split())
q=int(raw_input())
m=map(int, raw_input().split())

def solve(j, m):
  if m == 0:
    return 1
  if j >= n or sum(A)<m:
    return 0
  res = solve(j + 1, m) or solve(j + 1, m - A[j])
  return res

for i range(0,q):
  if solve(0,m[i]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n=int(raw_input())
A=map(int, raw_input().split())
q=int(raw_input())
m=map(int, raw_input().split())

def solve(j, m):
  if m == 0:
    return 1
  if j >= n or m>sum(A):
    return 0
  res = solve(j + 1, m) or solve(j + 1, m - A[j])
  return res

for i range(0,q):
  if solve(0,m[i]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n=int(raw_input())
A=map(int, raw_input().split())
q=int(raw_input())
m=map(int, raw_input().split())

def solve(j, m):
  if m == 0:
    return 1
  if j >= n or m > sum(A):
    return 0
  res = solve(j + 1, m) or solve(j + 1, m - A[j])
  return res

for i range(0,q):
  if solve(0,m[i]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n,q = raw_input()
A,m = map(int, raw_input().split())
 
def ans(i, m):
   if m == 0:
     return True
   if i >= n or m > sum(A):
     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"

Submission status: Runtime Error

Solution code:
def ans(n, AA, x):
    tmp = n + AA[0]
    if len(AA) == 1:
        try: x[tmp] = 1
        except: pass
    else:
        f3(n, AA[1:], x)
        try:
            x[tmp] = 1
            f3(tmp, AA[1:],x)
        except:
            pass
    return
 
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
M = map(int, raw_input().split())
 
x = [0 for i in range(max(M)+1)]
f3(0, A, x)
 
for e in M:
    if x[e] == 1:
        print 'yes'
    else:
        print 'no'

Submission status: Runtime Error

Solution code:
def ans(n, AA, x):
    tmp = n + AA[0]
    if len(AA) == 1:
        try: x[tmp] = 1
        except: pass
    else:
        ans(n, AA[1:], x)
        try:
            x[tmp] = 1
            ans(tmp, AA[1:],x)
        except:
            pass
    return
 
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
M = map(int, raw_input().split())
 
x = [0 for i in range(max(M)+1)]
f3(0, A, x)
 
for e in M:
    if x[e] == 1:
        print 'yes'
    else:
        print 'no'

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int,input().split())
p = int(input())
m = map(int,input().split())
def goukei(i,m):
  if m ==0:
    return True
  if i >= n or m > sum(a):
    return False
  r = goukei(i + 1, m) or goukei(i + 1, m - a[i])
  return r
 
for u in range(answer):

  if s(0, m[u]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int,raw_input().split())
p = int(input())
m = map(int,raw_input().split())
def goukei(i,m):
  if m ==0:
    return True
  if i >= n or m > sum(a):
    return False
  r = goukei(i + 1, m) or goukei(i + 1, m - a[i])
  return r
 
for u in range(answer):

  if s(0, m[u]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int,raw_input().split())
p = int(input())
m = map(int,raw_input().split())
def goukei(i,m):
  if m ==0:
    return True
  if i >= n or m > sum(a):
    return False
  r = goukei(i + 1, m) or goukei(i + 1, m - a[i])
  return r
 
for u in range(0,p):

  if s(0, m[u]):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))
def ans(i, m):
    if m == 0:
        return 1
    if i  >= n or m > sum(A):
        return 0
    res = ans(i + 1, m) or ans(i + 1, m - A[i])
    return res
           
for j in range(0, q):
    if ans(0, m[j]):
        print "yes"
    else:
        print"no"

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))

def ans(i, m):
    if m == 0:
        return 1
    if i  >= n or m > sum(A):
        return 0
    res = ans(i + 1, m) or ans(i + 1, m - A[i])
    return res
           
for j in range(0, q):
    if ans(0, m[j]):
        print "yes"
    else:
        print"no"

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))

def ans(i, m):
    if m == 0:
        return 1
    if i  >= n or m > sum(A):
        return 0
    res = ans(i + 1, M) or ans(i + 1, M - A[i])
    return res
           
for j in range(0, q):
    if ans(0, M[j]):
        print "yes"
    else:
        print"no"

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))

def ans(i, M):
    if M == 0:
        return 1
    if i  >= n or m > sum(A):
        return 0
    res = ans(i + 1, M) or ans(i + 1, M - A[i])
    return res
           
for j in range(0, q):
    if ans(0, M[j]):
        print "yes"
    else:
        print"no"

Submission status: Runtime Error

Solution code:
num_n = raw_input()
ele_n = raw_input()
num_m = raw_input()
ele_m = raw_input()
 
n = ele_n.split()
m = ele_m.split()

def solve(i, t):
   if t == 0:
      return 1
   if i >= num_n:
      return 0
   res = solve(i + 1, t) or solve(i + 1,t - n[i])
   return res

for t in m:
   if solve(0,m):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = [input() for i in range(n)]
q = input()
m = [input() for i in range(q)]
i = 0
j = 0

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

while(i < q):
  while(j < n):
    if solve(n, m[q]):
      print 'yes'
    else:
      print 'no'
    n = n+1
  m = m+1

Submission status: Runtime Error

Solution code:
num_n = raw_input()
ele_n = raw_input()
num_m = raw_input()
ele_m = raw_input()
  
n = int(ele_n.split())
m = int(ele_m.split())
 
def solve(i, t):
   if t == 0:
      return True
   if i >= num_n:
      return False
   res = solve(i + 1, t) or solve(i + 1,t - n[i])
   return res
 
for t in m:
   if solve(0, t):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = [input() for i in range(n)]
q = input()
m = [input() for i in range(q)]
i = 0
j = 0

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

while(i < q):
  while(j < n):
    if solve(n, m[q]):
      print 'yes'
    else:
      print 'no'
    n = n+1
  m = m+1

Submission status: Runtime Error

Solution code:
n = input()
A = [input() for i in range(n)]
q = input()
m = [input() for i in range(q)]
i = 0
j = 0

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

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

Submission status: Runtime Error

Solution code:
n = input()
A = [input() for i in range(n)]
q = input()
m = [input() for i in range(q)]
i = 0
j = 0

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

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

Submission status: Runtime Error

Solution code:
num_n = input()
N = map(int, raw_input())
num_m = input()
M = map(int, raw_input())

def solve(i, m):
   if m == 0:
      return True
   if i >= num_n:
      return False
   res = solve(i + 1, m) or solve(i + 1,m - N[i])
   return res
 
for m in M:
   if solve(0, m):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
num_n = raw_input()
ele_n = raw_input()
num_m = raw_input()
ele_m = raw_input()
   
n = int(ele_n.split())
m = int(ele_m.split())
  
def solve(i, t):
   if t == 0:
      return True
   if i >= num_n or t > sum(n):
      return False
   res = solve(i + 1, t) or solve(i + 1,t - n[i])
   return res
  
for t in m:
   if solve(0, t):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
num_n = input()
N = map(int, raw_input())
num_m = input()
M = map(int, raw_input())

def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(M):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - N[i])
   return res
 
for m in M:
   if solve(0, m):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

def solve(i, m):
    if m == 0:
        return True
    if n <= i or sum(A) < m:
        return False
    res = (solve(i+1, m) or solve(i+1, m-A[i]))
    return res 
 
for m inrange M:
    if solve(0, m):
        print "yes"
    else:
        print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

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

Submission status: Runtime Error

Solution code:
num_n = input()
N = map(int, raw_input().split)
num_m = input()
M = map(int, raw_input().split)
 
def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(M):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - N[i])
   return res
  
for m in M:
   if solve(0, m):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

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

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

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())

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

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

Submission status: Runtime Error

Solution code:
num_n = input()
n = map(int, raw_input().split())
num_m = input()
m = map(int, raw_input().split())
    
def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(n):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - n[i])
   return res
     
for k in m:
   if solve(0, m[k]):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
m = input()

def solve(i,j):
  if m == 0:
    return 1
  if i >= n:
    return 0
  res = solve(i + 1, m) or solve(i + 1, m - A[i])
for k in range(n)
  if solve(0,m):
    print 'Yes'
  else:
    print 'No'

Submission status: Runtime Error

Solution code:
n_n = int(input())
n = map(int, raw_input().split())
n_m= int(input())
m = map(int, raw_input().split())
     
def solve(i, m):
   if m == 0:
      return True
   if i >= n_n or m > sum(n):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - n[i])
   return res
      
for k in range(m_m):
   if solve(0, m[k]):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
class ExhaustiveSearch:
    def solve(self, n, a, q, m):
        for mm in m:
            if self.es(0, mm):
                print("yes")
            else:
                print("no")
    def es(self, i, m): 
        if m == 0:
            return True
        if i >= n:
            return False
        res = self.es(i + 1, m) or self.es(i + 1, m - a[i])
        return res

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split(" ")))
    q = int(input())
    m = list(map(int, input().split(" ")))
    x = ExhaustiveSearch()
    x.solve(n, a, q, m)

Submission status: Runtime Error

Solution code:
class ExhaustiveSearch:
    def solve(self, n, a, q, m):
        for mm in m:
            if self.es(0, mm):
                print("yes")
            else:
                print("no")
    def es(self, i, m): 
        if m == 0:
            return True
        if i >= n:
            return False
        res = self.es(i + 1, m) or self.es(i + 1, m - a[i])
        return res

n = int(input())
a = list(map(int, input().split(" ")))
q = int(input())
m = list(map(int, input().split(" ")))
x = ExhaustiveSearch()
x.solve(n, a, q, m)

Submission status: Runtime Error

Solution code:
n = input()
A = map(int, raw_input().split())
q = input()
M = map(int, raw_input().split())
    
def solve(i, m):
  if m=0:
    return True
  if i>=n or m>sum(A):
    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"

Submission status: Runtime Error

Solution code:
def solve(i, j):
    if i = 0:
        return True
    if j < n and A[0] <= i <= sum(A[j:]):
        x = solve(i-A[j], j+1)
        if x:
            return x
        y = solve(i, j+1)
        if y:
            return y
 
n = input()
A = sorted(map(int, raw_input().split()))
p = input()
m = map(int, raw_input().split())
 
for k in m:
    if solve(k, 0):
        print "yes"
    else:
        print "no"

Submission status: Runtime Error

Solution code:
'''
Created on 2016/03/18

@author: toshi
'''
from veusz.document.export import m_inch

#n = map(int, raw_input())
n = int(raw_input())
A = map(int, raw_input().split())
#q = map(int, raw_input())
q = int(raw_input())
m = map(int, raw_input().split())

A = sorted(A)

def sum_A(A, n, pos, sum, m, flg):
    if flg[0] == "yes":
        return 0
    if sum == m:
        flg[0] = "yes"
        return 0
    if pos + 1 > n - 1:
        return 0
    sum_A(A, n, pos + 1, sum + A[pos], m, flg)
    sum_A(A, n, pos + 1, sum, m, flg)

for i, m_i in enumerate(m):
    sum = 0
    flg = ["no"]
    sum_A(A, n, 0, sum, m_i, flg)
    print flg[0]

Submission status: Runtime Error

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

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

for num in m:
    if solve(0, num):
        return 'yes'
    else:
        return 'no'

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
mi = map(int, raw_input().split())

def f(m, A):
    a = list(A)
    i = 0
    while True:
        while (i < len(a)) and (a[i] <= m): i+=1
        m -= a[i-1]
        a.pop(i-1)
        if   m == 0:
            return True
        elif m > 0:
            return f(m, a)
        else:
            return False

for m in mi:
    if f(m, A):
        print "yes"
    else:
        print "no"

Submission status: Runtime Error

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

is_able_make = [False for i in range(2000)]


for i in A:
    for j in range(2000-i,0,-1):

        if is_able_make[j] == True:
            is_able_make[i+j] = True
        is_able_make[i] = True
        
    for x in m:
        if(is_able_make[x] == True):
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

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

is_able_make = [False for i in range(2000)]


for i in A:
    for j in range(2000-i,0,-1):
   
        if is_able_make[j] == True:
            is_able_make[i+j] = True
        is_able_make[i] = True

    for x in m:
        if(is_able_make[x] == True):
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

Solution code:
import numpy as np

n1 = int(input())
A = np.array(list(map(int, input().split())))
n2 = int(input())
q = list(map(int, input().split()))

B = []

n = n1

for r in q:
    ans = "no"
    for i in range(2 ** n):
        B = np.array(list(map(int, format(i, "b").zfill(n)))[::-1])
        C = A * B
        if sum(C) == r:
            ans = "yes"
            break
    print(ans)

Submission status: Runtime Error

Solution code:
n1 = int(input())
A = list(map(int, input().split()))
n2 = int(input())
q = list(map(int, input().split()))

B = []

n = n1
ans = list("no" for i in range(n2))

for i in range(2 ** n):
    C0 = []
    B = list(map(int, format(i, "b").zfill(n)))[::-1]
    C0 = [ x*y for x, y in zip(A, B)]
    C.append(sum(C0))

for j, r in enumerate(q):    
    if  r in C:
        ans[j] = "yes"

print(*ans, sep="\n")

Submission status: Runtime Error

Solution code:
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A&lang=jp
def solve(input_data, target_num):
    for i in range(len(input_data)):
        #print("begin")
        if exhaustive_search(input_data, i, target_num):
            return True
    return False

def exhaustive_search(input_list, input_index, target_num):
    #print(target_num, input_list[input_index])
    if target_num == 0:
        return True
    elif target_num < input_list[input_index]:
        return False
    return exhaustive_search(input_list, input_index + 1, target_num - input_list[input_index]) or exhaustive_search(input_list, input_index + 1, target_num)
 
def main():
    n_input = int(input())
    input_data = [int(a) for a in input().split()]
    n_target = int(input())
    target_list = [int(a) for a in input().split()]

    for m in target_list:
        if solve(input_data, m):
            print("yes")
        else:
            print("no")
            
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
input()
m = [int(input()) for _ in range(n)]

aa = [0 for _ in range(n**2)]
for i in range(n):
    t = 2**i
    for j in range(n**2):
        if (j//t)%2:
            aa[j] += a[i]
aa = set(aa)

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

Submission status: Runtime Error

Solution code:
n = input()
A = input().split(' ').sort()
q = input()
M = input().split(' ')

for m in M:
    print_yn(search(0, m))
    
def search(sum_base, m):
    if sum_base == m:
        return true
    result = false
    for a in A:
        if sum_base + a <= m:
            r_branch = search(sum_base + a, m)
            result = result || r_branch
    return result

def print_yn(result):
    if result:
        print('yes')
    else:
        print('no')
    return

Submission status: Runtime Error

Solution code:
n = input()
A = input().split(' ').sort()
q = input()
M = input().split(' ')

Submission status: Runtime Error

Solution code:
n = input()
A = input().split(' ')
A.sort()
q = input()
M = input().split(' ')

for m in M:
    print_yn(search(0, m))
    
def search(sum_base, m):
    if sum_base == m:
        return true
    result = false
    for a in A:
        if sum_base + a <= m:
            r_branch = search(sum_base + a, m)
            result = result || r_branch
    return result

def print_yn(result):
    if result:
        print('yes')
    else:
        print('no')
    return

Submission status: Runtime Error

Solution code:
def solve(m, A, i):
	if m==0: return True
	if i>n-1: return False

	f1 = solve(m-A[i], A, i+1)
	f2 = solve(m, A, i+1)

	return f1 or f2


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

for i in map( int, input().split() ):
	print( 'yes' if solve(M[i], A, 0) else 'no')

Submission status: Runtime Error

Solution code:
def solve(A, m):
	if m == 0:
		return True
	if m<0 or len(m)==0:
	else:
		no_use = solve(A[1:], m-int(A[0]))
		if no_use:
			return True
		else:
			return (solve(A[1:], m))

def main():
	n = int(input())
	A = input()
	A = A.split()
	q = int(input())
	ms= input()
	for m in ms.split():
		if solve(A, int(m)):
			print('yes')
		else:
			print('no')

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
def solve(A, m):
	if m == 0:
		return True
	if m<0 or len(m)==0:
		return False
	else:
		no_use = solve(A[1:], m-int(A[0]))
		if no_use:
			return True
		else:
			return (solve(A[1:], m))

def main():
	n = int(input())
	A = input()
	A = A.split()
	q = int(input())
	ms= input()
	for m in ms.split():
		if solve(A, int(m)):
			print('yes')
		else:
			print('no')

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
class MyClass():
    def main(self):
        self.n = input()
        self.A = map(int,raw_input().split())
        self.q = input()
        self.M = map(int,raw_input().split())
        
        W = map(self.solve,self.M)
        for w in W:
            print w

    def solve(self,m):
        w = self.rec(m,self.A)
        if w:
            return "yes"
        else:
            return "no"

    def rec(self,m,A):
        if len(A) == 1:
            r1 = False
        else:
            r1 = self.rec(m,A[1:])
        
        m_new = m - A[0]
        if m_new < 0:
            r2 = False
        elif m_new == 0:
            r2 = True
        elif m_new < min(A[1:]) or len(A) == 1:
            r2 = False
        else:
            r2 = self.rec(m_new,A[1:])
        
        if r1 or r2:
            return True
        else:
            return False
    
if __name__ == "__main__":
    MC = MyClass()
    MC.main()

Submission status: Runtime Error

Solution code:
from collections import deque
import numpy as np

def main():
    n = input()
    A = deque(map(int,raw_input().split()))
    q = input()
    M = map(int,raw_input().split())

    a = np.array([0])
    p = rec(a,A)

    for m in M:
        print "yes" if m in p else "no"

def rec(a,A):
    if len(A) == 0:
        return a
    else:
        a = np.append(a,a+A.popleft())
        return rec(a,A)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

ans = ''
s = sum(A)
for mm in m:
	if s < mm:
		ans += 'no'
	else:
		ans += solve(0,mm)
#ans = [{True:'yes',False:'no'}[solve(0,mm)] for mm in m]
print('\n'.join(ans))

Submission status: Runtime Error

Solution code:
wimport numpy as np

n = int(raw_input())
data = map(int, raw_input().split())
m = int(raw_input())
test = map(int, raw_input().split())

# def solve(i,left):
#     if left == 0:
#         return True
#     elif i >= n:
#         return False
#     return solve(i+1, left) or solve(i+1, left - data[i])

# for j in range(m):
#     if solve(0, test[j]):
#         print 'yes'
#     else:
#         print 'no'

a = [0]
for i in range(n):
    a = a + [a[j] + data[i] for j in range(len(a))]

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

np.sort(a)
a = np.array(a)
for m in ms:
    if m > a[-1]:
        print("no")
    elif a.any()==m:
        print("yes")
    else:
        a_new = a[a < m]
        print(a_new)
        select = []
        length = len(a_new)
        selects = np.zeros(2**length, length)

Submission status: Runtime Error

Solution code:
def exhaustive_search(start, Sum, answer):
    for i in range(start, n):
        Sum = Sum + A[i]
        if Sum == answer:
            return True
        elif Sum > answer:
            Sum = Sum - A[i]
            next
        else:
            r = exhaustive_search(i+1, Sum, answer)
            if r == True:
                return True
            else:
                Sum = Sum - A[i]
    return False


for i in M:
    r = exhaustive_search(0, 0, i)
    if r == True:
        print('yes')
    else:
        print('no')

Submission status: Runtime Error

Solution code:
def exhaustive_search(start, Sum, answer):
    for i in range(start, n):
        Sum = Sum + A[i]
        if Sum == answer:
            return True
        elif Sum > answer:
            Sum = Sum - A[i]
            next
        else:
            r = exhaustive_search(i+1, Sum, answer)
            if r == True:
                return True
            else:
                Sum = Sum - A[i]
    return False


for i in M:
    r = exhaustive_search(0, 0, i)
    if r == True:
        print('yes')
    else:
        print('no')

return 0

Submission status: Runtime Error

Solution code:
def exhaustive_search(start, Sum, answer):
    for i in range(start, n):
        Sum = Sum + A[i]
        if Sum == answer:
            return True
        elif Sum > answer:
            Sum = Sum - A[i]
            next
        else:
            r = exhaustive_search(i+1, Sum, answer)
            if r == True:
                return True
            else:
                Sum = Sum - A[i]
    return False


for i in M:
    r = exhaustive_search(0, 0, i)
    if r == True:
        print('yes')
    else:
        print('no')
print('')

Submission status: Runtime Error

Solution code:
def exhaustive_search(start, Sum, answer):
    for i in range(start, n):
        Sum = Sum + A[i]
        if Sum == answer:
            return True
        elif Sum > answer:
            Sum = Sum - A[i]
            next
        else:
            r = exhaustive_search(i+1, Sum, answer)
            if r == True:
                return True
            else:
                Sum = Sum - A[i]
    return False


for i in M:
    r = exhaustive_search(0, 0, i)
    if r == True:
        print('yes')
    else:
        print('no')
print(' ')

Submission status: Runtime Error

Solution code:
def exhaustive_search(start, Sum, answer):
    for i in range(start, n):
        Sum = Sum + A[i]
        if Sum == answer:
            return True
        elif Sum > answer:
            Sum = Sum - A[i]
            next
        else:
            r = exhaustive_search(i+1, Sum, answer)
            if r == True:
                return True
            else:
                Sum = Sum - A[i]
    return False


for i in M:
    r = exhaustive_search(0, 0, i)
    if r == True:
        print('yes')
    else:
        print('no')
print(?\n)

Submission status: Runtime Error

Solution code:
a_len = int(input())
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(input())
b_ar = [int(n) for n in input().split(" ")]
max_b = max(b_ar)
dp = [0 for n in range(max_b + 1)]
for a in a_ar:
    new_dp = dp[:]
    new_dp[a] = 1
    for i,d in enumerate(dp):
        if d and i + a <= max_b + 1:
            new_dp[i + a] = 1
    dp = new_dp
for b in b_ar:
    if dp[b]:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())

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

for i in mi:
    if solve(0, m):
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())

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

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