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 = int(input())
a = list(map(int, input().split(' ')))
q = int(input())
M = list(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 j in M:
    if solve(0, j):
        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(' ')))
minA = min(a)
sumA = sum(a)

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 j in M:
    if j < minA or m>sumA:
        print('no')
    if solve(0, j):
        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(' ')))
minA = min(a)
sumA = sum(a)

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 j in M:
    if j < minA or m>sumA:
        print('no')
    else:
        if solve(0, j):
            print('yes')
        else:
            print('no')

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().split()
q=int(input())
M=input().split()
ans=[]
for i in range(n):
    A[i]=int(A[i])
for i in range(q):
    M[i]=int(M[i])
    ans=solve(0,M[i])
    if ans==True:
        print("yes")
    else:
        print("no")

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().split()
q=int(input())
m=input().split()
ans=[]
for i in range(n):
    a[i]=int(a[i])
for i in range(q):
    m[i]=int(m[i])
    ans=solve(0,m[i]);
    if ans==True:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
sys.setrecursionlimit(20000)

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=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
m=int(input())
B=list(input().split())
ans=[]
for i in range(m):
    B[i]=int(B[i])
    ans=solve(0,B[i])
    if ans==True:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(20000)

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=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
m=int(input())
B=list(input().split())
ans=[]
for i in range(m):
    B[i]=int(B[i])
    ans=solve(0,B[i])
    if ans==True:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
#import sys
#sys.setrecursionlimit(20000)

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

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
m=int(input())
B=list(input().split())
ans=[]
for i in range(m):
    B[i]=int(B[i])
    ans=solve(0,B[i])
    if ans==True:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
#import sys
#sys.setrecursionlimit(20000)

def solve(i,sum):
    if i==n:
        ans[sum] = 1
        ans[sum+A[i]] = 1
    solve(i+1,sum)
    if sum+A[i] <=2000:
        solve(i+1,sum+A[i])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
def solve(i,sum):
    if i==n:
        ans[sum] = 1
        ans[sum+A[i]] = 1
    solve(i+1,sum)
    if sum+A[i] <= 2000:
        solve(i+1,sum+A[i])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    B[i]=int(B[i])
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
def solve(i,sum):
    if i==n:
        ans[sum] = 1
        if sum+A[i] <= 2000:
            ans[sum+A[i]] = 1
    solve(i+1,sum)
    if sum+A[i] <= 2000:
        solve(i+1,sum+A[i])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    B[i]=int(B[i])
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
def solve(i,sum):
    if i==n-1:
        ans[sum] = 1
        if sum+A[i] <= 2000:
            ans[sum+A[i]] = 1
    solve(i+1,sum)
    if sum+A[i] <= 2000:
        solve(i+1,sum+A[i])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    B[i]=int(B[i])
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
def solve(j,sum):
    if j==n-1:
        ans[sum] = 1
        if sum+A[j] <= 2000:
            ans[sum+A[j]] = 1
    solve(j+1,sum)
    if sum+A[j] <= 2000:
        solve(j+1,sum+A[j])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    B[i]=int(B[i])
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
def solve(j,sum):
    print j, sum
    if j==n-1:
        ans[sum] = 1
        if sum+A[j] <= 2000:
            ans[sum+A[j]] = 1
    solve(j+1,sum)
    if sum+A[j] <= 2000:
        solve(j+1,sum+A[j])

n=int(input())
A=[]*n
A=list(input().split())
for i in range(n):
    A[i]=int(A[i])
ans=[0]*2001    
solve(0,0)   

m=int(input())
B=list(input().split())
for i in range(m):
    B[i]=int(B[i])
for i in range(m):
    if ans[B[i]]==1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

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

    res1 = solve(i+1,m,n,A)
    res2 = solve(i+1,m-A[i],n,A)
    if(res1 == 1 or res2 == 1):
        return 1
    else:
        return 0



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

for i in range(q):
    if(solve(0,M[i],n,A)):
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

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

    return max(solve(i+1,m,n,A),solve(i+1,m-A[i],n,A))


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

for i in range(q):
    if(solve(0,M[i],n,A)):
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(input().split())
for i in range(n):
    A[i] = int(A[i])
m = int(input())
B = list(input().split())
for i in range(m):
    B[i] = int(B[i])

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(input().split())
for i in range(n):
    A[i] = int(A[i])
m = int(input())
B = list(input().split())
for i in range(m):
    B[i] = int(B[i])

