Problem:


Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Accepted

Solution code:
#
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    #s.append(sorted(input())) # !!!
    s.append([''.join(sorted(input()))])
    #s += [''.join(sorted(input()))]
    #''.join(sorted((sorted(input()))
s = sorted(s)
#print(s)

a = []
x = 1
for i in range(1,n):
    if s[i] == s[i-1]:
        x += 1
    else:
        a.append(x)
        x = 1
else:
    a.append(x)
#print(a)

y = 0
for j in a:
    y += j*(j-1)/2

print(int(y))

Submission status: Accepted

Solution code:
#
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    #s.append(sorted(input())) # !!!
    s += [''.join(sorted(input()))]
    #''.join(sorted((sorted(input()))
s = sorted(s)
#print(s)

a = []
x = 1
for i in range(1,n):
    if s[i] == s[i-1]:
        x += 1
    else:
        a.append(x)
        x = 1
else:
    a.append(x)
#print(a)

y = 0
for j in a:
    y += j*(j-1)/2

print(int(y))

Submission status: Accepted

Solution code:
#
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    s.append(sorted(input())) # !!!
    #s += [''.join(sorted(input()))]
    #''.join(sorted((sorted(input()))
s = sorted(s)
#print(s)

a = []
x = 1
for i in range(1,n):
    if s[i] == s[i-1]:
        x += 1
    else:
        a.append(x)
        x = 1
else:
    a.append(x)
#print(a)

y = 0
for j in a:
    y += j*(j-1)/2

print(int(y))

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    #s.append(sorted(input())) # !!!
    s += [''.join(sorted(input()))]
    #''.join(sorted((sorted(input()))
s = sorted(s)
#s.append('X')
#print(s)

a = []
x = 1
for i in range(1,n):
    if s[i] == s[i-1]:
        x += 1
    else:
        a.append(x)
        x = 1
else:
    a.append(x)

#print(a)
y = 0

for j in a:
    y += j*(j-1)/2

print(int(y))

Submission status: Accepted

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    #s.append(sorted(input())) # !!!
    s += [''.join(sorted(input()))]
    #''.join(sorted((sorted(input()))
s = sorted(s)
s.append('X')
#print(s)

a = []
x = 1
for i in range(1,n+1):
    if s[i] == s[i-1]:
        x += 1
    else:
        a.append(x)
        x = 1
#print(a)
y = 0

for j in a:
    y += j*(j-1)/2

print(int(y))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    S = cin.stringList(N)
    D = _collections.defaultdict(int)
    for s in S:
        D["".join(sorted(s))] +=1
    ans = 0
    for v in D.values():
        ans += v * (v - 1) // 2
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import factorial
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))

def main():
    n = int(input())
    str_list = [input() for _ in range(n)]

    count = 0

    for i,s in enumerate(str_list):
        str_list[i] = sorted(s)

    str_list = sorted(str_list)

    i = 0
    j = 1
    while i < n:
        tmp = 0
        while i + j < n and str_list[i] == str_list[i + j]:
            tmp += 1
            j += 1
        if tmp != 0:
            count += com(tmp+1, 2)
        i += j
        j = 1

    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = []
d = {}
for i in range(n):
	x = input()
	l = list(x)
	list.sort(l)
	ll = "".join(l)
	if ll in d:
		d[ll] += 1
	else:
		d[ll] = 1

ans = 0
for i in d:
	ss = d[i]
	if d[i] >= 2:
		ans += ss*(ss-1)/2
print (int(ans))

Submission status: Accepted

Solution code:
N = int(input())
l = []

for i in range(N):
    l.append(''.join(sorted(input())))

l.sort()
count = ans = 0

for i in range(N-1):
    if (l[i] == l[i+1]):
        count += 1
        ans += count
    else:
        count = 0

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

anagrams = defaultdict(int)
for _ in range(int(input())):
    anagrams[str(sorted(input()))] += 1

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

print(int(total))

Submission status: Accepted

Solution code:
import math, collections

def combinations_count(n):
  d = 2
  if n < d:
    return 0
  return math.factorial(n) // (math.factorial(n - d) * math.factorial(d))
      

rows = int(input()) 
str_list = [input() for i in range(rows)]
sorted_str_list = map(lambda s: ''.join(sorted(s)), str_list)
  
counter = collections.Counter(sorted_str_list)
ans = sum(map(lambda v: combinations_count(v), counter.values()))
print(ans)

Submission status: Accepted

Solution code:
from scipy.misc import comb
n=int(input())
d={}
cnt=0
for i in range(n):
  a=[i for i in input()]
  a.sort()
  b="".join(a)
  d[b]= d[b]+1 if b in d else 1
