1850G.md (2530B)
1 Source: https://codeforces.com/problemset/problem/1850/G 2 3 G. The Morning Star 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 A compass points directly toward the morning star. It can only point in one of eight directions: the four cardinal directions (N, S, E, W) or some combination (NW, NE, SW, SE). Otherwise, it will break. 22 23  The directions the compass can point. 24 25 There are $n$ distinct points with integer coordinates on a plane. How many ways can you put a compass at one point and the morning star at another so that the compass does not break? 26 27 Input 28 29 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows. 30 31 The first line of each test case contains a single integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the number of points. 32 33 Then $n$ lines follow, each line containing two integers $x_i$, $y_i$ ($-10^9 \leq x_i, y_i \leq 10^9$) — the coordinates of each point, all points have distinct coordinates. 34 35 It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$. 36 37 Output 38 39 For each test case, output a single integer — the number of pairs of points that don't break the compass. 40 41 Example 42 43 Input 44 45 ``` 46 5 47 48 3 49 50 0 0 51 52 -1 -1 53 54 1 1 55 56 4 57 58 4 5 59 60 5 7 61 62 6 9 63 64 10 13 65 66 3 67 68 -1000000000 1000000000 69 70 0 0 71 72 1000000000 -1000000000 73 74 5 75 76 0 0 77 78 2 2 79 80 -1 5 81 82 -1 10 83 84 2 11 85 86 3 87 88 0 0 89 90 -1 2 91 92 1 -2 93 ``` 94 95 Output 96 97 ``` 98 6 99 2 100 6 101 8 102 0 103 ``` 104 105 Note 106 107 In the first test case, any pair of points won't break the compass: 108 109 * The compass is at $(0,0)$, the morning star is at $(-1,-1)$: the compass will point $\text{SW}$. 110 * The compass is at $(0,0)$, the morning star is at $(1,1)$: the compass will point $\text{NE}$. 111 * The compass is at $(-1,-1)$, the morning star is at $(0,0)$: the compass will point $\text{NE}$. 112 * The compass is at $(-1,-1)$, the morning star is at $(1,1)$: the compass will point $\text{NE}$. 113 * The compass is at $(1,1)$, the morning star is at $(0,0)$: the compass will point $\text{SW}$. 114 * The compass is at $(1,1)$, the morning star is at $(-1,-1)$: the compass will point $\text{SW}$. 115 116 In the second test case, only two pairs of points won't break the compass: 117 118 * The compass is at $(6,9)$, the morning star is at $(10,13)$: the compass will point $\text{NE}$. 119 * The compass is at $(10,13)$, the morning star is at $(6,9)$: the compass will point $\text{SW}$.