#include <iostream>

using namespace std;

int main()
{
    string n;
    cin >> n;

    int cfr[10], tr[10];
    int br = 0, res = 0; //brojac

    tr[0] = n[0];

    for(int j = 1; j < n.size(); j++){
        int p = 1;
        if(n[j] == tr[br])
            cfr[br]++;
        else{
            br++;
            cfr[br]++;
            tr[br] = n[j];
            for(int i = 0; i < br-1 && p; i++)
                if(n[j] == tr[i]){
                    p = 0;
                    for(int t = i; t < br-1; t++)
                        res += cfr[i];
                }
        }
    }
    cout << res;
    return 0;
}