for k,v in d.items():
  cnt+=comb(v,2,exact=True)
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
l = [''.join(sorted(input())) for _ in range(n)]

d = {}
ans = 0

for s in l:
  if s in d:
    d[s] += 1
    ans += d[s]-1
  else:
    d[s] = 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
  l.append(''.join(sorted(input())))
l.sort()

cnt = 0
ans = 0
for i in range(n-1):
  if l[i+1] == l[i]:
    cnt += 1
    ans += cnt
  else:
    cnt = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
    str = ''.join(sorted(input()))
    dic[str] += 1
count = 0
memos = defaultdict(lambda : 0)
for key in dic.keys():
    value = dic[key]
    if not value in memos.keys():
        x = value*(value-1)/2
        memos[value] = int(x)
    else:
        x = memos[value]
    count += x
print(int(count))

Submission status: Accepted

Solution code:
N = int(input())
s = sorted([''.join(sorted(input())) for _ in range(N)])
chk = {}
for i in range(N):
    if s[i] in chk:
        chk[s[i]] += 1
    else:
        chk[s[i]] = 1
print(sum([v*(v-1)//2 for k, v in chk.items()]))

Submission status: Accepted

Solution code:
n = int(input())
from collections import defaultdict as dd
dic = dd(lambda: 0)

counter = 0
for i in range(n):
  s = input()
  s_s = sorted(s)
  s_s_s = "".join(s_s)
  counter += dic[s_s_s]
  dic[s_s_s] += 1

print(counter)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = 0
d = {}
for i in range(n):
  sortsi = ''.join(sorted(s[i]))
  if sortsi in d:
    cnt+=d[sortsi]
    d[sortsi]+=1
  else: 
    d[sortsi]=1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for _ in range(n)]

l = []

for x in s:
  l.append(tuple(sorted(x)))

import collections
ans = 0
for _, c in collections.Counter(l).most_common():
  if c >= 1:
    ans += c * (c - 1) // 2

print(ans)

Submission status: Accepted

Solution code:
def conb(a, b):
    nume = 1
    deno = 1
    for i in range(b):
        nume *= a - i
        deno *= i + 1

    return int(nume / deno)


n = int(input())

cnt_dict = {}
for i in range(n):
    si = input()
    si_sorted = ''.join( sorted(si) )
    if si_sorted in cnt_dict:
        cnt_dict[ si_sorted ] = cnt_dict[ si_sorted ] + 1
    else:
        cnt_dict[ si_sorted ] = 1

sum = 0
for k in cnt_dict:
    v = cnt_dict[k]
    if v > 1:
        sum += conb(v, 2)

print(sum)

Submission status: Accepted

Solution code:
n=int(input())

s=[]

d={}

ans=0

for i in range(n):
    tmp="".join(sorted(input()))
    if tmp not in d:
        d[tmp]=1
    else:
        d[tmp]+=1

for dd in d.values():
    ans += dd*(dd-1)//2

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
S = ["".join(sorted(input())) for i in range(n)]
s = Counter(S)


def calc(x):
    return x * (x-1) // 2


ans = 0
for i in s.values():
    ans += calc(i)
print(ans)

Submission status: Accepted

Solution code:
import string
import collections

N = int(input())
count = 0

s = []

for i in range(0,N):
  s.append(''.join(sorted(input())))

  
c = collections.Counter(s)
go = c.most_common()

for i in range(len(go)):
  k = go[i][1]
  count+=k*(k-1)//2
  
print(count)

Submission status: Accepted

Solution code:
n = int(input())
words = set()
from collections import defaultdict
count_dict = defaultdict(int)
ans = 0

for i in range(n):
  word = str(sorted(input()))
  if word in words:
    count_dict[word] += 1
    ans += count_dict[word]
  else:
    words.add(word)
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
st = dict()
cnt = 0
for i in range(n):
    stx="".join(sorted(list(input())))
    if stx not in st:
        st[stx] = 0
    else:
        st[stx] +=1
        cnt += st[stx]
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
dct = defaultdict(int)

for i in range(n):
    s = input()
    sorted_s = "".join(sorted(s))
    dct[sorted_s] += 1

ans = 0
for a, b in dct.items():
    ans += b *(b-1)//2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
D = {}
count = 0
for i in range(n):
    line = "".join(sorted(list(input())))
    if line not in D:
        D[line] = 0
    else:
        D[line] += 1
        count += D[line]

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
snm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
l=[]
d=defaultdict(int)
for i in range(n):
    s=list(si())
    s.sort()
    tmp=''
    for ss in s:
        tmp+=ss
    l.append(tmp)

for ll in l:
    d[ll]+=1

ans=0
for k,v in d.items():
    if v>=2:
        ans+=(v*(v-1))//2

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
slist=[]
for i in range(n):
    s10=input()
    si=[]
    for ii in range(10):
        si.append(s10[ii])
    si.sort()
    stmp=""
    for ii in range(10):
        stmp=stmp+si[ii]
    slist.append(stmp)
slist.sort()
    
icnt=0   
i=0 
while i<=n-2:
    j=i+1
    jcnt=0
    while slist[i]==slist[j]:
        jcnt=jcnt+1
        icnt=icnt+jcnt
        j=j+1
        if j>=n:
            break
    i=j
    if i>=n-1:
        break
            
print(icnt)

Submission status: Accepted

Solution code:
from math import factorial


def combination2(num: int) -> int:
    return int(factorial(num) / (2 * factorial(num - 2)))


n = int(input())
ss = [input() for _ in range(n)]

dictionary = {}

for s in ss:
    sorted_string = "".join(sorted(s))
    count = dictionary.get(sorted_string)
    if count is None:
        dictionary[sorted_string] = 1
    else:
        dictionary[sorted_string] = count + 1

counter = 0

for count in dictionary.values():
    if count > 1:
        counter += combination2(count)

print(counter)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = []
for i in range(N):
  s += [''.join(sorted(input()))]
cnt = sum([x*(x - 1) // 2 for x in Counter(s).values()])
print(int(cnt+0.5))

Submission status: Accepted

Solution code:
N = int(input())
d = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in d:
        d[S] += 1
    else:
        d[S] = 1
ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]

answer = 0
counter = defaultdict(int)

for s in S:
  tmp = 0
  ss = list(s)
  ss.sort()
  for i in range(10):
    tmp += (ord(ss[i]) - ord("a")) * 26 ** i
  answer += counter[tmp]
  counter[tmp] += 1
  
print(answer)

Submission status: Accepted

Solution code:
from scipy.misc import comb
n = int(input())
dic = {}
for _ in range(n):
  s = input()
  tmp = [0]*26
  for i in s:
    tmp[ord(i)-97] += 1
  tmp = tuple(tmp)
  if tmp in dic:
    dic[tmp] += 1
  else:
    dic[tmp] = 1
total = 0
for i in dic.values():
  if i<2:
    continue
  total += comb(i, 2, exact=True)
print(total)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
slis=[]
for i in range(n):
	s=sorted(list(input()))
	slis.append(s)
ctr=Counter()
ans=0
for s in slis:
	a="".join(s)
	if a in ctr:
		ans+=ctr[a]
	ctr[a] +=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
d = {}
ans = 0
for s in S:
    ss = "".join(sorted(s))
    if ss in d:
        d[ss] += 1
        ans += d[ss]
    else:
        d[ss] = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
 
n = int(input())
S = [input() for _ in range(n)]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i])))
    d[s] += 1
 
ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
s = [input() for _ in range(n)]

