This page is still under construction.

Parts of this page are still being built. What you see may change.

Hide and Seek 5

Time limit0.25sMemory limit512 MB

Summary
Subin walks (X±1) or teleports (2X) each second while her sibling's position grows by an accelerating walk; find the earliest second she can land exactly on the sibling, or -1.
Level

Medium7 of 10

Topics
BFS, Graph, Math, Implementation
Solved
No attempts yet

Problem

Subin is playing hide and seek with her younger sibling. Subin is currently at point N(0≤N≤500,000)N(0 \le N \le 500{,}000), and her sibling is at point K(0≤K≤500,000)K(0 \le K \le 500{,}000).

Subin can walk or teleport. When Subin is at position XX, walking moves her to X−1X-1 or X+1X+1 after 1 second, and teleporting moves her to 2X2X after 1 second.

The sibling only walks. The sibling moves every second, and the distance covered accelerates. Each move covers 1 more than the previous move. That is, the sibling's initial position is KK, after 1 second it is K+1K+1, after 2 seconds it is K+1+2K+1+2, and after 3 seconds it is K+1+2+3K+1+2+3.

Given the positions of Subin and her sibling, write a program that finds how many seconds it takes at the earliest for Subin to find her sibling. The position where Subin finds her sibling must be an integer coordinate, and Subin cannot move to a coordinate less than 00 or greater than 500,000500{,}000.

Input

The first line gives Subin's position NN and her sibling's position KK. NN and KK are integers.

Output

Print the earliest time in seconds for Subin to find her sibling. If Subin cannot find her sibling, or the position where she finds it exceeds 500,000500{,}000, print −1-1.

Examples5

  1. Example 1

    Input
    5 17
    
    Expected output
    2
    
  2. Example 2

    Input
    17 5
    
    Expected output
    4
    
  3. Example 3

    Input
    6 6
    
    Expected output
    0
    
  4. Example 4

    Input
    1 500000
    
    Expected output
    -1
    
  5. Example 5

    Input
    250000 499999
    
    Expected output
    1