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):
import collections
from operator import mul
from functools import reduce

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

c = collections.Counter(words)
nums = list(c.values())

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

print(sum([cmb(i,2) for i in nums]))

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

dic = {}
count_dic = {}
n = int(input())

for i in range(n):
    x = input().rstrip('\n')
    text = ''.join(sorted(list(x)))
    if text not in dic:
        dic[text] = 0
        count_dic[text] = 1
    else:
        dic[text] += count_dic[text]
        count_dic[text] += 1

ans = sum(list(dic.values()))
print(ans)

Solution (Python):
from collections import defaultdict
n=int(input())
d=defaultdict(int)
ans=0
for _ in range(n):
    d["".join(sorted(input()))]+=1

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

Solution (Python):
import math
n = int(input())
s = [input() for _ in range(n)]

cnt = 0

for i, item in enumerate(s):
    s[i] = ''.join(sorted(s[i]))
s = sorted(s)


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


cnt2 = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        if cnt2 == 0:
            cnt2 += 2
        else:
            cnt2 += 1
    else:
        if cnt2 != 0:
            f = combinations_count(cnt2, 2)
            cnt += f
            cnt2 = 0

if cnt2 != 0:
    f = combinations_count(cnt2, 2)
    cnt += f
    cnt2 = 0
print(cnt)

Solution (Python):
import collections
import math
def cmb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
count = 0
l_s =[]
for i in range(N):
    s = input()
    l = list(s)
    l.sort()
    s = ''.join(l)
    l_s.append(s)
d_s = collections.Counter(l_s)
for i in d_s.values():
        count+=cmb(i,2)
print(count)

Solution (Python):

n = int(input())


c_list = []

for i in range(n):
    s = input()
    c_list.append(''.join(sorted(s)))



c_hash = {}
for c in c_list:
    if c not in c_hash:
        c_hash[c] = 0
    c_hash[c] += 1
count = 0    
for k, v in c_hash.items():
    if v >= 2:

        
        
        
        temp = v * (v-1)/ 2
        count += temp

print(int(count))

Solution (Python):
characters = ['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']
numbers = []
for i in range(26):
    numbers.append(1*10**(i))

def calc(str):
    x = 0
    for i in str:
        ind = characters.index(i)
        x += numbers[ind]
    return x

n = int(input())
s = [input() for i in range(n)]
d = {}
for i in s:
    num = str(calc(i))
    if num in d:
        d[num] += 1
    else:
        d[num] = 1

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

print(int(ans))

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

s.sort()

ans = 0
pre_same = 1
for i in range(1,N):

    if(s[i-1] == s[i]):
        pre_same = pre_same +1
    else:
        if(pre_same > 1):
            ans = ans + (pre_same * (pre_same-1) / 2)
        pre_same = 1


if(pre_same > 1):
    ans = ans + (pre_same * (pre_same-1) / 2)

print(int(ans))

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

ans = []
tmp = 1
for idx,val in enumerate(s):
        if idx == 0:
                continue
        if val == s[idx - 1]:
                tmp += 1
        else:
                ans.append(tmp)
                tmp = 1
else:
        ans.append(tmp)

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

Solution (Python):
from collections import Counter
import math

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

n = int(input())
S = [[s for s in input()] for _ in range(n)]
for i in range(n):
    tmp = ''.join(sorted(S[i]))
    S[i] = tmp

ans = 0
for v in Counter(S).values():
    if v!=1: ans += cc(v,2)
print(ans)

Solution (Python):
N = int(input())
s = []
for i in range(N):
    s.append(''.join(sorted(input())))
s.sort()
count = 0
ans = 0
for i in range(1,N):
    if(s[i]==s[i-1]):
        count  = count+1
        ans = ans+count
    else:
        count = 0

print(ans)

Solution (Python):

import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  
  sys.stderr.write(_s+"\n")


N = int(input())						

from collections import defaultdict
D = defaultdict(int)

for i in range(N):
	s = input()
	l = sorted(s)
	s = "".join(l)
	D[s]+=1

p("D ",D)


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

print(ans)

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

