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 fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

s = input()
s = sorted(s)
g = gb(s)
l = len(s)

res = l * (l - 1) // 2 + 1
for k, v in g:
    p = len(list(v))
    res -= p * (p - 1) // 2
print(res)

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

a = ns()
n = len(a)

cnt = Counter(a)

eqs = 0
for k,v in cnt.items():
    eqs += v*(v-1)//2
    
print(1 + n*(n-1)//2 - eqs)

Solution (Python):
A = input()
D = [0]*(26)
ans = 0
D[ord( A[0]) - ord("a")] = 1
for i, a in enumerate(A[1:]):
    ans += i + 1- D[ ord( a) - ord("a")]
    D[ ord( a) - ord("a")] += 1
print( ans + 1)

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

Solution (Python):
from collections import defaultdict
A = input()
Alphabet = defaultdict(int)

for i in range(len(A)):
    Alphabet[A[i]] += 1
Total = (len(A) - 1) * len(A) // 2 + 1
for key in Alphabet:
    if Alphabet[key] > 1:
        double = (Alphabet[key] - 1) * Alphabet[key] // 2
        Total -= double
print(Total)

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

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

Solution (Python):



"""
自力ではわからず解説PDFを見て実装
"""

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

A = input()
counter = Counter(A)

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

Solution (Python):
ch = ['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']

p = []

a = list(input())
n = len(a)
for i in range(len(ch)):
    p.append(a.count(ch[i]))

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

for i in range(len(ch)):
    res = res - p[i] * (p[i]-1) //2
print(res+1)

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

Solution (Python):
import collections
A = input()
Ac = collections.Counter(A)
ans = len(A)*(len(A)-1)//2
for i in Ac.values():
    ans -= i*(i-1)//2

print(ans+1)

Solution (Python):

from collections import Counter

s = list(input())
cnt = Counter(s)

ans = len(s) * (len(s) - 1) / 2 + 1
for v in cnt.values():
    ans -= v * (v - 1) / 2

print(int(ans))

Solution (Python):
from collections import defaultdict
A = input()
N = len(A)
ans = N * (N + 1) // 2
dic = defaultdict(int)
for i in range(N):
    dic[A[i]] += 1

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

print(ans + 1)

Solution (Python):
from collections import Counter

As = input()

lenA = len(As)
cnt = Counter(As)

ans = lenA * (lenA - 1) // 2
for c, num in cnt.items():
    ans -= num * (num - 1) // 2
print(ans + 1)

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

Solution (Python):
a=raw_input()
cnt=[0]*26
for ch in a:
	cnt[ord(ch)-ord('a')]+=1
result=1+len(a)*(len(a)-1)/2
for i in range(26):
	result-=cnt[i]*(cnt[i]-1)/2
print result

Solution (Python):
from collections import Counter

a = input()
n = len(a)
c = Counter()
ans = 1
c[a[0]] = 1
for i in range(1, n):
	ans += i - c[a[i]]
	c[a[i]] += 1
print(ans)

Solution (Python):
import collections
import math

def C(n, r):
    if n == 0 or r == 0: return 1
    return C(n, r-1) * (n-r+1) // r 

a = list(input())
n = len(a)
aa = collections.Counter(a)
ans = C(n,2)
for i in aa:
    if aa[i] >= 2:
        ans += -C(aa[i],2)
print(ans+1)

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

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

aa = list(input())
N = len(aa)
cnt = [0]*26

for a in aa:
    cnt[ord(a)-97] += 1

ans = N*(N-1)//2+1
for n in cnt:
    ans -= n*(n-1)//2

print(ans)

Solution (Python):
from collections import Counter
a = input()
n = len(a)
cnt = Counter(a)
print(n * (n - 1) // 2 - sum(v * (v - 1) // 2 for k, v in cnt.items()) + 1)

Solution (Python):
from collections import Counter

s=input()
n=len(s)
v=n*(n-1)//2
for i in Counter(s).values():
  v-=i*(i-1)//2
print(v+1)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A):
    c = Counter(A)
    N = len(A)
    s = 0
    for v in c.values():
        s += v*(v-1)//2

    return N*(N-1)//2 - s + 1


def main():
    A = read_str()
    
    print(slv(A))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A):
    c = Counter(A)
    N = len(A)
    s = 0
    for v in c.values():
        s += v*(v-1)//2

    return N*(N-1)//2 - s + 1


