#include <iostream>
using namespace std;

typedef long long LL;

const int N = 100010, M = 150;

string s;
int Pre[N], Next[N], Idx[M];

int main()
{
    cin >> s;

    int n = s.size();
    s = ' ' + s;

    for (int i = 1; i <= n; i++)
    {
        Pre[i] = Idx[s[i]];
        Idx[s[i]] = i;
    }

    for (int i = 97; i <= 122; i++)
        Idx[i] = n + 1; // 右边界初始化

    for (int i = n; i >= 1; i--)
    {
        Next[i] = Idx[s[i]];
        Idx[s[i]] = i;
    }

    LL ans = 0;
    for (int i = 1; i <= n; i++)
        ans += (LL)(i - Pre[i]) * (Next[i] - i);

    cout << ans << endl;
    return 0;
}
