Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <map>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using LL = long long;
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.   ios_base::sync_with_stdio(false);
  12.   string s;
  13.   cin >> s;
  14.   map<char, LL> cnt;
  15.   for (char c : s)
  16.     cnt[c]++;
  17.  
  18.   LL res = 0;
  19.   for (char c = 'a'; c <= 'z'; ++c) {
  20.     for (char c2 = 'a'; c2 <= 'z'; ++c2) {
  21.       res += abs(LL(c) - LL(c2)) * cnt[c] * cnt[c2];
  22.     }
  23.   }
  24.  
  25.   res /= 2;
  26.   cout << res * s.size() << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement