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())
seq = list(map(int, input().split()))
q = int(input())
mlist = list(map(int, input().split()))
mins = min(seq)
sums = 0
for a in seq:
    sums += a

def check(i, m):
    global mins
    if m == 0:
        return True
    elif i >= n or mins > m:
        return False
    res = check(i+1, m) + check(i+1, m - seq[i])
    return res

for m in mlist:
    if (mins > m or sums < m):
        print('no')
    elif(check(0,m)):
        print('yes')
    else:
        print('no')

Submission status: Runtime Error

Solution code:
import numpy as np

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

def deci_to_bin_list(num, n):
    out = np.zeros(n, dtype='int')
    for i in range(n-1, -1, -1):
        denom = 2**i
        out[i] = num // denom
        num = num % denom
    return out

def sums_to_num(A, num):
    n = len(A)
    for cnt in range(2**n - 1):
        selected = deci_to_bin_list(cnt, n)
        if np.sum(A*selected) == num:
            return 'yes'
    return 'no'

for num in m:
    print(sums_to_num(A, num))

Submission status: Runtime Error

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

	return False



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

q = int(raw_input())
for i in xrange(q):
	m = int(raw_input())
	if solve(0, m):
		print "yes"
	else:
		print "no"

Submission status: Runtime Error

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

	return False


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

q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
	if solve(0, m):
		print "yes"
	else:
		print "no"

Submission status: Runtime Error

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

aset = set()
for i in range(1, len(a) + 1):
    aset |= set(sum(combi) for combi in itertools.combinations(a, i))

for m in map(int, input().split()):
    print('yes' if m in aset else '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())

S = []
for k in range(1,2**len(A)):
    S.append(map(int,list((format(k,'b').zfill(len(A))))))

for m in mi:
    for k in range(len(S)):
        tot = 0
        for j in range(len(S[k])):
            if S[k][j]:
                tot += A[j]
        if m == tot:
            print 'yes'
            break
    else:
        print '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())

S = []
for k in xrange(1,2**len(A)):
    S.append(map(int,list((format(k,'b').zfill(len(A))))))

for m in mi:
    for k in xrange(len(S)):
        tot = 0
        for j in xrange(len(S[k])):
            if S[k][j]:
                tot += A[j]
        if m == tot:
            print 'yes'
            break
    else:
        print 'no'

Submission status: Runtime Error

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_A
# Exhaustive Search
# Result:
import sys

def calc(target, cur_sum, ary, ary_idx):
    new_sum = cur_sum + ary[ary_idx]
    if new_sum == target:
        return True
    ary_idx += 1
    if ary_idx == len(ary):
        return False
    return calc(target, cur_sum, ary, ary_idx) or \
           calc(target, new_sum, ary, ary_idx)

### main
nums_len = int(sys.stdin.readline().rstrip())
nums = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert len(nums) == nums_len
vals_len = int(sys.stdin.readline().rstrip())
vals = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert len(vals) == vals_len

for val in vals:
    if calc(val, 0, nums, 0):
        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())
ans=chk=0
bits=(1<<n)-1
for i in m:
    p=bits
    flag=0
    while p:
        chk=str(bin(p))[2:]
        chk='0'*(n-len(chk))+chk
        p-=1
        h=0
        for j,k in enumerate(chk):
            if k=='1':
                h+=a[j]
            if h==i:
                print 'yes'
                p=0
                flag=1
                continue
            elif h>i:
                break
    if flag==0:
        print 'no'

Submission status: Runtime Error

Solution code:
def solve( p, t ):
	global isExist
	global n
	global A
	isExist[ t ] = True
	if p < n:
		solve( p+1, t-A[p] )
		solve( p+1, t )

isExist = [False]*2001 
n = int( raw_input() )
A = map( int, raw_input().split( " " ) )
q = int( raw_input() )
M = map( int, raw_input().split( " " ) )
s = sum( A )
solve( 0, s )
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
def solve( p, t ):
	global isExist
	global n
	global A
	isExist[ t ] = True
	if p < n:
		solve( p+1, t-A[p] )
		solve( p+1, t )

isExist = [False]*2001 
n = int( input() )
A = map( int, input().split( " " ) )
q = int( input() )
M = map( int, input().split( " " ) )
s = sum( A )
solve( 0, s )
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
def solve( p, t ):
	global isExist
	global n
	global A
	isExist[ t ] = True
	if p < n:
		solve( p+1, t-A[p] )
		solve( p+1, t )

