279A.md (1282B)
1 Source: https://codeforces.com/problemset/problem/279/A 2 3 A. Point on Spiral 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane. 22 23 Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (*x*, *y*). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (*x*, *y*). 24 25 Input 26 27 The first line contains two space-separated integers *x* and *y* (|*x*|, |*y*| ≤ 100). 28 29 Output 30 31 Print a single integer, showing how many times Valera has to turn. 32 33 Examples 34 35 Input 36 37 ``` 38 0 0 39 ``` 40 41 Output 42 43 ``` 44 0 45 ``` 46 47 Input 48 49 ``` 50 1 0 51 ``` 52 53 Output 54 55 ``` 56 0 57 ``` 58 59 Input 60 61 ``` 62 0 1 63 ``` 64 65 Output 66 67 ``` 68 2 69 ``` 70 71 Input 72 73 ``` 74 -1 -1 75 ``` 76 77 Output 78 79 ``` 80 3 81 ```