#P6747. 『MdOI R3』Teleport

『MdOI R3』Teleport

Description

Matt Horner wants to control the Hyperion to perform a warp. To warp, he must activate all nn nodes on the Hyperion.

There are nn nodes on the Hyperion. The ii-th node has aia_i energy. To activate them, Matt Horner will consume k×nk\times n units of terrazine. These k×nk\times n units of terrazine are evenly distributed to the nn nodes. After each node receives kk units of terrazine, it will be triggered and gain aixorka_i \operatorname{xor} k units of high energy. The total sum of high energy over all nodes is the warp cost SS.

To warp as fast as possible, Matt Horner decides to use as much as k×nk\times n units of terrazine as possible. Unfortunately, if too much terrazine is used so that the cost SS exceeds the limit mm, the Hyperion will be overloaded and eventually explode.

Now, your task is to help Matt Horner find the maximum kk such that the Hyperion can warp away as fast as possible while staying safe. If it is impossible to warp safely under any circumstances, output 1-1.

Here, xor\operatorname{xor} denotes the bitwise XOR operation.

Input Format

The first line contains an integer nn, the number of nodes.

The second line contains nn integers a1,a2,,ana_1,a_2,\cdots,a_n, representing the energy of each node.

The third line contains an integer qq, the number of queries.

The next qq lines describe the queries. Each line contains one number mm.

Output Format

For each query, output one line containing a non-negative integer, the maximum kk. If there is no solution, output 1-1.

3
1 2 3 
2 
10 
1
3
-1
1
0
1
1073741824000000
1073741824000000

Hint

For the first query, the maximum kk is 33. At this time, S=2+1+0=310S=2+1+0=3 \le 10. It can be proven that no larger kk satisfies the condition.

For the second query, there is no kk that satisfies the condition.

Test Point nn aia_i mm qq
11 10\le 10 220\le 2^{20} =1=1
22 103\le 10^3 103\le10^3 103\le 10^3
33 230\le 2^{30} 103\le 10^3
464\sim 6 105\le 10^5 220\le 2^{20} 106\le 10^6 105\le 10^5
7107\sim 10 230\le 2^{30} 230×106\le 2^{30}\times10^6

This problem does not use bundled tests.

The Constraints for all test points are shown above. For all data, $0<n,q\leq 10^5,\ 0\leq a_i\leq 2^{30},\ 0\leq m\leq 2^{30}\times 10^6$.

Translated by ChatGPT 5