dic = {}
for i in range(n):
    tmp = sorted(list(s[i]))
    tmp2 = "".join(tmp)
    if dic.get(tmp2) == None:
        dic[tmp2] = 1
    else:
        dic[tmp2] += 1

#print(dic)
ans = 0
for k, v in dic.items():
    #print(k, v)
    if v >= 2:
        num = (v-1)
        #print("num: ", num)
        #print("num//2*(num+1): ", num//2*(num+1))
        ans += num*(num+1)//2
        #print(ans)

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
inputs = sys.stdin.readlines()

n = int(inputs[0])
S = inputs[1:]

d = defaultdict(lambda: -1)
for i in range(n):
    s = ''.join(sorted(list(S[i].rstrip())))
    d[s] += 1

ans = 0
for v in d.values():
    ans += v*(v+1)//2
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    
    from collections import Counter
    c = Counter(s)
    res = 0
    for i in c.values():
        if i < 2:
            continue
        else:
            res += i * (i-1) // 2
    print(res)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

n = int(input())
x = []
for i in range(n):
  x.append(sorted(input()))
  
x_sort = sorted(x)
ans = 0

counter = Counter(map(tuple, x_sort))
for word, cnt in counter.most_common():
  ans += (cnt*(cnt-1))//2
  
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(s):
    c = Counter(s)

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

    return ans


n = int(input())
s = []

for i in range(n):
    tmp = sorted(input())
    s.append("".join(tmp))

print(solve(s))

Submission status: Accepted

Solution code:
from scipy.misc import comb
n = int(input())
s = sorted([''.join(sorted(list(input()))) for i in range(n)])
ans = 0
tmp = 1
for i in range(1, n):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        ans += comb(tmp, 2, exact = True)
        tmp = 1
