#P8060. [POI 2003] Sums

    ID: 9156 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2003POI(波兰)最短路中国剩余定理 CRT

[POI 2003] Sums

Problem Description

You are given a set of integers AA. Consider a set of non-negative integers AA'. A number xx belongs to AA' if and only if it can be represented as the sum of some elements from AA (elements may be used repeatedly).

For example, if A={2,5,7}A = \{2,5,7\}, then numbers in AA' include: 00 (the sum of 00 elements), 22, 44 (2+22 + 2), and 1212 (5+75 + 7 or 7+57 + 5 or 2+2+2+2+2+22 + 2 + 2 + 2 + 2 + 2). However, 11 and 33 do not belong to AA'.

Input Format

The first line contains an integer nn, the number of elements in set AA. Each of the next lines contains one integer aia_i, describing an element. A={a1,a2,...,an}A = \{a_1,a_2,...,a_n\}.

Then an integer kk follows, and each of the next lines contains one integer, representing b1,b2,...,bkb_1,b_2,...,b_k.

Output Format

Output kk lines. If bib_i belongs to AA', print TAK on the ii-th line; otherwise, print NIE.

3
2
5
7
6
0
1
4
12
3
2
TAK
NIE
TAK
TAK
NIE
TAK

Hint

For all testdata, 1n5×1031 \le n \le 5 \times 10^3, 1k1041 \le k \le 10^4, 1a1<a2<...<an5×1041 \le a_1 < a_2 < ... < a_n \le 5 \times 10^4, 0bi1090 \le b_i \le 10^9.

Translated by ChatGPT 5