Solution (Python):
from math import *
from collections import deque, defaultdict, Counter
from itertools import product, permutations, combinations, accumulate
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappush, heappop
from copy import copy, deepcopy

N = int(input())
xs = []
for i in range(N):
    x = input()
    xs.append(x)

us = "abcdefghijklmnopqrstuvwxyz"

cs = []
ess = []
for x in xs:
    c = Counter(x)
    es = [0,] * 26
    for i,u in enumerate(us):
        e = c[u]
        es[i] = e
    cs.append(c)
    ess.append(tuple(es))


g = Counter(ess)

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

Solution (Python):
import sys
import collections


def input():
    return sys.stdin.readline()[:-1]


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

    print(ans)


if __name__ == '__main__':
    main()

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

N = int(input())
S = [[0 for j in range(10)] for i in range(N)]
for i in range(N):
    s = str(input())
    for j in range(10):
        S[i][j] = s[j]
    S[i].sort()
S.sort()
ans = 0
i = 0
j = 1
while i < N:
    tmp = 0
    while i + j < N and S[i] == S[i + j]:
        tmp += 1
        j += 1
    if tmp != 0:
        ans += com(tmp+1, 2)
    i += j
    j = 1
print(ans)

Solution (Python):
n=int(input())
s=[]
for _ in range(n):
    s1=sorted(input())
    s1=''.join(s1)
    s.append(s1)
s.sort()
cnt=[1]*len(set(s))
j=0
for i in range(n-1):
    if s[i]==s[i+1]:
        cnt[j]+=1
    else:
        cnt[j]=cnt[j]*(cnt[j]-1)//2
        j+=1
cnt[-1]=cnt[-1]*(cnt[-1]-1)//2
print(sum(cnt))

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

dic = {}

for _ in range(n) :
  s = "".join(sorted(input()))
  if (s in dic):
    dic[s] += 1
  else:
    dic[s] = 0
  
res = 0
for v in dic.values():
  if v > 0:
    res += v*(1+v)/2

print(int(res))

Solution (Python):
import math

N = int(input())
sl = []

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

ans_d = {}
ans = 0
for _ in range(N):
    sl.append(input())


for s in sl:
    key = "".join(sorted(s))
    if(key not in ans_d.keys()):
        ans_d[key] = 1
    else:
        ans_d[key] += 1


print(sum([combinations_count(ans,2) for ans in ans_d.values() if ans>1]))

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

sList =[0] * N

for i in range(N):
    sList[i] = ''.join(sorted(list(input())))

sList = sorted(sList)

ans = 0
tmp = 1

for i in range(N-1):
    if sList[i] == sList[i+1]:
        tmp += 1
    else:
        ans += (tmp * (tmp - 1)) // 2
        tmp = 1
if sList[N-2] == sList[N-1]:
    ans += (tmp * (tmp - 1)) // 2
            
print(ans)

Solution (Python):

N = int(input())
pairdic = {}
s = ''.join(sorted(input()))
pairdic[s] = 1
for i in range(1, N):
    s = ''.join(sorted(input()))
    if s in pairdic:
        pairdic[s] += 1        
    else:
        pairdic[s] = 1
result = 0
for i in pairdic:
    result += (pairdic[i] * (pairdic[i]-1))//2
print(result)

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=list(list(input()) for i in range(n))
count=0
for i in range(n):
    s[i].sort()
s.sort()

for i in range(n):
    s[i]=''.join(map(str, s[i]))
    
c = collections.Counter(s)
d=c.most_common()

for i in range(len(d)):
    if d[i][1]>1:
        count+=combinations_count(d[i][1], 2)
    else:
        break
print(count)

Solution (Python):
import collections
N = int(input())
s_list = []
for i in range(N):
  s_list.append(''.join(sorted(input())))
s_list = collections.Counter(s_list)
def f(n):
  return int(n*(n+1)/2)
result = sum([f(n-1) for n in s_list.values()])
print(result)

Solution (Python):
import collections

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

answer = 0
for k in d.keys():
    if d[k]>1:
        answer += d[k]*(d[k]-1)/2