def solve(x,y):
    if x==n:
        S[y] = 1
    else:
        solve(x+1,y)
        if y+A[x] < 2001:
            solve(x+1,y+A[x]
            
S = [0]*2001
solve(0,0)
    
for i in range(m):
    if S[B[i]] == 1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(input().split())
for i in range(n):
    A[i] = int(A[i])
m = int(input())
B = list(input().split())
for i in range(m):
    B[i] = int(B[i])

def solve(x,y):
    if x==n:
        S[y] = 1
    else:
        solve(x+1,y)
        if y+A[x] < 2001:
            solve(x+1,y+A[x]
            
S = [0 for i in range(2001)]

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

def solve2(x,y):
    if x==n:
        S[y] = 1
    else:
        solve2(x+1,y)
        if y+A[x] < 2001:
            solve2(x+1,y+A[x])
            
S = [0 for i in range(2001)]

solve2(0,0)

def solve(x,y):
    if y<0:
        return False
    elif y==0:
        return True
    elif x==n:
        return False
    else:
        return solve(x+1,y) or solve(x+1,y-A[x])
    
for i in range(m):
    if (i>80 and (S[B[i]] == 1)):
        print("yes")
    elif (i>80 and (S[B[i]] == 0)):
        print("no")
    else:
        if solve(0,B[i]):
            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()))

box=[]
for i in range(2**n):
	b = '{0:0{1}b}'.format(i,n)
	tmp=[]
	for j in rangee(n):
		if b[j]=='1':
			if b[j]=='1':
				tmp.append(A[j])
	sum_list.append(box(tmp))
	
for k in m:
	if k in box:
		print("yes")
	else:
		print("no")

Submission status: Runtime Error

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

T = [[0]*2001 for i in range(n)]

T[0][0] = 1
T[0][A[0]] = 1
for i in range(1:n):
    for j in range(2001):
        T[i][j] = T[i-1][j]
        if (j - B[i] >=0) and (T[i-1][j-B[i]] == 1):
            T[i][j] = 1
    
for i in range(m):
    if T[n-1][B[i]] == 1:
        print("yes")
    else:
        print("no")

Submission status: Runtime Error

Solution code:
import numpy as np
def rec(x,y):
    x.sort()
    for i in range(len(x)):
        if x[i]>y:
            return "no"
        for j in range(len(x)):
            if i!=j:
                if x[i]+x[j]==y:
                    return "yes"
n=int(input())
A=list(map(int,input().split(' ')))
p=int(input())
m=list(map(int,input().split(' ')))
for i in range(len(m)):
    print(rec(A,m[i])

Submission status: Runtime Error

Solution code:
n = int(input())
ary = [int(_) for _ in input().split()]
q = int(input())
qs = [int(_) for _ in input().split()]


def search(ary, s, q):

    if not ary:
        return False

    else:
        tmp = ary[0]

        if s + tmp == q:
            return True
        else:
            return search(ary[1:], s, q) or search(ary[1:], s + tmp, q)


for q in qs:
    if search(ary, 0, q):
        print('yes')
    else:
        print('no')

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2 ** 20)

n = int(input())
ary = [int(_) for _ in input().split()]
q = int(input())
qs = [int(_) for _ in input().split()]


def search(ary, s, q):

    if not ary:
        return False

    else:
        tmp = ary[0]

        if s + tmp == q:
            return True
        else:
            return search(ary[1:], s, q) or search(ary[1:], s + tmp, q)


for q in qs:
    if search(ary, 0, q):
        print('yes')
    else:
        print('no')

Submission status: Runtime Error

Solution code:
n = int(input())
ary = [int(_) for _ in input().split()]
q = int(input())
qs = [int(_) for _ in input().split()]


def search(ind, s, q):

    if ind == n:
        return False

    else:
        tmp = ary[ind]

        if s + tmp == q:
            return True
        else:
            return search(ind + 1, s, q) or search(ind + 1, s + tmp, q)


for q in qs:
    if search(0, 0, q):
        print('yes')
    else:
        print('no')

Submission status: Runtime Error

Solution code:

class ES:
	def solve(self, A, M):
		for m in M:
			if self.search(0, m):
				print("yes")
			else:
				print("no")

	def search(self, i, m):
		if m == 0:
			return True
		elif i >= n:
			return False

		return self.search(i + 1, m) or self.search(i + 1, m - A[i])

if __name__ == '__main__':
	n = int(input())
	A = [int(i) for i in input().rstrip().split(" ")]
	q = int(input())
	M = [int(i) for i in input().rstrip().split(" ")]

	x = ES()
	x.solve(A, M)

Submission status: Runtime Error

