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 math
import sys
import itertools
import queue
from fractions import gcd

sys.setrecursionlimit(10000)

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""

from math import factorial
import collections

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    sl = []
    for _ in range(N):
        tmp = sorted(sys.stdin.readline().rstrip())
        sl.append(''.join(tmp))
    c = collections.Counter(sl)
    ans = 0
    for n in c.values():
        r = 2
        if n > 1:
            ans += factorial(n) // (factorial(n - r) * factorial(r))

    print(int(ans))

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

slist = []
for h in range(n):
  slist.append(input())

newlist = []
word=[]
wordy = ""
for i in range(n):
  word = list(slist[i])
  word.sort()
  for jk in range(len(word)):
	  wordy = wordy+word.pop()
  newlist.append(wordy)
  wordy=""

resdic = {}
count = 0
for item in newlist:
  if not item in resdic:
    resdic[item] = 1
  else:
    count += resdic[item]
    resdic[item] += 1
    
print(count)

Solution (Python):
N = int(input())
A=[]
S={}
for i in range(N):
    a = list(input())
    a.sort()
    b = ''.join(a)
    if b not in S:
        S[b] = 1
    else:
        S[b] += 1


count=0
for i in S.values():
    if i==1:
        continue
    count += i*(i-1)//2
print(count)

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

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

line={}
c=0

for i in range(n):
    string = ''.join(sorted(list(input())))
    
    if string in line:
        c+=line[string]
    if string in line:
        line[string]+=1
    else:
        line[string]=1
    

print(c)

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

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

print(int(sum(map(lambda x: (x+1)*x/2, d.values()))))

Solution (Python):
import collections

cnt = 0
s = []
tmp = []
n = int(input())
for i in range(n):
    string = input()
    string = ''.join(sorted(string))
    s.append(string)






cc = collections.Counter(s)

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

print(cnt)

Solution (Python):

from operator import mul
from functools import reduce

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

n = int(input())
s = {}
for i in range(n):
    str = ''.join(sorted(input()))
    if str in s.keys():
        s[str] += 1
    else:
        s[str] = 1
ans = 0
for i in s:
    ans += combination(s[i], 2)
print(ans)

Solution (Python):
n =int(input())
A=[]
for I in range(n):
  moji=list(input())
  moji.sort()
  moji=''.join(moji)
  A.append(moji)
A.sort()
N=0
SUM=0
i=0
while True:
  if i==n-1:
    SUM=SUM+int(0.5*N*(N+1))
    break
  a=A[i]
  for s in range(i+1,n,1):
    b=A[s]
    if a==b:
      N+=1
      i+=1
    else:
      SUM=SUM+int(0.5*N*(N+1))
      N=0
      i=s
      break
print(SUM)

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

print(k)

Solution (Python):
from collections import Counter

n = int(input())
count = 0
lists =[]
count_dict = Counter()

for i in range(n):
    input_data = ''.join(sorted(input()))
    if input_data in count_dict:
        count += count_dict[input_data]
        count_dict[input_data] += 1
    else:
        count_dict[input_data] = 1

print(count)

Solution (Python):
n = int(input())
 
string = {}
count = 0

for i in range(n):
    base = sorted(input())

    if string.get("".join(base)) != None:
        count += int(string["".join(base)])
        string["".join(base)] += 1
    else:
        string["".join(base)] = 1

print(count)

Solution (Python):
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]
s.sort()
ss = s[0]
num = 0
ans=0
for i in range(N):
    if ss == s[i]:
        num+=1
    else:
        ans+=num*(num-1)//2
        num=1
        ss=s[i]
ans+=num*(num-1)//2
print(ans)

Solution (Python):
def sort_str(s):
  temp = sorted(list(s))
  return ''.join(list(temp))

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

s_dict = {}
count = 0

for s_i in s:
  k = sort_str(s_i)
  if k in s_dict:
    count += s_dict[k]
    s_dict[k] += 1
  else:
    s_dict[k] = 1
    
print(count)

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

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

if __name__ == "__main__":
    main()

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 = []
for i in range(N):
    tmp = list(input())
    tmp = sorted(tmp)
    tmp = ','.join(tmp)
    s.append(tmp)
c = collections.Counter(s)
ans_list = c.values()
ans_list = [i for i in ans_list if i >= 2]
ans = 0
if len(ans_list) != 0:
    for i in ans_list:
        ans += cmb(i, 2)
    print(ans)
else:
    print(ans)

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

