#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000000+5;
char s[N];
int n;
int main(){
freopen ("strts.in","r",stdin);
freopen ("strts.out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
int l=1,r=n;ll ans=0;
while(l<r){
if (s[l]==s[r]){
l++,r--;
}
else{
int p=l,q=r;
while(s[p]!=s[r])p++;
while(s[q]!=s[l])q--;
int n1=p-l,n2=r-q;
if (n1<=n2){
ans+=n1;
for (int i=p;i>l;i--)swap(s[i],s[i-1]);
}
else{
ans+=n2;
for (int i=q;i<r;i++)swap(s[i],s[i+1]);
}
l++,r--;
}
}
printf("%lld\n",ans);
return 0;
}