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())
import collections
chk = collections.deque([])
for i in range(n):
  s = input()
  s = sorted(s)
  chk.append(''.join(s))

c = collections.Counter(chk)
c = dict(c)
ans = 0
for i in c.values():
  ans += i*(i-1)//2
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)




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


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

Solution (Python):
n = int(input())
s = [input()for  _ in range(n)]
cnt = {}
for x in s:
    p = list(x)
    p.sort()
    b = "".join(p)
    if "".join(p) not in cnt:cnt[b] = 1
    else:cnt[b] +=1
ans = 0
for key in cnt:
    v = cnt[key]
    ans +=v*(v-1)//2
print(ans)

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

Solution (Python):
from collections import Counter
n = int(input())
b = []
for i in range(n):
    a = "".join(sorted(input()))
    b.append(a)
c = list(Counter(b).values())
ans = 0
for j in c:
    ans += int((j-1)*j/2)
print(ans)

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

s=[]
for i in range(n):
  S=input()
  S=list(S)
  S.sort()
  S=''.join(S)
  s.append(S)
from collections import defaultdict as dd
d=dd(int)
for ss in s:
  d[ss]+=1
ans=0
for k,v in d.items():
  ans+=v*(v-1)//2
print(ans)

Solution (Python):
import collections
N = int(input())
l = []
for i in range(N):
  s = input()
  ls = []
  for j in range(10):
    ls.append(s[j])
  ls.sort()
  sm = ""
  for j in range(10):
    sm += ls[j]
  l.append(sm)

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

Solution (Python):
N = int(input())
Sn = [ ''.join(sorted(input())) for _ in range(N)]
Sn_key = {}
for s in Sn:
    if s not in Sn_key:
        Sn_key[s] = 1
    else:
        Sn_key[s] += 1
cnt = 0

for v in Sn_key.values():
    if v >= 2:
        cnt += v * (v-1) // 2
print(cnt)

Solution (Python):
from collections import defaultdict

N = int(input())

cnt = defaultdict(int)

ans = 0
for _ in range(N):
    s = list(input())
    s.sort()
    s = str(s)
    ans += cnt[s]
    cnt[s] += 1

print(ans)

Solution (Python):
from collections import defaultdict
counter = defaultdict(int)
N = int(input())
for i in range(N):
    counter[tuple(sorted(list(input())))] += 1
ans = 0
for n in counter.values():
    ans += n * (n - 1) // 2
print(ans)

Solution (Python):
N = int(input())
s = {}
for _ in range(N):
  a = "".join(sorted(input()))
  if a not in s:
    s[a] = 0
  else: s[a] += 1

ans = 0
for v in s.values():
  if v < 2: ans += v
  if v > 1: ans += v * (v+1) // 2
print(ans)

Solution (Python):
n = int(input())
s = []
for _ in range(n):
    s.append(input())
di = {}
for i in s:
    tmp = [0]*26
    for c in i:
        tmp[ord(c)-ord('a')] += 1
    tmp = tuple(tmp)
    if tmp in di:
        di[tmp] += 1
    else:
        di[tmp] = 1

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

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

t = collections.defaultdict(int)
ans = 0

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


for x in t:
    ans += (t[x] * (t[x] - 1)) // 2

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

memo = defaultdict(int)
L = []
for i in range(N):
    l = list(S[i])
    l.sort()
    l = "".join(l)
    memo[str(l)] += 1

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

Solution (Python):
N = int(input())
counts = dict()
for i in range(N):
    s = input()
    s_lst = list(s)
    s_lst.sort()
    s = "".join(s_lst)
    if s in counts:
        counts[s] += 1
    else:
        counts[s] = 1

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

Solution (Python):
from collections import Counter

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

ans = 0

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

print(ans)

Solution (Python):
def examA():
    N = I()
    L = LI()
    L.sort()
    if sum(L)<=L[-1]*2:
        print("No")
    else:
        print("Yes")
    return

def examB():
    N, M = LI()
    A = [LI()for _ in range(N)]
    A.sort(key=lambda x:x[0])
    ans = 0
    for a,b in A:
        if M<=b:
            ans += a*M
            break
        ans += a*b
        M -= b
    print(ans)
    return

