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

n = int(input())
di = dict()
answer = 0

for i in range(n):
    tmp = str(sorted(input()))
    if di.get(tmp, 0) == 0:
        di[tmp] = 1
    else:
        answer += di[tmp]
        di[tmp] += 1

print(answer)

Solution (Python):
from collections import Counter

num = int(input())
input = [input() for i in range(num)]
rv = 0
counters = [sorted(Counter(s).elements()) for s in input]
strings = ["".join(s) for s in counters]
counts = list(Counter(strings).values())
for c in counts:
  rv += sum(x for x in range(1,c))
print(rv)

Solution (Python):
from collections import Counter

num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
x = Counter(words)
res = 0
for c in x.values():
    res += (c**2 - c)//2
print(res)

Solution (Python):
import collections


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

S = collections.Counter(S)

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

print(ans)

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

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if str(L[i]) in flag:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)

Solution (Python):
n = int(input())
dicte = {}
count = 0
for i in range(n):
    s = list(input())
    z = ''.join(sorted(s))
    if z in dicte:
        dicte[z] += 1
    else:
        dicte[z] = 1
for i in dicte.keys():
    count += ((dicte[i] * (dicte[i]-1))//2)
print(count)

Solution (Python):
from sys import stdin, exit
from math import factorial
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

def choose(x):
  return factorial(x)/(2*factorial(x-2))

words = {}

for i in range(int(input())):
    s = "".join(sorted(si()))
    if s not in words:
        words[s] = 1
    else:
        words[s] += 1
ans = 0
for i in words:
    if words[i] == 1: continue
    ans += choose(words[i])
print(int(ans))

Solution (Python):
dct, count = {}, 0
N = int(input())
for i in range(N):
    tmp = "".join(sorted(input()))
    if dct.get(tmp) is None:
        dct[tmp] = 1
    else:
        count += dct[tmp]
        dct[tmp] += 1
print(count)

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

def com(n , r):
    if n == 1:
        return 0
    else:
        return factorial(n) // (factorial(n - r) * factorial(r))
N = int(input())
S = []
for _ in range(N):
    s = input()
    S.append("".join(sorted(s)))
CS = Counter(S)
ans = 0
for val in CS.values():
    ans += com(val , 2 )
print(ans)

Solution (Python):


def solve():
    N = int(input())
    d = dict()
    for i in range(N):
        s = list(input())
        s.sort()
        s = tuple(s)
        if s in d:
            d[s] += 1
            continue
        d[s] = 0

    ans = 0
    for key, val in d.items():
        if val == 0:
            continue
        ans += (val+1)*val//2

    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
s = list(list(input()) for _ in range(N))

for i in range(N):
    s[i].sort()

s.sort()

a = 0
answer = 0

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

print(answer)

Solution (Python):
N = int(input())
dic = {}
s = 0
for n in range(N):
  v = ''.join(sorted(input()))
  if dic.get(v) is None:
    dic[v] = 1
  else:
    s += dic[v]
    dic[v] += 1
print(s)

Solution (Python):
from math import factorial
N = int(input())
s = {}
for i in range(N):
    w = sorted(list(input()))
    w = ''.join(w)
    if w in s :
      s[w]+=1
    else:
      s[w] = 1

count = 0
for k in s:
  if s[k] >= 2:
    count += factorial(s[k]) // (factorial(s[k] - 2) * factorial(2))
    
print(count)

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = collections.Counter(["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)])
    cnt = 0
    for k, v in s.items():
        for i in range(1, v):
            cnt += i
    print(cnt)


if __name__ == '__main__':
    slove()

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = collections.Counter(["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)])
    cnt = 0
    for k, v in s.items():
        for i in range(1, v):
            cnt += i
    print(cnt)


if __name__ == '__main__':
    slove()

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

Solution (Python):
import collections

n = int(input())
a = [0]*n
count = 0
for i in range(n):
  a[i] = list(input())
  a[i].sort()
  d = ""
  for j in a[i]:
    d += j
  a[i] = d
c = collections.Counter(a)
for i in c.values():
  count += (i-1) * i // 2
print(count)

Solution (Python):
from collections import Counter

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

count = Counter(si)

ans = 0
for s in set(si):
    n = count[s]
    ans += n * (n-1) // 2

print(ans)

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

L = ["0"]*N
for i in range(N):
    temp = ["0"]*10
    for j in range(10):
        temp[j] = S[i][j]
    temp.sort()
    L[i] = temp
        
L.sort()
ans = 0
cnt = 1
temp = L[0]
for i in range(1, N):
    if temp == L[i]:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt = 1
        temp = L[i]
        
ans += cnt*(cnt-1)//2
print(ans)

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

L = ["0"]*N
for i in range(N):
    temp = ["0"]*10
    for j in range(10):
        temp[j] = S[i][j]
    temp.sort()
    L[i] = temp
        
L.sort()
ans = 0
cnt = 1
temp = L[0]
for i in range(1, N):
    if temp == L[i]:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        cnt = 1
        temp = L[i]
        
ans += cnt*(cnt-1)//2
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter

N = map(int,readline())
S = [''.join(sorted(x.decode('utf-8'))) for x in read().split()]

counter = Counter(S)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

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

l = []
cnt = 0
t = 0

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

l.sort()

tmp = l[0]

for i in range(1, n):
  if tmp == l[i]:
    cnt += 1
  else:
    tmp = l[i]
    t += int(cnt * (cnt + 1) / 2)
    cnt = 0
else:
    t += int(cnt * (cnt + 1) / 2)

print(t)

Solution (Python):
from collections import defaultdict

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

d = defaultdict(lambda: 0)
ans = 0

for i in s:
    d[ str(sorted(i)) ] += 1

for i in d.keys():
    count = int(d[i])
    if count > 1:
        ans += (count * (count - 1)//2)

print(ans)

Solution (Python):
n = int(input())
l = []
for _ in range(n):
	s = input()
	l.append(''.join(sorted(s)))
l.sort()
res=0
ile = 1
for i in range(1, n):
	if l[i] == l[i-1]:
		ile+=1
	else:
		res+=ile * (ile-1) // 2
		ile=1
res+=ile * (ile-1) // 2
print (res)

Solution (Python):
N=int(input())
S=["".join(sorted(input())) for n in range(N)]
d={}
for s in S:
    if s not in d:
        d[s]=1
    else:
        d[s]+=1
c=0
for k in d:
    n=d[k]
    c+=(n*(n-1))//2
print(c)

Solution (Python):
N = int(input())
S =[]
for i in range(N):
  s = list(str(input()))
  s.sort()
  s = ''.join(s)
  S.append(s)
from collections import Counter
l = Counter(S)
count = []
for i in l.values():
  count.append(i*(i-1)/2)
print(int(sum(count)))

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    string = {}
    ret = 0
    for n in range(N):
        cur_char = ''.join(sorted(input()))
        if cur_char in string:
            ret += string[cur_char]
        string[cur_char] = string.get(cur_char, 0) + 1
    print(ret)

Solution (Python):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()

  d = {}
  for _ in range(n):
    s = "".join(sorted(ns()))
    if s in d:
      d[s] += 1
    else:
      d[s] = 1

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

main()

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

for idx in range(N):
	s = input()
	allist = [c for c in s]
	allist.sort()
	sortedstr = ''.join(allist)
	count[sortedstr] = count.get(sortedstr, 0) + 1

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

print(ans)

Solution (Python):
from collections import defaultdict
myDict = defaultdict(int)

n = int(input().strip())
ans = 0
for _ in range(n):
    s = input().strip()
    s = ''.join(sorted(s)) 
    ans += myDict[s]
    myDict[s] += 1

print(ans)

Solution (Python):
import sys



def solve(lines):
    def c(n):
        if n == 1:
            return 0
        else:
            return n * (n - 1) // 2


    N = int(lines.pop(0))
    NLIST = {}
    for i in range(N):
        l = ''.join(sorted(lines.pop(0)))
        if l in NLIST:
            NLIST[l] += 1
        else:
            NLIST[l] = 1

    re = 0
    for n in NLIST.values():
        re += c(n)
    print(re)
lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

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

to = 0
for i in range(N):
	st = input()
	st = str(sorted(st))
	if i == 0 or not st in s:
		s[st] = 1
	elif st in s:
		cnt = s[st]
		to += cnt
		s[st] = cnt + 1

print(to)

Solution (Python):
from collections import Counter as co
n=int(input())
a=[str(sorted(input())) for _ in range(n)]
d=co(a)
l=d.values()
c=0
for i in l:
  c+=(i*(i-1))//2
print(c)

Solution (Python):
def aa(num):
    b=1
    c=0
    for i in range(num-1):
        c+=b
        b+=1
    return c

n=int(input())
s=[]
for i in range(n):
    word=list(input())
    word2=sorted(word)
    word3="".join(word2)
    s.append(word3)
s2=sorted(s)
ans=0
now=s2[0]
num=0
for i in range(n):
    if now==s2[i]:
        num+=1
    else:
        ans+=aa(num)
        now=s2[i]
        num=1
print(ans+aa(num))

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

for index in range(n):
    temp = ''.join(sorted(list(input())))
    
    if temp in dic:
        dic[temp] = dic[temp] + 1
        
    else:
        dic[temp] = 1
        
ans = 0

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

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

dic = {}

for index in range(N):
    temp = "".join(sorted(list(input())))
    if temp in dic:
        dic[temp] = dic[temp] + 1
    else:
        dic[temp] = 1
ans = 0
for k in dic.values():
    cnt = 0
    for i in range(k):
        cnt += i
    ans += cnt

print(ans)

Solution (Python):
n = int(input())
strings = {}
answer = 0
for i in range(n):
  string = input()
  string = ''.join(sorted(string))
  if string not in strings:
    strings[string]=1
  else:
    answer += strings[string]
    strings[string] += 1
print(answer)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def conb(n,r): 
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
s = []
for i in range(n):
    tmp = list(input())
    s.append(sorted(tmp))
s.sort()

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

res = 0
for i in cnt:
    res += conb(i+1, 2)
print(res)

Solution (Python):
n = int(input())
dic = {}
ans = 0
for i in range(n):
    s = str(sorted(input()))
    if dic.get(s) != None:
        ans += dic[s]
        dic[s] = dic[s] + 1
    else:
        dic[s] = 1
print(ans)

Solution (Python):
from collections import defaultdict

if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    words = defaultdict(lambda: 0)
    for i in range(n):
        words[''.join(sorted(input()))] += 1
    sum = 0
    for word in words:
        sum += int(words[word]*(words[word] - 1)/2)
    print(sum)

Solution (Python):
from collections import defaultdict
from math import factorial
if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    words = defaultdict(lambda: 0)
    for i in range(n):
        words[''.join(sorted(input()))] += 1
    sum = 0
    for word in words:
        sum += int(factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2))))
    print(sum)

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

mem = dict()
for _ in range(N):
    s = ''.join(sorted(input()))
    if s in mem.keys():
        mem[s] += 1
    else:
        mem[s] = 1

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

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


def main():
    N = int(input().strip())
    s_list = [sorted(input().strip()) for _ in range(N)]
    s_list = sorted(s_list)
    ans = 0
    duplicate_num = 0
    for index in range(len(s_list)-1):
        if s_list[index] == s_list[index+1]:
            duplicate_num += 1
        else:
            ans += duplicate_num * (duplicate_num+1) // 2
            duplicate_num = 0
    ans += duplicate_num * (duplicate_num+1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import collections
import math

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

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

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()
len_C = len(C)

for n in range(len_C):
    if C[n][1] > 1:
        ans += combination(C[n][1], 2)
    else:
        pass

print(round(ans))

Solution (Python):
n = int(input())
col = {}
for i in range(n):
  s = list(input())
  s.sort()
  s2 =''.join(s)
  if s2 in col:
    col[s2]+=1
  else:
  	col[s2] = 1
com = lambda x : x*(x-1)/2
print(int(sum(com(col[k]) for k in col)))

Solution (Python):
N=int(input())
S=[''.join(sorted((input()))) for i in range(N)]
P={}
for i in range(N):
    if S[i] in P:
        P[S[i]]+=1
    else:
        P[S[i]]=0
for i in P.keys():
    if P[i]>=2:
        P[i]=P[i]*(P[i]+1)/2
print(int(sum(P.values())))

Solution (Python):
n=int(input())
s=[input() for i 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())

d={}
for i in range(n):
      tx="".join(sorted(input()))
      if tx in d:
            d[tx] += 1
      else:
            d[tx] = 1


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

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

c = Counter(s)
print(sum((x * (x - 1)) // 2 for x in c.values()))

Solution (Python):

"""
Created on Wed Sep 25 08:58:11 2019

@author: avina
"""

n = int(input())
d = {}
for i in range(n):
  a = list(input())
  a.sort()
  a = ''.join(a)
  if a not in d:
    d[a] = 1
  else:
    d[a]+=1
ans = 0
for i in d:
    ans += ((d[i])*(d[i]-1))//2
print(ans)

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

import sys
input = sys.stdin.readline

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

for i in range(N):
    s[i].sort()

out=0

d={}

for i in range(N):
    if str(s[i]) in d:
        out+=d[str(s[i])]
        d[str(s[i])]+=1
    else:
        d[str(s[i])]=1

print(out)

Solution (Python):
from collections import Counter
import itertools

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

Solution (Python):

import collections
n=int(input())
Words = [input() for t in range(n)]

Words2=[]
for i in Words:
        i=''.join(sorted(i))
        Words2.append(i)

c = collections.Counter(Words2)

values, counts = zip(*c.most_common())

ans=0
for j in counts:
        ans+=j*(j-1)//2
print(ans)

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = collections.Counter(["".join(sorted(str(input().rstrip('\n')))) for _ in range(n)])
    t = 0
    for k, v in s.items():
        for i in range(1, v):
            t += i
    print(t)


if __name__ == '__main__':
    slove()

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

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

s_srt = []
for i in range(n):
    s_srt.append(''.join(sorted(s[i])))
s_srt.sort()

tmp = [0,]
k = 0
next = False
for i in range(n - 1):
    if s_srt[i] == s_srt[i + 1]:
        tmp[k] += 1
        next = True
    else:
        if next:
            tmp.append(0)
            k += 1
if tmp[-1] == 0:
    tmp.remove(0)

ans = 0
m = len(tmp)
if m != 0:
    for i in range(m):
        ans += int((tmp[i] + 1) * tmp[i] / 2)

print(ans)

Solution (Python):
import collections as co
n=int(input())
cnt=0
s=[''.join(sorted(input())) for _ in range(n)]
m=co.Counter(s)
for item in m:
    cnt += m[item]*(m[item]-1)/2
print(int(cnt))

Solution (Python):
import collections as co
n=int(input())
cnt=0
s=[''.join(sorted(input())) for _ in range(n)]
m=co.Counter(s)
for item in m:
    cnt += m[item]*(m[item]-1)/2
print(int(cnt))
'''
for i in range(1,n):
    for j in range(i):
        if s[j] == s[i]:
            cnt+=1
print(cnt)
'''

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

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
dup = collections.Counter(s).values()

ans = sum(c*(c-1)//2 for c in dup)
print(ans)

Solution (Python):
import collections, math

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

for idx in range(N):
    s_l[idx] = "".join(sorted(s_l[idx]))

c = collections.Counter(s_l)
ans = 0

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

print(int(ans))

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

N=int(input())

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

print(ans)

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

s_sorted = sorted([sorted(si) for si in s])

ans = 0
for i, si in enumerate(s_sorted):
    if i == 0:
        cnt = 1
        si_prev = si
    else:
        if si != si_prev:
            ans += (cnt * (cnt - 1) // 2)
            cnt = 1
        else:
            cnt += 1
        
        si_prev = si
else:
    ans += (cnt * (cnt - 1) // 2)
    
print(ans)

Solution (Python):
import collections
N=int(input())
su=["".join(sorted(list(input()))) for _ in range(N)]

C=list(collections.Counter(su).values())

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

print(ans)

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

a=[]

for j in s:
    a.append("".join(sorted(j)))

import collections
c = collections.Counter(a)

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

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

ans = 0
count = 1
s_pre = s[0]

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

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

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

count=0
dic=dict()

for i in range(N):
    s="".join(sorted(input()))


    if s in dic:
        count+=dic[s]

        dic[s]+=1
    else:
        dic[s]=1


print(count)

Solution (Python):
import collections

n = int(input())

a = [str(sorted(input())) for _ in range(n)]
a.sort()
s = set(a)

c = collections.Counter(a)

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

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = [''.join(sorted(input())) for i in range(N)]
result = 0
c = {}
for s in S:
    if c.get(s) is None:
        
        c[s] = 1
    else:
        result += c[s]
        c[s] += 1
print(result)

Solution (Python):
from collections import  Counter

N=int(input())

S=[input() for i in range(N)]

ctr= Counter()

ans=0

for s in S:
    a = ''.join(sorted(list(s)))
    if a in ctr:
        ans += ctr[a]
    ctr[a] +=1

print(ans)

Solution (Python):
from collections import defaultdict


def main():
    s = ["".join(sorted(i)) for i in open(0).read().split()[1:]]
    d = defaultdict(lambda: 0)
    ans = 0
    for i in s:
        ans += d[i]
        d[i] += 1
    print(ans)
    return


main()

Solution (Python):
from collections import Counter


from scipy.misc import comb



def main():
    s = Counter(["".join(sorted(i)) for i in open(0).read().split()[1:]])
    ans = 0
    for v in s.values():
        ans += comb(v, 2, exact=True)
    print(int(ans))
    return


main()

Solution (Python):
N = int(input())
l = {}
result = 0

for i in range(N):
  s = "".join(sorted(list(input())))
  l[s] = l.get(s, 0) + 1
  
for v in l.values():
  result += v * (v - 1) / 2

print(int(result))

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

for i in range(N):
  S = "".join(sorted(input()))
  if S in dic:
    dic[S] += 1
  else:
    dic[S] = 1

ans = 0

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

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

s = {}
for i in range(n):
      text ="".join(sorted(input()))
      if text in s:
            s[text] += 1
      else:
            s[text] = 1

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

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

ans = 0
ans_dict = {}

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

Solution (Python):
import collections

n=int(input())
s=[]
set={}
for i in range(n):
    s.append(input())
for i in range(n):
    temp=list(s[i])
    temp.sort()
    s[i]=''.join(temp)
count=0
ans=collections.Counter(s)
countlist=ans.most_common()
for i in range(len(countlist)):
    if countlist[i][1]<=1:
        break
    else:
        temp=countlist[i][1]-1
        count+=(temp+1)*temp//2

print(count)

Solution (Python):
from collections import Counter
from math import factorial
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = Counter(s)
counter = 0


def kza(a, b):
    return (factorial(a) / factorial(a-b)) / factorial(b)


for i in c.values():
    if i == 1:
        continue
    counter += kza(i, 2)


print(int(counter))

Solution (Python):
from math import factorial as fac


def binomial(x, y):
    try:
        binom = fac(x) // fac(y) // fac(x - y)
    except ValueError:
        binom = 0
    return binom

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

dct = {}
for i in range(n):
    if arr[i] not in dct.keys(): 
        dct[arr[i]] = 1
    else:
        dct[arr[i]] += 1
        
cnt = 0
l = len(dct.keys())
dctlist = list(dct.keys())
for i in range(l):
    el = dctlist[i]
    if dct[el] > 1:
        cnt += binomial(dct[el],2)
print(cnt)

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


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


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

    cnt = 0
    for key in d:
        cnt += cmb(d[key], 2)
    
    print(cnt)


if __name__ == '__main__':
    main()

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

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

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

count = {}
for i in s:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1

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

print(sum)

Solution (Python):
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += c * (c-1) // 2
print(t)

Solution (Python):
n=int(input())
L={}
for i in range(n):
    l=''.join(sorted(list(input())))
    if l in L:
        L[l]+=1
    else:
        L[l]=1
c=0
for v in L.values():
    if v>=2:
        c+=v*(v-1)//2
print(c)

Solution (Python):
N = int(input())
S = dict()
for i in range(N):
    r = 0
    s = input()
    s = "".join(sorted(s))
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1
res = 0
for s in S:
    if S[s] > 1:
        res += (S[s]-1)*S[s] // 2
print(res)

Solution (Python):
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)

Solution (Python):
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())

S = list()
num = {}
ans = 0

for i in range(N):
    S.append(list(input()))
    S[i].sort()
    if "".join(S[i]) in num:
        num["".join(S[i])] += 1
        ans += num["".join(S[i])]
    else:
        num["".join(S[i])] = 0

print(ans)

Solution (Python):
import collections

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

for i in range(N):
  s = input()
  ss = [i for i in s]
  ss.sort()
  s = ''.join(ss)
  S.append(s)
  
c = collections.Counter(S)
ans = 0

for b in c:
  ans += c[b] * (c[b] - 1) // 2
  
print(ans)

Solution (Python):
N = int(input())
d = {}
x = 0
for i in [0]*N:
    s = ''.join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0
for p in d.values():
    x += (p+1) * p // 2
print(x)

Solution (Python):
N = int(input())
dic = {}
 
for i in range(N):
    s = list(input())
    s.sort()
    key = str(s)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1
 
ans = 0
for value in dic.values():
    ans += value*(value-1) / 2
print(int(ans))

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

print(ans)

Solution (Python):


import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq





def solve(f):
    n = f.read_int()
    d = collections.defaultdict(int)
    for _ in xrange(n):
        s = f.read_str()
        ss = "".join(sorted(list(s)))
        d[ss] += 1

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

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case 
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Solution (Python):
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)

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

ans = 0
count = {}
for i in range(n):
    c = ''.join(sorted(s[i]))
    count.setdefault(c,0)
    count[c] += 1
    if(count[c] > 0):
        ans += count[c] -1

print(ans)