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

from collections import Counter


def main():
    N = int(input())
    A = Counter("".join(sorted(input())) for _ in range(N))
    ans = sum(i * (i - 1) // 2 for i in A.values())
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = sorted([sorted(input()) for _ in range(N)])
ans = [1]
for i in range(N - 1):
    if S[i] == S[i + 1]:
        ans[-1] += 1
    elif ans[-1] > 1:
        ans += [1]
ret = 0
for a in ans:
    ret += a * (a - 1) // 2
print(ret)

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

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

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

print(ans)

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

Solution (Python):
N = int(input())
l = [input() for _ in range(N)]
ans = 0
dic = {}
for n in range(N):
    new = sorted(l[n])
    if not str(new) in dic:
        count = 1
        dic[str(new)] = count
    else:
        ans += dic[str(new)]
        dic[str(new)] += 1
print(ans)

Solution (Python):
from collections import Counter
c = Counter(''.join(sorted(input())) for _ in range(int(input())))
print(sum(x * (x - 1) // 2 for x in c.values()))

Solution (Python):
c = {}
n = int(input())
r = 0
for _ in range(n):
    s = ''.join(sorted(input()))
    v = c.get(s, 0)
    r += v
    c[s] = v + 1
print(r)

Solution (Python):
import math

def calc_comb(n):
    k = 2
    if n <= 1 :
        return 0
    elif n ==2 :
        return 1
    return math.factorial(n)/(math.factorial(n-k) * math.factorial(k))

n = int(raw_input(""))

smap = {}
tmp = ""
for i in range(0, n):
    tmp = ''.join(sorted(raw_input("")))
    if smap.get(tmp, None) == None:
        smap[tmp] = 1
    else:
        smap[tmp] += 1
count = 0
for s, num in smap.items():
    
    count += calc_comb(num)
print count

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

d = dict()

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

ans=0

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

print(ans)

Solution (Python):
import math

def calc_comb(n):
    k = 2
    if n <= 1 :
        return 0
    elif n ==2 :
        return 1
    return math.factorial(n)/(math.factorial(n-k) * math.factorial(k))

n = int(raw_input(""))

smap = {}
tmp = ""
for i in range(0, n):
    tmp = ''.join(sorted(raw_input("")))
    if smap.get(tmp, None) == None:
        smap[tmp] = 1
    else:
        smap[tmp] += 1
count = 0
for s, num in smap.items():
    
    count += calc_comb(num)
print count

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



t = {}
for i in range(num):
  if stl[i] in t:
    t[stl[i]] += 1
  else:
    t[stl[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Solution (Python):
def sort_str(str):
  return ''.join(sorted(list(str)))

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

ans = 0
pool = {}
for i in range(n):
  if not s[i] in pool.keys():
    pool[s[i]] = 0
  else:
    pool[s[i]] += 1
    ans += pool[s[i]]
print(ans)

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

Solution (Python):
n=int(input())
l=[['0']*10 for _ in range(n)]
for i in range(n):
        a=str(input())
        for j in range(10):
                l[i][j]=a[j]
        l[i].sort()
l.sort()

c=0
d=[]
for j in range(n-1):
        if l[j]==l[j+1] and j==n-2:
                c+=2
                d.append(c)
        elif l[j]==l[j+1]:
                c+=1
        else:
                c+=1
                d.append(c)
                c=0
aa=0
for k in range(len(d)):
        aa+=d[k]*(d[k]-1)//2
print(aa)

Solution (Python):



from collections import Counter

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    ds = Counter()
    for _ in range(n):
        s = input()
        s = "".join(sorted(s))
        ds[s] += 1
    ans = 0
    for c in ds.values():
        ans += (c-1)*c//2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
l=[['0']*10 for _ in range(n)]
for i in range(n):
        a=str(input())
        for j in range(10):
                l[i][j]=a[j]
        l[i].sort()
l.sort()

c=0
d=[]
for j in range(n-1):
        if l[j]==l[j+1] and j==n-2:
                c+=2
                d.append(c)
        elif l[j]==l[j+1]:
                c+=1
        else:
                c+=1
                d.append(c)
                c=0
aa=0
for k in range(len(d)):
        aa+=d[k]*(d[k]-1)//2
print(aa)

Solution (Python):
N=int(input())
dic={}
cnt=0
for i in range(N):
    temp=' '.join(sorted(input()))
    if temp in dic:
        dic[temp]+=1
    else:
        dic[temp]=1
for k,v in dic.items():
    cnt+=v*(v-1)//2
print(cnt)

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

lst = []

for i in range(N):
    lst.append("".join(sorted(list(input()))))


d={}
count = 0

for i in lst:
  if not i in d:
    d[i] = 1
    continue
  else:
    d[i] = d[i] + 1
    count = count + d[i]-1


print(count)

Solution (Python):

N = int(input())
l = {}
ans = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    if tmp in l.keys():
        l[tmp] += 1
        ans += l[tmp]
    else: 
        l[tmp] = 0
print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Solution (Python):
n = int(input())
s = []
for i in range(n):
  tmp = input()
  s.append(tmp)
  
for i in range(n):
  l = [c for c in s[i]]
  l.sort()
  s[i] = ''.join(l)
  
import collections
d = dict(collections.Counter(s))


def henkan(n):
  return n * (n-1) // 2

ans = 0
for key in d.keys():
  value = d[key]
  if value != 1:
    ans += henkan(value)
    
print(ans)

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

memo = {}
for x in s:
    if x not in memo:
        memo[x] = 1
    else:
        memo[x] += 1

print(sum(x*(x-1)//2 for x in memo.values()))

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

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

m = {}
ans = 0

for s in l:
    if s in m:
        m[s] += 1
        ans += m[s]
    else:
        m[s] = 0

print(ans)

Solution (Python):
import collections
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())

lst = ["".join(sorted(list(input()))) for i in range(N)]
c = collections.Counter(lst)

ans = 0
for k,v in c.items():
  if (v > 1):
    ans += combinations_count(v, 2)

print(ans)

Solution (Python):
from collections import Counter

class hashabledict(dict):
    def __hash__(self):
        return hash(tuple(sorted(self.items())))

N = int(input())
words = [hashabledict(dict(Counter(input()))) for _ in range(N)]
ans = 0
counter_hash = {}
for counter in words:
    if counter not in counter_hash.keys():
        counter_hash[counter] = 1
    else:
        counter_hash[counter] += 1
 
for count in counter_hash.values():
    ans += int((count * (count-1)) / 2)
print(ans)

Solution (Python):
n = int(input())
dic = {}
ans = 0
for i in range(n):
	tmp = list(input())
	sorted_str = "".join(sorted(tmp))
	if not(sorted_str in dic):
		dic[sorted_str] = 0
	else:
		dic[sorted_str] += 1
		ans += dic[sorted_str]

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
    
v = list(Counter(s).values())
ans = []
for i in range(len(v)):
    if v[i] >= 2:
        ans.append((v[i] * (v[i]-1))/2)

print(int(sum(ans)))

Solution (Python):
N = int(input())
s_list = [input() for _ in range(int(N))]
import math
ok = {}
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        ok[s] += 1 
    else:
        ok[s] = 1

for val in ok:
    prev = (ok[val] - 1)
    if prev != 0:
        count += math.floor(ok[val] * prev / 2)
print(count)

Solution (Python):
import collections
import math


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


n = int(input())
s = []
for i in range(n):
    a = sorted(input())
    s.append(a)

ss = []

for i in range(n):
    ss.append(''.join(s[i]))

c = collections.Counter(ss)
d = sorted(list(c.values()), reverse=True)

sum = 0

for i in d:
    if i == 1:
        print(sum)
        exit()
    else:
        a = combinations_count(i, 2)
        sum += a

print(sum)

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

Solution (Python):
d={}
c=0
for i in open(0):i=tuple(sorted(i));t=d.get(i,0);c+=t;d[i]=t+1
print(c)

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

s=[]
ans=0
count=1

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

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

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

print(int(ans))

Solution (Python):
from collections import Counter

num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def sort(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: sort(v), strs))
strs_length = len(new_strs)

sum = 0
counter = Counter()
for tmp_str in new_strs:
    sum += counter[tmp_str]
    counter[tmp_str] += 1

print(sum)

Solution (Python):
from collections import Counter

num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))

_sum = 0
counter = Counter()
for tmp_str in new_strs:
    _sum += counter[tmp_str]
    counter[tmp_str] += 1

print(_sum)

Solution (Python):
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

Solution (Python):
N = int(input())
dicts = {}
for i in range(N):
    s = "".join(sorted(input()))
    dicts[s] = dicts[s] + 1 if s in dicts.keys() else 1

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

Solution (Python):
while True:
    try:
        N = int(input())
        result = dict()
        for i in range(N):
            S = input()
            ss = ''.join(sorted(S))
            if ss not in result:
                result[ss] = 0
            result[ss] += 1
        print(sum(map(int, map(lambda x: x*(x-1)/2, result.values()))))
    except EOFError:
        break

Solution (Python):
from collections import Counter

n = int(input())
lst = ["".join(sorted(list(input()))) for i in range(n)]





def cmb(n, r):
    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


cnt = 0
for i in Counter(lst).values():
  if i == 1:
    continue
  cnt += cmb(i, 2)
"""
for i in range(len(lst)-1):
  for j in range(i+1,len(lst)):
    
    if lst[i]==lst[j]:
      cnt += 1
"""
print(cnt)

Solution (Python):
n=int(input())
arr=[input() for _ in range(n)]
dic={}
alphabet='abcdefghijklmnopqrstuvwxyz'
for s in arr:
  count=[0]*26
  for i in range(10):
    for j in range(26):
      if s[i]==alphabet[j]:
        count[j]+=1
        break
  count=tuple(count)
  if count not in dic:
    dic[count]=1
  else:
    dic[count]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

Solution (Python):
import collections

n=int(input())
arr=[input() for _ in range(n)]
dic={}
for s in arr:
  count=[0]*26
  tmp=collections.Counter(s)
  for char in tmp.keys():
    count[ord(char)-ord('a')]+=tmp[char]
  count=tuple(count)
  if count not in dic:
    dic[count]=1
  else:
    dic[count]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

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

Solution (Python):
import sys
from collections import defaultdict
def cmb(n, r):
    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


input = sys.stdin.readline

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += cmb(d[key], 2)
print(int(ans))

Solution (Python):
import sys

n=int(input())
l=["".join(sorted(sys.stdin.readline().strip())) for i in range(n)]


res={}
ans=0
 
for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    if aa in res:
        ans+=res[aa]
        res[aa]+=1
    else:
        res[aa]=1

print(int(ans))

Solution (Python):
N = int(input())
S = {}

for i in range(N):
    str = ''.join(sorted(input()))
    if str in S.keys():
        S[str] += 1
    else:
        S.setdefault(str, 1)

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

print(cnt)

Solution (Python):


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

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)

Solution (Python):
import sys
n = int(sys.stdin.readline().strip())
list = [''.join(sorted(sys.stdin.readline().strip())) for i in range(n)]
d = {}
ans = 0
for x in list:
  if x in d:
    ans += d[x]
    d[x] += 1
  else:
    d[x] = 1
print(ans)

Solution (Python):
N = int(input())
alldict = {}
nsame = 0
for i in range(N):
  tmp = list(input())
  tmp.sort()
  if ''.join(tmp) in alldict:
    alldict[''.join(tmp)] = alldict[''.join(tmp)] + 1
  else:
    alldict[''.join(tmp)] = 1

from operator import mul
from functools import reduce
def cmb(n,r):
    if n == 1:
        return 0
    r = min(n-r,r)
    if r == 0:
        return 1
    ov = reduce(mul, range(n, n-r, -1))
    un = reduce(mul, range(1, r+1))
    return ov // un

print(sum([cmb(i, 2) for i in alldict.values()]))

Solution (Python):
def main():
    n = int(input())
    words = {}
    for i in range(n):
        s = list(input())
        s.sort()
        s = tuple(s)
        if s not in words.keys():
            words[s] = 1
        else:
            words[s] += 1

    ans = 0
    for i in words.keys():
        x = words[i]
        ans += x*(x-1)//2

    print(ans)


main()

Solution (Python):
n = int(input())
sdict = {}
for i in range(n):
    w = input()
    _w = ''.join(sorted(w))
    if _w not in sdict.keys():
        sdict[_w] = 1
    else:
        sdict[_w] += 1

def nc2(n):
    return int(n * (n-1) / 2)

n_dup = sum([nc2(val) for val in sdict.values() if val > 1])
print(int(n_dup))

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
mydict = {}
ans = 0
for i in range(N):
    T = [str(x) for x in S[i]]
    T.sort()
    S[i] = ''.join(T)
for j in range(N):
    if S[j] in mydict.keys():
        ans += mydict[S[j]]
        mydict[S[j]] += 1
    else:
        mydict.setdefault(S[j],1)
print(ans)

Solution (Python):
def init_load(ipt):
    return "".join(sorted([x for x in ipt]))
 

n = int(input())
s = [init_load(input()) for _ in range(n)]
 
 
dictS = {}
for new_st in s:
    if new_st in dictS:
        dictS[new_st] += 1
    else:
        dictS[new_st] = 1
 
ans = sum([int(x * (x - 1) / 2) for x in dictS.values()])
print(ans)

Solution (Python):

N = int(input())
dic = {}
count = 0
for i in range(N):
  temp = "".join(sorted(input()))
  if temp in dic:
    count += dic[temp]
    dic[temp] += 1
  else:
    dic[temp] = 1

print(count)

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

cnt = 0
dic = {}
for i in s:
    dic.setdefault(i, 0)
    cnt += dic[i]
    dic[i] += 1

print(cnt)

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

S=[]
ans = 0
count=1

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

S.sort()

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count+=1
    else:
        ans+=count*(count-1)/2
        count=1

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

print(int(ans))

Solution (Python):


import re
from collections import deque
from functools import reduce
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep
from queue import PriorityQueue
from sys import stdin


def rline() -> str:
    return stdin.readline().strip()


def rlines(hint: int = 1):
    ret = ['' for i in range(hint)]
    for i in range(hint):
        ret[i] = rline()
    return ret


def htokens(hint: int = 1):
    lns = rlines(hint)
    ret = list(map(lambda ln: ln.split(), lns))
    
    if hint == 1:
        
        ret.append([])
    return ret


def vtokens(hint: int = 1):
    m, _ = htokens()
    wint = len(m)
    ret = [[None] * hint for i in range(wint)]
    for y in range(hint):
        if y != 0:
            m, _ = htokens()
        
        x = 0
        for v in m:
            ret[x][y] = v
            x += 1
    
    if wint == 1:
        
        ret.append([])
    return ret


def rint(radix: int = 10) -> int:
    return int(rline(), radix)


def hints(hint: int = 1, radix: int = 10):
    ret = htokens(hint)
    for i in range(len(ret)):
        ret[i] = list(map(lambda v: int(v, radix), ret[i]))
    return ret


def vints(hint: int = 1, radix: int = 10):
    ret = vtokens(hint)
    for i in range(len(ret)):
        ret[i] = list(map(lambda v: int(v, radix), ret[i]))
    return ret


def mat(hint: int, wint: int):
    return [[None]*wint for i in range(hint)]


def filllist(lst, value: int) -> None:
    
    for i in range(len(lst)):
        lst[i] = value


def isprime(n: int) -> bool:
    if n <= 1:
        return False
    if n in (2, 3, 5):
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    lst = int(n**0.5)
    f = 5
    while f <= lst:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True


def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:
    return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))


