650A.md (2026B)
1 Source: https://codeforces.com/problemset/problem/650/A 2 3 A. Watchmen 4 5 time limit per test 6 7 3 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 Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*, *y**i*). 22 23 They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i* - *x**j*| + |*y**i* - *y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . 24 25 The success of the operation relies on the number of pairs (*i*, *j*) (1 ≤ *i* < *j* ≤ *n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. 26 27 Input 28 29 The first line of the input contains the single integer *n* (1 ≤ *n* ≤ 200 000) — the number of watchmen. 30 31 Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|, |*y**i*| ≤ 109). 32 33 Some positions may coincide. 34 35 Output 36 37 Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. 38 39 Examples 40 41 Input 42 43 ``` 44 3 45 1 1 46 7 5 47 1 5 48 ``` 49 50 Output 51 52 ``` 53 2 54 ``` 55 56 Input 57 58 ``` 59 6 60 0 0 61 0 1 62 0 2 63 -1 1 64 0 1 65 1 1 66 ``` 67 68 Output 69 70 ``` 71 11 72 ``` 73 74 Note 75 76 In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and  for Daniel. For pairs (1, 1), (1, 5) and (7, 5), (1, 5) Doctor Manhattan and Daniel will calculate the same distances.