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

from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__

from collections import Counter


def main():
    n = int(input())
    c = Counter()
    for i in range(n):
        c[''.join(sorted(input()))] += 1

    cnt = 0
    for val in c.values():
        cnt += (val * (val - 1)) >> 1

    print(cnt)




BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0,
                              2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict

N = int(input())
cnt = defaultdict(int)
for _ in range(N):
    s = [c for c in input()]
    s.sort()
    a = ''.join(s)
    cnt[a] += 1

ans = 0
for c, f in cnt.items():
    ans += f * (f - 1) // 2
print(ans)

Solution (Python):
n = int(input())
G = {}
p = 31
M1, M2 = (10 ** 9 + 7, 998244353)
for _ in range(n):
    s = input()
    s = sorted(list(s))
    yt = 0
    yt2 = 0
    for i in range(len(s)):
        yt += p ** (i + 1) * (ord(s[i]) - 95)
        yt2 += p ** (i + 1) * (ord(s[i]) - 95)
        yt %= M1
        yt2 %= M2
    if (yt, yt2) not in G:
        G[(yt, yt2)] = 0
    G[(yt, yt2)] += 1
ans = 0
for i in G:
    ans += G[i] * (G[i] - 1) // 2
print(ans)

Solution (Python):
import sys
from collections import Counter


def solve(N: int, s: "List[str]"):
    c = Counter()
    for x in s:
        c["".join(sorted(x))] += 1
    ans = 0
    for i in c.values():
        ans += i * (i - 1) // 2
    return ans



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()

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

    ans = solve(N, s)
    if ans is not None:
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(N: int, s: "List[str]"):
    s.sort()
    count = 0
    res = 0
    prev = ""
    for string in s:
        if string != prev:
            prev = string
            res += count * (count+1) // 2
            count = 0
        else:
            count += 1
    res += count * (count+1) // 2    
    print(res)
    return



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

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
arr=[input() for _ in range(n)]
dic={}
check='abcdefghijklmnopqrstuvwxyz'
for s in arr:
  count=[0]*26
  for i in range(10):
    for j in range(26):
      if s[i]==check[j]:
        count[j]+=1
        break
  count=tuple(count)
  if count not in dic:
    dic[count]=1
  else:
    dic[count]+=1
ans=0
for val in dic.values():
  ans+=val*(val-1)//2
print(ans)

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

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)

for s in S:
  d["".join(sorted(s))] += 1

sum_ = 0
for v in d.values():
  sum_ += v * (v - 1) // 2

print(sum_)

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

freq_sorted_word = {}
for i in range(N):
    sorted_word = ''.join(sorted(input()))
    freq_sorted_word.setdefault(sorted_word, 0)
    freq_sorted_word[sorted_word] += 1

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

print(sum(map(pair_num, freq_sorted_word.values())))

Solution (Python):
from collections import defaultdict

N = int(input())
d = defaultdict(int)

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

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

print(res)

Solution (Python):


import collections


