Buggy python submission (verdict: Runtime Error):

n = int(raw_input())
A = map(int, raw_input().split())
sorted(A)

q = int(raw_input())
M = map(int, raw_input().split())
sorted(M)

result = []
for i in range(q):
    result.append('no ')

for i in range(n-1):
    sum_n = A[i]
    M_clone = M[:]
    flag = False
    for j in range(n-1-i):
        if flag:
            break
        sum_n += A[i+1+j]
        for k in range(len(M)):
            if M_clone[k] == sum_n:
                result[k] = 'yes '
                M.pop(k)
                flag = True
                break
            elif M_clone[k] < sum_n:
                M_clone.pop(k)

for i in range(q):
    print result[i]

Fixed submission:

n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

Buggy python submission (verdict: Runtime Error):

n = int(raw_input())
A = map(int, raw_input().split())
A.sort()

q = int(raw_input())
M = map(int, raw_input().split())
M.sort()

result = []
for i in range(q):
    result.append('no')

for i in range(n-1):
    sum_n = A[i]
    M_clone = M[:]
    flag = False
    for j in range(n-1-i):
        if flag:
            break
        sum_n = sum_n + A[i+1+j]
        for k in range(len(M)):
            if M_clone[k] == sum_n:
                result[k] = 'yes'
                M.pop(k)
                flag = True
                break
            elif M_clone[k] < sum_n:
                M_clone.pop(k)

for i in range(q):
    print result[i]

Fixed submission:

n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

Buggy python submission (verdict: Runtime Error):

n = int(raw_input())
A = map(int, raw_input().split())
A.sort()

q = int(raw_input())
M = map(int, raw_input().split())
M.sort()

result = []
for i in range(q):
    result.append('no')

for i in range(n-1):
    sum_n = A[i]
    M_clone = M[:]
    flag = False
    for j in range(n-1-i):
        if flag:
            break
        sum_n = sum_n + A[i+1+j]
        for k in range(len(M)):
            if M_clone[k] == sum_n:
                result[k] = 'yes'
                M.pop(k)
                flag = True
                break
            elif M_clone[k] < sum_n:
                M_clone.pop(k)

for i in result:
    print(i)

Fixed submission:

n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

Buggy python submission (verdict: Runtime Error):

n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

for i in range(n-1):
    sum_n = A[i]
    for j in range(n-1-i):
        ad = A[i+1+j]
        for k in range(n-2-j):
            sum_n = sum_n + ad
            ad = ad + A[i+j+2+k]
            if M[k] == sum_n:
                result[k] = 'yes'

for i in result:
    print(i)

Fixed submission:

n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

Buggy python submission (verdict: Runtime Error):
for i in range(n):
    sum_n = A[i]
    for j in range(q):
        if M[j] == sum_n:
            result[j] = 'yes'
    for j in range(n-1-i):
        sum_n = A[i]
        ad = A[i+j+1]
        sum_n = sum_n + ad
        for k in range(q):
            if M[k] == sum_n:
                result[k] = 'yes'
        for k in range(n-2-i-j):
            ad = ad + A[i+j+2+k]
            sum_n = sum_n + ad
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

Fixed submission:

n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)