PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000164. Định nghĩa kỳ lạ (Strange Definition)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Định nghĩa kỳ lạ (Strange Definition)

Strange Definition

Source: Codeforces 1470B — https://codeforces.com/problemset/problem/1470/B
Edition: Phuoc Hung OJ Extended; one dataset per program run. Subtasks are authored for PHOJ, not claimed to be official.

Problem

Two values x,yx,y are adjacent if lcm(x,y)/gcd⁡(x,y)\mathrm{lcm}(x,y)/\gcd(x,y) is a perfect square. At each second, every entry becomes the product of all entries adjacent to it, including itself. The beauty is the maximum adjacent-group size. Answer multiple queries asking for the beauty after ww seconds.

Input

An integer nn, then nn integers aia_i, then qq followed by qq integer queries ww.

Output

Print one integer per query.

Subtasks

  • Subtask 1 (20 points): n,q≤20n,q\le20, ai≤100a_i\le100.
  • Subtask 2 (30 points): n,q≤2000n,q\le2000, ai≤105a_i\le10^5.
  • Subtask 3 (50 points): n,q≤3⋅105n,q\le3\cdot10^5, ai≤106a_i\le10^6.

Example

Input

4
6 8 4 2
3
0
1
100

Output

2
3
3

Explanation

The square-free kernels are 6,2,1,26,2,1,2. At w=0w=0, the largest class has size 22; after one second, the even-size class with kernel 22 merges into kernel 11, giving beauty 33.