Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    int ans = 1e9;
    for (char i = 'a'; i <= 'z'; ++i) {
        int cost = 0;
        for (char &x : s) {
            cost += abs(x - i);
        }
        ans = min(ans, cost);
    }
    cout << ans << '\n';
    return 0;
}
Copy
Palindrome Substrings Heartbeat
GNU G++17
4 ms
440 KB
Accepted