Language: C++

#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 200100;
const int B[] = {13337, 1007};
const int MOD[] = {1e9+7, 1e9+9};

int add(int a, int b, int m) {
  a += b;
  if (a < 0) a += MOD[m];
  if (a >= MOD[m]) a -= MOD[m];
  return a;
}

int mul(int a, int b, int m) {
  return (ll)a * b % MOD[m];
}

int n, pot[MAXN][2];
pii h1[MAXN], h2[MAXN];

char s[MAXN];

pii f1(int a, int b) {
  pii k = mp(0, 0);
  if (a) k = mp(mul(h1[a - 1].fi, pot[b][0], 0), mul(h1[a - 1].sec, pot[b][1], 1));
  return mp(add(h1[a + b - 1].fi, -k.fi, 0), add(h1[a + b - 1].sec, -k.sec, 1));
}

pii f2(int a, int b) {
  pii k = mp(0, 0);
  k = mp(mul(h2[a + 1].fi, pot[b][0], 0), mul(h2[a + 1].sec, pot[b][1], 1));
  return mp(add(h2[a - b + 1].fi, -k.fi, 0), add(h2[a - b + 1].sec, -k.sec, 1));
}

int cnt[200];

int main() {
  scanf("%s",s);
  n = strlen(s);
  
  ll sol = (ll)n * (n + 1) / 2;
  REP(i, n) cnt[s[i] - 'a']++;
  REP(i, 'z') sol -= (ll)cnt[i] * (cnt[i] + 1) / 2;
  printf("%lld\n",sol + 1);
  return 0;


  pot[0][0] = pot[0][1] = 1;
  h1[0] = mp(s[0] - 'a' + 1, s[0] - 'a' + 1);
  FOR(i, 1, n) {
    REP(j, 2) pot[i][j] = mul(pot[i - 1][j], B[j], j);
    h1[i].fi = mul(h1[i - 1].fi, B[0], 0);
    h1[i].fi = add(h1[i].fi, s[i] - 'a' + 1, 0);
    h1[i].sec = mul(h1[i - 1].sec, B[1], 1);
    h1[i].sec = add(h1[i].sec, s[i] - 'a' + 1, 1);
  }

  for (int i = n - 1; i >= 0; i--) {
    h2[i].fi = mul(h2[i + 1].fi, B[0], 0);
    h2[i].fi = add(h2[i].fi, s[i] - 'a' + 1, 0);
    h2[i].sec = mul(h2[i + 1].sec, B[1], 1);
    h2[i].sec = add(h2[i].sec, s[i] - 'a' + 1, 1);
  }

  REP(i, n) {
    int lo = 1, hi = n, mid;
    while (lo != hi) {
      mid = (lo + hi + 1) / 2;
      if (i - mid + 1 < 0 || i + mid - 1 >= n) {
        hi = mid - 1;
        continue;
      }
      if (f1(i - mid + 1, mid) == f2(i + mid - 1, mid)) lo = mid;
      else hi = mid - 1;
    }
    TRACE("prvo" _ i _ lo);
    sol -= lo;
    
    lo = 0; hi = n;
    while (lo != hi) {
      mid = (lo + hi + 1) / 2;
      if (i - mid + 1 < 0 || i + mid >= n) {
        hi = mid - 1;
        continue;
      }
      if (f1(i - mid + 1, mid) == f2(i + mid, mid)) lo = mid;
      else hi = mid - 1;
    }
    TRACE("drugo" _ i _ lo);
    sol -= lo;
  }

  printf("%lld\n",sol + 1);
  return 0;
}


Compiler output:
a.cc:34:23: error: narrowing conversion of '1.000000007e+9' from 'double' to 'int' [-Wnarrowing]
   34 | const int MOD[] = {1e9+7, 1e9+9};
      |                    ~~~^~
a.cc:34:30: error: narrowing conversion of '1.000000009e+9' from 'double' to 'int' [-Wnarrowing]
   34 | const int MOD[] = {1e9+7, 1e9+9};
      |                           ~~~^~