fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int f[100005]; // caay o vi tri i da chet chua
  5.  
  6.  
  7. int main(){
  8.  
  9. string s;
  10. while(cin >> s){
  11. f[s.size()]++;
  12. }
  13. vector<int> a;
  14. for(int i = 1; i <= 100000; i++){
  15. if(f[i] >= 2){
  16. int cnt = f[i]/2;
  17. while(cnt--)a.push_back(i);
  18. }
  19. }
  20. sort(a.begin(), a.end(), greater<int>());
  21. int totals = 0;
  22. for(int i = 1; i < a.size(); i+= 2){
  23. totals += a[i-1]* a[i];
  24. }
  25. cout << totals;
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty