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
468 KB
Accepted
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
192 KB
Accepted
Input
ababab
Output
3
Judge Output
3
Checker Message
single line: '3'
Test Case #3
1 ms
192 KB
Accepted
Input
xzziioiizzx
Output
77
Judge Output
77
Checker Message
single line: '77'
Test Case #4
3 ms
468 KB
Accepted
Input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
Output
1250000
Judge Output
1250000
Checker Message
single line: '1250000'
Test Case #5
0 ms
192 KB
Accepted
Input
hqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvs
Output
282
Judge Output
282
Checker Message
single line: '282'
Test Case #6
0 ms
204 KB
Accepted
Input
tkjprepggxrpnrvystmwcysyycqpevikef
Output
199
Judge Output
199
Checker Message
single line: '199'
Test Case #7
0 ms
216 KB
Accepted
Input
aboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovao
Output
249
Judge Output
249
Checker Message
single line: '249'
Test Case #8
0 ms
220 KB
Accepted
Input
uxwhmsncbxcoksfzkvatx
Output
150
Judge Output
150
Checker Message
single line: '150'
Test Case #9
1 ms
204 KB
Accepted
Input
hqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvshqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvs
Output
564
Judge Output
564
Checker Message
single line: '564'
Test Case #10
1 ms
400 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
0 ms
192 KB
Accepted
Input
lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
Output
0
Judge Output
0
Checker Message
single line: '0'
Test Case #13
0 ms
220 KB
Accepted
Input
azzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Output
25
Judge Output
25
Checker Message
single line: '25'
Test Case #14
0 ms
204 KB
Accepted
Input
sfybglgzmbintattnhodtonpyzwotkgnguphpkxeatowzabsdnvqhkfcmofisfrfqgvpmvorpjfzslzmpjjnehrykxjzubuacclfkcyzobghtuoxrajvprecwgxxpswcgmmvedewdmfnqwcuqdsciliqecihluilgmfcswtwkkxlcbhqkvcswjebkrjlpgfgratzbsguvzifnhyxwjsjavwauxpannamxjdvzuhnaczyhepwzolhuslrk...
Output
13959
Judge Output
13959
Checker Message
single line: '13959'
Test Case #15
0 ms
204 KB
Accepted
Input
aqqiannyhqouizveavgzjwoblsgwnkvjlnivqcwvzxtcthynmuxqkwwmtfisgglgcoxpipytdbamrykbokmwgsddpqkrzyjchztmiepagwhroqkhwudbcihpqwaqzxugkvakvlavkswfzsdbvqidhtbcdeytmpphkuhsxorpufwhjrutksslhlrxlydxvkosaggmpbgzvbafazjohqsswtorckqaxsrehnrlyjiwtmhglkozfkmmxtyvo...
Output
29735
Judge Output
29735
Checker Message
single line: '29735'
Test Case #16
1 ms
324 KB
Accepted
Input
qkwhhyipqzevbyktbvtpwvttgecajylqvuizfsoayxziljzegblcatmvefqrzxwktndpbbzdrwlphlgdywdofnzxqlxvkhdjyalhvvpaangodnlxhlsxshhtifxickobixbbduzvngqiaggcxfgrjmarwupaybnqgudbewkgwgtocblxjeccgqhbczibhqufqqxvllvmtzhfmbezplhqakbmmvafqyxjyexdsswbjiouymhlzcltjudob...
Output
62424
Judge Output
62424
Checker Message
single line: '62424'
Test Case #17
0 ms
216 KB
Accepted
Input
xxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxyyyy...
Output
273
Judge Output
273
Checker Message
single line: '273'
Test Case #18
1 ms
280 KB
Accepted
Input
az
Output
25
Judge Output
25
Checker Message
single line: '25'
Test Case #19
0 ms
272 KB
Accepted
Input
abcdefghijklmnopqrstuvwxyz
Output
169
Judge Output
169
Checker Message
single line: '169'
Test Case #20
0 ms
192 KB
Accepted
Input
qwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwe...
Output
6552
Judge Output
6552
Checker Message
single line: '6552'
Test Case #21
0 ms
220 KB
Accepted
Input
ithiumezcqnqfdbfgrxvsxbhhywkfntdubwfnfoavsithiumezcqnqfdbfgrxvsxbhhywkfntdubwfnfoavsithiumezcqnqfdbfgrxvsxbhhywkfntdubwfnfoavsithiumezcqnqfdbfgrxvsxbhhywkfntdubwfnfoavsithiumezcqnqfdbfgrxvsxbhhywkfntdubwfnfoavsithiumezcqnqfdbfgrxvsxbhhywkfntdubwfnfo...
Output
1752
Judge Output
1752
Checker Message
single line: '1752'
Test Case #22
0 ms
220 KB
Accepted
Input
abababababababababaaaaaaaaaaabbbbbbbbbbbbbzzzzzzzzzzzzzzzzzzzzzzhhhhhhhhhhhhhhhhbbbbbbbbbbbbzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaa
Output
1143
Judge Output
1143
Checker Message
single line: '1143'
Test Case #23
0 ms
220 KB
Accepted
Input
a
Output
0
Judge Output
0
Checker Message
single line: '0'
Test Case #24
0 ms
220 KB
Accepted
Input
jfjfjfjfjfjfjfjfjfjfjfjjfjjjjjjfffffffffjjjjjjj
Output
84
Judge Output
84
Checker Message
single line: '84'
Test Case #25
0 ms
220 KB
Accepted
Input
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Output
0
Judge Output
0
Checker Message
single line: '0'
Test Case #26
0 ms
216 KB
Accepted
Input
qazwsxedcrfvcdexswzaqplmoknnkomlpplmoknnkomlp
Output
220
Judge Output
220
Checker Message
single line: '220'
Test Case #27
0 ms
220 KB
Accepted
Input
hgfjkdsllaksjdhfdjskaksdjndsksdndsmdfndskjdjsksjdjskjdjskjdnjsjdnjskdndsmnxbcxdnsnxcxcccccccccccccccccccccccccccccccccccddddddddddddddddddd
Output
660
Judge Output
660
Checker Message
single line: '660'
Test Case #28
0 ms
208 KB
Accepted
Input
ddddddddddddddddddddddddddddddddd
Output
0
Judge Output
0
Checker Message
single line: '0'
Test Case #29
0 ms
216 KB
Accepted
Input
wwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeewwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Output
1260
Judge Output
1260
Checker Message
single line: '1260'
Test Case #30
0 ms
220 KB
Accepted
Input
okjfpwowowowoowowowowowowowoowowow
Output
131
Judge Output
131
Checker Message
single line: '131'
Test Case #31
0 ms
220 KB
Accepted
Input
kskskskskskkskssklskslakslkdnnvnvnvnvnvnvnnvnvnvnvnvnvnvnvnvnvnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Output
1357
Judge Output
1357
Checker Message
single line: '1357'
Test Case #32
0 ms
204 KB
Accepted
Input
qbqbqbqbqbqbqbqbqbqbbqbqbqbqbqbqbqbqbbqbqbbq
Output
315
Judge Output
315
Checker Message
single line: '315'
Test Case #33
0 ms
204 KB
Accepted
Input
zzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazz
Output
100
Judge Output
100
Checker Message
single line: '100'
Test Case #34
1 ms
236 KB
Accepted
Input
ishiumezcqnqfdbfgsxvsxbhhywkfnsdubwfnfoavs
Output
291
Judge Output
291
Checker Message
single line: '291'
Test Case #35
0 ms
216 KB
Accepted
Input
lkjzsezhhbsznsvcslmwxcsccxszevgkeffmangmkkzsvwssenakcxbfblqshczsfzdzooefbayxoejuvzvzyochzoecqfzynzqjvsvgzczmceiwsnssszmbujjqoovzowubwimsnxybxoksfakvzlbdknqcjcifgbjswnkkufnubbasaymnmhsookelqcinkozuhassxddgulegojwzccazvsxmzszjqfvhuyfzzovqacqnlskdxzwss...
Output
2310
Judge Output
2310
Checker Message
single line: '2310'
Test Case #36
0 ms
220 KB
Accepted
Input
ezasikqjuhhhekjdsajenzevshbgezjssdajzaujqqxiiyfsmkgmwaoygwcybduunfsksssslekmsdxcajeeuimsssxoagjgzfgoneeddzsasnzvcmmlzlydassoemuvnzzzsuzxyzaubmiexliqehszunkdmyzzweslhjozzsmowadscobcljyyizwdcdxzsjybziooizkwscuissainynfuvsnssqsajzbgohvqgebdauaossksusvo...
Output
14844
Judge Output
14844
Checker Message
single line: '14844'
Test Case #37
0 ms
220 KB
Accepted
Input
sfcyhqhamygnlzllniodlonzcawolkhnhuzizkbezlowazysdnvsikfxmofgsfsfshvzmvoszjfasqamzjjneisckbjauyuzxxqfkxcaoyhiluobszjvzsexwhbbzswxhmmvedewdmfnswxusdsxgqgsexgiqugqhmfxswlwkkbqxyiskvxswjeyksjqzhfhszlayshuvagfnicbwjsjzvwzubzznnzmbjdvauinzxaciezwaoqiusqsk...
Output
14872
Judge Output
14872
Checker Message
single line: '14872'
Test Case #38
1 ms
220 KB
Accepted
Input
zssgznncisougavezvhajwoyqshwnkvjqngvsxwvablxlicnmubskwwmlfgshhqhxobzgzcldyzmsckyokmwhsddzsksacjxialmgezzhwisoskiwudyxgizswzsabuhkvzkvqzvkswfasdyvsgdilyxdeclmzzikuisboszufwijsulkssqiqsbqcdbvkoszhhmzyhavyzfzajoissswlosxkszbsseinsqcjgwlmihqkoafkmmblcvo...
Output
31453
Judge Output
31453
Checker Message
single line: '31453'
Test Case #39
1 ms
324 KB
Accepted
Input
skwiicgzsaevycklyvlzwvllhexzjcqsvugafsozcbagqjaehyqxzlmvefssabwklndzyyadswqziqhdcwdofnabsqbvkidjczqivvzzznhodnqbiqsbsiilgfbgxkoygbyyduavnhsgzhhxbfhsjmzswuzzcynshudyewkhwhloxyqbjexxhsiyxagyisufssbvqqvmlaifmyeazqiszkymmvzfscbjcebdsswyjgoucmiqaxqljudoy...
Output
66400
Judge Output
66400
Checker Message
single line: '66400'
Test Case #40
1 ms
340 KB
Accepted
Input
lkjzazzaabazaavcslmwxcsccxszzvakzzzmaaamkkzsvwsazaakcxbzblqsaczszzzzoozzbayxozjuvzvzyocazozcqzzyazqjvavazczmczawsasaszmbujjqoovzowubwamsaxybxokszakvzlbzkaqcjcazabjswakkuzaubbaaaymamasookzlqcaakozuaasaxzzaulzaojwzccazvsxmzszjqzvauyzzzovqacqalakzxzwsa...
Output
265027
Judge Output
265027
Checker Message
single line: '265027'
Test Case #41
1 ms
220 KB
Accepted
Input
ackkzzxlcczzasaszxlzyajvsauckoaaqvzzazawxsuzazmavlzauajosmaabvczsszmwozczczajzlsaoaaoaxqkacyxaasauysajzaqxkxmvzjujazsawjaaacwlosqybwoaozxxjyaozcqlsqzszzqssasvomzuojzyzaasomasjocblbuskzxomaaovxaauwazajmwkwskzzzyajcqbzazzvmyzamzkyqzsyzazkzzawsukaaxjaq...
Output
34846
Judge Output
34846
Checker Message
single line: '34846'
Test Case #42
1 ms
344 KB
Accepted
Input
ojoazocbzazvcazsvslyxqkvzaswmsaayzxzycaaamuaacssazwzajjzwaulzssaoacuomaaazkazzwzoazawaazqlazusamkymaqzywakmycuszzmxmzkaazzaamqkzzaasaavbzazmsozmvaajkskyjaakzazaazzzbuzbsaqlaaqyzjvsjzzzjqsjkzavxxzoyzaxakmaxwasvazzclaabvzcvoamaaaaaajazuazzkqvcwjqalxmo...
Output
187565
Judge Output
187565
Checker Message
single line: '187565'
Test Case #43
1 ms
404 KB
Accepted
Input
laczvyzyzajkyjblazazyxaqaksajskacybzjxszsjowsvqzzawcavzvyzzzabszszazaayzzzawsczlaycyzqlaxvqaazskzlvczczsjzqazyzazwszzuaaasuzjaoqkmuljycbjazxlzbsbajsausavombbxaczaavzxakazaqavcbqqzsazaaamcokazoxwvwzjaoaxjoaybaajvmzazzaozaaswacsambyskazvuzkyozzlzaswws...
Output
218149
Judge Output
218149
Checker Message
single line: '218149'
Test Case #44
1 ms
340 KB
Accepted
Input
aqasbvuzwmzysoaayzssszyzllazcmxujaavaajozsxajwazbjuzaawcwzxszckczkaaawbwbvaxazzmavayazkbmkbcobzvuawqazjjaakazxwajzjzuausasszaalaasmzjyaxakaakalyzwsczzazabzakzcaozzxaxaazaaauaoszyabzsayvujzzjkabzalazzyazjubzkabzojzujavzbazaozwjmzaazaazyjzvzaaobajamaa...
Output
173428
Judge Output
173428
Checker Message
single line: '173428'
Test Case #45
1 ms
216 KB
Accepted
Input
asaaumzzcqaqzzbzaaxvsxbaaywkzaszubwzazoavs
Output
384
Judge Output
384
Checker Message
single line: '384'
Test Case #46
0 ms
220 KB
Accepted
Input
aczasuzcxalkbkzkqzzmawmzcbwqzlzlzbzaykulbx
Output
360
Judge Output
360
Checker Message
single line: '360'
Test Case #47
1 ms
312 KB
Accepted
Input
bxzklszwsbzklzkzzlwazszwzzwmwbcwubzxmzzszwcwasazxylsqubamlvuaumxluaawsablzzasaaaaazzasqczccszzkbvlbbzakxluwcxcbqzlaazzuaxzymxwvxwzamabuzyzayuxaqyaxkayzmzlksaxamqlvxsmwsulvwmybbvzsawzuuawxazqyvaaccqzslxabszmxaqzaxsqllkzuuluqzvllzsaaxqqbvzzmbmkcyqkccb...
Output
235133
Judge Output
235133
Checker Message
single line: '235133'
Test Case #48
1 ms
216 KB
Accepted
Input
bqsuzcqbzamzwqzazczqykzzukqscuzykymazzazccsqzyszlazvcxkwsqwuzbsuzwazqzwzywqkkybxbqlxwmsaszwkzzusvzbczzyzzzucukbaavvasyxkakyuzvzckvawzmaaqabvzcwuzzczbuwaaqcvqbazaxcbyvzaaxzxzzmwxlkvusaqsuwzlslsacaabyavzqcuqwzlwbbysbkbykbvcyybsmczlzqvzqbxzbzqzxcbbwbmz...
Output
31596
Judge Output
31596
Checker Message
single line: '31596'
Test Case #49
0 ms
216 KB
Accepted
Input
xmzzszwcwasazxylsqubamlvuaumxluaawsablzzasaaaaazzasqczccszzkbvlbbzakxluwcxcbqzlaazzuaxzymxwvxw
Output
826
Judge Output
826
Checker Message
single line: '826'
Test Case #50
1 ms
220 KB
Accepted
Input
qzqlzsbswqwvzulwkazquuqzakqayuzkwazxaaxavwvabvckxlbkzm
Output
407
Judge Output
407
Checker Message
single line: '407'
Test Case #51
0 ms
216 KB
Accepted
Input
z
Output
0
Judge Output
0
Checker Message
single line: '0'
Test Case #52
1 ms
216 KB
Accepted
Input
azb
Output
25
Judge Output
25
Checker Message
single line: '25'
Test Case #53
1 ms
208 KB
Accepted
Input
eh
Output
3
Judge Output
3
Checker Message
single line: '3'
Test Case #54
1 ms
216 KB
Accepted
Input
zaz
Output
25
Judge Output
25
Checker Message
single line: '25'