While sitting on a call about live coding on the topic of "trees", two programmers from "Kanda Software" started playing a game on paper — drawing trees. Naturally, not green ones with leaves, but graphs.
They started with a tree consisting of a single vertex numbered $$$1$$$. Then they added a vertex numbered $$$2$$$ and connected them with an edge, resulting in the second tree, and they named vertex number $$$2$$$ its root.
Then they agreed that each subsequent $$$n$$$-th tree would be constructed from the $$$(n - 1)$$$-th tree using the following procedure:
After several trees, they ran out of space on the paper, and they decided to stop drawing and start counting, posing problems to each other to compute characteristics of their sequence of trees.
One would think of two numbers, $$$n$$$ and $$$v$$$, and the other had to calculate the sum of the vertex numbers on the shortest path from the root of the $$$n$$$-th tree to vertex $$$v$$$ (including both the starting and ending vertices).
At this point, Slava noticed their game and suggested that for better understanding of the material, they compute the required sum for sufficiently large values of $$$n$$$. Naturally, performing such complex calculations on paper is impossible. Help them do this.
The first line contains two integers $$$n$$$ and $$$v$$$ $$$(1 \le v \le n \le 10^{18})$$$ — the number of the tree and the number of the vertex in the tree, respectively.
In a single line, output the integer $$$S$$$ – the sum of the vertex numbers on the shortest path from the root of the $$$n$$$-th tree to vertex $$$v$$$ (including both the starting and ending vertices).
It is guaranteed that $$$S$$$ does not exceed $$$9 \cdot 10^{18}$$$.
2 1
3
3 2
5
6 1
12
9 6
23
![]() | ![]() |
The $$$2$$$-nd and $$$3$$$-rd trees, respectively.
![]() | ![]() |
The $$$6$$$-th and $$$9$$$-th trees, respectively.
First test example
The sum of the vertex numbers on the path is $$$2 + 1 = 3$$$.
Second test example
The sum of the vertex numbers on the path is $$$3 + 2 = 5$$$.
Third test example
The sum of the vertex numbers on the path is $$$6 + 5 + 1 = 12$$$.
Fourth test example
The sum of the vertex numbers on the path is $$$9 + 8 + 6 = 23$$$.