fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. void solve() {
  7. int n;
  8. cin >> n;
  9. vector<string> arr(n);
  10. for (int i = 0; i < n; i++) cin >> arr[i];
  11. int cnt=0;
  12. vector<vector<int>>wordsfreq(n,vector<int>(26,0));
  13. for(int i=0;i<n;i++){
  14. for(int j=0;j<arr[i].size();j++){
  15. wordsfreq[i][arr[i][j]-'a']++;
  16. wordsfreq[i][arr[i][j]-'a']=wordsfreq[i][arr[i][j]-'a']%2; //making the (freq%2) 2D array;
  17. }
  18. }
  19. map<vector<int>,int>mapy;
  20. for(int i=0;i<n;i++){
  21. vector<int>curr=wordsfreq[i];
  22. cnt+=mapy[curr];//same array
  23. for(int j=0;j<26;j++){//changing one freq at a time;
  24. curr[j]=!curr[j];//toggle the freq 0->1 , 1->0
  25. cnt+=mapy[curr];
  26. curr[j]=!curr[j];//back to normal
  27. }
  28. mapy[curr]++;
  29. }
  30. cout<<cnt<<endl;
  31. }
  32.  
  33. int32_t main() {
  34. ios::sync_with_stdio(false);
  35. cin.tie(nullptr);
  36. solve();
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
0