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.

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

t = {}
ans = 0
for s in S:
    st = "".join(sorted(list(s)))
    if st in t.keys():
        t[st] += 1
        ans += t[st]
    else:
        t[st] = 0

print(ans)

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

Solution (Python):
import collections
from math import factorial

N = int(input())
S = [0]*N
for i in range(N):
    s = list(str(input()))
    s.sort()
    S[i] = "".join(s)

c = collections.Counter(S)
cnt = 0
r = 2

for n in c.values():
    if n >= 2:
        cnt += factorial(n)/(factorial(r)*factorial(n - r))
print(int(cnt))

Solution (Python):
import collections
from math import factorial

N = int(input())
S = [0]*N
for i in range(N):
    s = list(str(input()))
    s.sort()
    S[i] = "".join(s)

c = collections.Counter(S)
cnt = 0
r = 2

for n in c.values():
    if n >= 2:
        a = factorial(n)
        b = factorial(r)*factorial(n - r)
        cnt += a/b
print(int(cnt))

Solution (Python):
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
dict = {}
ans = 0

for i in s:
    if i in dict:
        ans += dict[i]
        dict[i] += 1
    else:
        dict[i] = 1

print(ans)

Solution (Python):
import sys
from collections import deque
sys.setrecursionlimit(20000000)


def main():

    n = int(input())
    dic = {}
    for _ in range(n):
        t = ''.join(sorted(list(input())))
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 0

    def pattern(num):
        tmp = 0

        for i in range(1, num+1):
            tmp += i
        return tmp

    ans = 0
    for d in dic:
        if dic[d]:
            ans += pattern(dic[d])

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

N = int(input())
s = [0]*N
for i in range(N):
    s[i] = ''.join(sorted(list(input())))

ct = Counter(s).values()
ct2 = Counter(ct).items()

ans = 0
for i, j in ct2:
    if i >= 2:
        ans += j*i*(i-1)//2

print(ans)

Solution (Python):
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
ans=0
dict={}
for i in s:
    if i in dict:
        ans+=dict[i]
        dict[i]+=1
    else:
        dict[i]=1
print(ans)

Solution (Python):
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
x=set()
d={}
cnt=0
for i in range(n):
  if s[i] not in x:
    x.add(s[i])
    d[s[i]]=1
  else:
    cnt+=d[s[i]]
    d[s[i]]=d[s[i]]+1
print(cnt)

Solution (Python):


n = int(input())
s = dict()

for i in range(0, n):
    char = list(input())
    char.sort()
    _str = ''.join(char)
    cnt = s[_str] + 1 if _str in s else 1
    s[_str] = cnt

ret = 0
for key, val in s.items():
    if val > 1:
        ret += sum([x for x in range(0, val)])

print(ret)

Solution (Python):
N =int(input())

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


for i in range(len(s)):
    s[i].sort()
s.sort()   
ans = 0 
cnt = 1
for i in range(1,N):
    for j in range(10):
        
        
        if(s[i][j] != s[i-1][j]):
            break
    else:
        cnt +=1
        continue
    ans += cnt*(cnt-1)//2
    cnt =1
ans +=cnt*(cnt-1)//2
print(ans)

Solution (Python):
N =int(input())

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


for i in range(len(s)):
    s[i].sort()
s.sort()   
ans = 0 
cnt = 1
for i in range(1,N):
    for j in range(10):
        
        
        if(s[i][j] != s[i-1][j]):
            break
    else:
        cnt +=1
        continue
    ans += cnt*(cnt-1)//2
    cnt =1
ans +=cnt*(cnt-1)//2
print(ans)

Solution (Python):
import collections
import math

n = int(input())
s = list(input() for i in range(n))

for i in range(n):
    new_str_list = sorted(list(s[i]))
    new_str = ''.join(new_str_list)
    s[i] = new_str