count=0
for i in range(n):
  s_elem=''.join(sorted(list(input())))
  if s_elem in dic:
    count+=dic[s_elem]
    dic[s_elem]+=1
  else:
    dic[s_elem]=1

print(count)

Solution (Python):
from collections import Counter
n=int(input())
l={}
ans=0
for i in range(n):
  s=input()
  ss=sorted(s)
  s="".join(ss)
  ans+=l.setdefault(s, 0) 
  l[s]+=1
print(ans)

Solution (Python):
from math import factorial
from collections import Counter
 
def conb(n):
    if n <= 1:
        return 0
    else:
        return factorial(n) // factorial(n-2) // factorial(2) 

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

print(int(sum([conb(i) for i in Counter(S).values()])))

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

Solution (Python):
from collections import Counter as C
n,*s=open(0)
print(int(sum(map(lambda x:x*(x-1)//2,C(tuple(sorted(C(i.strip()).most_common(),key=lambda x:x[0]))for i in s).values()))))

Solution (Python):
from collections import Counter

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

for _ in range(N):
    s = sorted(input())
    s = str(s)
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1

print(sum(d * (d-1) // 2 for d in dic.values() if d > 1))

Solution (Python):
from collections import Counter

n = int(input())
ans = 0

l = ["".join(sorted(input())) for _ in range(n)]

a = Counter(l).values()

for i in a:
    ans += sum(range(i))

print(ans)

Solution (Python):


import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

N = int(input())





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



ans = 0
dic = {}
for s in S :
    if not s in dic :
        dic[s] = 0
    
    ans += dic[s]
    dic[s] += 1

print(ans)

Solution (Python):

N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  

result_dic = {}

for i in range(0, len(s)):
  sorted_val = ''.join(sorted(s[i]))
  if sorted_val in result_dic:
    result_dic[sorted_val] += 1
  else:
    result_dic[sorted_val] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Solution (Python):
import collections

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

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

Solution (Python):
N = int(input())
para = [[c for c in input()] for i in range(N)]
b = []
dict = {}
ans = 0
for i in range(N):
    para[i].sort()
    b.append("".join(para[i]))
    if b[i] not in dict:
        dict[b[i]] = 1
    else :
        ans += dict[b[i]]
        dict[b[i]] += 1 

print(ans)

Solution (Python):
d = {}
n = int(input())
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))

Solution (Python):
from collections import Counter

def p_c():
    n = int(input())
    ans = 0

    l = ["".join(sorted(input())) for _ in range(n)]

    a = Counter(l).values()

    for i in a:
        ans += sum(range(i))

    print(ans)
    
    
if __name__ == '__main__':
    p_c()

Solution (Python):
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic.values():
    c += i*(i-1)

print(c//2)

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

ans=0
import collections
c=collections.Counter(s)

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

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

num = 0
num_same = 1
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += int(num_same * (num_same - 1) / 2)
        num_same = 1
        prev = sorted_s[i]
    else:
        num_same += 1
num += int(num_same * (num_same - 1) / 2)
print(num)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
s = ["".join(sorted(input().split()[0])) for _ in range(n)]
cnt = {}
result = 0
for si in s:
    if si in cnt:
        result += cnt[si]
        cnt[si] += 1
    else:
        cnt[si] = 1
print(result)

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

dic = {}
ans = 0
for s in S:
    sortstr = str(sorted(s))
    if sortstr in dic:
        ans += dic[sortstr]
        dic[sortstr] += 1
    else:
        dic[sortstr] = 1
print(ans)

Solution (Python):
n = int(input())
count = 0
ls = dict([])
for i in range(n):
    si = ''.join(sorted(input()))
    if si in ls.keys():
        count += ls[si]
        ls[si] += 1
    else:
        ls[si] = 1
print(count)

Solution (Python):

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

    A = []
    for _ in range(N):
        a = sorted(list(input()))
        A.append(''.join(a))
    td = {}
    for t in A:
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] += 1
    count = 0
    for v in td.values():
        count += v * (v - 1) // 2
    print(count)


main()

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

N = int(input())

sentences = [None]*N

dp = {}

for i in range(N):
     k = list(map(str,input()))
     k.sort()
     k = ''.join(k)
     if k in dp:
         dp[k] += 1
     else:
         dp[k] = 1

ans = 0

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

print(int(ans))

Solution (Python):

import math

anagramed = []

def main():
    
    n = int(input())
    m = []
    r = {}
    count = 0

    for _ in range(n):
        m.append(input())
        anagramed.append(False)

    for i in range(n):
        s = "".join(sorted(m[i]))
        if r.get(s) is None :
            r[s] = 1
        else:
            count += r[s]
            r[s] += 1
    print(count)


main()

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

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

s.sort()

cnt = 0
t_cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        t_cnt += 1
    elif s[i] != s[i+1]:
        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

    if i == n-2:

        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

print(cnt)

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())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		

		
ans = 0
for v in dicS.values():
	if v != 1:
		ans += cmb(v, 2)
	
print(ans)

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

ans = 0
d = {}
for i in s:
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
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(list(input()))) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for i in c.values():
    if i > 1:
        ans += cmb(i, 2)
print(ans)

Solution (Python):
import math

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']

s_abc = {}
multiple = []
count = 0
for i in range(n):
    abc_dict = dict.fromkeys(alphabet, 0)
    s = input()
    for c in s:
        abc_dict[c] += 1
    lst = []
    for x in abc_dict.values():
        lst.append(str(x))
    strlst = ''.join(lst)
    if strlst in s_abc:
        s_abc[strlst] += 1
    else:
        s_abc[strlst] = 1
for v in s_abc.values():
    if v != 1:
        count += math.factorial(v) // (math.factorial(v - 2) * 2)

print(count)

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

strings = sorted([''.join(sorted(list(input()))) for i in range(n)])
strings.append('XXXXXXXXXX')

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

Solution (Python):
import collections
N=int(input())
s=["".join(sorted(input())) for _ in range(N)]
print(int(sum(list(map(lambda x: x*(x-1)/2*1, collections.Counter(s).values())))))

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

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

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

Solution (Python):
import sys
 
Ans = 0
N = int(input())
S = []
T = []
U = []
for _ in range(N):
  S.append(str(input()))
T = ['a'] * N  
U = ['a'] * N
 
for i in range(N):
  U[i] = ''.join(sorted(S[i]))
 
T = sorted(U)
 
j = 0
while j < N:
  for k in range(1,N):
    if j + k == N - 1:
      if T[j] != T[j + k]:
        Ans = Ans + (k-1) * k / 2
      else:
        Ans = Ans + (k+1) * k / 2
        
      print(int(Ans))
      sys.exit()
      
    if T[j] != T[j + k]:
      Ans = Ans + (k-1) * k / 2
      a = k
      break
  
  j = j + a
  
print(int(Ans))

Solution (Python):
import collections

chars = ["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"]


def eratosthenes_sieve(n):
    primes = [2]
    for odd in range(3, n + 1, 2):
        for p in primes:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                primes.append(odd)
                break
    return primes


era = eratosthenes_sieve(150)
n = int(input())
array = [0] * n
for i in range(n):
    new = input()
    var = 1

    for j in range(10):
        h = chars.index(new[j])
        var *= era[h]

    array[i] = var

c = collections.Counter(array)
cv = list(c.values())
ans = 0
for i in range(len(c)):
    ans += cv[i] * (cv[i] - 1) // 2

print(ans)

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

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


N = int(input())

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

s.sort()
s.append('0')
ans_tmp = 0
ans = 0
for i in range(N):
    if(s[i]== s[i+1]):
        ans_tmp += 1
    elif(ans_tmp>=1):
        ans+= cmb(ans_tmp+1, 2)
        ans_tmp=0


print(ans)

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

ans=0
for k in X:
    ans+=(k*(k-1))//2
print(ans)

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

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

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

ans = 0

c = collections.Counter(s)
for v in c.values():
    ans += (1/2) * v * (v-1)

print(int(ans))

Solution (Python):
n = int(input())
s = [input()for _ in range (n)]
dic = {}

for ss in s:
    sss = list(ss)
    
    sss.sort()
    
    ssss = ''.join(sss)


    if ssss not in dic :
        dic[ssss] = 1
    
    else:
        dic[ssss]= dic[ssss]+1

  

sum = 0

for aaa in dic.values():
    sum += aaa*(aaa-1)//2
    
print(sum)

Solution (Python):
N = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    s = input()
    num = 0
    sorted(alphabet)
    for i,a in enumerate(alphabet):
        if s.count(a) == 10:
            continue 
        num += s.count(a)*10**i
    d[num] += 1

ans = 0

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

Solution (Python):
N=int(input())
ABCS=[[0 for i in range(28)] for j in range(N)]

for i in range(N):
    S=input()
    for j in range(10):
       
        ABCS[i][ord(S[j:j+1])-97]=ABCS[i][ord(S[j:j+1])-97]+1
ABCS.sort()

dabu=[None]
ct=1
test=ABCS[0]
for i in range(N):
    if i>0:
        if ABCS[i]==test:
            ct=ct+1
        else:
            dabu.append(ct)
            test=ABCS[i]
            ct=1
    if i==N-1:
        dabu.append(ct)
kumi=0
for x in dabu:
    if x != None:
        kumi=kumi+x*(x-1)/2
    

print(int(kumi))

Solution (Python):
N = int(input())
s = [''] * N
for _ in range(N):
    tmp = sorted(input())
    s[_] = ''.join(tmp)
tmp = sorted(s)
cnt = 1
index = 0
ansFlag = True
ans1 = 0
while ansFlag:
    cnt = 1
    for j in range(index + 1, N):
        if tmp[index] == tmp[j]:
            cnt += 1
            index += 1
        else:
            index += 1
            break

    tmp2 = 0
    for i in range(cnt, 0, -1):
        tmp1 = i - 1
        tmp2 += tmp1
        ans = tmp2
    ans1 += ans
    if index == (N - 1):
        ansFlag = False

print(ans1)

Solution (Python):
from collections import defaultdict
import math

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

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

for c in L.values():
    if c > 1:
        ans += combination(c, 2)
print(ans)

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

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

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

for c in L.values():
    if c > 1:
        ans += combination(c, 2)
print(ans)

Solution (Python):
import math

from collections import Counter


def func(i):
    if i >= 1:
        return math.factorial(i)
    else:
        return 1


N = int(input())

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

print(sum([func(i) // func(i-2) // 2 for i in Counter(S).values()]))

Solution (Python):
from collections import Counter
n = int(input())
s = []
for i in range(n):
    t = input()
    q = [t[i] for i in range(10)]
    q.sort()
    r = ""
    for i in range(10):
        r += q[i]
    s.append(r)

x = Counter(s).most_common()
ans = 0
for a,b in x:
    ans += b*(b-1)//2

print(ans)

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

N = int(input())
s = [None]*N
for i in range(N):
    s[i] = ''.join(sorted(input().rstrip('\n')))
s.sort()

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

Solution (Python):
import math

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

def c(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

s_list = []
for i in s:
    s_list.append(sorted(i))

s_list = sorted(s_list)

ans = 0
i = 0
while i < n-1:
    count = 0
    while s_list[i] == s_list[i+1]:
        count += 1
        i += 1
        if i == n-1:
            ans += c(count+1)
            break
        elif i+1 <= n-1:
            if s_list[i] != s_list[i+1]:
                ans += c(count+1)
                break
    i += 1

print(ans)

Solution (Python):
import math
import copy

n = int(input())









s = [input() for i in range(n)]

for i in range(n):
    moji = list(map(lambda x: x, s[i]))
    moji.sort()
    s[i] = moji

s.sort()

count = 0
i = 0
j = 1
temp = 0
while (j < n):
    if (s[i] == s[j] and j < n - 1):
        j += 1
    elif (s[i] != s[j] and j < n - 1):
        count += (j - i) * (j - i - 1) / 2
        i = j
        j = i + 1
    elif (s[i] == s[j] and j == n - 1):
        count += (j - i) * (j - i + 1) / 2
        i = j
        j = i + 1
    else:
        count += (j - i) * (j - i - 1) / 2
        i = j
        j = i + 1

print(int(count))

Solution (Python):
n=int(input())
string=[]
ang=0
charcou=[[0]*26 for i in [1]*n]
for c in range(n):
    string.append(input())
    for d in range(10):
        charcou[c][ord(string[c][d])-97]+=1
charcou.sort()
c=0
while c<n-1:
    comb=1
    while charcou[c]==charcou[c+1]:
        comb+=1
        c+=1
        if c>=n-1:
            break
    if comb!=1:
        ang+=int(comb*(comb-1)/2)
    c+=1
print(ang)

Solution (Python):
from collections import Counter, defaultdict

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

dd = defaultdict(int)

for i in S:
    p = 0
    for j in i:
        p += 26**(ord(j)-ord('a'))*(i[j])
    dd[p] += 1

ans = 0
a = dd.keys()
for i in a:
    ans += (dd[i]-1)*dd[i]//2
print(ans)

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

N = int(input())
s = {}
h = {'a': 2, 'b': 3, 'c': 5, 'd': 7, 'e':11, 'f':13, 'g':17,'h':19,'i':23,'j':29,'k':31,'l':37,'m':41,'n':43,'o':47,'p':53,'q':59,'r':61,'s':67,'t':71,'u':73,'v':79,'w':83,'x':89,'y':97,'z':101}
for i in range(N):
    total = 1
    chs = list(input())
    for j in range(10):
        total *= h[chs[j]]
    s[total] = s.get(total, 0) + 1

cnt = 0
for v in s.values():
    if v < 2: continue
    a = cmb(v, 2)
    cnt += a

print(int(cnt))

Solution (Python):
import sys,math,itertools
def r(x):
    sum = 0
    for i in range(1,x+1):
        sum += i
    return sum

N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

data = {}
a = set()
a.add(s[N-1])
for i in range(N-2,-1,-1):
    if s[i] in a:
        if s[i] in data:
            data[s[i]] += 1
        else:
            data[s[i]] = 1 
    else:
        a.add(s[i])
for i in data:
    data[i] = r(data[i])
print(sum(data.values()))

Solution (Python):
from operator import itemgetter

n=int(input())
s=[]
li=[]
ans=0
cnt=1

for i in range(n):
  s.append(sorted(input()))
s.sort(key=itemgetter(9,8,7,6,5,4,3,2,1,0))
s=s+['']

for i in range(n):
  if s[i]==s[i+1]:
    cnt+=1
  elif cnt>1:
    li.append(int(cnt*(cnt-1)/2))
    cnt=1
  else:
    cnt=1
print(int(sum(li)))

Solution (Python):
from collections import Counter

N = int(input())
a = [''.join(sorted(input())) for i in range(N)]
count = Counter(a).values()
b = 0
for i in count:
    b = b + i * (i-1)
b=int(b/2)
print(b)

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

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = []
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))

Solution (Python):
import sys
import math

dic = {}

N = int(sys.stdin.readline())

for _ in range(N):
  line = sys.stdin.readline()[0:10]
  key = ''.join(sorted(line))
  dic[key] = dic[key] + 1 if (key in dic) else 1
print(sum(map(lambda x: 0 if x==1 else math.factorial(x) // (math.factorial(x - 2) * 2), dic.values())))

Solution (Python):
import sys

N = int(input())
L = {}
count = 0
for i in range(N):
    A = ''.join(sorted(sys.stdin.readline().strip()))
    if A not in L:
        L[A] = 1
    else:
        count += L[A]
        L[A] += 1

print(count)

Solution (Python):
from collections import Counter

from operator import mul
from functools import reduce

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


N = int(input())
matched = [False] * N
s = [None] * N
for i in range(N):
    moji = list(input())
    moji.sort()
    tmp = "".join(moji)
    s[i]= tmp

s.sort()

ans = 0
i = 0
j = 1
while i < N-1:
    cnt = 0
    
    if j == N:
        break
    while j <= N-1:
        
        if s[i] == s[j]:
            cnt += 1
            j += 1
            continue
        else:

            i = j
            j = i+1
            break
    if cnt >= 1:
        ans += cmb(cnt+1,2)
    

print(ans)

Solution (Python):

from collections import defaultdict

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

n = int(input())
d = defaultdict(int)
for i in range(n):
    w = input()
    ws = sorted(w)
    ww = ''.join(ws)
    d[ww] += 1

ans = 0
for i in d.keys():
    if d[i] > 1:
        ans += x(d[i])

print(int(ans))

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

def cmb(n,r):
    if n < r:
        return 0

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


sList = {}

N = int(input())


for i in range(N):
    s = list(input())
    s.sort()

    s_data = ''.join(s)

    if s_data in sList.keys():
        sList[s_data] = sList[s_data] + 1

    else:    
        sList[s_data] = 1

result = 0
for i in sList:
    result += cmb(sList[i],2)

print(str(result))

Solution (Python):
import math
n = int(input())
lst = list()
num = 0
flag = 1
for i in range(n):

    s = input()
    s = list(s)
    s.sort()
    lst.append(s)

lst.sort()

for i in range(n-1):
    if (lst[i] == lst[i+1]):
        flag = flag + 1
    else:
        if (flag > 1):
            num = num + math.factorial(flag) // (math.factorial(flag - 2) * 2)
        flag = 1
if (flag > 1):
    num = num + math.factorial(flag) // (math.factorial(flag - 2) * 2)
print(num)

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())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) if v>= 2 else 0 for v in str_dict.values()]))

Solution (Python):
from collections import Counter
N = int(input())
s = []
cnt = 0
for _ in range(N):
  a = str(input())
  alist = sorted(list(a))
  s.append(str(''.join(alist)))
  
l = Counter(s)
for i in l.values():
  if i > 1:
    cnt += (i - 1) * i / 2
print(int(cnt))