print(int(answer))

Solution (Python):
import string


n = int(input())

Ss = list()
for i in range(n):
    Ss.append(input())







count_dict = dict()
for s in Ss:
    count = [0 for i in range(len(string.ascii_lowercase))]
    for j in range(len(s)):
        count[ord(s[j]) - ord('a')] += 1
    count = tuple(count)
    if count in count_dict:
        count_dict[count] += 1
    else:
        count_dict[count] = 1

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

Solution (Python):
N = int(input())
A = []
for x in range(N):
    A.append([y for y in input()])
    A[-1].sort()
A.sort()
count = 0
l = 1
r = 0
for i in range(1,N):
    if A[r] == A[i]:
        l += 1
    else:
        count += l * (l - 1) / 2
        l = 1
        r = i
count += l * (l - 1) / 2
print(int(count))

Solution (Python):
import collections
n = int(input())
s = []
dic = collections.defaultdict(int)
for sent in range(n):
  sent_s = "".join(sorted(input()))
  dic[sent_s] += 1

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

Solution (Python):
moji = ['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']

ans = 0
n = int(input())
s1 = ['' for _ in range(n)]
for j in range(n):
    s = input()
    a = ''
    for i in  moji:
        a += i + str(s.count(i))
    s1[j] = a
s1.sort()
cnts = []
before = s1[0]
cnt = 0
for S in s1:
    if before == S:
        cnt += 1
    else:
        cnts.append(cnt)
        before = S
        cnt = 1
cnts.append(cnt)
for i in cnts:
    if i == 1:
        continue
    ans += i * (i - 1) / 2
