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_list = []

for i in range(N):
    s = list(input())
    s.sort()
    s1 = ''.join(s)
    S_list.append(s1)

S_list.sort()
s_compare = S_list[0]
ans = 0
count = 1

for i in range(1,N):
    if S_list[i] == s_compare:
        count += 1
    else:
        ans += count * (count - 1) / 2
        count = 1
        s_compare = S_list[i]

ans += count * (count - 1) / 2
print(int(ans))

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

for i in range(N):
    s = list(input())
    s.sort()
    s1 = ''.join(s)
    S_list.append(s1)

S_list.sort()
s_compare = S_list[0]
ans = 0
count = 1

for i in range(1,N):
    if S_list[i] == s_compare:
        count += 1
    else:
        ans += count * (count - 1) / 2
        count = 1
        s_compare = S_list[i]

ans += count * (count - 1) / 2
print(int(ans))

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

d = {}
ans = 0
for s in S:
    s = "".join(sorted(s))
    if s in d:
        ans += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(ans)

Solution (Python):
def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        s = sorted(s)
        s = ''.join(s)
        S.append(s)
    S.sort()
    SS = sorted(list(set(S)))
    SN = []
    M = len(SS)
    l = 0
    r = len(S)
    for i in range(M):
        for j in range(l, r):
            if S[j] != SS[i]:
                r = j
                break
        SN.append(r - l)
        l = r
        r = len(S)        

    res = 0
    for sn in SN:
        res += sn * (sn - 1) // 2

    print(res)
if __name__ == "__main__":
    main()

Solution (Python):
def number(x):
  return int((1 + (1 + 8*x)**0.5) / 2)


N = int(input())
d = {}
for i in range(N):
  s = ''.join(sorted(input()))
  if s in d.keys():
    d[s] += number(d[s])
  else:
    d[s] = 0


print(sum(d.values()))

Solution (Python):
import sys

n = int(input())
originals = [input() for i in range(n)]

ret = {}
count = 0
for original in originals:
  str = "".join(sorted(list(original)))
  if str in ret:
    count += ret[str]
    ret[str] += 1
  else:
    ret[str] = 1
print(count)

Solution (Python):
def sum_a(x):
    t = 0
    for i in range(x):
        t += i
    return t

N = int(input())
dic = {}

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

total = 0
for i in dic.values():
    if i > 1:
        total += sum_a(i)

print(total)

Solution (Python):
import itertools
from math import factorial
from scipy.misc import comb

N = int(input())
s = {}
for _ in range(N):
    b = list(input())
    b.sort()
    c = ''.join(b)
    if not c in s:
        s[c] = 1
    else:
        s[c] += 1

a = [comb(v, 2, exact=True) for v in s.values()]
print(sum(a))

Solution (Python):
n = int(input())
dic = dict()
ans = 0

for i in range(n):
    buf = input()
    seq = [buf[i] for i in range(len(buf))]
    seq.sort()
    bf2 = "".join(seq)
    
    if bf2 not in dic:
        dic[bf2] = 0
    else:
        dic[bf2] += 1
        ans += dic[bf2]

print(ans)

Solution (Python):
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

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

print(round(ans))

Solution (Python):
import collections

n = int(input())
L = []
cnt = 0
for i in range(n):
    s = sorted(input())
    s = "".join(s)
    L.append(s)
c = collections.Counter(L).values()
for i in c:
    cnt += i*(i-1)//2
print(cnt)

Solution (Python):


def resolve():
    n = int(input())
    table = {}
    for _ in range(n):
        s = input()
        arr = [c for c in s]
        arr.sort()
        ss = "".join(arr)
        if ss in table:
            table[ss] += 1
        else:
            table[ss] = 1

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

if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input()) 
inlist = [input() for i in range(N)] 
result = {}

def combination(a):
    x = 1
    x = a * (a-1) / 2
    return x


for component in inlist :
    dic = []
    for n in component:
        dic.append(n)
    dic.sort()
    dic2 = "".join(dic)
    if dic2 in result.keys():
        result[dic2] += 1
    else :
        result[dic2] = 1


counter = 0
for v in result.values():
    counter += combination(v)

print (int(counter))

Solution (Python):


