fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void executeTime() {
  5. cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
  6. }
  7.  
  8. int main() {
  9.  
  10. int n, x, y, w, b, z;
  11. cin >> n >> x >> y >> w >> b >> z;
  12.  
  13. vector<int> v(n);
  14. for (auto &x : v) {
  15. cin >> x;
  16. }
  17.  
  18.  
  19. map<array<int, 4>, int> freq;
  20.  
  21. freq[ {0, 0, 0, 0}] = 1;
  22.  
  23. int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0;
  24. int ans = 0;
  25.  
  26. for (int j = 0; j < n; j++) {
  27. if (v[j] == x) c1++;
  28. else if (v[j] == y) c2++;
  29. else if (v[j] == z) c3++;
  30. else if (v[j] == b) c4++;
  31. else c5++;
  32.  
  33. int d1 = c1 - c2, d2 = c3 - c4, d3 = c4 - c5, d4 = c1 - c5;
  34.  
  35. ans += freq[ {d1, d2, d3, d4}];
  36. freq[ {d1, d2, d3, d4}]++;
  37. }
  38.  
  39. cout << ans << endl;
  40.  
  41. executeTime();
  42. return 0;
  43. }
Success #stdin #stdout #stderr 0s 5320KB
stdin
10 1 2 3 4 5
1 2 3 4 5 1 2 3 4 5
stdout
7
stderr
Time Taken: 0.00445 secs