This page is still under construction.

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

Turn Game

Time limit2sMemory limit512 MB

Summary
Given final scores x and y, decide whether some prefix of 1,2,3,... can be partitioned into two groups summing to x and y, and find the minimum count of terms in Yunho's group.
Level

Medium7 of 10

Topics
Math, Greedy, Binary search, Number theory
Solved
No attempts yet

Problem

Yunho and Donghyuk are at an algorithm camp. When a problem refuses to come out, the two of them play a game instead.

The game is made of turns, and each turn is won by one of the two players. Turns are numbered starting from 11, and whoever wins turn ii earns ii points.

Given two integers xx and yy, write a program that decides whether the game can end with Yunho holding xx points and Donghyuk holding yy points. If it can, also find the smallest number of turns Yunho has to win.

Input

The first line contains two integers xx and yy. (0≤x,y≤10120 \le x, y \le 10^{12})

Output

Print the smallest number of turns Yunho has to win. If no such game exists, print −1-1.

Hint

If Yunho scores 77 and Donghyuk scores 1414, the game runs for 66 turns. Yunho winning turns 1,2,41, 2, 4 while Donghyuk wins turns 3,5,63, 5, 6 is one possible result. Yunho wins the fewest turns when he takes turns 11 and 66 and Donghyuk takes turns 2,3,4,52, 3, 4, 5.

Examples4

  1. Example 1

    Input
    7 14
    
    Expected output
    2
    
  2. Example 2

    Input
    10 0
    
    Expected output
    4
    
  3. Example 3

    Input
    932599670050 67400241741
    
    Expected output
    1047062
    
  4. Example 4

    Input
    7 13
    
    Expected output
    -1