n=int(raw_input())
s=[''.join(sorted(raw_input())) for i in xrange(n)]
h={}
res=0
for si in s:
 if si in h:
  res+=h[si]
  h[si]+=1
 else:
  h[si]=1
print res

Solution (Python):


def fact(n, m):
    ans = 1
    for i in range(n-m+1, n+1):
        ans *= i
    return ans

if __name__ == "__main__":
    N = int(input())
    s = []
    c = {}
    for i in range(N):
        a = "".join(sorted(input()))
        s.append(a)
        try:
            c[a] += 1
        except KeyError:
            c[a] = 1
    
    ans = 0
    for k,v in c.items():
        ans += fact(v,2)/2
    
    print(int(ans))

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

string=list()
for i in range(N):
  c=list(input())
  c.sort()
 
  string.append(''.join(c))
  


a=collections.Counter(string)
b=list(a.values())

count=0
for j in range(len(b)):
  count=count +int(b[j]*(b[j]-1)/2)
  
print(count)

Solution (Python):
N = int(input())
l = [input() for i in range(N)]
mydict = {}
times = [1]*N
count = 0
value = 1

for i in range(N):
    l[i] = ''.join(sorted(l[i]))
    if l[i] in mydict.keys():
        count += times[mydict[l[i]]]
        times[mydict[l[i]]] += 1
    else:
        mydict[l[i]] = value
        value += 1
print(count)

Solution (Python):
from collections import Counter

n = int(input())
S = [input() for _ in range(n)]
ans = 0

ctr = Counter()

for s in S : 
    a = ''.join(sorted(list(s)))
    if ctr[a] != 0 : 
        ans += ctr[a]
    ctr[a] += 1
print(ans)

Solution (Python):
import collections

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

count = collections.Counter(s)
ans = 0

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

print(int(ans))

Solution (Python):
n,*sl, = map(lambda x:''.join(sorted(x)),open(0).read().split())
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):

n = int(input())
sl = []
for i in range(n):
  S = ''.join(sorted(input()))
  sl.append(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):
n = int( input() )
dd = {}
ans = 0
for i in range(n):
    s = ''.join( sorted( input() ))
    if s in dd:
        ans += dd[s]
        dd[s] += 1
    else:
        dd[s] = 1

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
L = [''.join(sorted(input())) for i in range(n)]
c = Counter(L)
cnt = 0
for ele in c.values():
    cnt += ele*(ele-1)/2
print(int(cnt))

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

Ssort=[sorted(s) for s in S]
sort2=sorted(Ssort)

total=0
counter=0
ref=sort2[0]
for i in range(1,N):
    if(sort2[i]==ref):
        counter=counter+1
        if(i==N-1):
            total=total+sum(list(range(counter+1)))
    else:
        total=total+sum(list(range(counter+1)))
        counter=0
        ref=sort2[i]

print(total)

Solution (Python):
n=int(input())
s=[]
r=[]
c=0
for i in range(n):
    a=input()
    b=[]
    for k in a:
      b.append(k)
    b.sort()
    s.append(b)
s.sort()
for i in range(n-1):
    if s[i]==s[i+1]:
        c+=1
        r.append(c)
    else:
        c=0
        r.append(c)
print(sum(r))

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

for i in L.values():
    if i>1:
        ans+=(i*(i-1))//2
    else:
        continue
print(ans)

Solution (Python):
import itertools

n = int(input())

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


def cmb(n, r):
    """
    組み合わせ数
    https://qiita.com/derodero24/items/91b6468e66923a87f39f
    :param n:
    :param r:
    :return:
    """
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


if __name__ == '__main__':
    count = 0
    for k, g in itertools.groupby(sorted(in_str)):
        n = sum(1 for _ in g)
        if n == 1:
            continue
        count += cmb(n, 2)
    print(count)

Solution (Python):
n = int(input())
di = {}
ans = 0

for i in range(n):
    s = sorted(input())
    s = "".join(s)
    if s in di:
        ans += di[s]
        di[s] += 1
    else:
        di[s] = 1

print(ans)

Solution (Python):

n = int(input())
d = {}

for _ in range(n):
    s = "".join(sorted(list(input())))
    if s not in d:
        d[s] = 0
    d[s] += 1

res = 0
for k in d:
    n = d[k]
    res += n*(n-1)//2