isExist = [False]*2001 
n = int( input() )
A = [ int( val ) for val in input().split( " " ) ]
q = int( input() )
M = [ int( val ) for val in input().split( " " ) ]
s = sum( A )
solve( 0, s )
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
def solve( p, t ):
	global isExist
	global n
	global A
	isExist[ t ] = True
	if p < n:
		solve( p+1, t-A[p] )
		solve( p+1, t )
	else:
		return


isExist = [False]*2001 
n = int( raw_input() )
A = [ int( val ) for val in raw_input().split( ' ' ) ]
q = int( raw_input() )
M = [ int( val ) for val in raw_input().split( ' ' ) ]
s = sum( A )
solve( 0, s )
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
isExist = [False]*2001 
n = int( raw_input() )
A = [ int( val ) for val in raw_input().split( ' ' ) ]
for i in A:
	for j in range( 2000-i, 0, -1 ):
		if isExist[j]:
			isExist[ i+j ] = True
	isExist[i] = True
 
q = int( raw_input() )
M = [ int( val ) for val in raw_input().split( ' ' ) ]
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
isExist = [False]*2001 
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
for i in A:
	for j in range( 2000-i, 0, -1 ):
		if isExist[j]:
			isExist[ i+j ] = True
	isExist[i] = True
 
q = int( input() )
M = [ int( val ) for val in input().split( ' ' ) ]
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
isExist = [False]*2001 
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]

