Buggy python submission (verdict: Runtime Error):

def solve(a, m):
	return solve_(a, 0, m)

def solve_(a, i, m):
	res = False
	if m == 0:
		res = True
	elif i >= len(a):
		res = False
	else:
		res1 = solve_(a, i + 1, m)
		res2 = solve_(a, i + 1, m - a[i])
		res = res1 or res2
	return res

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(a, m[i]):
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')

Buggy python submission (verdict: Time Limit Exceeded):
def subset_sum(s, a):
	return subset_rec(0, s, a)
	
def subset_rec(i, s, a):
	if s == 0:
		return True
	if i >= len(a):
		return False
	return subset_rec(i+1, s-a[i], a) or subset_rec(i+1, s, a)	

n = int(input())
a = list(map(int, input().split()))
p = int(input())
q = list(map(int, input().split()))
for i in range(p):
	if subset_sum(q[i], a):
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')

Buggy python submission (verdict: Runtime Error):

def solve(arr, target):
	return solve_rec(0, arr, target)

def solve_rec(i, arr, target):	
	if target == 0:
		return True
	if i >= len(arr):
		return False
	res1 = solve_rec(i + 1, arr, target)
	res2 = solve_rec(i + 1, arr, target - arr[i])
	if res1 == True or res2 == True:
		return True
	return False


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

for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')

Buggy python submission (verdict: Runtime Error):

def solve(arr, target):
	return solve_rec(0, arr, target)

def solve_rec(i, arr, target):	
	if target == 0:
		return True
	if i >= len(arr):
		return False
	res1 = solve_rec(i + 1, arr, target)
	res2 = solve_rec(i + 1, arr, target - arr[i])
	if res1 == True or res2 == True:
		return True
	return False


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

for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')

Buggy python submission (verdict: Runtime Error):

def solve(arr, target):
	return solve_rec(0, arr, target)

def solve_rec(i, arr, target):	
	if target == 0:
		return True
	if i >= len(arr):
		return False
	res1 = solve_rec(i + 1, arr, target)
	res2 = solve_rec(i + 1, arr, target - arr[i]
	return res1 or res2

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

for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')

Buggy python submission (verdict: Runtime Error):

def solve(arr, target):
	return solve_rec(0, arr, target)

def solve_rec(i, arr, target):	
	if target == 0:
		return True
	if i >= len(arr):
		return False
	res1 = solve_rec(i + 1, arr, target)
	res2 = solve_rec(i + 1, arr, target - arr[i])
	return res1 or res2

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

for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')

Buggy python submission (verdict: Runtime Error):

def solve(arr, target):
	return solve_rec(0, arr, target)

def solve_rec(i, arr, target):
	if target == 0:
		return True
	if i >= len(arr):
		return False
	res1 = solve_rec(i + 1, arr, target)
	res2 = solve_rec(i + 1, arr, target - arr[i])
	return res1 or res2

n = int(input())
arr = list(map(int, input().split()))
q = int(input())
targets = list(map(int, input().split()))
for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



Fixed submission:
def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 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 subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')