Memory limit: 32 MB
We are given a set of positive integers . Consider a set of
non-negative integers , such that a number belongs to
if and only if is a sum of some elements from
(the elements may be repeated). For example, if , then sample numbers belonging to the set
are: 0 (the sum of 0 elements), 2, 4 and 12
or or ; and
the following do not belong to : 1 and 3.
Write a program which:
- reads from the standard input the description of the set and
the sequence of numbers ,
- for each number determines whether it belongs to the set
- writes the result to the standard output.
In the first line there is one integer : the number of elements of
the set , . The following
lines contain the elements of the set , one per line.
In the -st line there is one positive integer ,
. , .
In the -nd line there is one integer , . Each of the following lines contains one
integer in the range from to , they
are respectively the numbers .
The output should consist of lines. The -th line should
contain the word TAK ("yes" in Polish), if
belongs to , and it should contain the word NIE
For the input data:
the correct result is:
Task author: Krzysztof Onak.