print(res)

Solution (Python):
n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=1
decount=0
for i in range(n-1):
  if data[i]==data[i+1]:
    count=count+1
  else:
    decount=decount+(count-1)*count/2
    count=1
decount=decount+(count-1)*count/2
print(int(decount))

Solution (Python):
from math import factorial
def comb(n, r):
  return factorial(n) // factorial(r) // factorial(n - r)

N = int(input())
S = []
for i in range(N):
  S.append(''.join(sorted(input())))
S = sorted(S)
S.append('ZZZZZZZZZZ')
ans = 0
count = 1
for i in range(1,len(S)):
  if S[i] == S[i-1]:
    count += 1
  else:
    if count > 1:
      ans += comb(count, 2)
    count = 1
print(ans)

Solution (Python):
N = int(input())
str = {}  
ans = 0
for i in range(N):
	word = []
	tmp = input()
	for j in range(10):
		word.append(tmp[j])
	word.sort()  
	word_add = ""
	for j in range(10):
		word_add += word[j]
		
	
	
	
	if word_add in str:
		str[word_add] += 1
	else:
		str[word_add] = 1

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

print(ans)

Solution (Python):
n = int(input())
words = {}
sum_cnt = 0

while n > 0:
    word = sorted(input())
    word = "".join(word)
    if word in words:
        sum_cnt += words[word]
        words[word] += 1
    else:
        words[word] = 1
    n -= 1

print(int(sum_cnt))

Solution (Python):
n = int(input())
combiList = {}
sum_cnt = 0

for _ in range(n):
    act_string = sorted(input())
    act_string = "".join(act_string)
    cnt = combiList.get(act_string)
    if cnt is None:
        combiList[act_string] = 1
    else:
        combiList[act_string] += 1
        sum_cnt += cnt

print(int(sum_cnt))

Solution (Python):
n = int(input())
combiList = {}
sum_cnt = 0

for _ in range(n):
    act_string = list(input())
    act_string.sort()
    act_string = "".join(act_string)
    cnt = combiList.get(act_string)
    if cnt is None:
        combiList[act_string] = 1
    else:
        combiList[act_string] += 1
        sum_cnt += cnt

print(int(sum_cnt))

Solution (Python):
import sys 
from collections import Counter

def main():
  input = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += (t * (t-1)) // 2
  print(cnt)
 
if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
combiList = {}

for _ in range(n):
    act_string = list(input())
    act_string.sort()
    act_string = "".join(act_string)
    
    if combiList.get(act_string) is None:
        combiList[act_string] = 1
    else:
        combiList[act_string] += 1
sum_cnt = 0
for cnt in combiList.values():
    sum_cnt += cnt * (cnt - 1) / 2

print(int(sum_cnt))

Solution (Python):
N = int(input())
s = {}
for i in range(N):
	word = []
	tmp = input()
	for j in range(10):
		word.append(tmp[j])
	word.sort()
	word_add = ""
	for j in range(10):
		word_add += word[j]

	if word_add in s:
		s[word_add] += 1
	else:
		s[word_add] = 1

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

Solution (Python):
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  input = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += combinations_count(t, 2)
  print(cnt)
 
if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
S = sorted([''.join(sorted(input())) for _ in range(N)])
S.append('')
keep = ''
result = cnt = 0
for s in S:
    if keep == s:
        cnt += 1
    else:
        result += ((cnt - 1) * cnt) // 2
        cnt = 1
        keep = s
print(result)

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

N = int(input())
S = []
for _ in range(N):
    S.append(''.join(sorted(input())))
print(int(reduce(lambda x, y: x + y, map(lambda x: ((x - 1) * x) / 2, Counter(S).values()))))

Solution (Python):
N=int(input())
s=sorted([str(sorted(input())) for i in range(N)])+[""]
ans=c=0
j=""
for i in s:
    if i==j:
        c+=1
    else:
        j=i
        ans+=c*(c+1)//2
        c=0
print(ans)

Solution (Python):
N=int(input())
s=sorted([str(sorted(input())) for i in range(N)])+[""]
ans=c=0
j=s[0]
for i in s[1:]:
    if i==j:
        c+=1
    else:
        j=i
        ans+=c*(c+1)//2
        c=0
print(ans)