c = collections.Counter(s)
cl = list(c.values())
cl = [i for i in cl if i >= 2]
ans = 0
for j in cl:
    ans = ans + math.factorial(j) // (math.factorial(j - 2) * math.factorial(2))

print(ans)

Solution (Python):
dic = {}
lop = int(input())
for i in range(lop):
    N = list(input())
    N.sort()
    N = "".join(N)
    if N in dic:
        dic[N] += 1
    else:
        dic[N] = 1
print(sum(list(map(lambda x: int((x * (x - 1)) / 2), list(dic.values())))))

Solution (Python):
import math
from collections import Counter, defaultdict

def ncr(p):
	return p*(p-1)//2

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1


ans = sum(ncr(val) for val in dct.values() if val>1)
print(ans)

Solution (Python):
import math
from collections import Counter, defaultdict

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

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1


ans = sum(ncr(val, 2) for val in dct.values() if val>1)
print(ans)

Solution (Python):
dic = {}
cou = 0
lop = int(input())
for i in range(lop):
    N = input()
    N = list(N)
    N.sort()
    N = "".join(N)
    if N in dic:
        dic[N] += 1
    else:
        dic[N] = 1
lis = list(dic.values())
print(sum(list(map(lambda x: int((x * (x - 1)) / 2), lis))))

Solution (Python):




def main():
    
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    s = list(map(lambda s: ''.join(sorted(s)), s))
    hash = {}

    count = 0
    for i in range(0, n):
        if s[i] in hash:
            hash[s[i]] += 1
        else:
            hash[s[i]] = 1
        count += hash[s[i]] - 1
    return count


if __name__ == "__main__":
    main()

Solution (Python):

"""
Created on Wed Aug 21 22:49:30 2019

@author: Yamazaki Kenichi
"""

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

for i in range(N):
    S[i] = ''.join(sorted(S[i]))
S.sort()
ans = 0
counta = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        counta += 1
    else:
        ans += counta*(counta+1)//2
        counta = 0
ans += counta*(counta+1)//2
print(ans)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

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

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
s = [0 for i in range(N)]
for i in range(N):
    s[i] = list(str(input()))


for i in range(N):
    s[i].sort()
    s[i] = "".join(s[i])


dic = {}
for i in range(N):
    if s[i] in dic.keys():
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

ans = 0
for key in dic.keys():
    if dic[key] > 1:
        ans += dic[key]*(dic[key] - 1)//2

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
ss = ["".join(sorted(input())) for i in range(n)]
cnt = 0
counter = Counter(ss)
for k, v in counter.items():
  cnt += v*(v-1)/2
print(int(cnt))

Solution (Python):
from collections import *
 
n = int(input())
dic = defaultdict(int)
for i in range(n):
  dic["".join(sorted(input()))] += 1
 
ans = 0
for k,v in dic.items(): 
  ans += int(v*(v-1)/2)
  
print(ans)

Solution (Python):
N = int(input())
s = [list(input()) for i in range(N)]

for i in range(len(s)):
  s[i].sort()
s.sort()

ans = 0
cnt = 1
for i in range(1, N):
  for j in range(10):
    if s[i][j] != s[i - 1][j]:
      break
  else:
    cnt += 1
    continue
  ans += cnt * (cnt - 1) // 2
  cnt = 1
ans += cnt * (cnt - 1) // 2

print(ans)

Solution (Python):
N, *s = open(0).read().split()
sl = [''.join(sorted(c)) for c in s]
count = 0
dict = {}
for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Solution (Python):
from math import factorial
N = int(input())
P = {}
ans = 0
def counter(s):
    ret = [0]*26
    for ss in s:
        ret[ord(ss)-ord('a')] += 1
    return tuple(ret)
for _ in range(N):
    s = input()
    c = counter(s)
    if not c in P.keys():
        P[c] = 1
    else:
        P[c] += 1
for v in P.values():
    if v > 1:
        ans += factorial(v) // factorial(2) // factorial(v-2)
print(ans)

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

    n = int(input())
    ans = 0
    used_s = {}
    for _ in range(n):
        s = "".join(sorted(input()))
        if not s in used_s.keys():
            used_s[s] = 0
        else:
            used_s[s] += 1
            ans += 1 * used_s[s]

    print(ans)

if __name__ == '__main__':
    main()

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

n = int(input())
ans = 0
used_s = {}
for _ in range(n):
    s = "".join(sorted(input()))
    if not s in used_s.keys():
        used_s[s] = 0
    else:
        used_s[s] += 1
        ans += 1 * used_s[s]

print(ans)

Solution (Python):
n = int(input())
ans = 0
used_s = {}
for _ in range(n):
    s = "".join(sorted(input()))
    if not s in used_s.keys():
        used_s[s] = 0
    else:
        used_s[s] += 1
        ans += 1 * used_s[s]

print(ans)

Solution (Python):
N= int(input())
s = []

for _ in range(N):
    s.append(input())

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

import collections
c = collections.Counter(s)
d = [i for i in c.values()]

counter = 0
from math import factorial
for i in d:
    if i > 1:
        counter += i*(i-1)/2

print(int(counter))

Solution (Python):

import copy

N = int(input())

d = dict()

res = 0
for i in range(N):
    s = input()
    s = ''.join(sorted(s))

    if s in d.keys():
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1

print(res)

Solution (Python):
import collections
from scipy.misc import comb

N = int(input())
s = []
for _ in range(N):
    s.append(list(input()))

for i in range(len(s)):
    s[i] = tuple(sorted(s[i]))
    
c = collections.Counter(s)

cnt = 0
for c_ in c.values():
    cnt += comb(c_, 2, exact=True)
    
print(cnt)

Solution (Python):
n = int(input())
dic = {}
for i in range(n):
    tmp = ''.join(sorted(input()))
    if tmp in dic:
        dic[tmp] = dic[tmp]+1
    else:
        dic.setdefault(tmp, 0)
ans = 0
for i in dic:
    ans += 1/2 * dic[i] * (dic[i]+1)
print(int(ans))

Solution (Python):
from collections import Counter

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

c = Counter()

for si in s:
    si = "".join(sorted(si))
    c[si] += 1

ans = 0

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

print(ans)

Solution (Python):
N=int(input())
d={}
for i in range(N):
    l=[0]*26
    for s in input():
        l[ord(s)-97]+=1
    l=tuple(l)
    if l in d:d[l]+=1
    else:d[l]=1

ans=0
for c in d:
    if d[c]==2:ans+=1
    elif d[c]!=1:ans+=d[c]*(d[c]-1)//2
print(ans)

Solution (Python):

from collections import *

n = int(input())
dic = defaultdict(lambda: 0)
for i in range(n): dic["".join(sorted(input()))] += 1

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

Solution (Python):
n,*S=open(0).read().split()

from collections import defaultdict
dic = defaultdict(int)

for s in S:
  dic["".join(sorted(s))]+=1

