Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/bit-birlar-yigindisi

Ones from 1 to n

Medium 1000 ms 128 MB 49%
Share

A positive integer $n$ is given. How many digits $1$ are there in total in the binary representations of the numbers $1, 2, \ldots, n$? For example, for $n = 5$: $1, 10, 11, 100, 101$ — $7$ in total.

Binary representations of the numbers from 1 to n one under another; the count of ones in each column below

Input

One positive integer $n$.

Output

One integer — the number of ones.

Note

$1 \le n \le 10^{17}$

Examples

Input #1
5
Output #1
7
Input #2
1
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.