#include <iostream>                                                                                                                                                                                                                                                                
#include <algorithm>                                                                                                                                                                                                                                                               
#include <cstring>                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                   
using namespace std;                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                   
int main()                                                                                                                                                                                                                                                                         
{                                                                                                                                                                                                                                                                                  
    long long cnt[26];                                                                                                                                                                                                                                                             
    memset(cnt, 0, sizeof(long long)*26);                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                   
    string s;                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                   
    cin >> s;                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                   
    long long n = strlen(s.c_str());                                                                                                                                                                                                                                               
    long long ans = n*(n-1)/2 + 1;                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                   
    for (auto c : s )                                                                                                                                                                                                                                                              
        cnt[c-'a']++;                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                   
    for (auto c : cnt)                                                                                                                                                                                                                                                             
        ans -= c*(c-1)/2;                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                   
    cout << ans << endl;                                                                                                                                                                                                                                                           
}  

Measured memory_bytes: 640