#P8668. [蓝桥杯 2018 省 B] 螺旋折线

[蓝桥杯 2018 省 B] 螺旋折线

Problem Description

As shown in the figure, the spiral polyline passes through every integer lattice point on the plane exactly once.

For a lattice point (X,Y)(X, Y), we define its distance to the origin dis(X,Y)\text{dis}(X, Y) as the length of the spiral polyline segment from the origin to (X,Y)(X, Y).

For example, dis(0,1)=3\text{dis}(0, 1)=3, and dis(2,1)=9\text{dis}(-2, -1)=9.

Given the integer coordinates (X,Y)(X, Y), can you compute dis(X,Y)\text{dis}(X, Y)?

Input Format

XX and YY.

Output Format

Output dis(X,Y)\text{dis}(X, Y).

0 1
3

Hint

For 40%40\% of the testdata, 1000X,Y1000-1000\le X, Y\le 1000.

For 70%70\% of the testdata, 105X,Y105-10^5\le X, Y \le 10^5.

For 100%100\% of the testdata, 109X,Y109-10^9\le X, Y \le 10^9.

Translated by ChatGPT 5