fork download
  1. #include <iostream>
  2. #include<queue>
  3. #include <algorithm>
  4. #include <map>
  5. #include<unordered_map>
  6. #include <set>
  7. #include <fstream>
  8. #include <vector>
  9. #include <math.h>
  10. #include <iomanip>
  11. #include <string>
  12. #include <cstring>
  13. using namespace std;
  14.  
  15. #define ll long long
  16.  
  17. ll mod = 1e9+7;
  18. const int MaxN = 1e5+5;
  19. int MOD = 998244353;
  20. int bit[200000];
  21. ll dem=0;
  22.  
  23. int main() {
  24. // freopen(".INP", "r", stdin);
  25. //freopen(".OUT", "w", stdout);
  26. ll n,x;
  27. cin >> n;
  28. multiset<ll> ms;
  29. set<ll> s;
  30. for(int i=1;i<=n;i++){
  31. cin >> x;
  32. s.insert(x);
  33. ms.insert(x);
  34. }
  35. for(ll i : s){
  36. dem += (ms.count(i)*(ms.count(i)-1))/2;
  37. }
  38. cout << dem;
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5308KB
stdin
7
7 8 6 8 6 3 6
stdout
4