Problem:
 Score : 300 points    Problem Statement We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a .  For example, greenbin is an anagram of beginner . As seen here, when the same character occurs multiple times, that character must be used that number of times.  Given are N strings s_1, s_2, \ldots, s_N . Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j  (1 \leq i < j \leq N) such that s_i is an anagram of s_j .      Constraints  2 \leq N \leq 10^5  s_i is a string of length 10 .  Each character in s_i is a lowercase English letter.  s_1, s_2, \ldots, s_N are all distinct.         Input Input is given from Standard Input in the following format:  N  s_1  s_2  :  s_N       Output Print the number of pairs of integers i, j  (1 \leq i < j \leq N) such that s_i is an anagram of s_j .        Sample Input 1 3
acornistnt
peanutbomb
constraint      Sample Output 1 1  s_1 =  acornistnt is an anagram of s_3 =  constraint . There are no other pairs i, j such that s_i is an anagram of s_j , so the answer is 1 .       Sample Input 2 2
oneplustwo
ninemodsix      Sample Output 2 0  If there is no pair i, j such that s_i is an anagram of s_j , print 0 .       Sample Input 3 5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa      Sample Output 3 4  Note that the answer may not fit into a 32 -bit integer type, though we cannot put such a case here.

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

Solution (Python):
import collections
n=int(input())
ab=[list(input()) for l in range(n)]

c=[0]*n
for i in range(n):
    c[i]=sorted(ab[i])
moji=[0]*n
for i in range(n):
    moji[i] = ','.join(c[i])

c = collections.Counter(moji)
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
d=c.values()
d=list(d)
ct=0
for i in range(len(d)):
    if d[i]==2:
        ct+=1
    elif d[i]>2:
        ct+=combinations_count(d[i], 2)
print(ct)

Solution (Python):
from sys import stdin
from math import factorial as f
N = int(input())
words = []
for s in stdin:
    words.append(
        ''.join(sorted(s.strip()))
    )

words = sorted(words)
ans = 0
p = words[0]
streak = 1
s = []

for i in range(1, N):
    if p == words[i]:
        streak += 1
    else:
        s.append(streak)
        streak = 1
        p = words[i]

s.append(streak)

for n in s:
    if n == 1:
        continue
    elif n == 2:
        ans += 1
    else:
        ans += f(n) // (2 * f(n - 2))

print(ans)

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

cnt = 0
p = 1
tmp = 0
while p<n:
  if s_list[p-1]==s_list[p]:
    tmp += 1
  else:
    if tmp==1:
      cnt += tmp
    elif tmp>1:
      tmp += 1
      cnt += (tmp*(tmp-1))//2
    tmp = 0
  p += 1
if tmp==1:
  cnt += tmp
elif tmp>1:
  tmp += 1
  cnt += (tmp*(tmp-1))//2
print(cnt)

Solution (Python):
import math
n = int(input())
s_list = []
for i in range(n):
    l = list(input())
    l.sort()
    s = ''.join(map(str, l))
    s_list.append(s)
    
s_list.sort()


old_s = ""
length = 1
num = 0
for s in s_list:
    if old_s == s:
        length += 1
    else:
        if length > 1:
          
          num += math.factorial(length) // (math.factorial(length - 2) * math.factorial(2))
        old_s = s
        length = 1
if length > 1:
	num += math.factorial(length) // (math.factorial(length - 2) * math.factorial(2))
print(num)

Solution (Python):
N=int(input())
ans=0
data={}

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

Solution (Python):


import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
slist = {}
ans = 0
for i in range(N):
    S = []
    moji = input()
    for j in range(10):
        S.append(moji[j])
    ins = "".join(sorted(S))
    if ins in slist:
        ans += slist[ins]
        slist[ins] += 1
    else:
        slist[ins] = 1

mul = slist.values()
ansl = [n for n in mul if n!=1]

ret = 0
for x in ansl:
    ret += combinations_count(x, 2)
print(ret)

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

s = []
for i in range(n):
    s.append(input())
a = {}
for i in range(n):
    tmp = [u for u in s[i]]
    tmp.sort()
    tmp="".join(tmp)
    if tmp in a:
        a[tmp] +=1
    else:
        a[tmp] =1

c =0
for  k,d in a.items():
    c +=d * (d-1) /2
