Under construction

Still being built. Things may change

Believer

Time limit2sMemory limit512 MB

Summary
For each n up to 1e18, find the maximum over all positive-integer sequences summing to n of the total popcount of the multiplicities of the distinct values.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy, Math, Bit manipulation
Solved
No attempts yet

Problem

Do you believe in dragons? Imagine one of them wakes you up at night and asks the following.

Consider sequences of positive integers a=⟨a1,a2,…,ak⟩a = \langle a_1, a_2, \ldots, a_k \rangle.

Let f(a,x)f(a, x) be the number of occurrences of xx in aa. For example, f(⟨1,4,1,1⟩,1)=3f(\langle 1, 4, 1, 1 \rangle, 1) = 3.

Let c(y)c(y) be the number of ones in the binary expansion of yy. For example, c(13)=c(11012)=3c(13) = c(1101_2) = 3.

Let b(a)=∑i∈ac(f(a,i))b(a) = \sum \limits_{i \in a} c(f(a, i)). For example, b(⟨1,4,1,1⟩)=c(3)+c(1)=2+1=3b(\langle 1, 4, 1, 1 \rangle) = c(3) + c(1) = 2 + 1 = 3.

For the given value of nn, find the maximum value of b(a)b(a) over all sequences with ∑i=1kai=n\sum \limits_{i=1}^{k} a_i = n.

What would you answer?

Input

The first line contains a single integer tt (1≤t≤1031 \le t \le 10^3).

Each of the next tt lines contains a single integer nn (1≤n≤10181 \le n \le 10^{18}).

Output

For each test case, in the order of the input, print a single integer on its own line: the answer to the problem.

Notes

In the first example, one sequence with b(a)=3b(a) = 3 is a=⟨1,4,1,1⟩a = \langle 1, 4, 1, 1 \rangle.

Examples1

  1. Example 1

    Input
    2
    7
    42
    
    Expected output
    3
    10