Solution code:
def solve(i,m):
	if m==0:
		return true
	elif i>=n:
		return false
	else:
		res=any(solve(i+1,m),solve(i+1,m-a[i]))
		return res

n=int(input())
a=input().split()
q=int(input())
m=input().split()
for j in range(n):
	a[j]=int(a[j])
for i in range(q):
	m[i]=int(m[i])
	if solve(i,m[i]):
		print("yes")
	else:
		print("no")

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
input()
M = [int(i) for i in input().split()]

def solve(i, m):
    if m == 0:
        res = True
    elif i >= n:
        res = False
    else:
        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:
n = int(input())
A = [int(i) for i in input().split()]
input()
M = [int(i) for i in 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 m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
input()
M = [int(i) for i in input().split()]

def solve(i, m):
    if m == 0:
        return True
    if i >= n or m < 0:
        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:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return 1
    if i >= n or num < 0:
        return ""
    return solve(i+1, num), solve(i+1, num-A[i])

    
for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return 1
    if i >= n or num < 0:
        return ""
    return solve(i+1, num), solve(i+1, num-A[i])

    
for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return
    if i >= n or num < 0:
        return
    return solve(i+1, num), solve(i+1, num-A[i])

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

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return
    if i >= n or num < 0:
        return
    return solve(i+1, num), solve(i+1, num-A[i])

    
for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    num = int(num)
    i = int(i)
    if num == 0:
        global sw
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
import numpy as np
n = int(input())
A = np.array(map(int, input().split()))
q = int(input())
m = np.array(map(int, input().split()))


def solve(i, num):
    if num == 0:
        global sw
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    global sw
    if sw == 1:
        return 1
    if num == 0:
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))


def solve(i, num):
    global sw
    if sw == 1:
        return 1
    if num == 0:
        sw = 1
        return 0
    if i >= n or num < 0:
        return 0
    if num < A[i]:
        return solve(i+1,num)
    return solve(i+1, num), solve(i+1, num-A[i])

for num in m:
    i = 0
    sw = 0
    solve(i,num)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

imList = []
def solve(i, m):
    global sw
    if sw == 1:
        return 0
    elif m == 0:
        sw = 1
        return 1
    elif [i,m] in imList:
        print("NN")
        imList.append([i,m])
        return 0
    elif m < 0 or i >= n:
        return 0
    else:
        return solve(i+1, m), solve(i+1, m-A[i])

for m in M:
    i = 0
    sw = 0
    solve(i,m)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

def solve(i, m):
    global sw
    if sw == 1:
        return 0
    if m == 0:
        sw = 1
        return 1
    if m < 0:
        return 0
    if [i,m] in imList:
        return 0
    else:
        imList.append([i,m])
        
    if i >= n:
        return 0
    else:
        return solve(i+1, m), solve(i+1, m-A[i])

for m in M:
    i = 0
    sw = 0
    imList = []
    solve(i,m)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

def solve(i, m):
    global sw
    if sw == 1:
        return 0
    if m == 0:
        sw = 1
        return 1
    if m < 0:
        return 0

    if i >= n:
        return 0
    else:
        return solve(i+1, m), solve(i+1, m-A[i])

for m in M:
    i = 0
    sw = 0
    imList = []
    solve(i,m)
    if sw == 0:
        print("no")
    if sw == 1:
        print("yes")

Submission status: Runtime Error

Solution code:
#coding:utf-8
import numpy as np
import math
pi = math.pi
cos = math.cos
sin = math.sin
n = int(input())
if n == 0:
    n = int(input())
A, B = np.array([0,0]), np.array([100,0])

def inc(A, B):
    AB = B - A
    rot = np.array([[cos(pi/2), -sin(pi/2)],[sin(pi/2), cos(pi/2)]])
    convertedAB = np.dot(rot, AB)
    normAB = np.linalg.norm(AB)
    D = AB / 2 + (3**(1/2)/6) * convertedAB
    return D


def koch(A, B, i):
    AB = B - A
    if i >= n:
        return 1
    C = A + AB/3
    koch(A,C,i+1)
    print(" ".join([str(num) for num in C]))
    D = inc(A, B)
    koch(C,D,i+1)
    print(" ".join([str(num) for num in D]))
    E = A + 2*AB/3
    koch(D,E,i+1)
    print(" ".join([str(num) for num in E]))
    koch(E,B,i+1)

    koch(A, C, i+1),koch(C, D, i+1), koch(D, E, i+1), koch(E,B,i+1)


