Source Code
#include<bits/stdc++.h>
#define _for(i,n) for(int i=0;i<n;i++)
#define _forr(i,n) for(int i=1;i<=n;i++)
#define _rof(i,n) for(int i=n-1;i>=0;i--)
#define _roff(i,n) for(int i=n;i>=1;i--)
#define nl cout << "\n"
#define ff first
#define ss second
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define pb push_back
#define pp pop_back
#define vl vector<ll>
#define lsb(x) (x & ~(x-1))
#define rand(l,r) uniform_int_distribution<int>(l, r)(rng);
#define IOS ios::sync_with_stdio(0); cout.tie(0); cin.tie(0)
#define pause system("pause")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

ll const mod=1e9+7;
ll const mod1=1013;
ll const MX = 2e6+100;

ll n, a[MX], b[MX];

int main()
{
    IOS;
    ll _t=1;
//    cin>>_t;
    while(_t--)
    {
        string s;
        cin>>s;
        ll ans=1e9,cur=0;
        for(char i='a';i<='z';i++)
        {
            cur=0;
            for(int j=0;j<s.size();j++)
            {
                cur+=abs(s[j]-i);
            }
            ans=min(ans, cur);
        }
        cout<<ans;nl;
    }
}

/**
Test Case:
8
5 2 5  3  -30 -30 6   9
5 7 12 15 -15 -45 -39 -30
                  15  9
*/
Copy
Palindrome Substrings ShakerOO7
GNU G++17
2 ms
912 KB
Accepted