Program Captain;
Var a,b:array[0..50001]of longint;
F:array[0..26]of longint;S:ansistring;
i,j,Sum:longint;
Begin
Assign(input,'xxxx.in');Reset(input);
Assign(output,'xxxx.out');Rewrite(output);
Readln(S);
F[ord(s[1])-96]:=1;a[1]:=1;a[0]:=1;
For i:=2 to length(s) do begin
If F[ord(s[i])-96]=0 then begin
Inc(a[0]);
a[a[0]]:=i;
F[ord(s[i])-96]:=a[0];
End
else Begin
B[f[ord(s[i])-96]]:=i;
F[ord(s[i])-96]:=0;
End;
End;Sum:=0;
For i:=1 to length(s) div 2 do
For j:=i+1 to length(s) div 2 do begin
If (a[j]<b[i]) and (b[j]>b[i]) then inc(sum);
If a[j]>b[i] then break;
End;
Writeln(Sum);
Close(input);Close(output);
End.