print(int(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 = {}
ans = 0
for i in range(n):
  _s = sorted(input())
  __s = ''
  for _ in _s:
    __s += _
  try:
    ans += s[__s]
    s[__s] += 1
  except:
    s[__s] = 1

print(ans)

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


dic = {}
for i in range(N):
    s = list(input())
    s_uniq = list(set(s))
    s_uniq.sort()
    key = ""
    for j in range(len(s_uniq)):
        s_cnt = s.count(s_uniq[j])
        key += s_uniq[j]+str(s_cnt)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

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

Solution (Python):

N=int(input())


alphas =list("abcdefghijklmnopqrstuvwxyz")
d = {}
for i,alpha in enumerate(alphas):
    d[alpha] = i



a = []
for n in range(N):
    s = input()
    
    
    sl = [0 for i in range(26)]
    for ss in s:
        sl[d[ss]] += 1
    a.append(tuple(sl))

des = {}
for aa in a:
    if aa not in des:
        des[aa] = 0
    des[aa] += 1






cnt = 0
for k in des:
    ddd = des[k]
    cnt += (ddd*(ddd-1))//2
print(cnt)

Solution (Python):
import collections

def cmb(n):
    sum = 0
    for i in range(n):
        sum += i
    return(sum)


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

ss_num = collections.Counter()

for s in S:
    ss_num[tuple(sorted(s))] += 1

ans = 0
for s,n in ss_num.items():
    ans += cmb(n)
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]

sscounts = Counter(ss)

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

print(ans)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7











from scipy.misc import comb  




def main(): 
    N = II()
    S = []
    for _ in range(N):
        s = tuple(sorted(list(SI())))
        S.append(s)

    S.sort()

    prev = None
    ans = 0
    same_count = 0
    for i in S:
        if prev == i:
            same_count += 1
            
        else:
            
            ans += comb(same_count, 2, exact=True)
            same_count = 1
            prev = i
    ans += comb(same_count, 2, exact=True)
    


    print(ans)

main()

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

d = dict()

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

count = 0

for i in d.items():
  count += (i[1] * (i[1] - 1)) // 2

print(count)

Solution (Python):
import collections
import math

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

ans = 0
for i in collections.Counter(str_list).values():
    if i >=2 :
        ans += math.factorial(i)//math.factorial(i-2)//math.factorial(2)
print(ans)

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

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

Solution (Python):
N = int(input())
c = {}
for _ in range(N):
    s = ''.join(sorted(list(input())))
    if s in c.keys():
        c[s] += 1
    else:
        c[s] = 0
ans = 0
for k in c.values():
    ans += (k * (k + 1)) // 2
print(ans)

Solution (Python):
from itertools import groupby

N = int(input())


ans=0
S=[]
for i in range(N):
    s=list(input())
    s.sort()
    S.append(''.join(x for x in s))

S.sort()

for key, value in groupby(S):
    l = len(list(value))
    ans += (l*(l-1) // 2)


print(str(ans))

Solution (Python):
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  
  

n = inn()
alpha = [ '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' ]
h = {}
for i in range(n):
    ch = {}
    for c in alpha:
        ch[c] = 0
    s = input().strip()
    for j in range(10):
        ch[s[j]] += 1
    x = (ch['a'], ch['b'], ch['c'], ch['d'], ch['e'], ch['f'], ch['g'], ch['h'], ch['i'], ch['j'], ch['k'], ch['l'], ch['m'], ch['n'], ch['o'], ch['p'], ch['q'], ch['r'], ch['s'], ch['t'], ch['u'], ch['v'], ch['w'], ch['x'], ch['y'], ch['z'])
    if x in h:
        h[x] += 1
    else:
        h[x] = 1

sum = 0
for x in h:
    y = h[x]
    if y>1:
        sum += (y*(y-1))//2
print(sum)

Solution (Python):


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


for i in range(len(S)):
    s = S[i]
    t = list(s)
    t.sort()
    S[i] = ''.join(t)

S.sort()


ans = 0
i = 0
count = 0
while i < N - 1:
    si = S[i]
    sj = S[i + 1]
    if si != sj:
        
        ans += count * (count + 1) // 2
        count = 0
    else:
        count += 1
        if i == N - 2:
            ans += count * (count + 1) // 2
    i += 1

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
ss = [input() for i in range(N)]
sdic = defaultdict(int)
ans = 0
for s in ss:
  dic = defaultdict(int)
  for c in s:
    dic[c] += 1
  key = tuple(sorted(dic.items()))
  sdic[key] += 1
  if sdic[key] >= 2:
    ans += sdic[key] - 1
print(ans)

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



import collections

c = collections.Counter(S)



ary = c.values()

import math

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


for i in ary:
    if i != 1:
        cnt += combinations_count(i)


print(cnt)

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

s = []
for _ in range(n):
    s += [''.join(map(str, (sorted(list(str(input()))))))]

import collections

c = collections.Counter(s)

from math import factorial

ans = 0

for x in c.values():
    if x >= 2:
        ans += factorial(x)//(factorial(x-2)*2)

print(ans)

Solution (Python):
import math
from collections import Counter

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):
    s.append(''.join(sorted(input())))

c = Counter(s)
l = len(c.most_common())
a = c.most_common()

cnt = 0
for i in range(l):
    if a[i][1] < 2:
        continue
    cnt += combinations_count(a[i][1], 2)

print(cnt)

Solution (Python):
import collections

N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]

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

print(ans)

Solution (Python):
def npr(n,r):
    if n == r:return 1
    ans1 = 1
    ans2 = 1
    for i in range(1,r+1):
        
        ans1 *= i
        ans2 *= (n-r+i)
    return ans2//ans1

N = int(input())
dics = {}
sl = []
for _ in range(N):
    s = input()
    sl.append(''.join(sorted(s)))
for c in sl:dics[c] = dics.get(c,0)+1
g = 0
for k in dics.keys():
    if dics[k] >=2:
        g += npr(dics[k],2)
print(g)

Solution (Python):
import sys
from math import factorial

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    string_type = {}
    for s in inputs:
        count = {}
        s_list = list(s)
        s_list.sort()
        for c in s_list:
            if c in count:
                count[c] += 1
            else:
                count[c] = 1
        key = ""
        for k in count.keys():
            key += "{}{}".format(k, count[k])
        if key in string_type:
            string_type[key] += 1
        else:
            string_type[key] = 1

    comb_count = 0
    for v in string_type.values():
        if v != 1:
            if v == 2:
                comb_count += 1
            else:
                comb_count += factorial(v) // factorial(v-2) // factorial(2)
    return comb_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Solution (Python):

