Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define vi vector<int>
#define vvi vector<vector<int,int>>
#define vll vector<ll>
#define sz(a) (int)a.size()
#define mp(x,y) make_pair(x,y)
#define read freopen("math.in","r",stdin);
#define fastinput ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//int dx[] = { -1,-1,-1,0,1,1,1,0 }, dy[] = { -1,0,1,1,1,0,-1,-1 }; //8 neighbours moving
//int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 }; //4 neighbours moving
const double PI = 3.14159265;
const auto EPS = 1e-9;
const ll N = 1e5 + 1, OO = 1e16, MOD = 1e9 + 7;

int main() 
{
	fastinput;
	string s;
	cin >> s;
	int n = s.length();
	int res = INT_MAX;
	for (char c = 'a'; c < 'z'; c++)
	{
		int cost = 0;
		for (int i = 0; i < n; i++)
		{
			cost += abs(s[i] - c);
		}
		res = min(res, cost);
	}
	cout << res;
	return 0;
}
Copy
Palindrome Substrings Khedr
GNU G++17
3 ms
504 KB
Wrong Answer
Test Case #1
1 ms
184 KB
Accepted
Input
abcfa
Output
7
Judge Output
7
Checker Message
single line: '7'
Test Case #2
1 ms
280 KB
Accepted
Input
ababab
Output
3
Judge Output
3
Checker Message
single line: '3'
Test Case #3
0 ms
216 KB
Accepted
Input
xzziioiizzx
Output
77
Judge Output
77
Checker Message
single line: '77'
Test Case #4
3 ms
504 KB
Accepted
Input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
Output
1250000
Judge Output
1250000
Checker Message
single line: '1250000'
Test Case #5
0 ms
204 KB
Accepted
Input
hqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvs
Output
282
Judge Output
282
Checker Message
single line: '282'
Test Case #6
1 ms
192 KB
Accepted
Input
tkjprepggxrpnrvystmwcysyycqpevikef
Output
199
Judge Output
199
Checker Message
single line: '199'
Test Case #7
1 ms
212 KB
Accepted
Input
aboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovao
Output
249
Judge Output
249
Checker Message
single line: '249'
Test Case #8
1 ms
216 KB
Accepted
Input
uxwhmsncbxcoksfzkvatx
Output
150
Judge Output
150
Checker Message
single line: '150'
Test Case #9
0 ms
220 KB
Accepted
Input
hqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvshqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvs
Output
564
Judge Output
564
Checker Message
single line: '564'
Test Case #10
2 ms
312 KB
Accepted
Input
tkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxfxtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknlyjyhfixjswnkkufnuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsajlfvgubfaaovlzylntrkdcpwsr...
Output
195765
Judge Output
195765
Checker Message
single line: '195765'
Test Case #11
1 ms
208 KB
Accepted
Input
epzshkljugggekjdqzjenpevqgxiepjsrdzjazujllchhbfqmkimwzobiwybxduunfsksrsrtekmqdcyzjeeuhmsrqcozijipfioneeddpszrnavymmtatbdzqsoemuvnpppsuacbazuxmhecthlegrpunkdmbppweqtgjoparmowzdqyoxytjbbhawdydcprjbxphoohpkwqyuhrqzhnbnfuvqnqqlrzjpxiogvliexdzuzosrkrusvo...
Output
14026
Judge Output
14026
Checker Message
single line: '14026'
Test Case #12
1 ms
256 KB
Accepted
Input
lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
Output
0
Judge Output
0
Checker Message
single line: '0'
Test Case #13
1 ms
272 KB
Wrong Answer
Input
azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Output
73
Judge Output
25
Checker Message
1st lines differ - expected: '25', found: '73'