print(" ".join([str(float(num)) for num in A]))
i = 0
koch(A,B,i)
print(" ".join([str(float(num)) for num in B]))

Submission status: Runtime Error

Solution code:
n = int(input())

arr = map(int,raw_input().split())

m = int(input())

arr_m = map(int,raw_input().split())

def rec(m,i,s):
	if s == m:
		return True

	elif i >= n:
		return False

	else :
		return rec(m,i+1,s) or rec(m,i+1,s+arr[i])


for i in range(m):
	print 'yes' if rec(arr_m[i],0,0) else 'no'

Submission status: Runtime Error

Solution code:
def solve(a, m): 
    if len(a) == 0:
        if m == 0:
            return True
        else:
            return False
    else:
        if solve(a[1:], m - a[0]):
            return True
        else:
            return solve(a[1:], m)

n = int(input())
tmp = input().split()
a = []
for i in range(n):
    a.append(int(tmp[i]))
q = int(input())
tmp = input().split()
m = []
for i in range(q):
    m.append(int(tmp[i]))

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

Submission status: Runtime Error

Solution code:
def solve(a, m): 
    if m < 0 or m > sumA:
        return False
    if m == 0:
        return True
    if len(a) == 0:
        return False
    return solve(a[1:], m - a[0]) or solve(a[1:], m)

n = int(input())
tmp = input().split()
a = []
for i in range(n):
    a.append(int(tmp[i]))
q = int(input())
tmp = input().split()
m = []
for i in range(q):
    m.append(int(tmp[i]))

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

Submission status: Runtime Error

Solution code:
int n
list=[]
int q,M,i

n=input()

i=0
while i<n:
	list.append(input())
	i=i+1

q=input()

i=0
while i<q:
	M=input()
	if(solve(0,M)): print("yes\n")
	else: print("no\n")
	i=i+1

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

Submission status: Runtime Error

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


n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes\n")
	else: print("no\n")
	i=i+1

Submission status: Runtime Error

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


n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes")
	else: print("no")
	i=i+1

Submission status: Runtime Error

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


n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes")
	else: print("no")
	i=i+1

Submission status: Runtime Error

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


n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes\n")
	else: print("no\n")
	i=i+1

Submission status: Runtime Error

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

n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes")
	else: print("no")
	i=i+1

return 0

Submission status: Runtime Error

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

n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes")
	else: print("no")
	i=i+1

Submission status: Runtime Error

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

n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes");
	else: print("no");
	i=i+1

Submission status: Runtime Error

Solution code:
n=0
list=[]
q=0
M=0

n=int(input())

i=0
while i<n:
	list.append(input())
	i=i+1

q=int(input())

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

i=0
while i<q:
	M=int(input())
	if(solve(0,M)): print("yes");
	else: print("no");
	i=i+1

Submission status: Runtime Error

Solution code:
def stdinput():
    from sys import stdin
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    A = list(sorted(map(int, stdinput().split(' '))))
    q = int(stdinput())
    M = list(map(int, stdinput().split(' ')))

    for m in M:
        if check(m, A):
            print('yes')
        else:
            print('no')

def check(m, A):
    # print(f'{m}:{A}')
    if m == 0:
        return True
    elif len(A) == 0:
        return False
    elif m > 0:
        for i, a in enumerate(A):
            if check(m-a, A[:i] + A[i+1:]):
                return True
    return False

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Runtime Error

Solution code:
def stdinput():
    from sys import stdin
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    A = list(sorted(map(int, stdinput().split(' '))))
    q = int(stdinput())
    M = list(map(int, stdinput().split(' ')))

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

def check(m, a, A):
    # print(f'{m}, {a}, {A}')
    for i, next_a in enumerate(A):
        this_a = a + next_a
        if this_a == m:
            return True
        elif this_a < m:
            if check(m, this_a, A[i+1:]):
                return True
    return False

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Runtime Error

Solution code:
def stdinput():
    from sys import stdin
    return stdin.readline().strip()

def main():
    n = int(stdinput())
    A = list(sorted(map(int, stdinput().split(' ')), reverse=True))
    q = int(stdinput())
    M = list(map(int, stdinput().split(' ')))

    for m in M:
        if check(m, 0, list(filter(lambda a: a <= m, A))):
            print('yes')
        else:
            print('no')

def check(m, a, A):
    # print(f'{m}, {a}, {A}')
    for i, next_a in enumerate(A):
        this_a = a + next_a
        if this_a == m:
            return True
        elif this_a < m:
            if check(m, this_a, A[i+1:]):
                return True
    return False

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')