Solution (Python):
n = int(input())
lists = [input() for _ in range(n)]

for i in range(n):
    lists[i] = ''.join(sorted(lists[i]))

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

answer = 0
for i in d:
    answer += d[i] * (d[i]-1) // 2

print(answer)

Solution (Python):
N = int(input())
str_dict = dict()
total_comb_num = 0
for _ in range(N):
    tmp_string = input()
    sorted_tmp_string = ''.join(sorted(tmp_string)) 
    if sorted_tmp_string in str_dict:
        total_comb_num += str_dict[sorted_tmp_string]
        str_dict[sorted_tmp_string] += 1
    else:
        str_dict[sorted_tmp_string] = 1
        
print(total_comb_num)

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



dict_s = {}
for n in range(N):
  _ = ''.join(sorted(input()))
  if _ in dict_s:
    dict_s[_] += 1
  else:
    dict_s[_] = 1


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

cnt_anagram = 0
for v in dict_s.values():
  if v > 1:
  	cnt_anagram += cmb(v, 2)


print(cnt_anagram)

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


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

print(counter)

Solution (Python):
n=int(input())
d={}
totl=0

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

for t in d:
  totl+=d[t]*(d[t]-1)/2

print(int(totl))

Solution (Python):

N = int(input())
strings = []
for i in range(N):
    string = list(input())
    string.sort()
    strings.append(string)
strings.sort()
wordAnagramCou = 0
anagramCou = 0
for i in range(N-1):
    if strings[i+1] == strings[i]:
        wordAnagramCou += 1
    else:
        wordAnagramCou=0
    anagramCou += wordAnagramCou
print(anagramCou)

Solution (Python):
def main():
    n = int(input())
    cnt = dict()
    for i in range(n):
        t = input()
        s = "".join(sorted(t))
        try:
            cnt[s] += 1
        except:
            cnt[s] = 1
    ans = 0
    for v in cnt.values():
        ans += (v * (v - 1)) // 2
    print(ans)

main()

Solution (Python):
import math
n = int(input())
anagram = {}
while n > 0:
    wordbef = list(input())
    wordbef.sort()
    word = "".join(wordbef)
    if word in anagram:
        anagram[word] = anagram[word] + 1
    else:
        anagram[word] = 1
    n -= 1
total = 0
for x in anagram:
    total += (anagram[x] * (anagram[x] - 1))/2
print(int(total))

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)]
lst_s.sort()

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):
n = int(input())
d = {}
sum = 0

for i in range(n):
  s = list(input())
  s.sort()
  t = "".join(s)
  s.clear()
  if t in d:
    d[t] += 1
  else:
    d[t] = 1
    
for i in d:
  if d[i] > 1:
    sum += (d[i]*(d[i]-1))/2

print(int(sum))

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

print(ans)

Solution (Python):
n = int(input())
dic = {}

for i in range(n):
    si = list(input())
    si.sort()
    str_si = ""
    for j in range(10):
        str_si += si[j]
    if str_si not in dic:
        dic[str_si] = 1
    else:
        dic[str_si] += 1

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

print(tot)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
dic={}
count=0
for i in range(n):
  s[i] = sorted(s[i],key=str)
  s[i] = ''.join(s[i])
  if(s[i] in dic.keys()):
    count=count+dic[s[i]]
    dic[s[i]] = dic[s[i]] + 1
  else:
    dic[s[i]] = 1
print(count)

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

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):
    n = c[si]
    ans += n * (n - 1) // 2
print(ans)

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

ans = 0
w_dic = {}
for l in li:
  if not w_dic.get(l):
    w_dic[l] = 1
  else:
    ans += w_dic[l]
    w_dic[l] = w_dic[l] + 1

print(int(ans))

Solution (Python):
n,*sl, = map(lambda x:''.join(sorted(x)),open(0).read().split())
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):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = [list(input()) for _ in range(n)]
for i in s:
    i.sort()
s = [''.join(i) for i in s]
t = list(Counter(s).items())
ans = 0
for i,j in t:
    if j == 1:
        continue
    else:
        ans += (j)*(j-1)//2
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def comb(n,r):
    return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
n = I()
s = [input() for _ in range(n)]
x = [list(Counter(s[i]).items()) for i in range(n)]
for i in x:
    i.sort()