def strbool(boolval: int) -> str:
    return ['No', 'Yes'][boolval]


def solve() -> None:
    
    n = rint()
    ss = rlines(n)

    
    dict = {}
    for s in ss:
        k = ''.join(sorted(list(s)))
        if not k in dict.keys():
            dict[k] = 0
        dict[k] += 1

    
    ans = sum(map(lambda x: 0 if x == 1 else x*(x-1)//2, dict.values()))

    
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())
d = dict()
for i in range(N):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

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

print(ans)

Solution (Python):
def init_load(ipt):
    return "".join(sorted([x for x in ipt]))


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


dictS = {}
for new_st in s:
    if new_st in dictS:
        dictS[new_st] += 1
    else:
        dictS[new_st] = 1

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

Solution (Python):
N = int(input())
s = list(list(input()) for i in range(N))
for i in range(N):
    s[i].sort()
s.sort()
ans = 0
same = 1
for i in range(1,N):
    if s[i] == s[i-1]:
        ans += same
        same += 1
    else:
        same = 1
print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(S).most_common()

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

print(ans)

Solution (Python):
import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

def get_runlength(s): 
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

n = int(input())
dic = {}
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    try:
        dic[sin] += 1
    except:
        dic[sin] = 1

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

Solution (Python):
n=int(input())
a = [input() for i in range(n)]
new_a = [0]*len(a)
cnt = 1
ans = 0
for i in range(len(a)):
    new_a[i] = sorted(a[i]) 
b = sorted(new_a)
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt - 1)/2 
        cnt = 1