def count_anagrams(n, ss):
    ctr = collections.Counter("".join(sorted(s)) for s in ss)
    res = sum(v * (v - 1) // 2 for v in ctr.values())
    return res


def main():
    n = int(input())
    ss = [input() for _ in range(n)]
    res = count_anagrams(n, ss)
    print(res)


if __name__ == "__main__":
    main()

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

N = int(input())
A = []
for _ in range(N):
    a = sorted(list(input()))
    A.append(''.join(a))

B = Counter(A)

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

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

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

print(num)

Solution (Python):
from collections import Counter
List = []
N=int(input())
for i in range(N):
    s = input()
    s = "".join(sorted(s))
    List.append(s)
ans = 0
for x in Counter(List).values():
    ans += (x*(x-1))//2
print(ans)

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

s = sorted([sorted(t) for t in s])
ans = 0
i = 0
while i<N:
  j = i
  while j<N and s[i]==s[j]:
    j += 1
  ans += (j-i)*(j-i-1)/2
  i = j
print ans

Solution (Python):
from collections import Counter
n = int(input())
ans = 0
dic = {}
for i in range(n):
    s = input()
    c = Counter(s)
    tmp = ''.join([k+str(v) for k,v in sorted(c.items())])
    if tmp not in dic:
        dic[tmp] = 1
    else:
        ans += dic[tmp]
        dic[tmp] += 1
print(ans)

Solution (Python):
from collections import Counter

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

C = Counter(S)
ans = 0
for v in C.values():
    ans += v * (v - 1) // 2

print(ans)

Solution (Python):
import os
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
S = [list(sys.stdin.readline().rstrip()) for _ in range(N)]

for s in S:
    s.sort()
S.sort()
ans = 0
cnt = 0
for s, t in zip(S, S[1:]):
    if s == t:
        cnt += 1
    else:
        if cnt > 0:
            ans += cnt * (cnt + 1) // 2
        cnt = 0
if cnt > 0:
    ans += cnt * (cnt + 1) // 2
print(ans)

Solution (Python):
from collections import defaultdict

base = ord('a')

d = defaultdict(int)

ans = 0

n = int(input())
for _ in range(n):
    s = input()
    lst = [0] * 26
    for c in s:
        idx = ord(c) - base
        lst[idx] += 1
    key = tuple(lst)
    ans += d[key]
    d[key] += 1

print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    a,b = LI()
    print(max(a+b,a-b,a*b))
    return


def B():
    k,x = LI()
    ans = []
    for i in range(x-k+1,x+k):
        ans.append(i)
    print(*ans)
    return


def C():
    def f(s):
        res = [0]*m
        for i in s:
            res[alp.index(i)] += 1
        return res
    alp = list("abcdefghijklmnopqrstuvwxyz")
    m = len(alp)
    n = I()
    s = [input() for i in range(n)]
    d = defaultdict(lambda : 0)
    for i in s:
        d[tuple(f(i))] += 1
    ans = 0
    for i in d.values():
        ans += (i*(i-1))//2
    print(ans)
    return


def D():

    return


def E():

    return


def F():

    return


if __name__ == "__main__":
    C()

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

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)

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

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

N = int(input())

A = [input().strip() for i in range(N)]

B = []
for a in A:
    NOW=[0]*26

    for k in a:
        NOW[ord(k)-97]+=1

    B.append(NOW)
B.sort()
NOW=1
ANS=0
for i in range(1,N):
    if B[i]==B[i-1]:
        NOW+=1
    else:
        ANS+=NOW*(NOW-1)//2
        NOW=1

ANS+=NOW*(NOW-1)//2

print(ANS)

Solution (Python):
def dic(s):
  dics,ans=[],""
  for i in range(len(s)):dics.append(s[i])
  dics.sort()
  for i in dics:ans+=i
  return ans
n=int(input())
s=[dic(input())for _ in range(n)]
s.sort()
a=b=1
c=""
for i in range(n):
  if c!=s[i]:
    b+=a*(a-1)//2
    a=1
    c=s[i]
  else:a+=1
b+=a*(a-1)//2
print(b-1)

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

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

print(ans)

Solution (Python):
import sys
from collections import defaultdict

stdin = sys.stdin

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

n = ni()
dic = defaultdict(int)
for i in range(n):
    s = ns()
    q = list(s)
    q.sort()
    q = "".join(q)
    dic[q] += 1

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

Solution (Python):


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

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

d = {}

ans = 0
for i in s:
    a = [c for c in i]
    a.sort()
    a = "".join(a)
    
    if a in d:
        ans += d[a]
        d[a] += 1
    else:
        d[a] = 1

print(ans)

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 Counter

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

c = Counter(' '.join(sorted(t)) for t in s)
ans = sum(v * (v - 1) // 2 for v in c.values())

print(ans)

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