Program Sentence;

Const MaxLen=2000000;

Var f: Text;
    a: Array [1..MaxLen+2] of Char; // data array
    p: Array [1..MaxLen div 2] of LongInt;  // array of the words indexes
    n: Int64;  // words amount
    res: Int64; // result
    i, k: LongInt;
    counter0: LongInt; //spaces counter
    counters: Array ['a'..'z'] of LongInt; // letters counters
    c: Char;

Begin
  {Read datum}
//  Assign(f, 'sentence.in'); Reset(f);
  k:= 0;
  Repeat
    Inc(k);
    Read(a[k]);
  Until EoF or (not (a[k] in ['a'..'z',' ']));
  If (a[k] in ['a'..'z']) Then Inc(k);
  a[k]:= ' ';  //End of the last word
  a[k+1]:= '@';  //End of sentence
//  Close(f);

  {p[k] - index of the k-th word first letter}
  i:= 1;
  n:= 0;
  While a[i]<>'@' Do Begin
    Inc(n);
    p[n]:= i;
    While a[i]<>' ' Do Begin
      Inc(i);
    End;
    While a[i]=' ' Do Begin
      Inc(i);
    End;
  End;

  {Counters evaluation}
  res:= 0;
  counter0:= 0;
  Repeat
    FillChar(counters, SizeOf(counters), 0);
    For i:= 1 To n Do Begin
      If a[p[i]]=' ' Then Begin
        Inc(counter0);
        a[p[i]]:='@';
      End
      Else Begin
        If a[p[i]]<>'@' {<=a[p[i]] in ['a'..'z']} Then Begin
          Inc(counters[a[p[i]]]);
          Inc(p[i]);
        End
        {Else: a[p[i]]='@' - no process}
      End;
    End;
    {result evaluation}
    res:= res + counter0*(n-counter0);
    For c:= 'a' To 'z' Do Begin
      res:= res + (n-counters[c])*counters[c];
    End;
  Until counter0=n;
  res:= res div 2;

  {Output}
//  Assign(f, 'sentence.out'); Rewrite(f);
  Writeln(res);
//  Close(f);
End.
