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



Sample input:
aatt


Sample output:
5

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)


# 初項a，交差dの数列n個の和
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import string

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

    # print(hist)

    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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 )

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:

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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
num=raw_input()
out=0
d={}
for i in set(num):
    d[i]=num.count(i)
#print d
#aaa
for i in range(len(num)):
    #out+=num[i:].count(num(i))
    #print len(num[i:])-num[i:].count(num[i])
    #out+=len(num[i:])-num[i:].count(num[i])
    out+=len(num[i:])-d[num[i]]
    d[num[i]]-=1

print out+1

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
# coding: utf-8
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()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# coding: utf-8

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())

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# B
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys

cin = sys.stdin
# cin = open("in.txt", "r")

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)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,K = MI()
S = LI2()

A = []
a = 1
for i in range(1,N):
    if S[i-1] == S[i]:
        a += 1
    else:
        A.append(a)
        a = 1
A.append(a)

l = len(A)
if l <= 2*K-1:
    print(N)
    exit()

if S[0] == 1:
    A = [1]+A
if S[-1] == 1:
    A = A+[1]

A = [0]+A
l = len(A)

from itertools import accumulate

A = list(accumulate(A))
ans = 0
for i in range(l//2-K+1):
    if i == 0:
        ans = max(ans,A[2*(K+i)]-A[2*i])
    elif i == l//2-K:
        ans = max(ans,A[2*(K+i)-1]-A[2*i-1])
    else:
        ans = max(ans,A[2*(K+i)]-A[2*i-1])

print(ans)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

A = input()
Ac = collections.Counter(A)
cnt = 0
for val in Ac.values():
    cnt += val * (val - 1) // 2
print(len(A) * (len(A)-1) // 2 - cnt + 1)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
A = input()
ans = 1
for i in range(len(A)):
  for j in range(j,len(A)):
    if A[i] != A[j]:
      ans += 1
      
print(ans)

Submission status: Runtime Error

Solution code:
A = input()
ans = 1
for i in range(len(A)):
  for j in range(len(j,A)):
    if A[i] != A[j]:
      ans += 1
      
print(ans)

Submission status: Runtime Error

Solution code:
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a'))


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))

Submission status: Runtime Error

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

from math import factorial
def c(n,r):
  return factorial(n)/factorial(r)/factorial(n - r)
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=int(c(a,2)-b)
print(ans+1)

Submission status: Runtime Error

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

from math import factorial
def c(n,r):
  return factorial(n)/factorial(r)/factorial(n - r)
a=len(A)
b=0
for i in cnt.values():
  if i>=2:
    b+=i*(i-1)//2