q = int( input() )
M = [ int( val ) for val in input().split( ' ' ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
q = int( input() )
M = [ int( val ) for val in input().split( ' ' ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
d = int( input() )
c = [ int( val ) for val in input().split( " " ) ]
f = int( input() )
b = [ int( val ) for val in input().split( " " ) ]
for i in range( 0, 3 ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
isExist = [False]*2001 
n = int( input() )
q = int( input() )
for i in range( 0, 3 ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
q = int( input() )
for i in range( 0, 3 ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
for i in A:
	for j in range( 2000-i, 0, -1 ):
		if 1 == isExist[j]:
			isExist[ i+j ] = 1
	isExist[i] = 1

q = int( input() )
M = [ int( val ) for val in input().split( ' ' ) ]
for i in range( 0, q ):
	if 1 == isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
q = int( input() )
M = [ int( val ) for val in input().split( ' ' ) ]
for i in range( 0, q ):
	if 1 == isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
q = int( input() )
for i in range( 0, q ):
	if 1 == isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
q = int( input() )
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
d = int( input() )
for i in range( 0, d ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
d = int( input() )
for i in range( 0, 5 ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
n = int( input() )
d = int( input() )
for i in range( 0, 5 ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
a = int( input() )
d = int( input() )
for i in range( 0, 5 ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
q = int( input() )
z = [ int( val ) for val in input().split( ' ' ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
import sys
n = int( sys.stdin.readline( ) )
A = [ int( val ) for val in sys.stdin.readline( ).split( ' ' ) ]
q = int( sys.stdin.readline( ) )
z = [ int( val ) for val in sys.stdin.readline( ).split( ' ' ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
n = int( input( ) )
t = [ int( val ) for val in input( ).rstrip( ).split( " " ) ]
q = int( input( ) )
s = [ int( val ) for val in input( ).split( " " ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
import sys
n = int( sys.stdin.readline( ) )
A = [ int( val ) for val in input( ).rstrip( ).split( " " ) ]
q = int( sys.stdin.readline( ) )
M = [ int( val ) for val in input( ).split( " " ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Runtime Error

Solution code:
isExist = [0]*2001 
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
for i in A:
	for j in range( 2000-i, 0, -1 ):
		if 1 == isExist[j]:
			isExist[ i+j ] = 1
	isExist[i] = 1

q = int( input() )
M = [ int( val ) for val in input().rstrip( ).split( ' ' ) ]
for i in range( 0, q ):
	if 1 == isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
def solve( p, t ):
	global isExist, n, A
	isExist[ t ] = True
	if p < n:
		solve( p+1, t-A[p] )
		solve( p+1, t )
	else:
		return

isExist = [False]*2001 
n = int( input() )
A = map( int, input().rstrip().split( " " ) )
q = int( input() )
M = map( int, input().rstrip().split( " " ) )
s = sum( A )
solve( 0, s )
for i in range( 0, q ):
	if isExist[ M[i] ]:
		print( "yes" )
	else:
		print( "no" )

Submission status: Runtime Error

Solution code:
import sys


def search_combination(elements, target):
    if len(elements) == 0:
        if target == 0:
            return True
        else:
            return False

    return search_combination(elements[1:], target - elements[0]) or search_combination(elements[1:], target)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    elements = [int(x) for x in lines[1].split(" ")]
    targets = [int(x) for x in lines[3].split(" ")]

    for target in targets:
        result = "yes" if search_combination(elements, target) else "no"
        print(result)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys


def search_combination(elements, target):
    if len(elements) == 0:
        if target == 0:
            return True
        else:
            return False

    return search_combination(elements[1:], target - elements[0]) or search_combination(elements[1:], target)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    elements = [int(x) for x in lines[1].split(" ")]
    targets = [int(x) for x in lines[3].split(" ")]

    for target in targets:
        result = "yes" if search_combination(elements, target) else "no"
        print(result)

Submission status: Runtime Error

Solution code:
#coding:utf-8
#1_5_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-numbers[i])
    return res

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

for i in range(q):
    if solve(0, int(input())):
        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()))


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

for m in M:
    if (solve(0, m)):
        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(' '))


S = [0]*len(A)
flags = [False]*len(M)
def brute_force(n):
    if n == len(S):
        ans = 0
        for i in range(len(S)):
            if S[i] == 1: ans += A[i]
        for i in range(len(M)):
            if ans == M[i]: flags[i] = True
    else:
        S[n] = 0
        brute_force(n+1)
        S[n] = 1
        brute_force(n+1)


brute_force(0)

for flag in flags:
    if flag: print "yes"
    else: print "no"

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(f.readline())
A = [int(i) for i in input().split()]
q = int(f.readline())
m = [int(i) for i in input().split()]
MAX_LENGTH = len(A)
#i番目以降の値を使ってmを作ればTrueを返す
def fullSearch(i, m):
    #終了条件
    if m == 0:
        return True
    elif i >= MAX_LENGTH:
        return False
    else:
        #全探索かっこわるい
        return fullSearch(i + 1, m) or fullSearch(i + 1, m - A[i])

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

Submission status: Runtime Error

Solution code:
n = input()

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

q = input()

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

for i in range(q):
  for j in range(n):
    if A[n-j] < m[i]:
      m[i] = m[i] - A[n-j]
    if m[i] <= 0:
      break
  if m[i] == 0:
    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() )

for i in n-1
  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

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() )

for i in n-1
  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

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() )

for i in range( len(A) + 1 ):
  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

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() )

for i in range( len(A) + 1 ):
  def solve(i, m)
    if m == 0:
      return yes
    if i >= n:
      return no
    res = solve( i+1 , m ) | solve( i+1 , m-A[i] )
    return res

Submission status: Runtime Error

Solution code:
n = input()

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

for i in m:
  for j in range(n):
    if A[-j] <= i
      i = i - A[-j]
    if i <= 0:
      break
  if i == 0:
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n = input()

A = {}
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 i in m:
  if solve(0,i):
    print "yes"
  else:
    print "no"

Submission status: Runtime Error

Solution code:
n = input()
 
A = {}
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:
n = int( raw_input() )
A = map( int , raw_input().split() )
q = int( raw_input() )
m = map( int , raw_input().split() )

for i in range( len(A) + 1 ):
  def solve(i, m)
    if m == 0 or solve( i+1 , m ) or solve( i+1 , m-A[i] ):
      return yes
    if i >= n or m < 0:
      return no

Submission status: Runtime Error

Solution code:
n = raw_input()
A = map(int, raw_input().split())
d = {}
 
def solution(i, m, n):
    if m == 0:
        return True
    if i >= n:
        return False
    if d.has_key((i, m)):
        return d[(i, m)]
    res = solution(i + 1, m, n) or solution(i + 1, m - A[i], n)
    d[(i, m)] = res
    return res
 
 
q = raw_input()
M = map(int, raw_input().split())
for m in M:
    if solution(0, m, n):
        print 'yes'
    else:
        print 'no'

Submission status: Runtime Error

Solution code:
n = raw_input()
A = map(raw_input().split())
d = {}
 
def solution(i, m, n):
    if m == 0:
        return True
    if i >= n:
        return False
    if d.has_key((i, m)):
        return d[(i, m)]
    res = solution(i + 1, m, n) or solution(i + 1, m - A[i], n)
    d[(i, m)] = res
    return res
 
 
q = raw_input()
M = map(raw_input().split())
for m in M:
    if solution(0, m, n):
        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() )

for i in range( len(A) + 1 ):
  def solve(i, m)
    if m == 0 or solve( i+1 , m ) or solve( i+1 , m-A[i] ):
      print 'yes'
    if i >= n or m < 0:
      print '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() )

for i in range( len(A) + 1 ):
  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 mi
  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()
mi = map( int , raw_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 mi
  if solve( 0 , m ):
    print 'yes'
  else:
    print 'no'

Submission status: Runtime Error

Solution code:
def main():
  n = input()
  A = map(int, raw_input().split())
  p = input()
  m = map(int, raw_input().split())
  for i in range(q)
    if solve(0, m[q], A)
  for j in range()

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

Submission status: Runtime Error

Solution code:
n = input()
A = map( int , raw_input().split() )
q = input()
mi = map( int , raw_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 mi:
  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 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:
n = input()
a = []
b = []

for i in range(n):
  a[i] = input()

m = input()
for j in range(m):
  b[j] = input()

for j in range(m):
  for i in range(n):
    if b[j] - a[i] < 0:
      i = i + 1
    elif b[j] - a[i] == 0:
      return yes
    elif b[j] - a[i] > 0:
      b[j] = b[j] - a[i]
return no

Submission status: Runtime Error

Solution code:
def main():
  n = input()
  A = map(int, raw_input().split())
  p = input()
  m = map(int, raw_input().split())
  for i in range(q)
    if solve(0, m[q], A):
      print 'yes'
    else:
      print 'no'

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

Submission status: Runtime Error

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


n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())
for i in range(q)
  if solve(0, m[q], A):
    print 'yes'
  else:
    print 'no'

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-A[i])
  return res


n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())
for i in range(q)
  if solve(0, m[q]):
    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() )
mi = map( int , raw_input().strip().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 mi:
  if solve( 0 , m ):
    print 'yes'
  else:
    print 'no'

Submission status: Runtime Error

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


n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())
for i in range(q)
  if solve(0, m[q], A, n):
    print 'yes'
  else:
    print 'no'

Submission status: Runtime Error

Solution code:
n = input()
a = []
b = []

for i in range(n):
  a[i] = input()

m = input()

for j in range(m):
  b[j] = input()
  for i in range(n):
    if b[j] - a[i] < 0:
      i = i + 1
    elif b[j] - a[i] == 0:
      return yes
    elif b[j] - a[i] > 0:
      b[j] = b[j] - a[i]
return no

Submission status: Runtime Error

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

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 mi:
  if solve( 0 , m ):
    print 'yes'
  else:
    print 'no'

Submission status: Runtime Error

Solution code:
n = input()
A = []
for i in range(n):
   A.append(int(raw_input()))

q = input()
M = []
for i in range(n):
   M.append(int(raw_input()))

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 i in range(len(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
  elif i >= n:
    return False
  else:
    res = solve( i+1 , m ) | solve( i+1 , m-A[i] )
    return res

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

Submission status: Runtime Error

Solution code:
n = input()
A = []
for i in range(n):
   A.append(int(raw_input()))

q = input()
M = []
for i in range(n):
   M.append(int(raw_input()))

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 i in M:
   if solve(0,m):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
n = input()
A = []
for i in range(n):
   A.append(int(raw_input()))

q = input()
M = []
for i in range(n):
   M.append(int(raw_input()))

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 M:
   if solve(0,m):
      print "yes"
   else:
      print "no"

Submission status: Runtime Error

Solution code:
def fact(k):
    if k == 0: 
     return 1
    return k * fact(k - 1)

n = input()
a=[0]*n

for i in range(n):
 a = input()

q = input()
m = [0]*q

for i in range(q):
 m = input()

ans=[0]*fact(k)

for s in range(t):
 for t in range(n):
   ans[s*(t+1)] +=a[t]
if x in ams:
 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()

for i in range(int(num_n) - 1):
    for j in range(2 ** (int(num_m) - 1)):
        sum[j] = 0
        sum[j] += m[j]
        sum += m[j]
        if n[i] == sum:
            print "yes"
            break
    print "no"

Submission status: Runtime Error

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

n2 = input()
q = map(int, raw_input().split())

list = set()

for i in range(n1):
 for j in range(n2):
  if i != j:
   list.add( A[i] + A[j] )

for i in range(n2):
  if q[i] in list:
   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 and m > sum(A)
return false
res = solve(i + 1, m) or solve(i + 1, m - A[i])
return res

for m in M
   if res = 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 and m > sum(A)
return False
res = solve(i + 1, m) or solve(i + 1, m - A[i])
return res

for m in M
   if res = 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 and m > sum(A)
   return False
res = solve(i + 1, m) or solve(i + 1, m - A[i])
return res

for m in M
   if res = 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 and 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:
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 and 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:
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:
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:
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:
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:
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"