1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+ #define all (x ) x.begin(), x.end()
4
+ typedef long long ll;
5
+
6
+ struct P {
7
+ ll x, y;
8
+ P operator +(P p) const { return P{x + p.x , y + p.y }; }
9
+ P operator -(P p) const { return P{x - p.x , y - p.y }; }
10
+ ll dot (P p) const { return x * p.x + y * p.y ; }
11
+ ll cross (P p) const { return x * p.y - y * p.x ; }
12
+ bool between (P a, P b, P c, P d, bool strict) {
13
+ auto s1 = (d - c).cross (*this - c);
14
+ auto s2 = (a - b).cross (*this - b);
15
+ if (strict) return s1 && s2 && ((s1 < 0 ) ^ (s2 < 0 ));
16
+ return (s1 == 0 ) || (s2 == 0 ) || ((s1 < 0 ) ^ (s2 < 0 ));
17
+ }
18
+ };
19
+
20
+ const ll mod = 1e9 + 7 ;
21
+
22
+ void solve () {
23
+ int n;
24
+ cin >> n;
25
+ vector<P> p (n);
26
+ vector<ll> keys;
27
+
28
+ auto key = [](P &p) {
29
+ auto [x, y] = p;
30
+ return (x + 1e6 ) + (y + 1e6 ) * mod;
31
+ };
32
+
33
+ for (auto &i : p) {
34
+ cin >> i.x >> i.y ;
35
+ keys.push_back (key (i));
36
+ }
37
+
38
+ sort (all (p), [&](auto x, auto y) { return key (x) <= key (y); });
39
+ sort (all (keys));
40
+
41
+ auto cnt = [&](int a, int b, int c, int d) {
42
+ int ans = 0 ;
43
+ for (int i = 0 ; i < n; i++) {
44
+ if (i == a || i == b || i == c || i == d) continue ;
45
+ if (p[i].between (p[a], p[b], p[c], p[d], true )) {
46
+ auto s1 = (p[i] - p[b]).cross (p[c] - p[b]);
47
+ auto s2 = (p[d] - p[b]).cross (p[c] - p[b]);
48
+ if (s1 && s2 && ((s1 < 0 ) ^ (s2 < 0 ))) {
49
+ // cout << a << " " << b << " " << c << " " << d << " " << i <<
50
+ // endl;
51
+ ans++;
52
+ }
53
+ }
54
+ }
55
+ return ans;
56
+ };
57
+
58
+ int res = 0 ;
59
+ for (int k = 0 ; k < n; k++) {
60
+ for (int i = k + 1 ; i < n; i++) {
61
+ for (int j = i + 1 ; j < n; j++) {
62
+ auto a = p[k], b = p[i], c = p[j];
63
+ if ((a - b).dot (c - b) != 0 || (a - b).cross (c - b) == 0 ) continue ;
64
+
65
+ /* *
66
+ * A ---------- D
67
+ * | |
68
+ * | |
69
+ * B ---------- C
70
+ */
71
+
72
+ auto d = a + (c - b); // OD = OB + BD = OB + BA + BC = OA + BC
73
+ assert ((b - a).dot (d - a) == 0 );
74
+ auto it = lower_bound (all (keys), key (d));
75
+ if (it == keys.end () || *it != key (d)) continue ;
76
+ int idx = it - keys.begin ();
77
+
78
+ // cout << "(" << a.x << "," << a.y << ") (" << b.x << "," << b.y
79
+ // << ") (" << c.x << "," << c.y << ") => (" << d.x << "," <<
80
+ // d.y
81
+ // << ")" << endl;
82
+ // cout << k << " " << i << " " << j << " " << idx << endl;
83
+
84
+ res += cnt (k, i, j, idx);
85
+ res += cnt (j, idx, k, i);
86
+ }
87
+ }
88
+ }
89
+
90
+ cout << res << endl;
91
+ }
92
+
93
+ signed main () {
94
+ ios::sync_with_stdio (false );
95
+ cin.tie (0 );
96
+
97
+ int tt = 1 ;
98
+ cin >> tt;
99
+ while (tt--) {
100
+ solve ();
101
+ }
102
+ }
0 commit comments