Source Code
#include <bits/stdc++.h>
#include<queue>

using namespace std;

/************************/
const int N = 1e5 + 10;
const int M = 1000000007;
const double eps = 1e9;
const double PI = acos(-1);
const int oo = 1e9;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back
#define rall(c) (c).rbegin(),(c).rend()
#define all(c) (c).begin(),(c).end()
#define print(c) for(auto x:c) cout<<x<<" ";puts("");
#define read(c) for(auto &x:c)cin>>x;
/************************/
/*********GLOBAL*********/


/************************/



int main() {
    string s; 
    cin>>s;

    int mn=1e9,sum=0;
    for(int i=0;i<26;i++){
        for(int j=0;j<s.size();j++){
            sum+=abs((s[j]-'a')-i);
        }

        if(sum<mn) mn = sum;

        sum =0;
    }
    
    cout<<mn<<endl;


}




Copy
Palindrome Substrings Rimawi
GNU G++17
8 ms
856 KB
Accepted