//I still luve you Kashish <3
#include<bits/stdc++.h>
using namespace std ;
#define int                long long
#define pb                 push_back
#define F                  first
#define S                  second
#define P                  push
#define nl                 "\n"
#define vvi                vector<vector<int>>
#define vi                 vector<int>
#define vc                 vector<char>
#define pii                vector<pair<int, int>>
#define sz(a)              (int)a.size()
#define all(a)             a.begin(),a.end()
#define sort(v)            sort(all(v))
#define sortr(v)           sort(v); reverse(all(v));
#define yes                cout << "YES"
#define no                 cout << "NO" 
#define PeeleMera          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N = 1e9 + 7 , N1 = 1e7 + 5 , N2 = 1e6 + 3, N3 = 1e5 + 3;
#define IM -1e18
#define IX 1e18


void solve()
{
    string s;
    cin>>s;
    
    int n=sz(s);
    vi v(26,0),v1(26,0);
    int ans=0;

    for(int i=n-1;i>0;i--)
    {   
        if(s[i]==s[i-1])
        {
            ans+=n-i-1-v[s[i]-97];
            // v.clear();
            v=v1;
            v[s[i]-97]+=n-i+1;
            i--;
            continue;
        }
        v[s[i]-97]++;
    }
    cout<<ans;
}

signed main(){
    PeeleMera;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    // cout<<fixed<<setprecision(9);
    while(t--)
    {
        solve();        
        cout<<endl;
    }
}
//Hoang Vu - CVA-BD High School for Gifted Student
#include <bits/stdc++.h>
using namespace std;
//ifstream f1("test.inp");
//ofstream f2("test.out");
//#define cin f1
//#define cout f2
#define fu(i,a,b) for(ll i=a;i<=b;++i)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define FastIO ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define fa(i,s) for(auto i:s)
#define ll long long
#define ld long double
#define pb push_back
//#define mp make_pair
#define ii pair<ll,ll>
#define fi first
#define se second
#define MOD 1000000007
#define inf 10000000000000000
#define MAXN 3000005
ll n,a[MAXN],res=1,su=0;
map<ll,ll> mp;
set<ll> s;
void solve()
{
    cin>>n;
    fu(i,1,n)
    {
        cin>>a[i];
        mp[a[i]]++;
        s.insert(a[i]);
    }
    vector<int> save;
    fa(i,s) save.pb(mp[i]);
    //res=save[0];
    su=save[0];
    fu(i,1,save.size()-1)
    {
        res+=save[i]*su;
        su+=save[i];
    }
    cout<<res-1;
}
int main()
{
    FastIO
    int t=1;
    //cin>>t;
    solve();
}