def examC():
    N = I()
    S = [SI()for _ in range(N)]
    D = defaultdict(int)
    for s in S:
        cur = []
        for i,j in Counter(s).items():
            cur.append((i,j))
        
        cur.sort()
        cur = tuple(cur)
        D[cur] += 1
    ans = 0
    for d in D.values():
        ans += (d-1)*d//2
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
def main():
    n = int(input())
    answer = 0
    count = {}
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in count:
            answer += count[s]
            count[s] += 1
        else:
            count[s] = 1
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import math

def ABC137C(i):
    if i!=1:
        return math.factorial(i)//math.factorial(i-2)//2
    else:
        return 0

n,*a=open(0).read().split()
a=[''.join(sorted(i)) for i in a]
d=dict()
p=0
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d.values():
    p+=ABC137C(i)
print(p)

Solution (Python):
def main():
    n=int(input())
    s=[]
    for i in range(n):
        si=list(input())
        si.sort()
        s.append(si)
    s.sort()
    s.append("X")
    cnt=1
    ans=0
    for i in range(n):
        if s[i]==s[i+1]:
            cnt+=1
        else:
            ans+=cnt*(cnt-1)//2
            cnt=1
    print(ans)
if __name__=="__main__":
    main()

Solution (Python):
import collections

N=int(input())
ans=0
s=[input() for x in range(N)]

d={}

for i in range(N):

  temp=str(sorted(s[i]))

  if temp in d.keys():
    ans+=d[temp]
    d[temp]+=1
  else:
    d[temp]=1

print(ans)

Solution (Python):
from collections import Counter
s = 0
n = int(input())
l =[k for j,k in Counter(["".join(sorted(input())) for i in range(n)]).items() if k>=2]
for i in l:
  s += (i*(i-1))//2
print(s)

Solution (Python):


data=int(input())
array=[''.join(sorted(input())) for i in range(data)]
sets={}
count=0
for i in range(data):
    if array[i] not in sets:
        sets[array[i]]=1
    else:
        sets[array[i]]+=1
        count+=sets[array[i]]-1
print(count)

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    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 k,v in dic.items():
        ans += (v * (v-1))//2
    print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = 0
    di = {}
    for n in range(N):
        s = ''.join(sorted(iss()))
        if s in di:
            di[s] += 1
            ret += di[s]
        else:
            di[s] = 0
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=[]
for _ in range(n):
  s0=list(input())
  s0.sort()
  s.append(''.join(s0))
s.sort()
ans=0
p=s[0]
pc=1
for i in range(1,n):
  if p==s[i]:
    pc+=1
  else:
    ans+=pc*(pc-1)//2
    pc=1
    p=s[i]
ans+=pc*(pc-1)//2
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


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

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

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

Solution (Python):
import sys
from collections import Counter

import sys
sys.setrecursionlimit(10**6)
table = dict()
def choose(n, r, mod=None): 
  if r > n or r < 0: return 0
  if r == 0: return 1
  if (n, r) in table: return table[(n, r)] 
  table[(n, r)] = (choose(n - 1, r) + choose(n - 1, r - 1))
  
  return table[(n,r)]

n = int(sys.stdin.readline().rstrip())
s = [''.join(sorted(s)) for s in sys.stdin.read().split()]

def main():
    tot = 0
    for c in Counter(s).values():
        tot += choose(c, 2)
    print(tot)

if __name__ ==  '__main__':
    main()

Solution (Python):
import sys
from collections import Counter

import sys
sys.setrecursionlimit(10**6)
table = dict()
def choose(n, r, mod=None): 
  if r > n or r < 0: return 0
  if r == 0: return 1
  if (n, r) in table: return table[(n, r)] 
  table[(n, r)] = (choose(n - 1, r) + choose(n - 1, r - 1))
  
  return table[(n,r)]

n = int(sys.stdin.readline().rstrip())
s = [''.join(sorted(s)) for s in sys.stdin.read().split()]

def main():
    tot = 0
    for c in Counter(s).values():
        tot += choose(c, 2)
    print(tot)

if __name__ ==  '__main__':
    main()

Solution (Python):
import collections
import math
n=int(input())
s=[]
for i in range(n):
    sl=list(input())
    sl.sort()
    s.append("".join(sl))

l=list(collections.Counter(s).values())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c=0
for i in range(len(l)):
    k=int(l[i])
    if k!=1:c+=combinations_count(k,2)
print(c)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


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

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