ans=int(c(a,2)-b)
print(ans+1)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(const char* s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(char s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int64 s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    cout << "(";
    print(p.first, false);
    cout << ", ";
    print(p.second, false);
    cout << ")";

    if (endline) print();
}

template <typename T>
void print(T& t, bool endline = true) {
    cout << "[";
    for (auto it = t.begin(); it != t.end(); ++it) {
        if (it != t.begin()) cout << ", ";
        print(*it, false);
    }
    cout << "]";

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

bool c(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.first + a.second > b.first + b.second); 
}

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp  
    
    string s;
    cin >> s;

    map<char, int> m;

    for(auto& c : s) {
        m[c]++;
    }

    int64 count = 1;

    for(char c = 'a'; c <= 'z'; c++) {
        for(char c2 = c + 1; c2 <= 'z'; c2++) {
            count += m[c] * m[c2];
        }
    }

    cout << count << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
A = input()
char = [0 for _ in range(26)]

for i in range(len(A)):
    char[ord(A[i])-96] += 1

ans = 1

for i in range(25):
    for j in range(i+1,26):
        ans += char[i]*char[j]

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
def cal(n):
  if len(s)==1:
    return 0
  else:
    new=s[0]
    ans=0
    cnt=0
    for i in range(1,n):
      if s[i]!=new:
        new=s[i]

        cnt=0

        ans+=(i+1)

        

      else: s[i]==new:

          
        cnt+=1

        ans+=cnt

    return ans

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(5000000)

S = list(input())
L = len(S)
A = Counter(S)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

ans = cmb(L, 2) + 1
for v in A.values():
    if v == 1: continue
    ans -= cmb(v, 2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(1000000)

S = list(input())
L = len(S)
A = Counter(S)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

ans = cmb(L, 2) + 1
for v in A.values():
    if v == 1: continue
    ans -= cmb(v, 2)
print(ans)

Submission status: Runtime Error

Solution code:
A = list(input())
N, ans = len(A), 0

for i in range(1, N-1):
    j = 1
    while i-j >= 0 and i+j-1 < N:
        if A[i-j] == A[i+j-1]:
            ans += 1
        j += 1

    j = 1
    while i-j >= 0 and i+j < N:
        if A[i-j] == A[i+j]:
            ans += 1
        j += 1

if A[-1] == A[-2]:
    ans += 1

print(N*(N-1)//2 + 1 - ans)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from collections import Counter
a=input()
c=Counter(a)
MOD = 10**9+7
n=len(a)
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
f_mod=[1]*(n+1)
f_mod_inverse=[1]*(n+1)
for i in range(1,n+1):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD
if n==1:print(1)
else:
    ans=comb_mod(n,2)
    for i in c.values():
        if i==1:continue
        else:ans-=comb_mod(i,2)
print(ans+1)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
strs = [x for x in input()]
ans = 1
for i in range(len(strs)):
  for j in range(i+1,len(strs)+1):
    if strs[i] == strs[j]:
      pass
    else:
      ans ++
print(ans)

Submission status: Runtime Error

Solution code:
a = input()
freq = [0 for __ in range(26)]
for i in range(len(a)):
	freq[ord(a[i]) - ord('a')] += 1

n = len(a)
# total number of pairs
total_pairs = n * (n - 1) / 2
for x in freq:
	# total number of pairs with i-th character equal
	total_pairs -= x * (x - 1) / 2
print total_pairs

Submission status: Runtime Error

Solution code:
import math
a = input()
b = len(a)
c = math.factorial(b) // (math.factorial(b - 2) * math.factorial(2)) +1

for i in a:
    d = (a.count(i) - 1)*0.5
    c -= d

print(int(c))

Submission status: Runtime Error

Solution code:
words = raw_input()
N = len(words)
word = list(words)
print word

ans = 0


def before_after(i, j):
  count = 0
  print "関数呼び出し"
  print i
  print j
  for k in range (0, j-i+1):
    print word[i+k-1]
    print word[j-k-1]
    if(word[i+k-1] == word[j-k-1]):
      count += 1
      print "count is " + str(count)


  if(count == j-i+1): #変更前と変更後が同じ
    return 1
  else:
    print "plus one"
    return 0


for i in range(1, N+1):
  for j in range(i+1, N+1):
    #ここで関数を呼び出して前と後が同じ文字列かどうかの判定を行う関数を作る。
    if(before_after(i, j) == 1):
      continue
    ans += 1
    print ans

print "Answer is " + str(ans+1)

Submission status: Runtime Error

Solution code:
str = list(input())
ans = 0
for i in range(len(str)):
    for j in range(i, len(str)+1, 1):
        if str[i:j] != list(reversed(str[i:j])):
            print (str[i:j], list(reversed(str[i:j])))
            ans += 1
print (ans+1)

Submission status: Runtime Error

Solution code:
A = input()
l = len(A)
count = 1 + l*(l-1)//2
j = 1
if A[1] == A[0]:
    count -= 1
for i in range(2,l):

    if A[i] == A[i-1]:
        while i-j:
            if i+j == l:
                break
            elif A[i+j] == A[i-j-1]:
                j += 1
            else:
                break
        
        count -= j
        j = 1
        
    if A[i] == A[i-2]:
        while i-j-1:
            if i+j == l:
                break
            elif A[i+j] == A[i-j-2]:
                j += 1
            else:
                break
        
        count -= j
        j = 1

print(count)

Submission status: Runtime Error

Solution code:
s = input()

count = 1

for i in range(1, len(s)):
    ss = s[0:i]
    # print(ss, s[i])

    n = len(ss) - ss.count(s[i])
    count += n
    # print(n, count)
print(n)