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: Runtime Error)

#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define ff first
#define mp make_pair

using namespace std;

const ll MOD = 1000000007LL;

ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];

ll ar[1000056];


ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return (((x*x)%MOD)*a)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;

}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}

inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}

ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}

void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {

      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 

      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}


map<ll,ll> mark,has;
map<string,bool> hav;

set<ll> st;


int main() 
{
    ll n,m,t,p,q,r,s,a,b,c,d,e,f,g,h,sum,res,flag,u,v,i,j,l,k,z,x,y,len,ans=0;
    
    string str,ptr,dtr;
    
    cin>>str;
    ptr=str;
    
    len=str.length();
    
    for(i=0;i<len;i++)
    {
    	for(j=i+1;j<len;j++)
    	{
    		reverse(ptr.begin()+i,ptr.begin()+j+1);
    		hav[ptr]=1;
    		ptr=str;
		}
	}
	
	cout<<hav.size();
    
    return 0;
}