ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2182. Broken Rum

Time limit: 1.0 second
Memory limit: 256 MB
A new batch of rum has arrived at the tavern “Admiral Benbow” — a total of 2n − 1 bottles, each numbered from 1 to 2n − 1. Additionally, there are 2n − 1 boxes, also numbered from 1 to 2n − 1.
Jimmy Hawkins wants to distribute all the rum bottles into the boxes, following an unusual rule: if he puts a bottle numbered k into the box with the same number k, an additional bottle appears, whose number equals the number of ones in the binary representation of k. However, if this number of ones equals k itself, then no new bottle appears.
Jimmy decided that he would only place the bottle numbered k into the box numbered k. He is also curious about how many bottles of rum will end up in each of the boxes numbered ai. Help Jimmy find the answer!
Problem illustration

Input

The first line contains an integer n (1 ≤ n ≤ 60).
The second line contains an integer q — the number of boxes that interest Jimmy (1 ≤ q ≤ 105).
The next line contains q integers ai — the numbers of the boxes that are of interest to Jimmy (1 ≤ iq, 1 ≤ ai ≤ 2n − 1).

Output

Output a single line with q numbers — the number of rum bottles in the boxes with numbers ai.

Sample

inputoutput
5
2
8 4
1 6

Notes

One bottle from the initial set will go into the box numbered 8. The box numbered 4 will also receive a bottle from the initial set and five additional ones obtained from boxes numbered: 30=111102, 29=111012, 27=110112, 23=101112, 15=11112.
Problem Author: Artyom Kutuzov
Problem Source: Ural School Programming Contest 2024