Buggy python submission (verdict: Runtime Error):
'''
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]

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

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

A = sorted(A)

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

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

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

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

A = sorted(A)
#m = sorted(m)

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

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

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

Buggy python submission (verdict: Time Limit Exceeded):
import time

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

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    start = time.time()
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
    end = time.time()
    #print end - start

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

Buggy python submission (verdict: Time Limit Exceeded):
import time
from array import array

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

if __name__ == '__main__':
    n = int(raw_input())
    A = array('I', map(int, raw_input().split()))
    q = int(raw_input())
    m = array('I', map(int, raw_input().split()))

    start = time.time()
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
    end = time.time()
    #print end - start

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

Buggy python submission (verdict: Time Limit Exceeded):
import time

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

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    #start = time.time()
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"
    #end = time.time()
    #print end - start

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"

Buggy python submission (verdict: Time Limit Exceeded):
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])

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

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

Fixed submission:
def sequence(A, n):
    dic = {}
    
    def solve(i, m):
        if (i, m) in dic:
            return dic[(i, m)]
        if m == 0:
            dic[(i, m)] = True
        elif i >= n:
            dic[(i, m)] = False
        elif solve(i+1, m):
            dic[(i, m)] = True
        elif solve(i+1, m-A[i]):
            dic[(i, m)] = True
        else:
            dic[(i, m)] = False
        return dic[(i, m)]
    
    return solve

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    q = int(raw_input())
    m = map(int, raw_input().split())

    solve = sequence(A, n)
    for m_i in m:
        print "yes" if solve(0, m_i) else "no"