Summing a sub-square of a quarter of an infinite chessboard Description of the problem

Imagine a quarter of an infinite chessboard, as in a square grid, extending up and right, so that you can see the lower left corner. Place a 0 in there. Now for every other cell in position (x,y), you place the smallest non-negative integer that hasn't showed up in the column x or the row y.

It can be shown that the number in position (x, y) is x ^ y, if the rows and columns are 0-indexed and ^ represents bitwise xor.

Task

Given a position (x, y), return the sum of all elements below that position and to the left of that position, inside the square with vertices (0, 0) and (x, y).

The input

Two non-negative integers in any sensible format. Due to the symmetry of the puzzle, you can assume the input is ordered if it helps you in any way.

Output

The sum of all the elements in the square delimited by (0, 0) and (x, y).

Test cases

5, 46 -&gt; 6501
0, 12 -&gt; 78
25, 46 -&gt; 30671
6, 11 -&gt; 510
4, 23 -&gt; 1380
17, 39 -&gt; 14808
5, 27 -&gt; 2300
32, 39 -&gt; 29580
14, 49 -&gt; 18571
0, 15 -&gt; 120
11, 17 -&gt; 1956
30, 49 -&gt; 41755
8, 9 -&gt; 501
7, 43 -&gt; 7632
13, 33 -&gt; 8022
Perl 6, 19 bytes



{sum [X+^] 0 X..@_}


Try it online!

The sum of the bitwise xor between all numbers in the range 0 to all inputs.