def main():
    A = read_str()
    
    print(slv(A))


if __name__ == '__main__':
    main()

Solution (Python):
s=list(input());print((len(s)**2-sum(s.count(chr(97+i))**2 for i in range(26)))//2+1)

Solution (Python):
cnt=[0]*200

ans=1

for i,c in enumerate(input()):
	ans+=i-cnt[ord(c)]
	cnt[ord(c)]+=1

print(ans)

Solution (Python):
cnt=[0]*200

ans=1

for i,c in enumerate(input()):
	ans+=i-cnt[ord(c)]
	cnt[ord(c)]+=1

print(ans)

Solution (Python):
cnt={}
tot=0

ans=1

for i,c in enumerate(input(),0):
	if c in cnt:
		ans+=i-cnt[c]
	else:
		cnt[c]=0
		ans+=i
	cnt[c]+=1

print(ans)

Solution (Python):
S = input()
gou = 1
N = len(S)
for i in range(N):
  gou += i
import collections
c = collections.Counter(S)
c = c.items()
for a,b in c:
  gou -= b*(b-1)/2
print(int(gou))

Solution (Python):
A = input()
N = len(A)
L = [0] * 26
for a in A:
    L[ord(a)-97] += 1
ans = N*(N-1)//2 + 1
for l in L:
    if l >= 2:
        ans -= l*(l-1)//2
print(ans)

Solution (Python):
s = input().rstrip()
total = 0
for i in range(ord('a'),ord('z')+1):
  tmp = s.count(chr(i))
  total += tmp*(tmp-1)//2
print(1 + len(s)*(len(s)-1)//2 - total)

Solution (Python):
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


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


A = input()
L = len(A)


def ctoi(char):
    return ord(char) - 97


cnt = [0] * 26

for a in A:
    cnt[ctoi(a)] += 1

ans = 1 + (L * (L - 1)) // 2
for n in cnt:
    ans -= (n * (n - 1)) // 2

print(ans)

Solution (Python):
ca = ord('a')
A = [ord(c) - ca for c in input()]

cnts = [0]*26
ans = 1
for i, a in enumerate(A):
    ans += i - cnts[a]
    cnts[a] += 1
print(ans)

Solution (Python):
from collections import Counter
a = input()
c,ans = Counter(a),1+len(a)*(len(a)-1)//2
for i in c.most_common():
	if i[1]==1: break
	else: ans -= i[1]*(i[1]-1)//2
print(ans)

Solution (Python):


import sys, math, copy




HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a = input()
    n = len(a)
    di = {c: 0 for c in ABC}
    for c in a:
        di[c] += 1
    invdi = {c: n - di[c] for c in ABC}
    res = 0
    for c in ABC:
        res += di[c] * invdi[c]
    assert res % 2 == 0
    res //= 2
    res += 1
    print(res)


main()

Solution (Python):
s = input()
x = 1
d = {}
for i, c in enumerate(s):
    k = d.get(c, 0)
    d[c] = k + 1
    x += (i - k)
print(x)

Solution (Python):
s = input()
x = 1
d = {}
for i, c in enumerate(s):
    k = d.get(c, 0)
    d[c] = k + 1
    x += (i - k)
print(x)

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

Solution (Python):
A=input()
N=len(A)
B=[]
C=[]
for i in range(N):
    flag=0
    for j in range(len(B)):
        if B[j]==A[i]:
            C[j]+=1
            flag=1
            break
    if flag==0:
        B.append(A[i])
        C.append(1)
M=((N*(N-1))//2)+1
for i in C:
    M -= (i*(i-1))//2
print(M)

Solution (Python):
A = input()
A_dic = {}
for i in A:
    if i in A_dic:
        A_dic[i] += 1
    else:
        A_dic[i] = 1

m = 1
for i in range(2,len(A)+1):
    m += len(A) - i + 1

for i in A_dic.values():
    m -= (i*(i-1))/2

print(int(m))

Solution (Python):
from collections import Counter
A=input()
n=len(A)
C=Counter(A)
tmp=0
for v in C.values():
    tmp+=v*(v-1)//2
print(n*(n-1)//2-tmp+1)

Solution (Python):
A=input()

dict={}

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

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

for k,v in dict.items():
  ans-=(v*(v-1)/2)

print(int(ans))

Solution (Python):
from collections import Counter

n=list(input())
l=len(n)
a=l*(l-1)/2

counter = Counter(n)
for w, c in counter.most_common():
  a -= c*(c-1)/2
print(int(a+1))

Solution (Python):
N = input()
ans = 0
n = len(N)
a = N.count("a")
ans += a * (a-1) // 2
a = N.count("b")
ans += a * (a-1) // 2
a = N.count("c")
ans += a * (a-1) // 2
a = N.count("d")
ans += a * (a-1) // 2
a = N.count("e")
ans += a * (a-1) // 2
a = N.count("f")
ans += a * (a-1) // 2
a = N.count("g")
ans += a * (a-1) // 2
a = N.count("h")
ans += a * (a-1) // 2
a = N.count("i")
ans += a * (a-1) // 2
a = N.count("j")
ans += a * (a-1) // 2
a = N.count("k")
ans += a * (a-1) // 2
a = N.count("l")
ans += a * (a-1) // 2
a = N.count("m")
ans += a * (a-1) // 2
a = N.count("n")
ans += a * (a-1) // 2
a = N.count("o")
ans += a * (a-1) // 2
a = N.count("p")
ans += a * (a-1) // 2
a = N.count("q")
ans += a * (a-1) // 2
a = N.count("r")
ans += a * (a-1) // 2
a = N.count("s")
ans += a * (a-1) // 2
a = N.count("t")
ans += a * (a-1) // 2
a = N.count("u")
ans += a * (a-1) // 2
a = N.count("v")
ans += a * (a-1) // 2
a = N.count("w")
ans += a * (a-1) // 2
a = N.count("x")
ans += a * (a-1) // 2
a = N.count("y")
ans += a * (a-1) // 2
a = N.count("z")
ans += a * (a-1) // 2
ans = n * (n-1) // 2 - ans + 1
print(ans)

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

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
import sys
sys.setrecursionlimit(10000)



def arithmetic_series(a, d, n):
    return n * (2 * a + (n - 1) * d) // 2


def solve(A):
    ans = arithmetic_series(1, 1, len(A) - 1) + 1
    c = Counter(A)
    for v in c.values():
        ans -= (v * (v - 1)) // 2
    return ans


def main():
    A = input()
    print(solve(A))


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import itertools
a=input()
n=len(a)
delete=int(0)
count=Counter(a).values()
print((n*(n-1)-sum([i*(i-1) for i in count]))//2 +1)

Solution (Python):
from functools import reduce

A = input()
dic = {}
for c in A:
    if c in dic.keys():
        dic[c] += 1
    else:
        dic[c] = 1

length = len(A)
print(int(1 + (length * (length - 1) - reduce(lambda a, b: a + b * (b - 1), dic.values(), 0)) / 2))

Solution (Python):
def conbi(n):
	return int(n*(n-1)/2)

A = input("")
num = 1 + conbi(len(A)) 
uniq = list(set(A))
for i in uniq:
	num -= conbi(A.count(i))
print(num)

Solution (Python):
def conbi(n):
	return int(n*(n-1)/2)

A = input("")
num = 1 + conbi(len(A)) 
uniq = list(set(A))
for i in uniq:
	num -= conbi(A.count(i))
print(num)

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

alp = [chr(i) for i in range(97, 97+26)]

for c in alp:
    z = a.count(c)
    ans -= z * (z - 1) // 2

print(ans)

Solution (Python):
s = input()
n = len(s)
ans = n * (n - 1) / 2 + 1
c_list = [0 for _ in range(26)]
for c in s:
	c_list[ord(c) - ord('a')] += 1

delta = 0
for i in c_list:
	if i > 0:
		delta += i * (i - 1) / 2
print(int(ans - delta))

Solution (Python):
def main() :
    a = input()
    L = len(a)
    ans = L*(L-1)//2 + 1
    alp = "abcdefghijklmnopqrstuvwxyz"

    for c in alp :
        cnt = a.count(c)
        ans -= cnt*(cnt-1)//2
    
    print(ans)

main()

Solution (Python):
A = input()

alphabet = "abcdefghijklmnopqrstuvwxyz"

N = len(A)
M = 0

for alp in alphabet:
    m = A.count(alp)
    M += m*(m-1)/2
    
print(int(N*(N-1)/2-M+1))

Solution (Python):
a=input()
n=len(a)
dupli=0
from collections import Counter
c=Counter(a)
for word,num in c.most_common():
    dupli+=num*(num-1)//2
print(n*(n-1)//2-dupli+1)

Solution (Python):
s = input()
n = len(s)
f = lambda x: x * (x - 1) // 2
ans = f(n)
for i in range(26):
    ans -= f(s.count(chr(ord('a') + i)))
print(ans + 1)

Solution (Python):
import collections

A = input()
n = len(A)
c = collections.Counter(A)

ans = 0

for e in c:
    ans += c[e] * (n - c[e])

ans = ans // 2 + 1
print(ans)

Solution (Python):
import string
s = input()

counter = [0] * 26

for item in s:
    counter[string.ascii_lowercase.index(item)] += 1

res = 1

for i in range(26):
    for j in range(i + 1, 26):
        res += counter[i] * counter[j]

print(res)

Solution (Python):
import string
s = input()

counter = [0] * 26

for item in s:
    counter[string.ascii_lowercase.index(item)] += 1

res = 1

for i in range(26):
    for j in range(i + 1, 26):
        res += counter[i] * counter[j]

print(res)

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

Solution (Python):
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)

Solution (Python):
import string

if __name__ == '__main__':
    A = list(input())
    hist = {}
    for c in string.ascii_lowercase:
        hist[c] = A.count(c)

    

    same_when_reverse = 0
    for v in hist.values():
        same_when_reverse += v * (v - 1) // 2

    num_len = len(A)
    print((num_len * (num_len - 1) // 2 + 1) - same_when_reverse)

Solution (Python):
ord_a = ord('a')

A = input()

L = 26
counter = [0]*L
for c in A:
  counter[ord(c)-ord_a] += 1

n = len(A)
res = n*(n-1) - sum(x*(x-1) for x in counter)
res = res//2 + 1
print(res)

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

dp = [0]*26

for c in s:
	dp[ord(c) - ord('a')] += 1

ans = 1
cnt = n
for e in dp:
	n -= e
	ans += e * n

print(ans)

Solution (Python):
from collections import *
s=input()
def f(n):
    return n*(n-1)//2
print(f(len(s))+1-sum(map(f,Counter(s).values())))

Solution (Python):
def main():
    A = input()

    num = dict()
    for s in A:
        num[s] = num.get(s, 0) + 1

    x = 0
    for key1, val1 in num.items():
        for key2, val2 in num.items():
            if key1 != key2:
                x += val1 * val2

    ans = x // 2 + 1
    print(ans)

main()

Solution (Python):
a = list(input())

n = len(a)
cnt = {}
for c in a:
    if c in cnt:
        cnt[c] += 1
    else:
        cnt[c] = 1

ans = 0
for c in cnt:
    k = cnt[c]
    ans += k * (n - k)
ans //= 2
ans += 1

print(ans)

Solution (Python):
a = list(input())

n = len(a)
cnt = {}
for c in a:
    if c in cnt:
        cnt[c] += 1
    else:
        cnt[c] = 1

ans = n * (n + 1) // 2 + 1
for c in cnt:
    k = cnt[c]
    ans -= k * (k + 1) // 2

print(ans)

Solution (Python):
N = input()

S = set(N)
C = []

for s in S:
    C.append(N.count(s))

S2 = set(C)
C2 = []

for s in S2:
    C2.append(C.count(s))

x = len(N)*(len(N)-1)
for s,c in zip(S2,C2):
    x -= (s * (s-1)) * c

print( 1 + x//2 )

Solution (Python):
N = input()

S = list(set(list(N)))
C = []

for s in S:
    C.append(N.count(s))

S2 = list(set(C))
C2 = []

for s in S2:
    C2.append(C.count(s))

x = 0
for s,c in zip(S2,C2):
    x += (s * (s-1)) * c

print(int(1+(len(N)*(len(N)-1)-x)/2))

Solution (Python):

def main():
    s = input()
    seq = [0]*26
    for i in range(len(s)):
        seq[ord(s[i])-ord('a')] += 1

    cnt = len(s)*(len(s)-1)//2

    for i in filter(lambda x:x!=0, seq):
        cnt -= i*(i-1)//2

    print(cnt+1)


if __name__ == '__main__':
    main()

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

Solution (Python):
A = input()
l = len(A)
from collections import Counter
from string import ascii_lowercase
c = Counter(A)
a = ((l * (l - 1)) // 2) + 1
for j in ascii_lowercase:
    a -= (c[j] * (c[j] - 1) // 2)
print(a)

Solution (Python):

from collections import defaultdict


def main():
    a = input()
    z = defaultdict(int)

    for c in a:
        z[c] += 1

    n = len(a)

    no_count = 0
    for k, v in z.items():
        no_count += v * (v - 1) // 2

    print(n * (n - 1) // 2 + 1 - no_count)


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
A = input()
l = len(A)
from collections import Counter
from string import ascii_lowercase
c = Counter(A)
a = (l * (l - 1)) // 2
s = sum([c[j] * (c[j] - 1) // 2 for j in ascii_lowercase])
print(a - s + 1)

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

for i in range(97, 97 + 26):
    atoz = (a.count(chr(i)) * (a.count(chr(i)) - 1)) // 2
    total -= atoz

print(total)

Solution (Python):
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)
trash = 0

for i in range(97, 97 + 26):
    atoz = (a.count(chr(i)) * (a.count(chr(i)) - 1)) // 2
    trash += atoz

print(total - trash)

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


for i in range(0, len(A)):
    counter[A[i]] -= 1
    count += (len(A[(i+1):N]) - counter[A[i]])

print(count)

Solution (Python):
num=raw_input()
out=0
d={}
for i in set(num):
    d[i]=num.count(i)


for i in range(len(num)):
    
    
    
    out+=len(num[i:])-d[num[i]]
    d[num[i]]-=1

print out+1

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):
s = input()

count = 1

alphabets = {}

alphabets[s[0]] = 1

for i in range(1, len(s)):
    for char, char_count in alphabets.items():
        if char != s[i]:
            count += char_count

    if s[i] in alphabets:
        alphabets[s[i]] += 1
    else:
        alphabets[s[i]] = 1

print(count)

Solution (Python):
from collections import defaultdict
a = raw_input().strip()
d = defaultdict(int)
n = len(a)
res = 1 + n * (n + 1) / 2
for c in a:
    d[c] += 1
    res -= d[c]
print res

Solution (Python):
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)

Solution (Python):

from collections import defaultdict
import math

def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n - r)


def main():
    A = str(input())
    d_ind = defaultdict(list)
    for ind, a in enumerate(A):
        d_ind[a].append(ind)
    ans = 1 + sum(range(len(A)))
    for ind in d_ind.values():
        if len(ind) == 1:
            continue
        ans -= nCr(len(ind), 2)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
di = {}
a = stdin.readline().strip()
l = len(a)
di = {}
for i in a:
    di[i] = di.get(i,0) + 1
i
total = (l * (l+1))/2
valid = 0

for i in xrange(l/2):
    if a[i]!=a[l-1-i]:
        valid = 1
        break

rem = 0

for kk in di:
    key = di[kk]
    rem += (key * (key+1))/2

print total - rem + 1

Solution (Python):



a = raw_input()

count = 0

for i in range(26):
    c = a.count(chr(i+97))
    x = c * (c-1) / 2
    count += x

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

print ans

Solution (Python):

from collections import Counter
from itertools import combinations
from string import ascii_lowercase

A = input()
c = Counter(A)
res = 1

if len(c) > 1:
    for a, b  in combinations(c.values(), 2):
        res += a*b
else:
    pass

print(res)

Solution (Python):
import itertools
a = input()
length = len(a)
alphabet = [chr(i) for i in range(ord('a'), ord('a') + 26)]
count = 0
l = [a.count(c) for c in alphabet if a.count(c) != 0]

for comb in itertools.combinations(l, 2):
    count += comb[0] * comb[1]

print(count + 1)

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

letter_counter = Counter()
ans = 0
for idx, letter in enumerate(idx___letter):
    ans += idx - letter_counter[letter]
    letter_counter[letter] += 1
ans += 1
print(ans)

Solution (Python):


import collections


def main():
    a = input().strip()
    l = len(a)
    ans = 1 + l * (l-1) // 2
    for c, v in collections.Counter(a).most_common():
        ans -= v * (v-1) // 2
    return ans


print(main())

Solution (Python):
a=raw_input()
l=len(a)
n=l*(l+1)/2-l+1
for i in range(26):
    c=a.count(chr(i+97))
    n-=c*(c-1)/2
print n

Solution (Python):
A = input()
cnt = dict()
for a in A:
    cnt[a] = cnt.get(a, 0) + 1
ans = len(A) * (len(A) - 1) // 2 + 1

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

Solution (Python):
A = input()

n = len(A)
all_c = int(n * (n - 1) / 2) + 1

count_c = {}
for c in A:
    if c in count_c:
        count_c[c] += 1
    else:
        count_c[c] = 1

dup = 0
for v in count_c.values():
    if v > 1:
        dup += int(v * (v - 1) / 2)

print(all_c - dup)

Solution (Python):
a,alpha=list(input()),list("abcdefghijklmnopqrstuvwxyz")
cnt,n=[sum(map(lambda x:x==i,a)) for i in alpha],len(a)
print(n*(n-1)//2-sum(map(lambda x:x*(x-1)//2,cnt))+1)

Solution (Python):
import string
A=raw_input()
B=[0 for i in range(26)]
for a in A:
    B[string.ascii_lowercase.index(a)]+=1
ans=1
for i in range(25):
    for j in range(i+1,26):
        ans+=B[i]*B[j]
print ans

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

ans = n*(n-1)//2
for q in C: ans-= C[q]*(C[q]-1)//2
ans+= 1
print(ans)

Solution (Python):
from collections import Counter


def c2(r):
    return r * (r - 1) // 2


def main():
    s = input().strip()
    c = Counter(s)
    ans = c2(len(s)) + 1
    for x in c.values():
        if x < 2:
            continue
        ans -= c2(x)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

s = input().strip()
l = len(s)
c = Counter(s)
dpl = 0
for n in c.values():
    if n == 1:
        continue
    dpl += n * (n - 1) // 2
print(l * (l - 1) // 2 - dpl + 1)

Solution (Python):

S = input()
res = (len(S) * (len(S) - 1)) // 2 + 1

cnt_dict = dict()
for s in "abcdefghijklmnopqrstuvwxyz":
    cnt_dict[s] = 0

for i in range(len(S)):
    cnt_dict[S[i]] += 1
    
for s in "abcdefghijklmnopqrstuvwxyz":
    if cnt_dict[s] >= 2:
        d = (cnt_dict[s] * (cnt_dict[s] - 1)) // 2
        res -= d
        
print(res)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    s = S()
    l = len(s)
    c = collections.Counter(s)
    r = l*(l-1) // 2 + 1
    for v in c.values():
        r -= v*(v-1) // 2

    return r

print(main())

Solution (Python):
A = input()

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

import string
for c in string.ascii_lowercase:
    f = A.count(c)
    ans -= f * (f - 1) // 2

print(ans)

Solution (Python):
import sys

cin = sys.stdin


def line2N():
    return map(int, cin.readline().split())

A = cin.readline().strip()

a = [0] * 26
for ch in A:
    a[ord(ch)-ord('a')] += 1

cnt = 1
for i in range(0,26):
    for j in range(i+1,26):
        cnt += a[i]*a[j]

print(cnt)