Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


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

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

for i in M:
    if solve(A, 0, i):
        print ("yes")
    else:
        print ("no")

Fixed submission:
n = int(input())
A = list(sorted(map(int, input().split())))
q = int(input())
M = list(map(int, input().split()))

R = [[None for j in range(2000)] for i in range(n + 1)]

def solve(i, m):
    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i > n - 1:
        R[i][m] = False
        return False
    else:
        ans = solve(i + 1, m) or solve(i + 1, m - A[i])
        R[i][m] = ans
        return ans

sum_A = sum(A)
for i in M:
    if sum_A < i:
        print('no')
    elif solve(0, i):
        print('yes')
    else:
        print('no')

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


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

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

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

Fixed submission:
n = int(input())
A = list(sorted(map(int, input().split())))
q = int(input())
M = list(map(int, input().split()))

R = [[None for j in range(2000)] for i in range(n + 1)]

def solve(i, m):
    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i > n - 1:
        R[i][m] = False
        return False
    else:
        ans = solve(i + 1, m) or solve(i + 1, m - A[i])
        R[i][m] = ans
        return ans

sum_A = sum(A)
for i in M:
    if sum_A < i:
        print('no')
    elif solve(0, i):
        print('yes')
    else:
        print('no')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(sorted(map(int, input().split())))
q = int(input())
M = list(map(int, input().split()))


def solve(j, i):
    '''A[j]?????§?????¨??????i???M?????????????´??????????A[0],..,A[j]??????????????????????????????
    '''
    if i == 0:
        return True
    if j > n - 1:
        return False

    if i >= A[j]:
        tmp1 = solve(j + 1, i - A[j])
        tmp2 = solve(j + 1, i)
    else:
        # A[j]???????????§???????????§????????????????????????j??????????????\?????????
        return False

    if tmp1 or tmp2:
        return True
    else:
        return False


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

Fixed submission:
n = int(input())
A = list(sorted(map(int, input().split())))
q = int(input())
M = list(map(int, input().split()))

R = [[None for j in range(2000)] for i in range(n + 1)]

def solve(i, m):
    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i > n - 1:
        R[i][m] = False
        return False
    else:
        ans = solve(i + 1, m) or solve(i + 1, m - A[i])
        R[i][m] = ans
        return ans

sum_A = sum(A)
for i in M:
    if sum_A < i:
        print('no')
    elif solve(0, i):
        print('yes')
    else:
        print('no')