print(ans)

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





dic={}
ans=0
for i in range(n):
    s=list(input())
    s.sort()
    st="".join(s)
    v=dic.get(st,0)
    ans+=v
    dic[st]=v+1
print(ans)

Solution (Python):
import collections
from math import factorial
A = int(input())
listA = []
total = 0
listB = {}
for i in range(A):
    B = list(input())
    B.sort()
    listA.append("".join(B))
for i in listA:
    if i in listB:
        listB[i] += 1
        total += listB[i]-1
    else:
        listB[i] = 1
print(total)

Solution (Python):










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    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 k,v in dic.items():
        ans += v * (v-1) //2 
    print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
import math
import sys
input = sys.stdin.readline
N=int(input())
d={}
for i in [0]*N:
 s = ''.join(sorted(input().strip()))
 if s in d:
  d[s]+=1
 else:
  d[s]=1
e=0
for v in d.values():
 if v>=2:
  e+=int(v*(v-1)/2)
print(e)

Solution (Python):
N, *S = open(0).read().split()
S = [str(sorted(s)) for s in S]
D = {}
ans = 0
for s in S:
    if s in D:
        ans += D[s]
        D[s] += 1
    else:
        D[s] = 1
print(ans)

Solution (Python):
n = int(input())
import itertools
A = []
t = 0
for i in range(n):
    A.append("".join(sorted(list(input()))))


import collections

C = collections.Counter(A)


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

Solution (Python):
import math
import collections


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


n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]
c = collections.Counter(s)
print(sum(comb(a, 2) for a in c.values() if a > 1))

Solution (Python):
n = int(input())
s = ['']*n
for i in range(n):
  s[i] = input()
dict = {}
num = 0
for i in range(n):
  k = ''.join(sorted(s[i]))
  if k not in dict.keys():
    dict[k] = 1
  else:
    num += dict[k]
    dict[k] += 1  
print(num)

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

Solution (Python):
n = int(input())
dic = {}
from collections import Counter
for i in range(n):
  s = input()
  s = sorted(s)
  s = ''.join(s)
  if s not in dic: dic[s] = 1
  else: dic[s] += 1
a = dic.values()
a = list(a)
ans = 0
for i in range(len(a)):
  ans += a[i]*(a[i]-1)/2
print(int(ans))

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import Counter

def c2s(c):
    s = ''
    for key, val in c:
        
        
        s = '{}{}{}'.format(s, key, val)
    
    return s

def choose2(n):
    if n == 1:
        return 0
    return n * (n - 1) // 2

def solve():
    n = II()
    S = ["".join(sorted(input())) for _ in range(n)]
    

    jisho = {}
    for s in S:
        
        
        
        jisho[s] = jisho.setdefault(s, 0) + 1
    
    ans = 0
    for val in jisho.values():
        ans = ans + choose2(val)

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):


int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import Counter

def c2s(c):
    s = ''
    for key, val in c:
        
        
        s = '{}{}{}'.format(s, key, val)
    
    return s

def choose2(n):
    if n == 1:
        return 0
    return n * (n - 1) // 2

def solve():
    n = II()
    S = [list(input()) for _ in range(n)]

    jisho = {}
    for s in S:
        c = sorted(Counter(s).items(), key=lambda x: x[0])
        
        key = c2s(c)
        jisho[key] = jisho.setdefault(key, 0) + 1
    
    ans = 0
    for val in jisho.values():
        ans = ans + choose2(val)

    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
s = [''.join(sorted(list(STR()))) for _ in range(n)]
t = set(s)
u = Counter(s)
ans = 0
for i in t:
    ans += u[i] * (u[i] - 1) // 2
print(ans)

Solution (Python):
import math

n = int(input())

check = {}
ans = 0

for _ in range(n):
    word = sorted(input())
    new_word = ''.join(list(word))
    check.setdefault(new_word, 0)
    check[new_word] += 1

for k in check:
    if check[k] >= 2:
        ans += int(math.factorial(check[k])/(math.factorial(check[k]-2)*2))

print(ans)

Solution (Python):
N = int(input())
li = [0]*N
for i in range(N):
    s = list(input())
    s.sort()
    li[i] = ''.join(s)
from collections import Counter
c = Counter(li)
ans = 0
key = list(c.keys())
for i in key:
    ans += c[i]*(c[i]-1)//2