ans += cnt*(cnt - 1)/2
print(int(ans))

Solution (Python):
def init_load(ipt):
    return "".join(sorted([x for x in ipt]))


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


dictS = {}
for new_st in s:
    if new_st in dictS:
        dictS[new_st] += 1
    else:
        dictS[new_st] = 1

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

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

for i in range(n):
  word = ''.join(sorted(input()))
  sorted_word.setdefault(word, 0)
  sorted_word[word] += 1

def pair_num(n):
  return (n * (n - 1)) // 2

print(sum(map(pair_num, sorted_word.values())))

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

    word_dict = dict()
    count = 0

    for i in range(N):
        word = ''.join(sorted(input()))
        if word not in word_dict.keys():
            word_dict[word] = 1
        else:
            count += word_dict[word]
            word_dict[word] += 1

    print(count)

if __name__ == '__main__':
    C()

Solution (Python):
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = n * (n-1) /2
    return int(a) 
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)

Solution (Python):
import sys

n = int(input())

d = {}
cnt = 0

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

Solution (Python):
a=int(input())
b=[sorted(input()) for j in range(a)]
c=[[0for i in range(26)] for j in range(a)]
for i in range(a):
  for j in range(10):
    c[i][ord(b[i][j])-97]+=1
sum=0
d=1
c.sort()
for i in range(a-1):
  if c[i]==c[i+1]:
    d+=1
  else:
    sum+=d*(d-1)//2
    d=1
  if i==a-2:
    sum+=d*(d-1)//2
    