print(int(c))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = []

import collections

for i in range(n):
    s = ns()
    s = sorted(s)
    a.append(''.join(s))

b = collections.Counter(a)
ans = 0


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

print(ans)

Solution (Python):
n=int(input())
List=[str(input()) for i in range(n)] 
S_List=[]
A_List=[]
ans=1
for i in range(n):
  S_List.append(sorted(List[i]))
S_List.sort()
tmp = S_List[0]
for i in range(1,n):
  if tmp == S_List[i]:
    ans+=1
  else:
    A_List.append(ans)
    ans=1
    tmp=S_List[i]
A_List.append(ans)
ANS=0
for i in range(len(A_List)):
  ANS+=int(A_List[i]*(A_List[i]-1)/2)
print(ANS)

Solution (Python):
def cmb(n, r):
    if n == 1: return 0
    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 = [input() for _ in range(n)]
S_sorted = ["".join(sorted(s)) for s in S]
S_sorted = sorted(S_sorted)

ans = 0
cnt = 1
for i in range(1, len(S_sorted)):
    if S_sorted[i] == S_sorted[i-1]:
        cnt += 1
    else:
        ans += cmb(cnt, 2)
        cnt = 1

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

print(int(ans))

Solution (Python):

from collections import defaultdict
import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)

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

    ans = 0
    for _, v in my_dict.items():
        logging.debug("{}".format(v))
        if v == 1:
            ans += 1
        else:
            ans += ((v + 1) * v / 2)

    return ans

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

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())
dic = {}
ans = 0
for i in range(N):
    si = input()
    si_list = sorted(si)
    key = ''.join(si_list)
    if key in dic:
        dic[key] = dic[key] + 1
    else:
        dic[key] = 1

for k in dic:
    v = dic[k]
    if v >= 2:
        ans += cmb(v, 2)

print(ans)

Solution (Python):
from collections import Counter
n = int(input())
arr = [list(str(input())) for _ in range(n)]

for i in range(n):
  arr[i].sort()
ans = list(Counter([tuple(i) for i in arr]).values())

a = 0
for i in range(len(ans)):
  tmp = ans[i]
  a += tmp*(tmp-1)//2
  
print(a)

Solution (Python):
N = int(input())
count = {}
ans = 0

for _ in range(N):
    ele = "".join(sorted(input()))
    if ele in count.keys():
        ans += count[ele]
        count[ele] += 1
    else:
        count[ele] = 1
  
print(ans)

Solution (Python):
import math

n = int(input())
lst = []
for i in range(n):
    s = sorted(str(input()))
    lst.append(s)
list.sort(lst)

cnt_1 = 0
x = lst[0]
i = 1
cnt_2 = 1
while i < n:

    if x == lst[i]:
        cnt_2 += 1

    else:
        x = lst[i]
        if cnt_2 != 1:        
            cnt_1 += int(math.factorial(cnt_2) / math.factorial(cnt_2 - 2) / 2)
        cnt_2 = 1
    i += 1

if cnt_2 != 1:
    cnt_1 += int(math.factorial(cnt_2) / math.factorial(cnt_2 - 2) / 2)


print(cnt_1)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    temp = input()
    S.append(''.join(sorted(temp)))
