Buggy python submission (verdict: Time Limit Exceeded):

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

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())

for i in xrange(0,q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Fixed submission:

        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp = [[-1 for i in xrange(2001)] for j in xrange(21)]
for i in xrange(q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Here your code !



for i in xrange(50):
    for j in xrange(50):
        dp[i][j] = 0
        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp =[[-1]*1000]*1000

for i in xrange(0,q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Fixed submission:

        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp = [[-1 for i in xrange(2001)] for j in xrange(21)]
for i in xrange(q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Here your code !



for i in xrange(50):
    for j in xrange(50):
        dp[i][j] = 0
        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp =[[-1]*1000]*1000

for i in xrange(0,q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Fixed submission:

        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp = [[-1 for i in xrange(2001)] for j in xrange(21)]
for i in xrange(q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):

def solve(i, m):
  if dp[i][m] != -1:
    return dp[i][m]
 
  if m == 0:
    dp[i][m] = 1
  elif i >= n:
    dp[i][m] = 0
  elif solve(i+1, m):
    dp[i][m] = 1
  elif solve(i+1, m-A[i]):
    dp[i][m] = 1
  else:
    dp[i][m] = 0
 
  return dp[i][m]
 
 
 
n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())
 
dp = [[-1 for i in range(max(m)+1)] for j in range(n+1)]
 
for i in range(p):
  if solve(0, m[i]):
    print 'yes'
  else:
    print 'no'

Fixed submission:

        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp = [[-1 for i in xrange(2001)] for j in xrange(21)]
for i in xrange(q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"

Buggy python submission (verdict: Runtime Error):

        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp = [[-1 for i in xrange(max(p)+1)] for j in xrange(n+1)]
for i in xrange(q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"
        

Fixed submission:

        
def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m-a[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

n = input()
a = map(int,raw_input().split())
q = input()
p = map(int,raw_input().split())
dp = [[-1 for i in xrange(2001)] for j in xrange(21)]
for i in xrange(q):
    if solve(0,p[i]):
        print "yes"
    else:
        print "no"