You are given a string consisting of lowercase English letters. You can choose any two indices and reverse the substring between those indices. You can perform this operation at most once. Determine how many different strings you can obtain by reversing any substring at most once. The input is the string, and the output is the number of different strings you can obtain.

# Buggy version:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = input()
N = len(A)

ans = N*(N-1)//2

for v in Counter(A).values():
	ans -= v*(v+1)//2

print(ans+1)

# Fixed version:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = input()
N = len(A)

ans = N*(N-1)//2

for v in Counter(A).values():
	ans -= v*(v-1)//2

print(ans+1)

# Buggy version:
a=list(input())

unko=[0]*(ord("z")+1-ord("a"))

for aa in a:
    unko[ord(aa)-ord("a")]+=1
tmp=0
for u in unko:
    tmp+=(u*(u-1))//2

print((n*(n-1))//2-tmp)

# Fixed version:
a=list(input())

unko=[0]*(ord("z")+1-ord("a"))

for aa in a:
    unko[ord(aa)-ord("a")]+=1
tmp=0
for u in unko:
    tmp+=(u*(u-1))//2

print((len(a)*(len(a)-1))//2-tmp+1)

# Buggy version:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    A=input()
    ac=list(Counter().values())
    len_a=len(A)
    ans=len_a*(len_a-1)//2
    for acc in ac:
        ans-=acc*(acc-1)//2
    print(ans)

if __name__=='__main__':
    main()

# Fixed version:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    A=input()
    ac=list(Counter(A).values())
    len_a=len(A)
    ans=len_a*(len_a-1)//2
    for acc in ac:
        ans-=acc*(acc-1)//2
    print(ans+1)

if __name__=='__main__':
    main()

# Buggy version:
s = input()
cnt = [0]*26
n = len(s)
for i in range(n):
  cnt[ord(s[i])-97] += 1
ans = n*(n+1)//2
for i in range(26):
  ans -= (cnt[i]*(cnt[i]+1)//2)*(cnt[i]>1)
print(ans+1)

# Fixed version:
s = input()
cnt = [0]*26
n = len(s)
for i in range(n):
  cnt[ord(s[i])-97] += 1
ans = n*(n-1)//2
for i in range(26):
  ans -= (cnt[i]*(cnt[i]-1)//2)
print(ans+1)

# Buggy version:

import numpy as np

dic={}
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

A = input()
for a in ascii_lowercase:
    dic[a]=[0]*len(A)

i=0
for l in A:
    dic[l][i]=1
    i+=1

for d in dic:
    dic[d]=np.cumsum(dic[d])



dp=[0]*len(A)
dp[0]=1
for i in range(1,len(A)):
    tmp = (i+1-dic[A[i]][i])
    print(tmp)
    dp[i]=dp[i-1]+tmp

print(dp[-1])

# Fixed version:

import numpy as np

dic={}
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

A = input()
for a in ascii_lowercase:
    dic[a]=[0]*len(A)

i=0
for l in A:
    dic[l][i]=1
    i+=1

for d in dic:
    dic[d]=np.cumsum(dic[d])



dp=[0]*len(A)
dp[0]=1
for i in range(1,len(A)):
    tmp = (i+1-dic[A[i]][i])
    #print(tmp)
    dp[i]=dp[i-1]+tmp

print(dp[-1])

# Buggy version:
from collections import Counter
s=list(input())
n=len(s)
c=s.Counter()
ans=1+n*(n-1)//2
for i in c.values():
  ans-=i*(i-1)//2
print(ans)

# Fixed version:
from collections import Counter
s=list(input())
n=len(s)
c=Counter(s)
ans=1+n*(n-1)//2
for i in c.values():
  ans-=i*(i-1)//2
print(ans)

# Buggy version:
A=input()
ans=0
a=A.count("a")
b=A.count("b")
c=A.count("c")
d=A.count("d")
e=A.count("e")
f=A.count("f")
g=A.count("g")
h=A.count("h")
i=A.count("i")
j=A.count("j")
k=A.count("k")
l=A.count("l")
m=A.count("m")
n=A.count("n")
o=A.count("o")
p=A.count("p")
q=A.count("q")
r=A.count("r")
s=A.count("s")
t=A.count("t")
u=A.count("u")
v=A.count("v")
w=A.count("w")
x=A.count("x")
y=A.count("y")
z=A.count("z")
B=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
for aa in range(26):
  ans=ans+B[aa]*(len(A)-B[aa])
print(ans)

# Fixed version:
A=input()
ans=0
a=A.count("a")
b=A.count("b")
c=A.count("c")
d=A.count("d")
e=A.count("e")
f=A.count("f")
g=A.count("g")
h=A.count("h")
i=A.count("i")
j=A.count("j")
k=A.count("k")
l=A.count("l")
m=A.count("m")
n=A.count("n")
o=A.count("o")
p=A.count("p")
q=A.count("q")
r=A.count("r")
s=A.count("s")
t=A.count("t")
u=A.count("u")
v=A.count("v")
w=A.count("w")
x=A.count("x")
y=A.count("y")
z=A.count("z")
B=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
for aa in range(26):
  ans=ans+B[aa]*(len(A)-B[aa])
print(ans//2+1)

# Buggy version:
s=list(input())
import collections
dics=collections.Counter(s)
num=len(s)
ans=num*(num-1)//2
for i in dics.values():
  ans-=(i*(i-1)//2)
print(ans)

# Fixed version:
s=list(input())
import collections
dics=collections.Counter(s)
num=len(s)
ans=num*(num-1)//2
for i in dics.values():
  ans-=(i*(i-1)//2)
print(ans+1)

# Buggy version:
from collections import Counter
a=input()
c=Counter(a)
if n==1:print(1)
else:
    ans=n*(n-1)//2
    for i in c.values():
        if i==1:continue
        else:ans-=i*(i-1)//2
    print(ans+1)


# Fixed version:
from collections import Counter
a=input()
c=Counter(a)
n=len(a)
if n==1:print(1)
else:
    ans=n*(n-1)//2
    for i in c.values():
        if i==1:continue
        else:ans-=i*(i-1)//2
    print(ans+1)

# Buggy version:
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    N = len(S)
    C = Counter(S)
    ans = 0
    for v in C.values():
        ans += v*(v-1)//2
    print(N*(N-1)//2-ans)


solve()


# Fixed version:
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    S = input()[:-1]
    N = len(S)
    C = Counter(S)
    ans = 0
    for v in C.values():
        ans += v*(v-1)//2
    print(N*(N-1)//2-ans+1)


solve()

# Buggy version:
from collections import Count
s = input()
n = len(s)
d = Count(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(n*(n-1)//2 - c)

# Fixed version:
from collections import Counter
s = input()
n = len(s)
d = Counter(s)
c = 0
for x in d:
  c += d[x]*(d[x]-1)//2
print(1 + n*(n-1)//2 - c)

# Buggy version:
S = input()
N = len(S)
ans = N * (N - 1) // 2
a = []
for c in [chr(i) for i in range(97, 97+26)]:
    a.append(S.count(c))
ans -= sum(a)
print(ans)

# Fixed version:
S = input()
N = len(S)
ans = N * (N - 1) // 2 + 1
a = []
cnt = 0
for c in [chr(i) for i in range(97, 97+26)]:
    cnt = S.count(c)
    a.append(cnt * (cnt - 1) // 2)
ans -= sum(a)
print(ans)

# Buggy version:
n = str(input())
lis = [0 for i in range(26)]
ans = 1
for i in range(1,len(n)+1):
  ans += i
  lis[ord(n[i])-"a"] += 1
for i in range(26):
  for k in range(lis[i]-1):
    ans -= (k+1)
print(ans)

# Fixed version:
n = str(input())
lis = [0 for i in range(26)]
ans = 1
for i in range(len(n)):
  ans += i
  lis[ord(n[i])-ord("a")] += 1
for i in range(26):
  for k in range(lis[i]-1):
    ans -= (k+1)
print(ans)

# Buggy version:
def main():
     s = list(input())
     count = (len(s)*len(s)-1)/2+1
     dic = {}
     for i in range(len(s)):
         try:
             dic[s[i]].append(i)
         except Exception:
             dic[s[i]] = [i]

     for j in dic.values():
         count-=(len(j)*len(j)-1)/2+1
     print(count)


if __name__=="__main__":
    main()

# Fixed version:
def main():
     s = list(input())
     count = int((len(s)*(len(s)-1))/2+1)
     dic = {}
     for i in range(len(s)):
         try:
             dic[s[i]].append(i)
         except Exception:
             dic[s[i]] = [i]

     for j in dic.values():
         count-=int((len(j)*(len(j)-1))/2)
     print(count)


if __name__=="__main__":
    main()

# Buggy version:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

alf = list("abcdefghijklmnopqrstuvwxyz")
A = rls()
n = len(A)
ans = n*(n-1)/2 + 1
for i in alf:
    count = 0
    for j in A:
        if(i == j):
            count += 1
    ans -= count*(count-1)/2

print(ans)


# Fixed version:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

alf = list("abcdefghijklmnopqrstuvwxyz")
A = rls()
n = len(A)
ans = n*(n-1)/2 + 1
for i in alf:
    count = 0
    for j in A:
        if(i == j):
            count += 1
    ans -= count*(count-1)/2

print(int(ans))

# Buggy version:
a=input()
l=len(a)
b=l*(l-1)/2+1
for i in range(97,123):
    c=a.count(chr(i))
    d=(c*(c-1))//2
    b-=d
print(b)

# Fixed version:
a=input()
b=1+(len(a)*(len(a)-1)//2)
for i in range(97,123):
    c=a.count(chr(i))
    d=(c*(c-1))//2
    b-=d
print(b)