-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Hossam_and_Combinatorics.cpp
62 lines (42 loc) · 1.08 KB
/
A_Hossam_and_Combinatorics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
// Everything in the Universe is Balanced
// Every Disappointment you face in life will be balanced with something good for you
// Keep Going, Never Give up .
#define int long long
#define TestCases int TOTALTC ; cin >> TOTALTC ; for(__case__ = 1 ; __case__ <= TOTALTC ; __case__++)
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin() , (x).end()
#define nl "\n"
int __case__ = 1 ;
void solve()
{
int n ;
cin >> n ;
vector<int> v(n) ;
map<int,int> m ;
for(auto &x : v)
{
cin >> x;
m[x]++;
}
sort(all(v)) ;
int diff = abs(v.back() - v.front()) ;
int ans = 0 ;
for(auto x : v)
{
int a = x + diff ;
int b = x - diff ;
ans += m[a] ;
if(a!=b)
ans += m[b] ;
if(v.front() == v.back())
{
ans -= 1 ;
if(a != b)
ans -= 1 ;
}
}
cout << ans << nl ;
}
signed main() { FAST TestCases solve(); }