print(sum)

Solution (Python):
from collections import Counter

n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]
"""
c = 0
c1 =  0
p = sorted(q)

for i in range(n):
	if p[i] == p[i+1]:
		c+=1
	else:
		
		if c>0:
			for j in range(c+1):
				c1+=j
				
		c=0
"""
count_by_kw = Counter()

for i in range(n):
	count_by_kw[q[i]] += 1
ans = 0
for kw, count in count_by_kw.most_common():

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

print(int(ans))

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

dictS = {}
for new_st in s:
    new_st = "".join(sorted([x for x in new_st]))
    if new_st in dictS:
        dictS[new_st] += 1
    else:
        dictS[new_st] = 1

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

Solution (Python):
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())
a = [''.join(sorted(input())) for _ in range(n)]
a.sort()
cnt = 0


cntsub = 1
for i in range(len(a) - 1):
    if a[i] == a[i + 1]:
        cntsub += 1
    elif cntsub > 1:
        
        cnt += int(cmb(cntsub, 2))
        cntsub = 1

if cntsub > 1:
    
    cnt += int(cmb(cntsub, 2))
print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def cmb(n,r):  
    retVal = 1
    for i in range(n-r+1,n+1):
        retVal *= i
    for i in range(2,r+1):
        retVal //= i
    return retVal
