Source Code
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N=2e5+5;

int n;

int main (){
string s;cin>>s;
vector <int>v;
for (auto u:s){
v.push_back(u-'a'+1);
}
sort (v.begin (),v.end ());
int m=v.size ()/2;
int ans=0;
for (auto u:v){
ans+=abs (u-v [m]);
}
cout <<ans;
}
Copy
Palindrome Substrings FEAR
GNU G++17
8 ms
1.4 MB
Accepted