Problem:
Exhaustive Search

Write a program which reads a sequence A of n elements and an integer M, and outputs "yes" if you can make M by adding elements in A, otherwise "no". You can use an element only once.

You are given the sequence A and q questions where each question contains Mi.

Input

In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers (Mi) are given.

Output

For each question Mi, print yes or no.

Constraints

n ≤ 20

q ≤ 200

1 ≤ elements in A ≤ 2000

1 ≤ Mi ≤ 2000

Sample Input 1

5
1 5 7 10 21
8
2 4 17 8 22 21 100 35

Sample Output 1

no
no
yes
yes
yes
yes
no
no

Notes

You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions:

solve(0, M)

solve(1, M-{sum created from elements before 1st element})

solve(2, M-{sum created from elements before 2nd element})

...

The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations.

For example, the following figure shows that 8 can be made by A[0] + A[2].

Solution in C (judge verdict: Accepted)

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define SEQUENCE_LEN_MIN (1)
#define SEQUENCE_LEN_MAX (20)
#define QUESTION_MIN (1)
#define QUESTION_MAX (200)
#define ELEMENT_MIN (1)
#define ELEMENT_MAX (2000)
#define QUESTION_INTEGER_MIN (1)
#define QUESTION_INTEGER_MAX (2000)
#define STR_SIZE    (5)
#define SUCCESS     (0)
#define FAILURE     (-1)
#define FALSE       (0)
#define TRUE        (1)


typedef enum
{
    LINE_FEED,
    BLANK,
    DELIMITER_ERROR
}DELIMITER_INFO;

int solve(int idx, int value, int *p_arr, int size);
int exhaustive_Search(int *pArr, int size);
DELIMITER_INFO get_int(int *num, int min, int max);
DELIMITER_INFO get_str(char *p_str, int min, int max);
int judge_constraint(int test_num, int min, int max);


int main(void)
{
    int num;
    int sequence[SEQUENCE_LEN_MAX];
    int i;
    
    if(get_int(&num, SEQUENCE_LEN_MIN, SEQUENCE_LEN_MAX) != LINE_FEED)
    {
        return FAILURE;
    }

    for(i = 0; i < num - 1; i++)
    {
        if(get_int(&sequence[i], ELEMENT_MIN, ELEMENT_MAX) != BLANK)
        {
            return FAILURE;
        }
    }
    if(get_int(&sequence[i], ELEMENT_MIN, ELEMENT_MAX) != LINE_FEED)
    {
        return FAILURE;
    }

    exhaustive_Search(&sequence[0], num);
    
    return SUCCESS;
}

int solve(int idx, int value, int *p_arr, int size)
{
    int rslt;
    
    if(value == 0)
    {
        return TRUE;
    }
    
    if(idx >= size)
    {
        return FALSE;
    }
    
    rslt = solve(idx + 1, value, p_arr, size) || solve(idx + 1, value - p_arr[idx], p_arr, size);
    
    return rslt;
}

int exhaustive_Search(int *pArr, int size)
{
    int i;
    int question;
    int arr[QUESTION_MAX];
    
    if(get_int(&question, QUESTION_MIN, QUESTION_MAX) != LINE_FEED)
    {
        return FAILURE;
    }

    for(i = 0; i < question - 1; i++)
    {
        if(get_int(&arr[i], QUESTION_INTEGER_MIN, QUESTION_INTEGER_MAX) != BLANK)
        {
            return FAILURE;
        }
    }
    
    if(get_int(&arr[i], QUESTION_INTEGER_MIN, QUESTION_INTEGER_MAX) != LINE_FEED)
    {
        return FAILURE;
    }

    for(i = 0; i < question; i++)
    { 
        if(solve(0, arr[i], pArr, size) == TRUE)
        {
            puts("yes");
        }
        else
        {
            puts("no");
        }
    }
   
     
    return 0;
}

DELIMITER_INFO get_int(int *num, int min, int max)
{
    char str[STR_SIZE];
    DELIMITER_INFO delimiter;
    unsigned int i;
    
    delimiter = get_str(str, min, max);
    
    for(i = 0; i < STR_SIZE; i++)
    {
        if(str[i] == '\0')
        {
            break;
        }
        if(!isdigit(str[i]))
        {
            return DELIMITER_ERROR;
        }
    }
    
    *num = atoi(str);
    
    if(judge_constraint(*num, min, max) == -1)
    {
        return DELIMITER_ERROR;
    }    

    return delimiter;
}

DELIMITER_INFO get_str(char *p_str, int min, int max)
{
    unsigned int cnt = 0;
    int ch;
    
    while((ch = getchar()) != -1)
    {
        if(ch == ' ' || ch == '\n')
        {
            p_str[cnt] = '\0';
            if(ch == ' ')
            {
                return BLANK;
            }
            else
            {
                return LINE_FEED;
            }
        }
                        
        p_str[cnt] = ch;
        cnt++;
        
        if(judge_constraint(cnt + 1, min, max) == -1)
        {
            break;
        }
    }
    
    return DELIMITER_ERROR;
}

int judge_constraint(int test_num, int min, int max)
{
    if(test_num < min || test_num > max)
    {
        return FAILURE;
    }
    
    return SUCCESS;
}