S.sort()
row = 1
ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        row += 1
    else:
        ans += (row*(row-1) // 2)
        row = 1
if row > 1:
    ans += (row*(row-1) // 2)
print(str(ans))

Solution (Python):
from collections import Counter

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

Solution (Python):

def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)

N = int(input())
ans = 0
unmatch_words = []
words = {}
for i in range(N):
    s = input()
    sorted_s = "".join(sorted(s))
    
    if sorted_s in words:
        ans += words[sorted_s]
        words[sorted_s] += 1
    else:
        words[sorted_s] = 1


print(ans)

Solution (Python):
import collections

n = int(input())
s_count = list()
for i in range(n):
    s = input()
    s_list = ""
    for j in range(26):
        s_list += str(s.count(chr(j + 97)))
    s_count.append(s_list)
s = collections.Counter(s_count)
res = 0
for i in s.values():
    if i >= 2:
        res += i * (i - 1) // 2
print(res)

Solution (Python):
from math import factorial
n=int(input())
s=[]
k=1
ans=0
for i in range(n):
  s.append(sorted(input()))
s=sorted(s)
for j in range(n-1):
  if s[j]==s[j+1]:
    k+=1
  elif s[j]!=s[j+1] and k>2:
    ans+=factorial(k)/(factorial(2)*factorial(k-2))
    k=1
  elif s[j]!=s[j+1] and k==2:
    ans+=1
    k=1
  else:
    k=1
if k>2:
  ans+=factorial(k)/(factorial(2)*factorial(k-2))
elif k==2:
  ans+=1
print(int(ans))

Solution (Python):
from collections import Counter

n = int(input())
ans = 0
k = set()
c = Counter()

for _ in range(n):
    s = ''.join(sorted(list(input().rstrip())))
    if s in k:
        c[s] += 1
    k.add(s)

ans = 0
for ck in c.keys():
    ans += c[ck] * (c[ck] + 1) // 2

print(ans)

Solution (Python):
import collections

N = int(input())

si = []
base_i = ord('a')
for i in range(N):
    inp = input()
    si.append(str(sorted(inp)))

c = collections.Counter(si)

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

ans = 0
for i in c.values():
    if i > 1:
        ans += nc2(i)

print(ans)

Solution (Python):
n = int(input())
lists = []
for i in range(n):
    a = input()
    k = []
    for i in range(10):
        k.append(a[i])
    k.sort()
    lists.append(k)
lists.sort()
lists.append([])
count = -1
ans = 0
for i in range(n):
    if lists[i] != lists[i+1]:
        c = i-count
        count = i
        ans += c*(c-1)//2
print(ans)

Solution (Python):

def get_tousa(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans

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

s_hash = {}

for i in s:
    tmp = sorted(i)
    tmp = ''.join(tmp) 
    if tmp in s_hash:
        s_hash[tmp] += 1
    else:
        s_hash[tmp] = 0
s_hash = sorted(s_hash.items(), key = lambda x: x[1])


ans = 0
for i in s_hash:
    ans += get_tousa(i[1])
print(ans)

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

cnt = 1
S.append('end')
last = S[0]
res = 0
for s in S[1:]:
    if last == s:
        cnt += 1
    else:
        res += cnt * (cnt-1) /2
        last = s
        cnt = 1

print(int(res))

Solution (Python):
import collections
from math import factorial
n = int(input())
strs = ["".join(sorted(input())) for i in range(n)]
c = collections.Counter(strs)
ans = 0
for key, val in c.items():
	if val < 2:
		continue
	elif val == 2:
		ans += 1
	else:
		ans += factorial(val) // (2 * factorial(val - 2))
print(ans)

Solution (Python):


import sys
input=sys.stdin.readline
from collections import Counter

n=int(input())
s=[]
for i in range(n):
    a=sorted(list((input().rstrip('\n'))))
    a=''.join(a)
    s.append(a)
c=Counter(s)

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

print(cnt)

Solution (Python):
import collections

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


def main():
    for _ in range(n):
        w = list(input())
        w.sort()
        s.append("".join(w))

    counter = collections.Counter(s)
    _, c = zip(*counter.most_common())

    ans = 0

    for num in c:
        if num == 1:
            return ans
        ans += num * (num-1) // 2

    return ans


print(main())

Solution (Python):
from scipy.misc import comb

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





alpha2num = lambda c: ord(c) - ord('a')





s_list = [[0 for i in range(26)]for j in range(n)]





for i in range(n):
    for j in range(10):
        
        s_list[i][alpha2num(s[i][j])] += 1
        

s_list.sort()



ans = []
tmp = 0

for i in range(n-1):
    if s_list[i] == s_list[i+1]:
        if i == n-2:
            tmp += 1
            ans.append(tmp)
        tmp += 1
    else:
        ans.append(tmp)
        tmp = 0

f_ans = 0

for i in range(len(ans)):
    f_ans += (ans[i] + 1) * ans[i] * 0.5

print(int(f_ans))

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())
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 = readi()
t = []
for i in range(n):
    s = list(read())
    s.sort()
    t.append(s)
t.sort()
index = 0
count = 0

d = 0
for i in range(1,n):
    if t[index] == t[i]:
        d += 1
    else:
        if d >= 1:
            d += 1
            count += cmb(d, 2)
        d = 0
        index = i
if d >= 1:
    d += 1
    count += cmb(d,2)
print(count)

Solution (Python):
a=[]
b=int(input())
c=[]
d=[]
i=0
n=0
nn=0
while i<b:
    for x in input():
        c.append(x)
    c.sort()
    a.append(''.join(c))
    c=[]
    i+=1
a.sort()
i=1
while i<b:
    if a[i-1]==a[i]:
        if n==0:
            n=2
        else:
            n+=1
    else:
        if n!=0:
            d.append(n)
            n=0
    i+=1
if n!=0:
    d.append(n)
for x in d:
    nn+=x*(x-1)//2
print(nn)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize

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
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))