def main():
    from collections import defaultdict
    N = int(input())
    d = defaultdict(lambda:0)
    base = ord('a')
    ans = 0
    for _ in range(N):
        s = input().strip() 
        s = ''.join(sorted(s))
        ans += d[s]
        d[s] += 1

    
    print(ans)

        

    





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

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

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

S=[]
ans_dic={}
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    temp = ''.join(temp)
    
    
    if temp in ans_dic:
        ans_dic[temp] += 1
    else:
        ans_dic[temp] = 1
    
for key,value in ans_dic.items():
    ans += value*(value-1)/2

print(round(ans))

Solution (Python):

"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

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

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

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

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

def cmb(num):
    if num == 1:
        return 0
    elif num == 2:
        return 1
    else:
        return (num * (num-1) // 2)
  
count = 0
for k in m.keys():
        count += cmb( m[k] )


print(count)

Solution (Python):
import collections

n = int(input())


sort_list = list()
for i in range(n):
  i_sort = "".join(sorted(input()))
  
  sort_list.append(i_sort)
  
  
  
counts = 0
cc = collections.Counter(sort_list)
v, c = zip(*cc.most_common())

for c_ in c:
  counts += (c_ * (c_ - 1)) / 2
print(int(counts))
"""
values, counts = zip(*cc.most_common())
if counts != 1:
  print(counts)
 """

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

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

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
s = Counter(["".join(sorted(input())) for _ in [0]*n]).values()

cnt = 0

for i in s:
    cnt += i*(i-1)//2

print(cnt)

Solution (Python):
n = int(input())
i = 0
sortedSet = {}
while i < n:
    temp = ''.join(sorted(input()))

    if temp in sortedSet:
        sortedSet[temp]+=1
    else:
        sortedSet[temp]=1
    i += 1

result = 0
for v in sortedSet.values():
    result = int(result + v*(v-1)/2)

print(result)