print(sum([(v*(v-1))//2 for v in dic.values()]))

Solution (Python):

from collections import defaultdict

def solve():
    N = int(input())
    
    d = defaultdict(int)
    for _ in range(N):
        s = input()
        l_s = list(s)
        l_s.sort()
        s = "".join(l_s)
        d[s] += 1

    ans = 0
    for key, value in d.items():
        
        ans += (((value-1)+1) * (value-1)) / 2
    print(int(ans))

if __name__ == "__main__":
    solve()

Solution (Python):
import collections

N =int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
cnt = 0
ans =0
for i in set(s):
    cnt = c[i]
    ans += cnt*(cnt-1)//2
print(ans)

Solution (Python):
import collections
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """
 
    
    r = min(r, n-r)
 
    
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
 
    
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
 
    return numerator // denominator
 
N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
set_lists = list(set(lists))
for i in range(len(set_lists)):
    cnt = c[str(set_lists[i])]
    if cnt == 1:
        pass
    else:
        Sum += nCr(cnt,2)
print(Sum)

Solution (Python):
import collections
 
N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
set_lists = list(set(lists))
for i in range(len(set_lists)):
    n = c[str(set_lists[i])]
    Sum += n * (n - 1) // 2
lists.sort()
print(Sum)

Solution (Python):
import collections

N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
for i in set(lists):
    n = c[i]
    Sum += n * (n - 1) // 2
lists.sort()
print(Sum)

Solution (Python):
from collections import *
print(sum(v * (v-1)//2 for v in Counter(frozenset(Counter(input()).items()) for _ in range(int(input()))).values()))

Solution (Python):
from collections import *
print(sum(v * (v-1)//2 for v in Counter(tuple(sorted(Counter(input()).items())) for _ in range(int(input()))).values()))

Solution (Python):
N = int(input())
dic = {}
sum = 0
for i in range(N):
    s = ''.join(sorted(str(input())))
    if s in dic:
      dic[s] += 1
    else:
      dic[s] = 1
for i in dic.values():
    if i > 1:
        sum += i*(i-1)/2
print(int(sum))

Solution (Python):
import collections
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]

c=collections.Counter(texts)

ans=sum([i*(i-1)/2 for i in c.values()])
print(int(ans))

Solution (Python):
import collections
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for si in set(s):
  a = c[si]
  ans += a * (a - 1) // 2
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

c = Counter(s)

ans = 0

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

print(int(ans))

Solution (Python):
n = int(input())
ans = 0
dic = {}
for i in range(n):
    s = input()
    s = str(sorted(s))
    tmp = dic.get(s,0)
    ans += tmp
    dic[s] = tmp + 1

print(ans)

Solution (Python):
n =  int(input())

s = []
for _ in range(n):
    s.append(''.join(sorted(input())))

d = {}

for e in s:
    if e in d:
        d[e] += 1
    else:
        d[e] = 1

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

print(ans)

Solution (Python):
n = int(input())
ss = []
cnt = 0










for _ in range(n):
    ss.append(input())

map = {}
for s in ss:
    sorted_s = ''.join(sorted(s))
    if sorted_s in map.keys():
        map[sorted_s] += 1
    else:
        map[sorted_s] = 1









for n in map.values():
    if n > 1:
        
        cnt += (n * (n - 1)) // 2
    
    

print(cnt)

Solution (Python):

n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(m)

Solution (Python):
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
t = {}

for i in range(n):
    if s[i] in t:
        t[s[i]] += 1
    else:
        t[s[i]] = 1
ans = sum((i * (i - 1)) // 2 for i in t.values())

print(ans)

Solution (Python):
import copy
import math
import sys

sys.setrecursionlimit(10 ** 7)

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


def split(word):
    return [char for char in word]


normalized_s_list = sorted([''.join(sorted(split(s))) for s in s_list])

uniqued_s_list = sorted(list(set(normalized_s_list)))

j = 0
counter = 0
result = 0
for s in normalized_s_list:
    if s == uniqued_s_list[j]:
        counter += 1
    else:
        result += (1 / 2) * counter * (counter - 1)
        j += 1
        counter = 1  

result += (1 / 2) * counter * (counter - 1)
print(int(result))

Solution (Python):
import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
arr = {}
ans = 0
for _ in range(N):
    S = input()
    tmp_arr = []
    for i in range(10):
        tmp_arr.append(S[i])
    tmp_arr.sort()
    moji_sorted = ''
    for i in tmp_arr:
        moji_sorted += i
    if moji_sorted in arr:
        arr[moji_sorted] += 1
    else:
        arr[moji_sorted] = 1


for i in arr.values():
    if i-2 >= 0:
        ans += C(i,2)

print(ans)

Solution (Python):

n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(m)

Solution (Python):
def main(ss):
    sorted_ss = ["".join(sorted(s)) for s in ss]
    
    visited = dict()
    count = 0
    for s in sorted_ss:
        if s in visited:
            count += visited[s]
            visited[s] += 1
        else:
            visited[s] = 1

    return count


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

print(main(ss))

Solution (Python):
import collections
n = int(input())
c = collections.Counter()
total = 0
for i in range(n):
    sn = input()
    l = list()
    sed = ''
    for j in range(10):
        l.append(sn[j])
    l.sort()
    for x in l:
        sed += x
    c[sed] += 1
for y in list(c.values()):
    total += y*(y-1)//2
print(total)

Solution (Python):
N = int(input())
S = [input() for i in range(N)]

list = {}
for i in S:
  i=''.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1

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

Solution (Python):
N = int(input())
S = [input() for i in range(N)]

dic = {}

for i in range(N):
    s = str(sorted(S[i]))
    if s not in dic:
        dic[s] = 0
    dic[s] += 1

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

Solution (Python):


N = int(input())


ar = []
for i in range(N):
  l = list(input())
  l.sort()
  ar.append("".join(l).__hash__())


list = {}
for i in ar:
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
  
count = 0
for i in list.values():
  n = i - 1
  count = count + int(((n * (n + 1)) / 2))

print(count)

Solution (Python):
n = int(input())

rifa = {}
ans = 0
for i in range(n):
    s = input()
    s = str(sorted(s))
    tmp = rifa.get(s, 0)
    ans += tmp
    rifa[s] = tmp + 1
print(ans)

Solution (Python):
import statistics as stat
import collections as cl

N = int(input())

s_li = []
s_dic = {}
c = 0
for i in range(N) :
    s = ''.join(sorted(list(input())))
    
    
    
    
    if (s in s_dic) :
        c += s_dic[s]
        s_dic[s] += 1
    else :
        s_dic[s] = 1

print(c)

Solution (Python):
import collections
n=int(input())
L=["".join(sorted(input()))for _ in range(n)]
C=collections.Counter(L)
a=0
for i in set(L):
    n=C[i]
    a+=n*(n-1)//2
print(a)

Solution (Python):
N = int(input())
s = [input() for i in range(N)]
ans ={}
num = 0

for i in range(N):
    s[i] = ''.join(sorted(s[i]))
    if s[i] in ans.keys():
        ans[s[i]] += 1
        num += ans[s[i]]
    else:
        ans[s[i]] = 0

print(num)

Solution (Python):
N = int(input())
u = ["".join(sorted(list(input()))) for i in range(N)]
d = {}
for i in range(N):
  if u[i] in d:
    d[u[i]] += 1
  else:
    d[u[i]] = 1
ans = sum((i * (i - 1)) // 2 for i in d.values())
print(ans)

Solution (Python):
import collections
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
d = collections.Counter(s)
i = 0

for k in d:
  if d[k] > 1:
    i += int(d[k] * (d[k] - 1) / 2)

print(i)

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

Solution (Python):
dic = { c: i for i, c in enumerate('abcdefghijklmnopqrstuvwxyz')}

n = int(input())
strs = [tuple(sorted(map(lambda x: dic[x], input())))  for _ in range(n)]

a = {}
for s in strs:
  if s not in a:
    a[s] = 1
  else:
    a[s] += 1

print(sum(item[1]*(item[1]-1)//2 for item in a.items()))

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

for i in range(N):
    S = input()
    
    S = sorted(S)
    str = ""
    for s in S:
        str += s
    d[str] += 1


ans = 0
for k in d.keys():
    num = d[k]
    ans += num*(num-1)//2

print(ans)

Solution (Python):

from collections import defaultdict
MOD = 10 ** 9 + 7

N = int(input())

ans = 0
sdic = defaultdict(int)
for i in range(N):
    s = input()
    s = str(sorted(s))
    sdic[s] += 1

for s in sdic:
    ans += sdic[s] * (sdic[s] - 1) // 2

print(ans)

Solution (Python):
N = int(input())
s = [list(input()) for i in range(N)]

count = 0
appeared = {}

for ss in s:
  sss = "".join(sorted(ss))
  if sss in appeared.keys():
    count += appeared[sss]
    appeared[sss] += 1
  else:
    appeared[sss] = 1

print(count)

Solution (Python):


import collections
import itertools
import math

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(''.join(sorted(s)))

counter = collections.Counter(s_list)

def C(n, k):
    return math.factorial(n) / (math.factorial(k) * math.factorial(n-k))

p_list = [C(value, 2) for key, value in counter.items() if value > 1]
ans = int(sum(p_list))

print(ans)

Solution (Python):
n=int(input())
d=[]
a=[2,3,5,7,11,13,17,23,29,31]

i=0
while(i<n):
	stri=input()
	stri=list(map(ord,stri))
	stri=list(map(lambda h: h-97,stri))
	stri.sort()
	
	j=0
	number=1
	leng=len(stri)
	while(j<leng):
		number*=a[j]**(stri[j])
		j+=1
	d.append(number)
	i+=1
d.sort()

j=0
super=0
while(j<n):
	pfinder=d[j]
	summer=0
	notFound=True
	
	while( notFound and j<n):
		if(d[j]==pfinder):
			summer+=1
			j+=1	
		else:
			notFound=False
	
	super+=int(summer*(summer-1)/2)

print(super)

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


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def comb(x):
    a = 1
    for i in range(1, x+1):
        a *= i
    return a//2


def main():
    N = int(input())
    M = {}
    for _ in range(N):
        s = ''.join(sorted(input()))
        if (s in M.keys()):
            M[s] += 1
            continue
        M[s] = 1

    print(sum([m*(m-1)//2 for m in M.values()]))


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
s_list = {}
out = 0

for i in range(N):
	s_in =''.join(sorted(list(input())))
	if s_in in s_list:
		s_list[s_in]+=1
	else:
		s_list[s_in]=1
    
for val in s_list.values():
  out += int(val*(val-1)/2)
    
print(out)

Solution (Python):
from collections import Counter
from functools import reduce

n = int(input())

s = []
for _ in range(n):
    s.append(reduce(lambda x, y: x + y, sorted(input())))


print(sum([x * (x - 1) // 2 for x in Counter(s).values()]))

Solution (Python):
from collections import Counter

def list2str(l):
    s = ""
    for c in l:
        s += c
    return s

n = int(input())

s = []
for _ in range(n):
    s.append(list2str(sorted(input())))

"""

cnt = 0
for i in range(1, n):
    for j in range(i):
        if s[j] == s[i]:
            cnt += 1
print(cnt)
"""

"""

print(sum([x * (x - 1) // 2 for x in Counter(sorted(s)).values()]))
"""

cnt = 0
a = Counter()
for b in s:
    if b in a:
        cnt += a[b]
    a[b] += 1
print(cnt)

Solution (Python):
from collections import Counter
from operator import mul
from functools import reduce


def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N = int(input())
lst_s = ["".join(sorted(input())) for _ in range(N)]

cnt_s = Counter(lst_s)

ans = 0
for v in cnt_s.values():
    if v == 1:
        continue
    else:
        ans += cmb(v, 2)
print(ans)

Solution (Python):
from collections import Counter

def list2str(l):
    s = ""
    for c in l:
        s += c
    return s

n = int(input())

s = []
for _ in range(n):
    s.append(list2str(sorted(input())))

"""

cnt = 0
for i in range(1, n):
    for j in range(i):
        if s[j] == s[i]:
            cnt += 1
"""

print(sum([x * (x - 1) // 2 for x in Counter(sorted(s)).values()]))

Solution (Python):

from sys import stdin




def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()

s_list = []
for _ in range(N):
    s = list(_s())
    s.sort()
    s_list.append(''.join(s))

s_list.sort()
s_list.append('')

ans = 0
pre = ''
cur = 0
for s in s_list:
    if s == pre:
        cur += 1
    else:
        ans += (cur + 1) * cur // 2
        cur = 0
        pre = s

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
string_list=["".join(sorted(list(input()))) for i in range(n)]
counter=Counter(string_list)
cnt=0
for k, v in counter.items():
  cnt+=int(v*(v-1)/2)
print(cnt)

Solution (Python):
n=int(input())
s={}
for i in range(n):
    ss=list(input())
    ss.sort()
    ss=tuple(ss)
    try:
        s[ss]+=1
    except:
        s[ss]=1
tot=0
for i in s:
    if s[i]>1:
        tot+=(s[i]*(s[i]-1))//2
print(tot)

Solution (Python):
N = int(input())

mydic = {}

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

mycnt = 0
for i in mydic.values():
    if i > 1:
        mycnt += i*(i-1)//2
print(mycnt)

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 permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N =  INT()
s = ["".join(sorted(input())) for _ in range(N)]

s.sort()

ans = 0
count = 0
tmp = ""
for i in s:
	if tmp == i:
		count += 1
	else:
		ans += count*(count+1)//2
		count = 0
		tmp = i
ans += count*(count+1)//2
print(ans)

Solution (Python):

qt = int(input())
sl = [input() for i in range(qt)]
d = {}
count = 0

for s in sl:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

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

print(count)

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

d = {}
for s in S:
  s = "".join(sorted(s))
  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)

Solution (Python):
import math as m

qt = int(input())
sl = [input() for i in range(qt)]
d = {}
count = 0

for s in sl:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for e in d.values():
    if e > 1:
        count += m.factorial(e) // (m.factorial(e - 2) * 2)

print(count)

Solution (Python):
from collections import Counter

N = int(input())
S = [""] * N

for i in range(N):
    S[i] = "".join(sorted(input()))

count = 0

for i in Counter(S).values():
    count += i * (i - 1) // 2

print(count)

Solution (Python):

import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
s=Counter(["".join(sorted(list(stdin.readline().rstrip()))) for _ in range(n)]).most_common()
cnt=0
for i in s:
    cnt+=sum(range(1,i[1]))
print(cnt)

Solution (Python):
N = int(input())
list_anagram = [''.join(sorted(str(input()))) for i in range(N)]
 
list_anagram.sort()
ans = 0
 
x = 1
 
for i in range(1, N):
    if i != N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
    elif i != N - 1 and list_anagram[i] != list_anagram[i - 1]:
        ans = ans + x * (x - 1) // 2
        x = 1
    elif i == N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
        ans = ans + x * (x - 1) //2
    else:
        ans = ans + x * (x - 1) // 2
 
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import defaultdict

n = int(input())
d = defaultdict(int)
for _ in range(n):
	s = ''.join(sorted(list(input().strip())))
	d[s] += 1
ans = 0
for x in d.values():
	ans += x * (x - 1) // 2
print(ans)

Solution (Python):
import collections,functools
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]

c=collections.Counter(texts)
ans=int(sum([i*(i-1)/2 for i in c.values()]))
print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
D = defaultdict(int)
for i in range(N):
    S = ''.join(sorted(input()))
    D[S] += 1

ans = 0
for key in D:
    M = D[key]
    if M >= 2:
        ans += M*(M-1)//2
    
print(ans)

Solution (Python):
N = int(input())
S = [input() for i in range(N)]

count = 0
appeared = {}
for i in range(N):
    S[i] = "".join(sorted(list(S[i])))
    if S[i] in appeared:
        count += appeared[S[i]]
        appeared[S[i]] += 1
    else:
        appeared[S[i]] = 1
print(int(count))