ans += comb(tmp, 2, exact = True)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()

mp={}

for i in range(N):
    key = "".join(sorted(input()))
    if key in mp:
        mp[key] += 1
    else:
        mp[key] = 1

res = 0
for k, v in mp.items():
    if v >= 2: res += (v * (v-1) // 2)

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
si = ["".join(sorted(input())) for _ in range(n)]

ans = 0
for i in Counter(si).values():
    ans += i * (i-1) // 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = []
for _ in range(N):
    s.append(''.join(sorted(input().lower())))

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

print(sum(l[k] * (l[k]-1) // 2 for k in l))

Submission status: Accepted

Solution code:
#python3
import collections as cl
n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]
sum=0
for i in cl.Counter(a).values():
  sum+=i*(i-1)//2
print(sum)

Submission status: Accepted

Solution code:
#python3
import collections as col
n=int(input())
a=[input() for i in range(n)]

b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1

#c = [''.join(sorted(a)) for _ in range(n)]

sum1=0
for i in b.values():
  sum1+=i*(i-1)//2
print(sum1)

Submission status: Accepted

Solution code:
#python3
import collections as col
n=int(input())
a=[input() for i in range(n)]
b=col.defaultdict(int)
for i in a:
  b[''.join(sorted(i))]+=1

sum=0
for i in b.values():
  sum+=i*(i-1)//2
print(sum)

Submission status: Accepted

Solution code:
#python3
from collections import defaultdict
n=int(input())
a=[input() for _ in range(n)]
b=defaultdict(int)
for i in a:
  k=''.join(sorted(i))
  b[k]+=1

c = dict(b)
ans=0
for i in c.values():
  ans+=i*(i-1)//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
cntS = {}
for _ in range(N):
  s = ''.join(sorted(input()))
  if s in cntS:
    cntS[s] += 1
  else:
    cntS[s] = 1

print(sum([cntS[key]*(cntS[key]-1)//2 for  key in cntS]))

Submission status: Accepted

Solution code:
import collections
N=int(input())
Slst=["".join(sorted(list(input()))) for i in range(N)]
dic={}
namelst=set()

for S in Slst:
    if S in namelst:
        dic[S]+=1
    else:
        namelst.add(S)
        dic.update({S:1})
#print(dic)

print(sum([dic[i]*(dic[i]-1)//2 for i in dic if dic[i]>=2]))

Submission status: Accepted

Solution code:
n = int(input())
a = {}
ans = 0

for i in range(n):
    s = sorted(input())
    s = ''.join(s)
    if s in a.keys():
        ans += int(a[s])
        a[s] += 1
    else:
        a[s] = 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for _ in range(N)]
d = {}
ans = 0
for s in S:
    ss = "".join(sorted(s))
    if ss in d:
        d[ss] += 1
        ans += d[ss]
    else:
        d[ss] = 0
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    dict = {}
    result = 0
    for i in range(N):
        s = "".join(sorted(input()))
        if s in dict:
            result += dict[s]
            dict[s] = dict[s] + 1
        else:
            dict[s] = 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    N = int(input())

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(sys.stdin.readline().rstrip()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()

Submission status: Accepted

Solution code:
import sys
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    N = int(input())

    Ss = {}
    for x in range(N):
        tmp = ''.join(sorted(input()))

        if tmp in Ss:
            Ss[tmp] += 1

        else:
            Ss[tmp] = 1


    ans = 0
    for i in Ss.values():
        if i != 1:
            ans += combinations_count(i, 2)

    print(ans)

main()

Submission status: Accepted

Solution code:
import collections

N=int(input())
s=[[] for _ in range(N)]

for i in range(N):
    s[i]=input()

p=101
ha=[0]*N
for i in range(N):
    for j in range(len(s[i])):
        ha[i]+=pow(p,(ord(s[i][j])-ord("a")))
c=collections.Counter(ha)

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

Submission status: Accepted

Solution code:
n = int(input())
s = ['' for i in range(n)]
for i in range(n):
    s[i] = sorted(input())
ss = sorted(s)

ans = 0
i = 0
while i < n-1:
    if i < n-1 and ss[i] == ss[i+1]:
        count = 2
        if i < n-2 and ss[i+1] == ss[i+2]:
            i+=1
            while i < n-1 and ss[i] == ss[i+1]:
                count+=1
                i+=1
            i-=1
        ans+=(count*(count-1)//2)
    i+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())

dic = {}
ans = 0

for i in S:
    tmp = "".join(sorted(i))
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
    
for i in dic.values():
    ##sum 1 to i-1 = (i^2-i)/2
    ans += (i*(i-1))//2

print(ans)

Submission status: Accepted

Solution code:
#python3
n = int(input())
s = [str(input()) for _ in range(n)]
sep = ''
dic = dict()
for string in s:
  tmp = sep.join(sorted(string))
  if tmp in dic:
    dic[tmp] += 1 
  else :
    dic[tmp] = 1
ans = 0
for i in dic.values(): 
  ans += i*(i-1)//2
print(ans)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
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 pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = collections.Counter(["".join(sorted([c for c in S()])) for _ in range(n)])
    r = 0
    for i in a.values():
        r += i * (i-1) // 2

    return r


print(main())

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [""]*n
for i in range(n):
    a[i] = ''.join(sorted(input()))
b = list(Counter(a).values())
print(sum(int((i-1)*i/2) for i in b))

Submission status: Accepted

Solution code:
import collections as cl

N = int(input())
a = [""]*N
for i in range(N):
    a[i] = "".join(sorted(list(input())))

b = list(cl.Counter(a).values())

ans = 0
for x in b:
    tmp = x * (x-1) // 2
    ans += tmp
print(ans)

Submission status: Accepted

Solution code:
import collections as cl

n = int(input())
a = [""]*n
for i in range(n):
  a[i] = "".join(sorted(list(input())))
b = list(cl.Counter(a).values())
s = 0
for x in b:
  s += x*(x-1)//2
print(s)

Submission status: Accepted

Solution code:
import collections
n=int(input())
lst=["i"]*n
for i in range(n):
    a=input()
    lst[i]="".join(sorted(a))
count=collections.Counter(lst)
ans=0

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
for i in range(n):
    b=input()
    b=sorted(b)
    b=' '.join(b)
    b=b.replace(" ","")
    a.append(b)
import collections
c=collections.Counter(a)
c=list(c.values())
ans=0
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in c:
    if i>=2:
        ans+=combinations_count(i,2)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d={}
ans=0
for i in range(n):
    s=list(input())
    s.sort()
    l=''.join(s)
    if l in d:
        ans+=d[l]
        d[l]+=1
    else:
        d[l]=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in range(N)]
num = 0
d = {}
for i in range(N):
    if ''.join(sorted(s[i])) in d:
        d[''.join(sorted(s[i]))] += 1
        num += d[''.join(sorted(s[i]))]
    else:
        d[''.join(sorted(s[i]))] = 0
print(num)

Submission status: Accepted

Solution code:
T = int(input())
dct ={}
for z in range(T):
    s = "".join(sorted(input()))
    if s in dct:
        dct[s] += 1
    else:
        dct[s] = 1
v = 0
for elem in dct.values():
    v += (elem*(elem-1))//2
print(v)

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = 0
for i in dic.values():
    if i > 1:
        ans += i*(i-1)//2
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    s = "".join(sorted(input()))
    dic = {s:1}
    ans = 0
    for _ in range(N-1):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for i in dic.values():
        ans += (i*(i-1))//2
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
N = int(input())
D = {}
for i in range(N):
  S = input()
  L = [S[j] for j in range(10)]
  L.sort()
  s = ""
  for j in range(10):
    s = s[:] + L[j]
  if s in D:
    D[s] += 1
  else:
    D[s] = 1
p = 0
for i in D:
  p += (D[i]*(D[i]-1))//2
print(p)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N=int(input())
s = [input() for i in range(N)]

count_by_kw=Counter()

for i in s:
    count_by_kw[''.join(sorted(i))]+=1

values, counts = zip(*count_by_kw.most_common())
cnt=0
for i in counts:
    if i>1:
        cnt+=combinations_count(i,2)

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
d = dict()

for _ in range(n):
    s = "".join(sorted([x for x in input()]))
    d[s] = d.get(s, 0) + 1

ans = 0

for v in d.values():
    if v >= 2:
        ans += (v * (v-1)) // 2

print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
d = dict()

for _ in range(n):
    s = "".join(sorted([x for x in input()]))
    d[s] = d.get(s, 0) + 1

ans = 0

for v in d.values():
    if v >= 2:
        ans += (v * (v-1)) // 2

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

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

Submission status: Accepted

Solution code:
n = int(input())
d = {}
ans = 0

for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
#print(d)
for k, v in d.items():
  #vC2の組み合わせ
  ans += v * (v - 1) / 2

print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
d = {}
ans = 0

for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
#print(d)
for k, v in d.items():
  ans += v * (v - 1) / 2

print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
d = {}
summ = 0

for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1

for k, v in d.items():
    summ += v*(v-1)/2

print(int(summ))