n = onem()
a =[]

for i in range(n):
    k = list(input())
    k.sort()
    a.append(k)

a.sort()
b = s(a)

co = 0

for i in range(len(b)):
    if b[i][1] != 1:
        co += cmb(b[i][1],2)
print(co)

Solution (Python):
N = int(input())
S = [input() for i in range(N)] 
s = []
for i in range(N):
  s+=["".join(sorted(S[i]))]
s.sort()
s+=[""]
before=s[0]
num=0
num2=1
for i in range(1,N+1):

  if s[i]==before:num2+=1
  else:
    if num2>1:
      num+=num2*(num2-1)//2
      num2=1
    before=s[i]
print(num)

Solution (Python):
from scipy.misc import comb
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
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"]
result = []
for n in range(N):
    res = {}
    for char in chars:
        res[char] = S[n].count(char)
    result.append(res)
result2 = Counter([str(i) for i in result ])
cnt = 0
for key in result2.keys():
    if result2[key] == 1:
        pass
    else:
        cnt += comb(result2[key],2,exact=True)
print(int(cnt))

Solution (Python):
from collections import Counter
n = int(input())
s = list(map(lambda x: ''.join(sorted(x)) ,[list(input()) for i in range(n)]))
ans = 0
for i in Counter(s).values():
    ans += int(i*(i-1) / 2)
print(ans)

Solution (Python):
N = int(input())
S = []
for i in range(N):
    S.append(input())
anaglams = {}
count = 0
for s in S:
    chrs = [0]*26
    for c in s:
        index = ord(c) - ord('a')
        chrs[index] += 1
    if str(chrs) not in anaglams:
        anaglams[str(chrs)] = 0
    else:
        anaglams[str(chrs)] += 1
    count += anaglams[str(chrs)]
print(count)

Solution (Python):
import collections

n=int(input())

alls=[]
for i in range(n):
  s=list(input())
  s.sort()
  s="".join(s)
  alls.append(s)
  
c = collections.Counter(alls)


aa=c.most_common()
n=len(aa)
allans=0
for j in range(n):
  num=aa[j][1]
  if num!=1:
    ans=num*(num-1)//2
    allans+=ans
print(allans)

Solution (Python):
import collections
n = int(input())
s = [input().strip() for u in range(n)]
r = [dict(collections.Counter(m)) for m in s]
t = ["".join(["{}{}".format(k, m[k]) for k in sorted(m.keys())]) for m in r]
u = dict(collections.Counter(t))
print(int(sum([v*(v-1)/2 for v in u.values()])))

Solution (Python):
N = int(input())
string = [0] * N
ans = 0
for i in range(N):

    mozi = input()
    for k in range(10):
        string[i] += (ord(mozi[k])-96)**10

string_new = sorted(string)
ite = 0
index = 0
while ite < N-1:
    index = ite + 1
    while string_new[ite] == string_new[index]:
        
        ans += index-ite
        index += 1

        if index >= N:
            break
    ite = index
print(ans)

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

string_dict = defaultdict(int)

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

    string_dict["".join(inp)] += 1


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

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

Solution (Python):
import sys
n = int(sys.stdin.readline())
s = [''.join(sorted(sys.stdin.readline().strip())) for _ in range(n)]

import collections
c = collections.Counter(s)

import math
def combination(v):
    return int(math.factorial(v) / (math.factorial(v - 2) * math.factorial(2)))
print(sum(combination(v) for v in c.values() if v != 1))

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

conbi = 0

strings = {}
for i in range(n):
  
  notinstr = 1
  s = input()
  l = 0
  for c in s:
    l += 10**(ord(c)-ord('a'))
  
  
  if l in strings:
    conbi += strings[l]
    strings[l] += 1
    
  else:
    strings[l] = 1
  
