Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end() 

int const N = 2e6;
int ad[500];

int main(){
    string s; 
    cin >> s; 
    for(int i = 0; i<s.size(); ++i){
          for(int a = 'a'; a <= 'z'; ++a){
                ad[a] += abs(a - s[i]);
          }
    }
    int an = 1e9;
    for(int a = 'a'; a <= 'z'; ++a)an = min(an, ad[a]);
    printf("%d\n", an);
     
}
Copy
Palindrome Substrings molukhyyeh
GNU G++17
10 ms
948 KB
Accepted