print(ans)

Solution (Python):
from time import time
from math import factorial

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

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

    d = {}
    for i in s:
        if i in d.keys():
            d[i] += 1
        else:
            d[i] = 1

    for i in d.values():
        if i >= 2:
            answer += combinations_count(i, 2)


    print(answer)

if __name__ == '__main__':
    start = time()
    main()

Solution (Python):
from collections import defaultdict
N = int(input())
d = defaultdict(int)
ans = 0
for i in range(N):
    S = list(input())
    S.sort()
    s = "".join(S)
    ans += d[s]
    d[s]+=1
print(ans)

Solution (Python):
N = int(input())
s = sorted(sorted(input()) for _ in range(N))
ans = 0
cnt = 1
for i in range(1, N):
    if s[i-1] == s[i]:
        cnt += 1
    else:
        if cnt > 1:
            ans += (cnt * (cnt - 1) // 2)
        cnt = 1
if cnt > 1:
    ans += (cnt * (cnt - 1) // 2)
print(ans)

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

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()


ans = 0
cnt = defaultdict(int)
for i in range(N):
  s = SS[i]
  s = ''.join(s)
  cnt[s] += 1
  
for _,v in cnt.items():
  ans += v * (v - 1) // 2
  
print(ans)

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

SS = []
for i in range(N):
  s = list(input())
  s.sort()
  SS.append(s)
  
SS.sort()

ans = 0
prev = None
cnt = 0
for i in range(N):
  s = SS[i]
  if s == prev:
    if not cnt:
      cnt = 2
    else:
      cnt += 1
  else:
    ans += cnt * (cnt - 1) // 2
    cnt = 0
  prev = s
  
ans += cnt * (cnt - 1) // 2
print(ans)

Solution (Python):
d = {}
c = 0
for i in open(0):
    i = str(sorted(i))
    t = d.get(i, 0)
    c += t
    d[i] = t + 1
print(c)

Solution (Python):
from collections import defaultdict
d=defaultdict(int)
n,*s=open(0).read().split()
for i in s:d["".join(sorted(list(i)))]+=1
print(sum(v*(v-1)//2 for v in d.values()))

Solution (Python):
from collections import defaultdict
d=defaultdict(int)
n,*s=open(0).read().split()
for i in s:d["".join(sorted(list(i)))]+=1
print(sum(v*(v-1)//2 for v in d.values()))

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

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

s.sort()

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

Solution (Python):
def f(n):
  return (n**2-n)//2
ans=0
N=int(input())
d=dict()
for i in range(N):
  s="".join(sorted(input()))
  if s not in d:
    d[s]=0
  d[s]+=1
for i in d:
  ans+=f(d[i])
print(ans)

Solution (Python):
def cmb(n, r):
	if n < r: return 0
	if r == 0: return 1
	if r == 1: return n
	if n - r < r: r = n - r

	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 = []
for _ in range(n):
	tmp = list(input())
	tmp.sort()
	s.append(tmp)

s.sort()

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

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

print(ans)

Solution (Python):
from collections import Counter

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

a = Counter(li)
ans = 0
for i in dict(a).values():
    ans += i*(i-1)//2
print(ans)

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Solution (Python):
n = int(input())
s = [input() for _ in range(n)]
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Solution (Python):
import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip()).items()) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


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

Solution (Python):
import collections


def calculateC(n):
    n_C_i = n * (n-1)
    return n_C_i // 2

n = int(input())
ans = []
for _ in range(n):
    s = list(input())
    s.sort()
    a = ''
    for i in range(len(s)):
        a += s[i]
    ans.append(a)
cnt = collections.Counter(ans).most_common()
aa = 0
for i in range(len(cnt)):
    if cnt[i][1] == 1:
        break
    aa += calculateC(cnt[i][1])
print(aa)

Solution (Python):
import collections

n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for si in set(s):
  n = c[si]
  ans += n*(n-1)//2
print(ans)

Solution (Python):

import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())
 
for i in range(n):
    s[i] = "".join(sorted(s[i]))
s.sort()

c = collections.Counter(s)

result = [x for x in c.values() if x > 1]

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

Solution (Python):
import sys
from collections import defaultdict
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
d = defaultdict(int)
ans = 0
for i in range(N):
    s = tuple(sorted(input()))
    ans += d[s]
    d[s] += 1
print(ans)

Solution (Python):
import sys
from collections import defaultdict
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
d = defaultdict(int)

for i in range(N):
    s = tuple(sorted(input()))
    d[s] += 1
ans = 0
for key, value in d.items():
    while value != 0:
        ans += value - 1
        value -= 1
print(ans)

Solution (Python):
from functools import reduce
from operator import mul
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    elif r<0: return 0
    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)]


ans = 0
d = {}
for i in s:
    d[i] = d.get(i, 0) + 1

for i in d.values():
    ans += cmb(i, 2)

print(ans)

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

import collections


N = int(input())







l = {}
for i in range(N):
    S = list(input())
    S.remove("\n")
    S.sort()
    S = tuple(S)
    if S in l.keys():
      l[S] += 1
    else:
      l[S] = 1
ans = 0
for j in l.values():
  ans += j*(j-1)/2
print(int(ans))

Solution (Python):



from math import *
from copy import *
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize
from operator import *				
from itertools import *
from collections import Counter		
from collections import defaultdict 

'''
3
acornistnt
peanutbomb
constraint
'''

def solve(l):
	n = len(l)
	L = []
	for s in l:
		a = [0]*26
		for i in s:
			a[ord(i)-97] += 1
		L.append(a)
	d = defaultdict(int)
	for i in L:
		d[str(i)] += 1
	
	ans = 0
	for i in d:
		ans += d[i]*(d[i]-1)//2
	return ans
	

N = int(stdin.readline())
l = []
for nn in range(N):
	l.append(input())
ans = solve(l)
print(ans)

Solution (Python):
N=int(input())
ans=0
dic={}
for i in range(N):
	a=sorted(str(input()))
	a=''.join(a)
	if a in dic.keys():
		ans+=dic[a]
		dic[a]+=1
	else:
		dic[a]=1
print(ans)

Solution (Python):
import math
def String_Sort(str):
    tmp = sorted(str)
    ans = ""
    for i in tmp:
        ans += i
    return ans

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


li = []
n = int(input())
ans = 0
for i in range(n):
    li.append(String_Sort(input()))
li.sort()

str = li[0]
num = 0
for i in li:
    if (i == str):
        num += 1
        continue
    else:
        if num>1:
            ans += sol(num)
        num = 1
        str = i
if (num > 1):
    ans+=sol(num)
print(ans)

Solution (Python):
n = int(input())
d = {}
for _ in range(n):
    s = sorted(input())
    if str(s) in d.keys():
        d[str(s)] += 1
    else:
        d[str(s)] = 1
ans = 0
for i in d.values():
    ans += i*(i-1) // 2
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
s_list = list()
for _ in range(N):
    s_list.append(''.join(sorted(input())))
    
count = 0
for k, v in Counter(s_list).items():
    count += v * (v-1) // 2

print(count)

Solution (Python):
N=int(input())
S=[]
for _ in range(N):
    L=sorted(input())
    S.append(''.join(L))
S.sort()


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

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

print(ans)

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

L = sorted(L)

s = L[0]
c = 0
n = 1
for i in range(1,N):
  if s == L[i]:
    n +=1
  else:
    if n >= 2:
      c += n*(n-1)//2
    s = L[i]
    n = 1
    
if n >=2:
  c +=n*(n-1)//2
print(c)

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

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

Solution (Python):
import math
import collections
n = int(input())
l = []
ans = 0
for i in range(n):
  a = list(input())
  a.sort()
  a = str(a)
  l.append(a)
c = collections.Counter(l)
for j in c.values():
  if j >= 2:
    ans += j*(j-1)//2
print(ans)

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

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

print(sum((x*(x-1))//2 for x in S.values() if x > 1))

Solution (Python):
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
strs=[]
for i in range(n):
    line=sorted(input().rstrip())
    STR=""
    for j in line:
        STR=STR+j
    strs.append(STR)

x=collections.Counter(strs)

sm=0
for j in x:
    sm+=x[j]*(x[j]-1)//2
print(sm)

Solution (Python):
n = int(input())
a = dict()
ans = 0
for i in range(n):
    string = input()
    b = ''.join(sorted(string))
    if b in a:
        a[b] += 1

    else:
        a[b] = 1
for i in a.values():
    if i > 1:
        ans += int(i*(i-1)/2)
print(ans)