N = int(input())

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

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

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

counter = {}
for s in S:
    if s in counter:
        counter[s] += 1
    else:
        counter[s] = 0

    
ans = 0
for v in counter.values():
    for i in range(1, v + 1):
        ans += i
print(ans)

Solution (Python):

n = int(input())
lines = [input() for x in range(n)]

order_lines = dict()
sum = 0
for i,line in enumerate(lines):
    sort_characters = "".join(sorted(line))
    if sort_characters not in order_lines:
        order_lines[sort_characters] = []
    else:
        sum += len(order_lines[sort_characters])
    order_lines[sort_characters].append(i)
print(sum)

Solution (Python):
N = int(input())
s = []
for i in range(N):
    si = list(input())
    si.sort()
    si = ''.join(si)
    s.append(si)
s.sort()

id = 1
now = s[0]
count = 0
ans = 0
while True:
    if id == N:
        if count != 0:
            ans += count*(count+1)//2
        break
    if s[id] == now:
        id += 1
        count += 1
        continue
    else:
        ans += count*(count+1)//2
        count = 0
        now = s[id]
        id += 1
print(ans)

Solution (Python):
import collections

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

c = collections.Counter(s)
sum = 0
for i in c.values():
    sum += i * (i-1) // 2

print(sum)

Solution (Python):
N = int(input())
str_list = {}
for i in range(N):
  str_dict = {}
  for j in input():
    if j in str_dict:
      str_dict[j] += 1
    else:
      str_dict[j] = 1
  key = "".join([str(k)+str(v) for k, v in sorted(str_dict.items(), key=lambda x:x[0])])
  if key in str_list:
    str_list[key] += 1
  else:
    str_list[key] = 1
  
