Buggy python submission (verdict: Time Limit Exceeded):
def soleve(i, m, A):
    if m == 0:
        return True
    if i >= len(A):
        return False
    res = soleve(i + 1, m, A) or soleve(i + 1, m - A[i], A)
    return res

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 soleve(0, m, A):
        print 'yes'
    else:
        print 'no'

Fixed submission:
n = int(raw_input())
A = map(int, raw_input().split())
d = {}

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


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

Buggy python submission (verdict: Time Limit Exceeded):
def soleve(i, m, A, n):
    if m == 0:
        return True
    if i >= n:
        return False
    res = soleve(i + 1, m, A, n) or soleve(i + 1, m - A[i], A, n)
    return res

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 soleve(0, m, A, n):
        print 'yes'
    else:
        print 'no'

Fixed submission:
n = int(raw_input())
A = map(int, raw_input().split())
d = {}

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


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
A = map(int, raw_input().split())

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


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

Fixed submission:
n = int(raw_input())
A = map(int, raw_input().split())
d = {}

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


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
A = map(int, raw_input().split())
result = []

def soleve(i, m, n):
    if m == 0:
        return True
    if i >= n:
        return False
    a = soleve(i + 1, m, n)
    b = soleve(i + 1, m - A[i], n)
    if a:
        result.append(m)
    if b:
        result.append(m - A[i])
    return a or b


q = int(raw_input())
M = map(int, raw_input().split())
for m in M:
    if m in result:
        print 'yes'
    elif soleve(0, m, n):
        print 'yes'
    else:
        print 'no'

Fixed submission:
n = int(raw_input())
A = map(int, raw_input().split())
d = {}

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


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
A = map(int, raw_input().split())
d = {}
def soleve(i, m):
    if (i, m) in d.keys():
        return d[(i, m)]
    if m == 0:
        return True
    if i >= n:
        return False
    a = soleve(i + 1, m)
    d[(i+1, m)] = a
    b = soleve(i + 1, m - A[i])
    d[(i+1, m-A[i])] = b
    return a or b


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

Fixed submission:
n = int(raw_input())
A = map(int, raw_input().split())
d = {}

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


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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
A = map(int, raw_input().split())

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


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

Fixed submission:
n = int(raw_input())
A = map(int, raw_input().split())
d = {}

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


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