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 (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    N = len(S)
    ans = N * (N - 1) // 2 + 1
    c = Counter(S)
    for k, v in c.items():
        if v > 1:
            ans -= v * (v - 1) // 2

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    A = input()
    N = len(A)
    answer = N * (N - 1) // 2 + 1
    count = Counter(A)
    key = list(count.keys())
    for k in key:
        if count[k] > 1:
            answer -= count[k] * (count[k] - 1) // 2
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

N = input()
n = len(N)

NC = Counter(N)
ans = n * (n - 1) // 2 + 1

for value in NC.values():
    ans -= value * (value - 1) // 2

print(ans)

Solution (Python):
A = list(input())
N = len(A)
letter0 = ord('a')
L = [0]*26
for i in range(N):
    L[ord(A[i])-letter0]+=1
out1 = 0
for i in range(26):
    out1 += L[i]*(L[i]-1)//2

out2 = N*(N-1)//2+1
print(out2-out1)

Solution (Python):
from collections import Counter
s = input()
ans = len(s)*(len(s)+1)//2
s = Counter(s)

for _, val in s.items():
    ans -= val*(val+1)//2

ans += 1
print(ans)

Solution (Python):
from collections import Counter
a = input()
n = len(a)
c = Counter(a).most_common()
ans = 1
tmp = 0
for i, j in c:
	ans += tmp * j
	tmp += j
print(ans)

Solution (Python):
from collections import defaultdict

A = list(input())
N = len(A)

dic = defaultdict(int)

tmp = 0
for a in A:
    tmp += dic[a]
    dic[a] += 1

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

print (ans)

Solution (Python):
from collections import Counter

s = input()
n = len(s)
ans = n * (n - 1) // 2 + 1
c = Counter(s)
for key, value in c.items():
    ans -= value * (value - 1) // 2
print(ans)

Solution (Python):
from collections import defaultdict

A = input()
N = len(A)
dp = [0] * N
dp[0] = 1
d = defaultdict(int)
d[A[0]] = 1

for i in range(1, N):
  a = A[i]
  dp[i] = dp[i-1]
  dp[i] += i - d[a]
  d[a] += 1

print(dp[-1])

Solution (Python):
a=input()
n=len(a)
S=n*(n-1)//2+1

l={}
for i in range(n):
    if a[i] in l:
        l[a[i]]+=1
    else:
        l[a[i]]=1

cnt=0
for i in l:
    if l[i]>1:
        cnt+=l[i]*(l[i]-1)//2

ans=S-cnt

print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline

A = readline().rstrip()

from collections import Counter
counter = Counter(A)

ans = 1 + (len(A) * (len(A) - 1)) // 2

for val in counter.values():
  ans -= (val * (val - 1)) // 2
  
print(ans)

Solution (Python):
import collections
def solve(A):
    counter = collections.Counter()
    ans = 1
    for i, a in enumerate(A):
        c = counter[a] if a in counter else 0
        ans += i - c
        counter.update([a])
    return ans






if __name__ == "__main__":
    A = input()
    print(solve(A))

Solution (Python):
s = input() 
n=len(s)

from collections import Counter
c = Counter(s)
cnt = 0

for k,v in c.items():
    if v>1:
        cnt+=v*(v-1)//2

ans = n*(n-1)//2 -cnt + 1

print(ans)

Solution (Python):
from collections import Counter

a = input()

n_all_pairs = (len(a)*(len(a)-1))/2
counts = Counter(a)

n_other_chars = 0
for c in counts.values():
    n_other_chars += (c * (c-1))/2

print(int(n_all_pairs - n_other_chars) + 1)

Solution (Python):
from collections import defaultdict
a = input()
n = len(a)
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 1 + n*(n-1)//2
for i in d.values():
    ans -= i*(i-1)//2

print(ans)

Solution (Python):
from collections import Counter

A = input()
C = Counter(A)

n = len(A)
minus = 0
for v in C.values():
  minus += v*(v-1)//2
  
print(1 + n*(n-1)//2 - minus)

Solution (Python):
from collections import Counter
A = input()

N = len(A)
c = Counter(A)

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

print(ans)

Solution (Python):
a = input()
from collections import Counter
c = Counter(a)
l = len(a)
ans = l*(l-1)//2+1
for i in c.values():
  ans -= i*(i-1)//2
print(ans)

Solution (Python):
A = input()
n = len(A)
alpha_dic = {}

for a in A:
    alpha_dic[a] = 1 + alpha_dic.get(a, 0)

ans = n * (n-1) //2
for key, num in alpha_dic.items():
    ans -= (num * (num-1) // 2)
print(ans+1)

Solution (Python):

from collections import defaultdict

A = input()
n = len(A)
cA = defaultdict(int)

for ch in A:
    cA[ch] += 1

all_num = 1 + n * (n - 1) // 2

for _, v in cA.items():
    all_num -= v * (v - 1) // 2

print(all_num)

Solution (Python):
a = list(input())
l = len(a)
alphcnt = [0] * 26
for i in a:
    alphcnt[ord(i) - 97] += 1
ans = (l * (l + 1)) // 2 + 1
for i in alphcnt:
    ans -= (i * (i + 1)) // 2
print(ans)

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict
def main():
    A=input()
    len_a=len(A)
    dp=[0]*len_a
    dp[0]=1
    dd=defaultdict(int)
    dd[A[0]]+=1
    for i in range(1,len_a):
        a=A[i]
        dp[i]=i-dd[a]
        dd[a]+=1
    print(sum(dp))

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict
def main():
    A=input()
    len_a=len(A)
    dp=[0]*len_a
    dp[0]=1
    dd=defaultdict(int)
    dd[A[0]]+=1
    for i in range(1,len_a):
        a=A[i]
        dp[i]=i-dd[a]
        dd[a]+=1
    print(sum(dp))

if __name__=='__main__':
    main()

Solution (Python):
from collections import Counter
a = input()
c = len(a)*(len(a)-1)//2
for i in Counter(a).values():
  c -= i*(i-1)//2
print(c+1)

Solution (Python):
from collections import*;a=input();j=lambda x:x*~-x//2;print(j(len(a))-sum(map(j,Counter(a).values()))+1)

Solution (Python):

from collections import*
a = input()
j = lambda x: x*~-x//2
print(j(len(a)) - sum(map(j, Counter(a).values())) + 1)

Solution (Python):
from string import ascii_lowercase
def lower_bound(al, key):
    """
    一般に左側が満たしておらず、右側は満たしている判定基準(境目は一つ)ならlower_boundになる
    (条件を満たすもののうち、最小のインデックスを返す)
    単調にさえなっていれば、左右が逆になっていても検索には使える(ng/okも一緒に逆にする必要がある)
    """
    def isOk(a):
        
        
        return a>key

    ng = -1
    ok = len(al)

    while abs(ok-ng)>1:
        mid = (ok+ng)//2

        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid

    return ok

s = input()
n = len(s)

d = {}
for c in ascii_lowercase:
    d[c] = []

for i in range(n):
    d[s[i]].append(i)

res = 1
for i in range(n):
    c = s[i]
    j = lower_bound(d[c],i)
    res += (n-i) - (len(d[c])-j) - 1
print(res)

Solution (Python):

A=input()
N=len(A)
D={}
for i in range(N):
    a=A[i]
    if a in D:
        D[a]+=1
    else:
        D[a]=1


ans=N*(N-1)//2
for v in D.values():
    ans-=v*(v-1)//2

print(ans+1)

Solution (Python):
l=input()
n=len(l)
import collections
c=collections.Counter(l)
ans=n*(n-1)//2+1
for i,j in c.items():
    ans-=j*(j-1)//2
print(ans)

Solution (Python):
s = input()
n = len(s)
s = list(s)
all_num = n * (n-1)/2
for i in range(97,123):
  tyouhuku = s.count(chr(i))
  all_num -= tyouhuku * (tyouhuku - 1) /2
  
print(int(all_num) + 1)

Solution (Python):
from collections import defaultdict
a = input()
n = len(a)
d = defaultdict(int)
ans = n * (n-1) // 2 + 1
for x in a: d[x] += 1
for x in d.values(): ans -= (x) * (x-1) // 2
print(ans)

Solution (Python):
from collections import defaultdict
A = input()
N = len(A)
d = defaultdict(int)
for a in A:
    d[a] += 1
cnt = 0
for k, v in d.items():
    cnt += v * (v - 1) // 2
ans = N * (N - 1) // 2 - cnt
print(ans + 1)

Solution (Python):
from collections import Counter
s = input()
c = Counter(s)
ans = len(s) * (len(s) - 1) // 2
for v in c.values():
    ans -= v * (v - 1) // 2
print(ans + 1)

Solution (Python):
import collections
a=input()
n=len(a)
A=collections.Counter(a)
v,c = zip(*A.most_common())
ans=n*(n-1)//2
for i in range(len(c)):
    ans-=c[i]*(c[i]-1)//2
print(ans+1)

Solution (Python):
from collections import Counter
A = input()
n = len(A)
C = Counter(A)

dup = 0
for k, cnt in C.items():
    dup += (cnt * (cnt-1)//2)

ans = n * (n-1) // 2 - dup + 1

print(ans)

Solution (Python):
a = input()
n = len(a)

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

ans = n*(n-1)//2
for i in dic.values():
    ans -= i*(i-1)//2
print(ans+1)

Solution (Python):
S = input()
from collections import defaultdict
d = defaultdict(int)

cnt = 1
for i,s in enumerate(S):
    cnt += i-d[s]
    d[s] += 1
    
print(cnt)

Solution (Python):
from collections import Counter
A = input()
N = len(A)

ans = N * (N - 1) // 2
cnt = Counter(list(A))

for c in cnt.values():
    ans -= c * (c - 1) // 2

print(ans + 1)

Solution (Python):
a=input()
n=len(a)
ans=n*(n-1)//2
from collections import Counter
d=Counter(list(a))
for i in d:ans-=d[i]*(d[i]-1)//2
print(ans+1)

Solution (Python):
A=input()
N=len(A)

sm=(N*(N-1))//2
sm+=1

x=dict()
for i in range(N):
    s=A[i]
    if s in x:
        x[s]+=1
    else:
        x[s]=1

val=0
for idx in x:
    v=x[idx]
    val+=(v*(v-1))//2

ans=sm-val
print(ans)

Solution (Python):
def main():
    s = input()
    a = [0]*26
    ans = 1
    cnt = 0
    for c in s:
        ans += cnt - a[ord(c) - ord("a")]
        a[ord(c) - ord("a")] += 1
        cnt += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
a = input()
n = len(a)
mp = [0]*26
for c in a:
    mp[ord(c) - ord('a')] += 1
t = sum([n*(n-1)/2 for n in mp])
print(int(n*(n-1) / 2 - t + 1))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a = read().rstrip().decode()
al = [chr(ord('a') + i) for i in range(26)]
ans = len(a) * (len(a) - 1) // 2 + 1
for check in al:
    cnt = a.count(check)
    ans -= cnt * (cnt - 1) // 2
print(ans)

Solution (Python):
a = input()
len_a = len(a)
cnt = [0] * 26
for i in a:
  cnt[ord(i)-ord("a")] += 1
ans = len_a * (len_a-1) // 2 + 1
for i in cnt:
  ans -= i * (i-1) // 2
print(ans)

Solution (Python):
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)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a = input()[:-1]

su = (len(a)*(len(a)-1))//2

po = [0 for i in range(26)]

for i in range(len(a)):
    on = ord(a[i]) - 97
    su -= po[on]
    po[on] += 1
print(su+1)

Solution (Python):
from collections import Counter
a = input()
n = len(a)
ans = (n-1)*n//2+1
c = Counter(a)
for i in c.values():
  ans -= i*(i-1)//2
print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

a = ns()
n = len(a)
c = Counter(a)
eq = 0
for _, v in c.items():
    eq += v * (v - 1) // 2

ans = (n * (n - 1) // 2) - eq + 1
print(ans)

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    a = input()
    dic = {}
    for s in a:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    
    ans = 0
    n = len(a)
    for v in dic.values():
        ans += v * (n - v)
    ans = ans//2 + 1
    print(ans)
if __name__ =='__main__':
    main()

Solution (Python):
from sys import stdin 
a = stdin.readline().rstrip()
n = len(a)
k = [0]*26
a = sorted(a)
t = "a"
tmp = 0
for i in range(n):
    if t == a[i]:
        k[tmp] += 1
    else:
        t = a[i]
        tmp += 1
        k[tmp] += 1
answer = (n*(n-1)) // 2
for i in range(26):
    if k[i] > 1:
        answer -= (k[i]*(k[i]-1)) // 2
print(answer + 1)

Solution (Python):
A = list(input())
backet = [0] * (ord('z') - ord('a') + 1)

for a in A:
  backet[ord(a) - ord('a')] += 1
n = len(A)
ans = n*(n-1)//2 + 1
for b in backet:
  ans -= b*(b-1)//2
print(ans)

Solution (Python):
a=input()
n=len(a)
ans=n*(n-1)//2+1
from collections import Counter as co
for i in co(list(a)).values():
    ans-=(i*(i-1))//2
print(ans)

Solution (Python):
a = input()
n = len(a)
ans =  n * (n-1) // 2
char = [0 for i in range(26)]
for i in range(n):
    char[ord(a[i])-ord('a')] += 1
for i in range(26):
    ans -= (char[i] * (char[i]-1))//2
print(ans+1)

Solution (Python):
from itertools import groupby

A=input()
N=len(A)
A=[A[i] for i in range(0,N)]
A.sort()
data=groupby(A)
ans=N*(N-1)//2+1
for key, group in data:
    g=len(list(group))
    ans-=g*(g-1)//2

print(ans)

Solution (Python):
from collections import defaultdict
A = input()
N = len(A)
cnt = defaultdict(int)
for k in A:
    cnt[k] += 1
print(1+N*(N+1)//2-sum([cnt[k]*(cnt[k]+1)//2 for k in cnt]))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    a = S()
    n = len(a)
    ans = (len(a)+1) * len(a) // 2
    d = defaultdict(int)
    for i in range(n):
        d[a[i]] += 1
    for val in d.values():
        ans -= val * (val + 1) // 2
    print(ans+1)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter
A = input()
N = len(A)
counter = Counter(A)
ans = N*(N-1)//2 + 1
for k,v in counter.items():
    if v==1:
        continue
    ans -= v*(v-1)//2
print(ans)

Solution (Python):
a=input()
p=len(a)
cnt=[0]*26
for i in range(p):
	cnt[ord(a[i])-ord("a")]+=1
ans=p*(p-1)//2+1
for x in cnt:
	ans-=x*(x-1)//2
print(ans)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    N=len(S)
    cnt = Counter(S)
    ans = 0
    for i,s in enumerate(S):
        cnt[s]-=1
        remain = N-i-1
        ans += remain - cnt[s]
    print(ans+1)
if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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)

Solution (Python):
A = input()
import collections
a_frq_dict = collections.Counter(A)

n_all = len(A) * (len(A)-1) * 0.5 + 1
n_duplication = 0
for frq in a_frq_dict.values():
    n_duplication += frq * (frq-1) * 0.5

print(int(n_all - n_duplication))

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

from collections import Counter

def main():
    a = input()
    n = len(a)

    base = n * (n - 1) // 2
    counter = Counter(a)

    def f():
        for c in counter.values():
            yield c * (c - 1) // 2

    print(base - sum(f()) + 1)

main()

Solution (Python):

A = list(input())
cnt = [0] * 26
for s in A:
    cnt[ord(s) - ord("a")] += 1

ans = len(A) * (len(A) - 1) // 2
ans -= sum(c * (c - 1) // 2 for c in cnt)
ans += 1

print(ans)

Solution (Python):
import math

a = input()

d = {}

for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1

ans = len(a) * (len(a) -1) // 2 + 1

for k in d:
    ans -= d[k] * (d[k] -1) // 2
print(ans)

Solution (Python):
A=input()
cnt={chr(code): 0 for code in range(ord('a'),ord('z')+1)}
for i in A:
  cnt[i]+=1

a=len(A)
if a==1:
  print(1)
  exit()
b=0
for i in cnt.values():
  if i>=2:
    b+=i*(i-1)//2
ans=a*(a-1)//2-b
print(ans+1)

Solution (Python):
from collections import Counter

A = input()
len_a = len(A)

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

print(ans)

Solution (Python):
from collections import Counter
A = input()
N = len(A)
ans = 1 + N*(N-1)//2
count = Counter(A)
for k, v in count.items():
    ans -= v*(v-1)//2
print(ans)

Solution (Python):
a=list(input())
ans=len(a)*(len(a)-1)//2
import collections
J=dict(collections.Counter(a))
for i in J.values():
    ans-=i*(i-1)//2
print(ans+1)

Solution (Python):
s = input()
n = len(s)
import string
DD = [chr(i) for i in range(ord("a"), ord("z")+1)]
D = {}
for i in range(len(DD)):
    D[DD[i]] = i
A = [0] * 26
ans = 1
for i in range(n):
    ans += i - A[D[s[i]]]
    A[D[s[i]]] += 1
print(ans)

Solution (Python):
def main():
    A=input()
    N=len(A)
    ans=1
    p={}
    for i,a in enumerate(A):
        if a not in p:
            p[a]=0
        ans+=i-p[a]
        p[a]+=1    
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
A = input()
n = len(A)
ans = (n-1)*n//2+1
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    num = A.count(i)
    ans -= num*(num-1)//2
print(ans)

Solution (Python):
a=input()
n=len(a)
ans=n*(n-1)//2+1
d=dict()
for i in range(n):
  if a[i] not in d:
    d[a[i]]=1
  else:
    d[a[i]]+=1
d=list(d.items())
for i,j in d:
  ans-=j*(j-1)//2
print(ans)

Solution (Python):
A = [ord(a) - 97 for a in input()]
N = len(A)
D = {}
ans = N * (N - 1) // 2 + 1
for i, a in enumerate(A):
    if a in D:
        ans -= D[a]
        D[a] += 1
    else:
        D[a] = 1
print(ans)

Solution (Python):
def main():
  A = input()
  N = len(A)
  ans = 0
  for i in range(26):
    c = ord('a')+i
    c = chr(c)
    m = A.count(c)
    ans += m*(m-1)//2
  print(N*(N-1)//2-ans+1)
if __name__=='__main__':
  main()

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7
from collections import defaultdict
def ddprint(x):
  if DBG:
    print(x)

a = ins()
h = defaultdict(int)
for i in range(len(a)):
    h[a[i]] += 1
sm = 1
keys = list(h.keys())
for i,x in enumerate(keys):
    for j in range(i+1,len(keys)):
        sm += h[keys[i]]*h[keys[j]]
print(sm)

Solution (Python):
from collections import defaultdict
A = input()
n = len(A)
ans = 1
cnt = defaultdict(int)
for i in range(n):
    ans += i - cnt[A[i]]    
    cnt[A[i]] += 1
print(ans)

Solution (Python):
A = raw_input()

C = [0]*26
for a in A:
  C[ord(a)-ord("a")] += 1
ans = len(A)*(len(A)+1)/2+1
for c in C:
  ans -= c*(c+1)/2
print ans

Solution (Python):
A = input()

dic = {}
for i in range(len(A)):
    if A[i] in dic:
        dic[A[i]] += 1
    else:
        dic[A[i]] = 1

ans = len(A)*(len(A)-1)//2 + 1
for key in dic:
    ans -= dic[key]*(dic[key]-1)//2

print(ans)

Solution (Python):
from collections import Counter


A = input()

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

Solution (Python):
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def f(A):
    N = len(A)
    D = {}

    for a in A:
        D[a] = D.setdefault(a, 0) + 1
    
    return sum([v * (v - 1) // 2 for v in D.values()])


def main():
    A = input().strip()

    c = f(A)

    N = len(A)
    print(N * (N - 1) // 2 - c + 1)

if __name__ == "__main__":
    main()

Solution (Python):
A = input()

freq = [0] * 26
freq_sum = 0

result = 1

for x in map(lambda c: ord(c) - ord('a'), A):
    result += freq_sum - freq[x]
    freq[x] += 1
    freq_sum += 1

print(result)

Solution (Python):

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])
    
    dp[i]=dp[i-1]+tmp

print(dp[-1])

Solution (Python):
from collections import Counter

A = input()
N = len(A)

c = Counter(A)
ans = 1 + sum(v*(N-v) for v in c.values()) // 2
print(ans)

Solution (Python):
from collections import Counter

A = input()
N = len(A)

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

print(ans)

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()

input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
 
show_flg=False
show_flg=True
 
ans=0

s=input()
n=len(s)

ans+=1+n*(n-1)//2
p=''
c=1
s=sorted(s)
for i in [1]+s+[0]:
    if p==i:
        c+=1
    else:
        ans-=c*(c-1)//2
        c=1
    p=i    
print(ans)

Solution (Python):
S = input()
ans = len(S) * (len(S)-1) // 2 + 1

for ch in 'abcdefghijklmnopqrstuvwxyz':
  n = S.count(ch)
  if n>0:
    
    ans -= n * (n-1) // 2
    
print(ans)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) 
def inpm(): return map(int,input().split()) 
def inpl(): return list(map(int, input().split())) 
def inpls(): return list(input().split())  
def inplm(n): return list(int(input()) for _ in range(n)) 
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    s = list(input())
    n = len(s)
    dic = defaultdict(int)
    for i in range(n):
        dic[s[i]] += 1
    ans = 0
    for e in dic:
        ans += (n-dic[e])*dic[e]
    print(ans//2+1)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



A = str(input())
N = len(A)

d = defaultdict(int)

dp = [0]*N
dp[0] = 1
d[A[0]] = 1
for i in range(1,N):
    dp[i] = dp[i-1]+i-d[A[i]]
    d[A[i]] += 1

print(dp[-1])

Solution (Python):
from collections import Counter
a=input()
n=len(a)
d=Counter(a)

res = (n*(n-1))//2+1

for c in d.values():
    res -= (c*(c-1))//2
print(res)

Solution (Python):
A=list(input())
N=len(A)

S=N*(N-1)//2+1

for s in "abcdefghijklmnopqrstuvwxyz":
    n=A.count(s)
    if n>=2:
        S=S-n*(n-1)//2

print(S)

Solution (Python):
from collections import Counter


A=list(input())
N=len(A)

num=Counter(A)

S=N*(N-1)//2+1

for i in num.values():
    if i==1:continue
    else:
        S=S-i*(i-1)//2

print(S)

Solution (Python):
A = input().strip()
C = {chr(i):0 for i in range(97,123)}
n = len(A)
for i in range(n):
    C[A[i]] += 1
cnt = 0
for a in C:
    cnt += (C[a]*(C[a]-1))//2
print(1+(n*(n-1))//2-cnt)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
a=input()
li=[0]*26
for i in range(len(a)):
    li[ord(a[i])-ord("a")]+=1
ans=len(a)*(len(a)-1)//2+1
for i in li:
    ans-=i*(i-1)//2
print(ans)

Solution (Python):
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)

Solution (Python):
from collections import Counter

A = input()

N = len(A)
C = Counter(A)

print(1 + N * (N - 1) // 2 - sum(v * (v - 1) // 2 for v in C.values()))

Solution (Python):
d = {}
for i in range(26):
    d[i] = 0
s = input()
n = len(s)
for i in range(n):
    x = s[i]
    y = ord(x) - 97
    d[y] += 1
ans = 0
for i in range(26):
    ans += d[i]*(n-d[i])
ans = ans // 2 + 1
print(ans)