621B.md (1587B)
1 Source: https://codeforces.com/problemset/problem/621/B 2 3 B. Wet Shark and Bishops 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 standard input 16 17 output 18 19 standard output 20 21 Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. 22 23 Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other. 24 25 Input 26 27 The first line of the input contains *n* (1 ≤ *n* ≤ 200 000) — the number of bishops. 28 29 Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1 ≤ *x**i*, *y**i* ≤ 1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops share the same position. 30 31 Output 32 33 Output one integer — the number of pairs of bishops which attack each other. 34 35 Examples 36 37 Input 38 39 ``` 40 5 41 1 1 42 1 5 43 3 3 44 5 1 45 5 5 46 ``` 47 48 Output 49 50 ``` 51 6 52 ``` 53 54 Input 55 56 ``` 57 3 58 1 1 59 2 3 60 3 5 61 ``` 62 63 Output 64 65 ``` 66 0 67 ``` 68 69 Note 70 71 In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.