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 __future__ import division, print_function

import os
import sys
from collections import Counter
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    c = Counter()
    for _ in range(n):
        s = input()
        a = [0] * 26

        for h in s:
            a[ord(h) - 97] += 1

        c[tuple(a)] += 1

    print(sum(((i - 1) * i) // 2 for i in c.values()))



BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
import math
import sys

sys.setrecursionlimit(10000000)

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

def main():
    N = int(input())
    S = []
    for i in range(N):
        s = input()
        s = sorted(s)
        S.append(s)
        
    S = sorted(S)
    ans = 0
    num = 0
    for i in range(N):
        if i < N - 1 and S[i] == S[i + 1]:
            num += 1
        else:
            if num == 0:
                continue
            else:
                ans += combinations_count(num + 1, 2)
            num = 0
    print(ans)
                

if __name__ == '__main__':
    main()

Solution (Python):
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def combi(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

N = I()
data = []

for _ in range(N):
  s = [i for i in S()]
  s.sort()
  data.append("".join(map(str,s)))

data.sort()


tmp = ""
cnt = 0
num = 1
for i in range(N):
  
  if tmp == data[i]:
    num += 1
    continue
  else:
    if num != 1:
      cnt += combi(num,2)
    tmp = data[i]
    num = 1
  
else:
  if num != 1:
    cnt += combi(num,2)
  tmp = data[i]
  num = 1

print(cnt)

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

dic = {}

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

result = 0
for key in dic:
    result += (dic[key])*(dic[key]-1)/2

print(int(result))

Solution (Python):

def main():
    n = int(input())
    ls = ["".join((sorted(list(input())))) for _ in range(n)]
    ls = sorted(ls)


    i =0
    cnt = 1
    ans = 0
    while 1:
        if ls[i]==ls[i+1]:
            ans += cnt
            cnt +=1
            i +=1
        else:
            cnt = 1
            i += 1
        if i == n-1:
            break
    print(ans)



       
if __name__ == '__main__':
    main()

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

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

print(max(sum([i * (i - 1) // 2 for i in d.values()]), 0))

Solution (Python):
import collections

n = int(input())
s = []
for i in range(n):
    x = input()
    y = collections.Counter(x)
    x = tuple(sorted(list(y.items())))
    s.append(x)
s_count = collections.Counter(s)
s_num = list(s_count.values())
ans = 0
for i in s_num:
    z = 0
    if i >= 2:
        z = int(i*(i-1)/2)
    ans += z
print(ans)

Solution (Python):
N = int(input())
lst = {}
for i in range(N):
    base = 0
    s = input()
    for j in range(10):
        base += 10**(ord(s[j])-ord('A'))
    if base not in lst:
        lst[base] = 0
    lst[base] += 1
ans = 0
for v in lst.values():
    ans += v*(v-1)/2
print(int(ans))

Solution (Python):

from collections import defaultdict


n = int(input())
words = defaultdict(int)
for _ in range(n):
    sorted_word = sorted(input())
    words[''.join(sorted_word)] += 1

cases = 0
for key, val in words.items():
    if val == 1:
        continue
    cases += (val * (val - 1) // 2)

print(cases)

Solution (Python):
import sys

input = sys.stdin.readline
N = int(input())
Ss = {}
for i in range(N):
    s = ''.join(sorted(list(input().rstrip("\n"))))
    if s in Ss:
        Ss[s] += 1
    else:
        Ss[s] = 1

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

print(c)

Solution (Python):
N = int(input())
S = [(input()) for i in range(N)]
A = {}
B = {}
for i in range(N):
    tmp = sorted(S[i])
    mojiretu = ' '
    
    for x in tmp:
        mojiretu += x
    if mojiretu in A:
        A[mojiretu] += B[mojiretu]
        B[mojiretu] += 1
    else:
        B[mojiretu] = 1
        A[mojiretu] = 0
answer = 0
for i in A:
    answer += A[i]
print(answer)

Solution (Python):
from itertools import groupby
N = int(input())
S = [sorted(input()) for _ in range(N)]
S.sort()
ans = 0
for _, g in groupby(S):
    l = len(list(g))
    ans += l * (l-1) // 2
print(ans)

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')
    for _ in range(N):
        s = input().strip()
        num = 0
        for c in s:
            num += 26 ** (ord(c) - base)
        d[num] += 1
    ans = 0
    
    for n in d.values():
        if n >= 2:
            ans += cmb(n,2)
    print(ans)

        

    





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

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

Solution (Python):
from collections import Counter
N = int(input())
S = set()
cnt = 0

def createStr(counter):
    ret = ""
    keys = list(counter.keys())
    keys.sort()
    for key in keys:
        ret += key
        ret += str(counter[key])
    return ret

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

for i in ret.values():
    cnt += i*(i-1)//2

print(cnt)

Solution (Python):
n = int(input())
s = ['']*n
for i in range(n):
    st = list(input())
    st.sort()
    s[i] = st
s.sort()


ans = 0
cnt = 0
for i in range(1,n):
    if s[i-1] == s[i]:
        cnt += 1
    else:
        ans += cnt*(cnt+1)//2
        cnt = 0
ans += cnt*(cnt+1)//2
print(ans)

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

for n in range(N):
    tmp = list(input())
    tmp.sort()
    s = "".join(tmp)
    S.append(s)

S.sort()

ans = 0
count = 0

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

print(ans)

Solution (Python):
N=int(input())
t={}
for i in range(N):
    s = input()
    s = list(s)
    s.sort()
    s = ''.join(s)
    if t.get(s, None) == None:
        t[s] = 1
    else:
        t[s] += 1

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

Solution (Python):
n=int(input())
s=[list(input()) for _ in range(n)]
for i in range(n):
    s[i].sort()
s.sort()
c=0
x=1
for i in range(1,n):
    if s[i]==s[i-1]:
        x+=1
    else:
        c+=(x*(x-1)//2)
        x=1
c+=(x*(x-1)//2)
print(c)

Solution (Python):
from collections import defaultdict
N = int(input())
dic1 = defaultdict(int)
x = ord("a")
for i in range(N):
    s = input()
    ls = [0]*26
    for j in range(10):
        ind = ord(s[j])-x
        ls[ind] += 1
    ls = tuple(ls)
    dic1[ls] += 1
ans = 0
for k in dic1.keys():
    x = dic1[k]
    ans += x*(x-1)//2
print(ans)

Solution (Python):

box=[list(input()) for i in range(int(input()))]
count=0
ans_box={}
for i in range(len(box)):
    line=sorted(box[i])
    line="".join(line)
    if line in ans_box:
        ans_box[line] +=1
    elif line not in ans_box:
        ans_box[line]=0

for v,m in ans_box.items():
    if m>=1:
        for i in range(m+1):
            count +=i

print(count)

Solution (Python):
from collections import defaultdict

n = int(input())
cnt = defaultdict(int)
for _ in range(n):
    s = list(input())
    s.sort()
    s = tuple(s)
    cnt[s] += 1
print(sum(v * (v - 1) // 2 for v in cnt.values() if v > 1))

Solution (Python):
import collections

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

for i in range(n):
    s = input()
    s = sorted(s)
    po = ""
    for i in range(len(s)):
        po += s[i]
    ss.append(po)
    
ss = sorted(ss)


ans = 0
c = collections.Counter(ss)

go = c.most_common()
for i in range(len(go)):
    k = go[i][1]
    ans += int((k-1)*k/2)
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
strings=[]
for _ in range(n):
    s=input()
    s=sorted(s)
    s="".join(s)
    strings.append(s)
c=Counter(strings)
ans=0
for i,v in c.items():
    ans+=int(v*(v-1)*0.5)
print(ans)

Solution (Python):
n = int(input())
s = []
for i in range(n):
    s1 = sorted(input())
    s2 = ''
    for j in s1:
        s2 += j
    s.append(s2)

s.sort()

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

print(ans)

Solution (Python):
N = int(input())
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
alphanum = dict()
for i in range(26): alphanum[alphabet[i]] = i

fact = [0] * (N + 1)
for i in range(1, N + 1): fact[i] = fact[i-1] + i

wordtype = dict()
for _ in range(N):
    s = input()
    s_num = [0] * 26
    for i in range(len(s)):
        s_num[alphanum[s[i]]] += 1
    s_str = ""
    for i in range(26):
        s_str += alphabet[i] + str(s_num[i])
    
    if s_str in wordtype: wordtype[s_str] += 1
    else: wordtype[s_str] = 1

ans = 0
for key in wordtype:
    ans += fact[wordtype[key] - 1]

print(ans)

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

S = {}
for _ in range(N):
    s = list(input())
    s.sort()
    s = tuple(s)
    if s in S:
        S[s] += 1
    else:
        S[s] = 1

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

print(ans)

Solution (Python):
from collections import defaultdict
import math
import sys

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

input = sys.stdin.readline

N = int(input().strip())
dic = defaultdict(int)
for _ in range(N):
    string = "".join(sorted(list(input().strip())))
    dic[string] += 1

count = 0
for key in dic.keys():
    n = dic[key]
    if dic[key] >= 2:
        count += comb(dic[key], 2)
print(count)

Solution (Python):
n=int(input())
d = {}
for i in range(n):
    a = str(input())
    a = sorted(a)
    a = tuple(a)
    
    if a in d:
        d[a] +=1
    else:
        d[a] = 1

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

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

def main():
	n = int(input().strip())
	st = defaultdict(int)
	for i in range(n):
		s = input().strip()
		d = []
		for c in s:
			d.append(ord(c))
		d.sort()
		st[tuple(d)] += 1
	ans = 0
	for v in st.values():
		if v == 1:
			continue
		ans += v*(v-1) // 2
	print(ans)

if __name__ == '__main__':
	main()

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


from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for i in range(N):
    S[i] = sorted(S[i])
    d["".join(S[i])] += 1
ans = 0
for i in d.values():
    if i >= 2:
        ans += cmb(i, 2)

print(ans)

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


prv = ''
ans = 0
cnt = 0
for i in range(n):
    if s[i] == prv:
        cnt += 1
    else: 
        ans += cnt * (cnt - 1) // 2
        cnt = 1
    prv = s[i]
    

ans += cnt * (cnt - 1) // 2
print(ans)

Solution (Python):

n = int(input())
from collections import  defaultdict
d = defaultdict(int)
for i in range(n):
    d["".join(sorted((input())))] += 1
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ret = 0
for k in d.values():
    if k == 1:
        continue
    ret += combinations_count(k,2)
print(ret)

Solution (Python):
N = int(input())
S = sorted([''.join(sorted(input())) for _ in range(N)])
prev = ''
ans = 0
n = 0
for i in range(N):
    if S[i]!=prev:
        ans += n*(n-1)//2
        prev=S[i]
        n=1
    else:
        n+=1
ans += n*(n-1)//2
 
print(ans)

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

ans = []

for _ in range(N):
    s = list(input())
    s.sort()
    s = ''.join(s)
    ans.append(s)
ans.sort()

now = ans[0]
count = 1
ansans = 0
for a in ans[1:]:
    if a == now:
        count += 1
    else:
        now = a
        tmp = count * (count - 1) // 2
        count = 1
        ansans += tmp

tmp = count * (count - 1) // 2
count = 1
ansans += tmp

print(ansans)

Solution (Python):
from collections import defaultdict
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 = defaultdict(int)

N = int(input())

buff = []
for i in range(N):
    _b = list(input())
    _b.sort()
    cnt[''.join(_b)] += 1

ans = 0
for el in cnt:
    if cnt[el] > 1:
        ans += cmb(cnt[el], 2)
print(ans)

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

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

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

print(ans)

Solution (Python):

import sys
from collections import Counter

def main():
    N = int(sys.stdin.readline().strip())
    ans = 0
    present = {}
    for i in range(N):
        temp = "".join(sorted(sys.stdin.readline().strip()))
        if temp not in present:
            present[temp] = 1
            
        else:
            ans += present[temp]
            present[temp] +=1
        
        
    print("%d" % ans)

def solve():
    pass


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
mojiretues = []
for _ in range(n):
	s = list(input())
	s.sort()
	mojiretues.append("".join(s))
mojiretues.sort()

prestr = mojiretues[0]
cnt = 1
ans = 0
for s in mojiretues[1:]:
	if prestr == s:
		ans += cnt
		cnt += 1
	else:
		prestr = s
		cnt = 1

print(ans)

Solution (Python):
N = int(input())
text_ls = []
for _ in range(N):
    text_ls.append(sorted(input()))

text_ls.sort()

num = 0
tmp_add = 0
for i in range(N-1):
    if text_ls[i] == text_ls[i+1]:
        num+=(1+tmp_add)
        tmp_add +=1
    else:
        tmp_add =0

print(num)

Solution (Python):
from collections import Counter

n = int(input())
c = Counter()

for i in range(n):
  c[''.join(sorted(input()))] += 1

l = c.most_common()
cnt = 0

for e in l:
  cnt += int((e[1] * (e[1] - 1))/2)

print(cnt)

Solution (Python):
from collections import defaultdict
b = defaultdict(int)
n = int(raw_input())
a = []
for i in xrange(n):
    x = list(raw_input())
    x.sort()
    a.append(''.join(x))
i = 0
ans = 0
for i in a:
    b[i] += 1
for i in b.values():
    ans += i*(i-1)/2
print ans

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

for i in range(N):
    s = ''.join(sorted(list(input())))
    d[s]+=1

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

Solution (Python):
def main():
    n = int(input())
    count = [[0]*26 for _ in range(n)]
    for i in range(n):
        s = input()
        for c in s:
            count[i][ord(c)-97] += 1
    d = dict()
    for lv in count:
        t = tuple(lv)
        if t not in d:
            d[t] = 1
        else:
             d[t] += 1
    
    output = 0
    for t in d:
        output += d[t] * (d[t]-1) // 2
    return output



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

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))



N = I()
s = []
for i in range(N):
  a = input()
  b = []
  for i in range(len(a)):
    b.append(ord(a[i]))
  b.sort()
  s.append(b)
s.sort()
ans = 0
temp = 1
for i in range(1,N):
  if s[i]==s[i-1]:
    temp += 1
  else:
    ans += temp*(temp-1)//2
    temp = 1
ans += temp*(temp-1)//2
print(ans)

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

dc = {}
ans = 0
for i in range(N):
    s = input()
    s = "".join(sorted(s))
    if dc.get(s):
        ans += dc.get(s)
        dc[s] += 1
    else:
        dc[s] = 1
print(ans)

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


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


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


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

d = {}
for s in S:
    tmp = list(s)
    tmp.sort()
    d[tuple(tmp)] = d.get(tuple(tmp), 0) + 1


for k, v in d.items():
    ans += cmb(v, 2)

print(ans)

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

res=0
for key in ans.keys():
    res += int((ans[key] * (ans[key]-1)) / 2)

print(res)

Solution (Python):
import collections
import math
n = int(input())
s_list = []
for _ in range(n):
    s = input()
    s = "".join(sorted(s))
    s_list.append(s)
ans = 0
s_dict = collections.Counter(s_list)
for i in s_dict.values():
    ans += i * (i - 1)
print(ans // 2)

Solution (Python):
N = int(input())
G = {}
for _ in range(N):
    s = "".join(sorted(list(input())))
    if s not in G:
        G[s] = 0
    G[s] += 1
cnt = 0
for s in G:
    if G[s]>1:
        cnt += (G[s]*(G[s]-1))//2
print(cnt)

Solution (Python):
from collections import Counter

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

S = ["".join(sorted(s)) for s in S]

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

Solution (Python):

acc = [0] * (10**5 + 1)
for i in range(10**5):
    acc[i + 1] = acc[i] + (i + 1)
n = int(input())
s = [input() for _ in range(n)]
dic = {}
for i in range(n):
    srt = ''.join(sorted(s[i]))
    dic[srt] = dic[srt] + 1 if srt in dic else 1
ans = 0
for v in dic.values():
    ans += acc[v - 1]
print(ans)

Solution (Python):
from collections import Counter


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

    slist2 = [''.join(sorted(s)) for s in slist]
    ans = 0
    counter = Counter(slist2)
    for _, v in counter.items():
        if v > 1:
            ans += v * (v - 1) // 2
    print(ans)


main()

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

for i in range(0, n):
	s = "".join(sorted(input()))
	
	if s in cs:
		cs[s] += 1
	else:
		cs[s] = 1
		
count = 0

for c in cs.values():
	count += c * (c - 1) // 2

print(count)

Solution (Python):


from collections import defaultdict



N = int(input())
S = []
for _i in range(N):
    S.append(input())

sortedS = ["".join(sorted(s)) for s in S]

cnt = defaultdict(int)
for s in sortedS:
    cnt[s] += 1

ans = 0
for s,c in cnt.items():
    if c >= 2:
        ans += c * (c-1) // 2
print(ans)

Solution (Python):
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N = int_raw()
    Ss = [input().strip("\n") for i in range(N)]
    hist_ana = {}
    for s in Ss:
        hist = [0]*27
        for c in s:
            hist[ord(c)-ord("a")]+=1
        hist = tuple(hist)
        if hist in hist_ana:
            hist_ana[hist]+=1
        else:
            hist_ana[hist]=1
    return sum([l*(l-1)//2 for k,l in hist_ana.items()])
    
print(main())

Solution (Python):
from collections import Counter
from collections import defaultdict
N = int(input())
S = [input() for i in range(N)]
d = defaultdict(lambda : 0)
ans = 0
for s in S:
    c = sorted(Counter(s).items())
    ans += d[str(c)]
    d[str(c)]+=1
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()

a = 0
answer = 0
for i in range(n-1):
    for j in range(10):
        if s[i][j] != s[i+1][j]:
            a = 0
            break
        elif j == 9:
            a += 1
    answer += a

print(answer)

Solution (Python):
def val(s):
    a = [0 for i in range(26)]
    for i in s:
        a[ord(i) - ord('a')] += 1
    sum = 0;
    for i in a:
        sum = sum * 10 + i
    return sum


n = int(input())
a = []
for i in range(n):
    a.append(input())
d = {}
for i in a:
    k = val(i)
    if k in d.keys():
        d[k].append(i)
    else:
        d[k] = list()
        d[k].append(i)
sum = 0
for i in d.keys():
    sum += len(d[i]) * (len(d[i]) - 1) // 2
print(sum)

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

Solution (Python):
from collections import Counter
N = int(input())
s = Counter("".join(sorted(list(input()))) for _ in range(N))

def func(k):
    w = 1
    for x in range(2, k+1):
        w *= x
    return w
ans = 0
for k in s:
    ans += s[k] * (s[k] - 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):
n = int(input())
word_list  = sorted([ sorted(input()) for v in range(n) ])
k = 1
mul_list = []


for i in range(n-1):
    if word_list[i] == word_list[i+1]:
        k += 1
    else:
        mul_list.append(k)
        k = 1
else:
    mul_list.append(k)


def com(a):
    return a*(a-1)//2

print(sum(map(com,mul_list)))

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

def main():
    N = int(input())
    Dic = {}
    for _ in range(N):
        S = input()    
        S_list = [S[i] for i in range(len(S))]
        S_list.sort()
        S_sorted = "".join(S_list)
        Dic[S_sorted] = Dic.get(S_sorted,0) + 1
        
    ans = 0
    for x in Dic:
        num = Dic[x]
        ans += num * (num-1) // 2
        
    print(ans)
        
    
    
if __name__ == "__main__":
    main()

Solution (Python):
import collections
n = int(input())
tmp = []
for i in range(n):
    s = list(str(input()))
    s.sort()
    tmpstr = "".join(s)
    tmp.append(tmpstr)
ans = 0
c = collections.Counter(tmp)
for i in c.keys():
    if c[i] >= 2:
        ans += (c[i]  - 1 )*(c[i] )//2
print(ans)

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

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

print(int(ans))

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

ans = 0
ana = {}
for i in range(N):
    s = input().rstrip()
    s = ''.join(sorted(s))

    if ana.get(s):
        ans += ana[s]
        ana[s] += 1
    else:
        ana[s] = 1

print(ans)

Solution (Python):
import numpy as np
from collections import Counter
from functools import reduce


N = int(input())

res = Counter()

res2 = 0
for _ in range(N):
    s = input()
    counter = Counter(s)
    code = ""
    for k in sorted(counter.keys()):
        code += str(k) + str(counter[k])
    res[code] += 1

for v in res.values():
    res2 += (v*(v-1)//2)



print(res2)

Solution (Python):
from collections import defaultdict
N = int(input())
H = defaultdict(int)
for _ in range(N):
  S = input()
  C = [0] * 26
  for s in S:
    C[ord(s) - 97] += 1
  H[str(C)] += 1
cnt = 0
for v in H.values():
  cnt += v * (v - 1) // 2
print(cnt)

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

s = sorted(s)

s.append("=end=")
t = ""
c = 0
total = 0
for a in s:
    if a != t:
        t = a
        total += c * (c-1) // 2
        c = 0
    c += 1

print(total)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
seen = {}
cnt = 0
for ind,s in enumerate(S):
    x = list(s)
    x.sort()
    y = ''.join(x)
    if(y in seen):
        seen[y] += 1
    else:
        seen[y] = 1

for i in seen:
    if(seen[i]==1):continue
    x = seen[i]
    cnt += x*(x-1)//2
print(cnt)

Solution (Python):




from math import factorial
def nCr(n, r):
  return factorial(n) // factorial(r) // factorial(n - r)

N = int(input())
Ss = ["".join(sorted(input())) for _ in range(N)]
m = {}
for s in Ss:
  m[s] = m.get(s, 0) + 1
ans = sum(nCr(n, 2) for n in m.values() if n >= 2)
print(ans)