result = sum([i*(i-1)//2 for i in str_list.values()])
print(result)

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

res = 0
cnt = 0
tmp = ''
for word in s:
    if word != tmp:
        tmp = word
        res += (cnt * (cnt-1)) // 2
        cnt = 1
    else:
        cnt += 1
else:
    res += (cnt * (cnt-1)) // 2

print(res)

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

def comb(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())
S = [input() for i in range(N)]

S_new = []
for s in S:
    S_new.append(''.join(sorted(s)))

c = collections.Counter(S_new)

cnt = 0
for num in c.values():
    if num > 1:
        if num == 2:
            cnt += 1
        else:
            cnt += comb(num, 2)
print(cnt)

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

S_c = collections.Counter(S)
S_cl = list(S_c.values())

ans = 0
for c in S_cl:
    ans += c*(c-1)//2

print(ans)

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

li = [0]*n
for i in range(n):
    s = input()
    li[i] = sorted(s)

li.sort()

cnt = 0
con = 0
pre = ""
for s in li:
    if pre == s:
        con += 1
        cnt += con
    else:
        con = 0
    pre = s

print(cnt)

Solution (Python):
"""
AtCoder
    :author: vierbein
"""
from __future__ import absolute_import, division, print_function


from collections import *
import sys
import functools


def pp(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

N = int(input().strip())
xs = ["".join(sorted(input())) for _ in range(N)]
res = sum(cnt * (cnt - 1) // 2 for cnt in Counter(xs).values())
print(res)

Solution (Python):
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle







INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)









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


N = int(input())
d = dict()
res = 0
for _ in range(N):
    s = "".join(sorted(list(input())))
    d[s] = d.get(s, 0) + 1

ans = 0
for v in d.values():
    if v >= 2:
        ans += comb(v, 2)

print(ans)

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

Solution (Python):
n = int(input())
counter = {}
uniqs = set()
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    counter[s] = counter.get(s,0) + 1
    uniqs.add(s)
    

ans = 0
for orig in uniqs:
    occurence = counter.get(orig)
    ans = ans + (occurence * (occurence -1)) // 2
print("{}".format(ans))

Solution (Python):
N = int(input())
s_list = [input() for _ in range(N)]
dic = {ord("a")+i: i for i in range(26)}
counter = {}
for s in s_list:
    str_cnt = [0]*26
    for char in s:
        str_cnt[dic[ord(char)]] += 1
    str_cnt = ''.join([str(i) for i in str_cnt])
    if (str_cnt in counter):
        counter[str_cnt] += 1
    else:
        counter[str_cnt] = 1
cnt = 0
for k, v in counter.items():
    if (v >= 2):
        cnt += v*(v-1)//2
print(cnt)

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


def main():
    N = int(input())
    d = defaultdict(lambda: 0)
    for _ in range(N):
        s = ''.join(sorted(input().strip()))
        d[s] += 1

    ans = 0
    for v in filter(lambda x: x > 1, d.values()):
        ans += (v - 1) * v // 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import collections
N = int(input())
s_lis = []
for _ in range(N):
    s_lis.append(input())
dic = {}
counts = 0
for s in s_lis:
    c = collections.Counter(s)
    tmp = str()
    for i in sorted(c.keys()):
        tmp += i+str(c[i])
    if tmp in dic.keys():
        dic[tmp] += 1
    else:
        dic[tmp] = 1
for i in dic:
    counts += dic[i]*(dic[i]-1)//2
print(counts)

Solution (Python):
from scipy import misc
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
s=sorted(s)
ans=0
c=1
t=s[0]
for i in range(1,n):
    if t==s[i]:
        c+=1
    else:
        ans+=misc.comb(c,2,True)
        t=s[i]
        c=1
ans+=misc.comb(c,2,True)
print(ans)

Solution (Python):

import sys
from collections import defaultdict
from collections import Counter

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(Counter(string).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1

    result = 0
    for _, v in count_dict.items():
        result += int((v-1) * 0.5 * (1 + v-1))
    print(result)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    s = [ next(tokens) for _ in range(N) ]  
    solve(N, s)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools
import math

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

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

ans = 0
dic = {}

for i in range(n):
    if l[i] in dic:
        dic[l[i]] +=1
    else:
        dic[l[i]] =1

for i in dic.values():
    if i>=2:
        ans += combinations_count(i, 2)
print(ans)

Solution (Python):
import collections

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

perm_s=["".join(sorted(list(item))) for item in s]

c = collections.Counter(perm_s)
vlist=list(c.values())
print(sum([int(v*(v-1)/2) for v in vlist]))

Solution (Python):
import math
def C(a,b):
    return math.factorial(a) // (math.factorial(b)*math.factorial(a-b))

N = int(input())
D = {} 
for i in range(N):
    s = list(input())
    if all(s[0] == s[j] for j in range(1,10)):
        continue
    else:
        temp = 10**26
        for j in range(10):
            temp += 10**(ord(s[j]) - 97)

        if temp in D:
            D[temp] = D[temp] + 1
        else:
            D[temp] = 1
ans = 0
for a in D.values():
    if a > 1:
        ans += C(a,2)
print(ans)

Solution (Python):
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
YNeos='YNeos'
mo=10**9+7
imp='IMPOSSIBLE'
alp=string.ascii_lowercase
num=enumerate(alp)
d=dict()
for i,j in num:
    d[j]=i

n=I()
w=[]
ans=0
di=defaultdict(int)
X=[]
for i in range(n):
    s=''.join(sorted(list(input())))
    di[s]+=1
for i,j in di.items():
    ans+=j*(j-1)//2
    
print(ans)

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

s = sorted(s)

ans = 0
cnt = 1

memo = []

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

for ss in s:
  if memo == ss:
    cnt += 1
  else:
    if cnt != 1:
      ans += cmb(cnt, 2)
    cnt = 1
    memo = ss

if cnt != 1:
  ans += cmb(cnt, 2)

print(ans)

Solution (Python):
import collections
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())
s = [''.join(sorted(input())) for i in range(n)]
c = collections.Counter(s)
count = list(c.values())
ans = 0
for num in count:
    if num >= 2:
        b = cmb(num, 2)
        ans += int(b)
print(ans)