Problem:
Score : 500 points

Problem Statement

You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters.

You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j.

You can perform this operation at most once.

How many different strings can you obtain?

Constraints

1 \leq |A| \leq 200,000

A consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

A

Output

Print the number of different strings you can obtain by reversing any substring in A at most once.

Sample Input 1

aatt

Sample Output 1

5

You can obtain aatt (don't do anything), atat (reverse A[2..3]), atta (reverse A[2..4]), ttaa (reverse A[1..4]) and taat (reverse A[1..3]).

Sample Input 2

xxxxxxxxxx

Sample Output 2

1

Whatever substring you reverse, you'll always get xxxxxxxxxx.

Sample Input 3

abracadabra

Sample Output 3

44

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef pair<int,int> pint;
typedef pair<tint,tint> ptint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

tint ele(tint a, tint b){
	if(b==0)return 1;
	if(b%2==0){
		return ele(a*a, b/2);
	}else{
		return a*ele(a*a, b/2);
	}
}

tint mcd(tint a, tint b){
	if(a==0)return b;
	return mcd(b%a, a);
}

double d_abs(long a, long b){
	if(a>b){
		return a-b;
	}
	return b-a;
}

string s;
vector<int> L, p;

void findLongestPalindromicString()
{
   string s2="|";
   forn(i, s.size()){
	   s2+=s[i];
	   s2+='|';
   }
   forn(i, s2.size()*2)p.pb(-1);
   int c = 0, r = 0; // Here the first element in s2 has been processed.
	int m = 0, n = 0; // The walking indices to compare if two elements are the same
	for (int i = 1; i<(int)s2.size(); i++) {
		if (i>r) {
			p[i] = 0; m = i-1; n = i+1;
		} else {
			int i2 = c*2-i;
			if (p[i2]<(r-i-1)) {
				p[i] = p[i2];
				m = -1; // This signals bypassing the while loop below. 
			} else {
				p[i] = r-i;
				n = r+1; m = i*2-n;
			}
		}
		while (m>=0 && n<(int)s2.size() && s2[m]==s2[n]) {
			p[i]++; m--; n++;
		}
		if ((i+p[i])>r) {
			c = i; r = i+p[i];
		}
	}
	
    
}

void posta(string t){
	int m=(int)t.size();
	set<string> ans;
	forn(i, m){
		forsn(j, i+2, m){
			//cout<<i<<", "<<j<<endl;
			string cambio=t.substr(0, i);
			string rev="";
			forsn(a, i, j){
				rev=t[a]+rev;
			}
			cambio+=rev;
			cambio+=t.substr(j);
			//cout<<"eee "<<cambio<<endl;
			if(ans.find(cambio)==ans.end()){
				ans.insert(cambio);
				cout<<"meto "<<t.substr(i, j-i)<<": "<<cambio<<endl;
			}else{
				cout<<"no meto "<<t.substr(i, j-i)<<endl;
			}
		}
	}
	cout<<ans.size()<<endl;
}


void solve(){
	string t;
	cin>>t;
	tint m=t.size();
	map<char, tint> mapi;
	for(char a='a'; a<='z'; a++)mapi[a]=0;
	forn(i, m)mapi[t[i]]++;
	tint total=m*(m-1)/2;
	total++;
	for(char a='a'; a<='z'; a++){
		total-=mapi[a]*(mapi[a]-1)/2;
	}
	cout<<total<<endl;
}




int main (){
	int T;
	T=1;
	while(T--){
		solve();
	}
}