#include using namespace std; int main(void) { string s; cin >> s; int n = s.size(); long long dp[n+1][26][3]; for (int i = 0; i < n+1; i++) { for (int j = 0; j < 26; j++) { for (int k = 0; k < 3; k++) { dp[i][j][k] = 0; } } } for (int i = 0; i < n; i++) { int c = s[i] - 'A'; for (int j = 0; j < 26; j++) { for (int k = 0; k < 3; k++) { dp[i+1][j][k] += dp[i][j][k]; } if (c != j) { dp[i+1][c][2] += dp[i][j][1]; } } dp[i+1][c][0] += 1; dp[i+1][c][1] += dp[i][c][0]; } long long ans = 0; for (int i = 0; i < 26; i++) { ans += dp[n][i][2]; } cout << ans << endl; }