print(conbi)

Solution (Python):
wa = [0, 0, 1]
for i in range(2, 100005):
    wa.append(wa[-1]+i)




N = int(input())


data = {}

ans = 0
for i in range(N):
    s_list = list(str(input()))
    s_list = sorted(s_list)
    hoge = "".join(s_list)
    data.setdefault(hoge, 0)
    data[hoge] += 1

for v in data.values():
    ans += wa[v]

print(ans)

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

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

Solution (Python):
counter = 0

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

import collections
dic = collections.Counter(lst)

for i in dic.values():
    if i == 0:
        continue
    counter = counter +  i * (i - 1) / 2
print(int(counter))

Solution (Python):
import collections
import math

n = int(input())
s = []
for i in range(n):
    ss = input()
    s.append(tuple(sorted(collections.Counter(list(ss)).items())))
s = sorted(s)

ans = []
px = None
a = 0
for x in s:
    if x == px:
        a += 1
    else:
        px = x
        if a > 0:
            ans.append(a + 1)
        a = 0
if a > 0:
    ans.append(a + 1)
print(sum([math.factorial(a) // (2 * math.factorial(a - 2)) for a in ans]))

Solution (Python):
from collections import Counter
N = int(input())
anagram = Counter()
for i in range(N):
    anagram[''.join(sorted(input()))]+=1

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

Solution (Python):
import collections
n = int(input())
moji = []
ans = 0
for i in range(n):
    tmp = list(input())
    tmp.sort()
    moji.append(''.join(tmp))
cnt = collections.Counter(moji)
for i in cnt.values():
    if i != 1:
        ans += i*(i-1)//2
print(ans)

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

Solution (Python):
n = int(input())
ans = 0
dic1 = {}
for _ in range(n):
    s = list(input())
    key = ""
    dic = {}
    for i in s:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
    for k in sorted(dic.keys()):
        key += "{}{}".format(k, dic[k])

    if key in dic1:
        dic1[key] += 1
    else:
        dic1[key] = 1

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

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

def get_sum(num):
    return num*(num-1)/2


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

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))

Solution (Python):
from collections import Counter

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

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

Solution (Python):
n=int(input())
mojilist=[]

for i in range(n):
    moji=input()
    moji2=sorted(moji)
    
    mojilist.append(moji2)

mojilist=sorted(mojilist)
combo=0
answer=0
for i in range(n-1):
    if mojilist[i]==mojilist[i+1]:
        combo+=1
    else:
        if combo!=0:
            answer+=int(combo*(combo+1)/2)
        combo=0

if combo!=0:
    answer+=int(combo*(combo+1)/2)

print(answer)

Solution (Python):
import math
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
s = [sorted(input())]
ans = 0
for i in range(N-1):
  s_i = sorted(input())
  s.append(s_i)
s = sorted(s)
count=1
for j in range(N-1):
  if s[j] == s[j+1]:
    count+=1
  else:
    if count != 1:
      ans += combinations(count,2)
    count=1
if count != 1:
  ans += combinations(count,2)
print(ans)

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

logging.basicConfig(level=logging.INFO, format="%(message)s")


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

def C(n, r):
    return P(n, r)//math.factorial(r)

def main():
    N = int(input())
    S_ = ["".join(sorted(list(input()))) for _ in range(N)]
    
    logging.info(S_)

    counters = dict(Counter(S_))

    logging.info(counters)
    
    ans = 0
    for key, val in counters.items():
        if val != 1:
            ans += C(val, 2)

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

Solution (Python):
import math
n = int(input())
s = []
for i in range(n):
    a = input()
    a = [i for i in a]
    a = sorted(a)
    s.append(a)
count = 0
s = sorted(s)
p = 0
try:
    for i in range(len(s)):
        if s[i]==s[i+1]:
            p+=1
        else:
            count+=sum(list(range(p+1)))
            p=0
except:
    count+=sum(list(range(p+1)))
print(count)

Solution (Python):
from collections import Counter
import math
n=int(input())
s=[['']*10]*n

def com(n, r):
    if n>=r:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
for i in range(n):
    s[i]=list(input())
    s[i].sort()
s=map(tuple,s)
c=dict(Counter(s))
x=0
for i in c.values():
    x+=com(i,2)
print(x)

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

N = int(sys.stdin.readline())
s_list = ["".join(sorted(list(sys.stdin.readline().rstrip()))) for x in range(N)]
s_list = Counter(s_list)
count = 0
for i in s_list.values():
    if i == 1:
        continue
    count += (math.factorial(i) // math.factorial(i - 2)) // math.factorial(2)
print(count)

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

res = []
ans = 0
res.append(s_list[0])
for j in range(N-1):
    if s_list[j] == s_list[j+1]:
        res.append(s_list[j+1])
    else:
        if len(res) >=2:
            ans += (len(res) * (len(res)-1)) //2
        res = []
        res.append(s_list[j+1])

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

print(ans)

Solution (Python):
def factorial(n):
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a

def nCr(n,r):
    if r > n:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def nC2(n):
    if n < 2:
        return 0
    else:
        return n * (n-1) // 2



N = int(input())
sorted_dic = {}
for i in range(N):
    s = "".join(sorted(input()))
    v = 0
    if s in sorted_dic:
        v = sorted_dic[s]
    sorted_dic[s] = v + 1

ans = 0
for k in sorted_dic:
    v = sorted_dic[k]
    
    ans = ans + nC2(v)

print(ans)

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

sList = {}

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

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

ans = 0
for _, num in sList.items() :
    ans += num * (num - 1) // 2

print(ans)

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

S = []
cnt = 0
c = {}

for i in range(N):
    s = "".join(sorted(list(input())))
    if s not in c.keys():
        c[s] = 1
    else:
        c[s] += 1
        cnt += c[s]-1
        
    S.append(s)

print(cnt)

Solution (Python):
from sys import stdin
data = []
N = int(stdin.readline().rstrip())
for _ in range(N):
    data.append(tuple(sorted(input())))


ans = dict()

for i in data:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1

from scipy.misc import comb
res = 0
for j in ans.values():
    res += comb(j, 2, exact=True)
print(res)

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 _ in range(n)]

c=collections.Counter(S)
ans=0
for i in c.values():
    if i==2:
        ans+=1
    elif i>2:
        ans+=cmb(i,2)
print(ans)

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

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

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

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

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

Solution (Python):



import sys
from operator import mul
from functools import reduce

input = sys.stdin.readline

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

def comb(a, b):
    n = a
    for _ in range(b):
        n -= 1
        a *= n

    for i in range(1, b):
        b *= i
    return int(a / b)


def main():
    n = int(input())
    m = {}
    for l in sys.stdin:
        s = ''.join(sorted(l.strip()))
        if s in m:
            m[s] += 1
        else:
            m[s] = 1
    cnt = 0
    for k, v in m.items():
        if v == 1:
            continue
        if v == 2:
            cnt += 1
        else:
            cnt += cmb(v, 2)
    print(cnt)

main()

Solution (Python):
def int_multiple():
    return  [int(c) for c in input().split()]

def int_single():
    return int(input())

def str_multiple():
    return [c for c in input().split()]

def str_single():
    return input()


N = int_single()


hash = []

d = {}

primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]

for i in range(N):
    tmp = str_single()
    checksum = 1
    for ch in tmp:
        checksum *= primes[ord(ch)-97]

    if checksum in d:
        d[checksum] += 1
    else:
        d[checksum] = 1

res = 0
for key in d:
    if d[key] >= 2:
        res += int((d[key] * (d[key] - 1)) / 2)

print(res)

Solution (Python):
from functools import reduce

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

N = int(input())

strings = {}
for i in range(N):
    key = ''.join(sorted(list(input())))
    strings.setdefault(key, 0)
    strings[key] += 1
ans = 0

for k, v in strings.items():
    if v > 1:
        ans += cmb(v, 2)

print(ans)

Solution (Python):
n=int(input())
s=[]
for _ in range(n):
    s.append(input())
for i in range(n):
    s[i]=sorted(s[i])
s.sort()
num=0
last=1
counter=[]
while num<n-1:
    if s[num]!=s[num+1]:
        num+=1
        counter.append(last)
        last=1
    elif s[num]==s[num+1]:
        num+=1
        last+=1
if last>1: counter.append(last)

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