Minesweeper II

View as PDF

Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type

Minesweeper II

You are standing in position 0,0 on an infinite minefield. By making moves down and to the right, you are trying to get to position X, Y.

The "riskiness" of your position is equal to the number of bits in the binary representation of the XOR between its row and column.

For example, if you're standing at position 5,17, then your riskiness is 2, because:

  • 5 XOR 17 = 0b101 XOR 0b10001 = 0b10100 = 20.
  • There are 2 set bits (1s) in the binary represenation of 20.

The "danger" of a path is defined as the maximum riskiness of all positions along that path.

Given a position X, Y you want to go to, what is the minimum danger you can have along the journey there?

Input

The first line of each test case contains two integers, X and Y, which represent the coordinates of the place you want to go to. The values of X and Y are constrained by 0 \leq X, Y \leq 10^6.

Output

Output the minimum "danger" you can have when travelling from 0,0 toX,Y, by making moves down and to the right.

Example

Input
3 2
Output
2
  • Begin at 0,0. Riskiness = bits(0 XOR 0) = 0
  • Move to 1,0. Riskiness = bits(1 XOR 0) = 1
  • Move to 2,0. Riskiness = bits(2 XOR 0) = 1
  • Move to 2,1. Riskiness = bits(2 XOR 1) = 2
  • Move to 2,2. Riskiness = bits(2 XOR 2) = 0
  • Move to 3,2. Riskiness = bits(3 XOR 2) = 1

The maximum riskiness along the path is 2, so the danger of this path is 2. It can be shown that 2 is the minimum danger possible to get to 3,2.


Comments

There are no comments at the moment.