y = [tuple(i) for i in x]
f = defaultdict(lambda : 0)
for i in range(n):
    f[y[i]] += 1
ans = 0
for i in f.values():
    if i < 2:
        continue
    ans += comb(i,2)
print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = [list(input()) for _ in range(n)]
for i in s:
    i.sort()
s = [''.join(i) for i in s]
t = list(Counter(s).items())
ans = 0
for i,j in t:
    if j == 1:
        continue
    else:
        ans += (j)*(j-1)//2
print(ans)

Solution (Python):
n=int(input())
count={}
result={}
for i in range(n):
	sentence=''.join(sorted(input()))
	if sentence not in count:
		count[sentence]=1
		result[sentence]=0
	else:
		result[sentence]+=count[sentence]
		count[sentence]+=1


print(sum(result.values()))

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

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


c = collections.Counter(s)

cnt = 0
for i in set(s):
    n = c[i]
    
    cnt += n*(n-1)//2
print(cnt)

Solution (Python):
n = int(input())
check = {}
lst = []

for _ in range(n):
  s = list(input())
  s.sort()
  s = "".join(s)
  lst.append(s)
  try:
    check[s]+=1
  except:
    check.update({s:1})
  
cnt=0
check_set = set(lst)
for c in check_set:
  temp_cnt = check[c]
  cnt +=  temp_cnt*(temp_cnt-1)/2
print(int(cnt))

Solution (Python):
import collections

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

Solution (Python):
import collections
n = int(input())
s = collections.Counter(["".join(sorted(list(input()))) for _ in range(n)]).most_common()
t = 0
for i in s:
    for j in range(1, i[1]):
        t += j
print(t)

Solution (Python):
def solve(n, s_list):
    
    sorted_list = sorted(s_list)

    ans = 0
    key = 0
    
    while key < n - 1:
        group_cnt = 0
        target = sorted_list[key]
        while key < n - 1 and target == sorted_list[key + 1]:
            group_cnt += 1
            key += 1
        if group_cnt:
            ans += group_cnt * (group_cnt + 1) // 2
        key += 1

    return ans


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

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

    ans = solve(n, s_list)
    print(ans)


main()

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

for i in s:
    t=dic.get(i,0)
    ans+=t
    dic[i]=t+1

print(ans)

Solution (Python):
import collections

def solve(n, s):
    records = []
    D = {}
    for i in range(n):
        counter = collections.Counter(s[i])
        k = ",".join(["%s:%d" % (k,v) for k, v in sorted(counter.items())])
        if not k in D:
            D[k] = 0
        D[k] += 1
    res = 0
    for k, v in D.items():
        res += v * (v-1) // 2
    return res

n = int(input())
s = [input() for i in range(n)]
print(solve(n, s))

Solution (Python):
def main():
     AlfaToNum={'a':2,'b':3,'c':5,'d':7,'e':11,'f':13,'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
     n=int(input())
     s=[]
     ans=0
     for i in range(n):
          si=input()
          cnt=1
          for j in si:
               cnt*=AlfaToNum[j]
          s.append(cnt)
     
     s.sort()
     cnt=1
     for i in range(n-1):
          if s[i]==s[i+1]:
               cnt+=1
          else:
               ans+=cnt*(cnt-1)//2
               cnt=1
     ans+=cnt*(cnt-1)//2
     print(ans)
if __name__ == '__main__':
     main()

Solution (Python):
d={}
for _ in range(int(input())):
  s=input()
  s=list(s)
  s.sort()
  t=''.join(s)
  if t in d:
    d[t]+=1
  else:
    d[t]=1
c=0

for i in d:
  c+=(d[i]*(d[i]-1))//2
print(c)

Solution (Python):
n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
ans = 0
temp = 1
for i in range(n-1):
    if data[i] == data[i+1]:
        temp += 1
    else:
        if temp != 0:
            ans += temp*(temp-1)//2
            temp = 1
if temp >= 2:
    ans += temp*(temp-1)//2
print(ans)

Solution (Python):
n=int(input())
l=[None for i in range(n)]
for i in range(n):
  l[i]=sorted(input())
l.sort()
l+="l"
cnt=1
ans=0
for i in range(n):
  if l[i]!=l[i+1]:
    ans+=(cnt-1)*cnt//2
    cnt=1
    continue
  cnt+=1
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
s_sorted = []
for _ in range(n):
    s_sorted.append(''.join(sorted(input())))
s_count = Counter(s_sorted)
ans = 0
for i in s_count:
    ans += (s_count[i] * (s_count[i] - 1)) // 2
print(ans)

Solution (Python):
from collections import Counter 
n = int(input())
anagram =[]
ans = 0
for _ in range(n):
    s = ''.join(sorted(input()))
    anagram.append(s)
count_ana = Counter(anagram)
for v in count_ana.values():
    ans += v * (v - 1) // 2
print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
dd = defaultdict(int)
ans = 0
for _ in range(N):
    s = ''.join(sorted(list(input())))
    ans += dd[s]
    dd[s] += 1

print(ans)

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline())
    s = [stdin.readline().rstrip().split() for _ in range(N)]

    s_flat = [flatten for inner in s for flatten in inner]

    s_dict = {}
    sum = 0

    for S in s_flat:
        new_S = ''.join(sorted(S))
        if not s_dict.get(new_S):
            s_dict[new_S] = 1
        else:
            sum += s_dict[new_S]
            s_dict[new_S] = s_dict[new_S] + 1

    print(sum)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = []
for i in range(n):
  s.append(''.join(sorted(list(input().strip()))))
ans = 0
tmp = 0
ss = sorted(s)
prev = ''
for iss in ss:
  if prev != iss:
    prev = iss
    ans += int((tmp*(tmp+1))/2)
    tmp = 0
  elif prev == iss:
    
    tmp += 1
if tmp != 0:
  ans += int((tmp*(tmp+1))/2)
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
arr = []
for _ in range(n):
    arr.append("".join(sorted(input())))

ctr = Counter(arr)

res = 0
for x in ctr:
    res += ctr[x]*(ctr[x]-1)//2

print(res)

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

ctr = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in ctr:
        ans += ctr[a]
    ctr[a] += 1
print(ans)

Solution (Python):
from collections import Counter


c = int(input())
str_input = []
sort_str_input = []

for i in range(c):
    str_input.append(input())
    char_input = []
    for j in range(len(str_input[i])):
        char_input.append(str_input[i][j])
    char_input.sort()
    sort_str_input.append(''.join(map(str,char_input)))

test = Counter(sort_str_input)
test = test.most_common()
count=0
for i in range(len(test)):
    for j in range(test[i][1]-1):
        count = count +(test[i][1]-1-j)
print(count)

Solution (Python):
from math import factorial

n = int(input())
s_dict = {}
for i in range(n):
  s = "".join(sorted(list(input())))
  if s in s_dict:
    s_dict[s] += 1
  else:
  	s_dict[s] = 1
  
count = 0
for v in s_dict.values():
  if v > 1:
    count += factorial(v) // (factorial(2) * factorial(v - 2))

print(count)

Solution (Python):
import collections

N = int(input())
lst = [''.join(sorted(input())) for _ in range(N)]
ret = 0
for x in collections.Counter(lst).values():
    ret += (x * (x - 1) // 2)
print(ret)

Solution (Python):



from collections import Counter

N = int(input())

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

cnt = Counter(s)

full_cnt = 0
for c in cnt.values():
    if c >= 2:
        
        
        full_cnt += c * (c - 1) // 2


print(full_cnt)

Solution (Python):
from collections import Counter as c
N = int(input())
a = []
for _ in range(N):
  a.append(" ".join(sorted(input())))
a.sort()
l = c(a).items()
res = 0
for e in l:
  k = e[1]
  res += k * (k - 1) // 2
print(res)

Solution (Python):
N = int(input())
li = list("".join(sorted(input())) for _ in range(N))
dic = {}
ans = 0
for i in range(N):
  if li[i] in dic:
    ans += dic[li[i]]
    dic[li[i]] += 1
  else:
    dic[li[i]] = 1
print(ans)

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


s = list(map(list, s))

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())

import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += (math.factorial(a[i])//(math.factorial(a[i]-2)*2))
print(count)

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


s = list(map(list, s))

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())

import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += int(math.factorial(a[i])/(math.factorial(a[i]-2)*2))
print(count)