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.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
str_list = []
count_list = []
S = [''.join(sorted(list(input()))) for _ in range(N)]
count = Counter(S)
ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
for i in range(n):
  temp = 0
  s = input()
  for j in s:
    temp += (12 ** (ord(j) - ord('a') + 1))
  dic.setdefault(temp, 0)
  dic[temp] += 1
#print(dic)
res = 0
for i in dic:
  if dic[i] >= 2:
    res += ((dic[i] * (dic[i] - 1)) // 2)
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())

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

S_num_list=[]

for n in range(N):
    S_=input()
    S_num=[0]*26
    for s in S_:
        S_num[alpha2num(s)] += 1
    S_num_list.append(''.join(map(str,S_num)))
    
S_counter=Counter(S_num_list)

ans=0
for s in S_counter.keys():
    s_num = S_counter[s]
    s_combination_num = int((s_num*(s_num-1))/2)
    ans += s_combination_num
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

S = sorted(S)
count = 1
ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        count += 1
    else:
        ans += (count * (count-1)) // 2
        count = 1
ans += (count * (count-1)) // 2
        
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
list1=[]
def apl1(l1):
    list1.append(l1)
for i in range(n):
    apl1(str(sorted(list(input()))))
list1.sort()
str1=list1[0]
ans=0
num=0
def num_1(num1):
    return ((num1+1)*num1)//2
for i in range(1,n):
    if str1==list1[i]:
        num+=1
    else:
        ans+=num_1(num)
        str1=list1[i]
        num=0
if num>=1:
    ans+=num_1(num)
print(ans)

Submission status: Accepted

Solution code:
# C - Green Bin
def main():
    import collections


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
ans=[]
tt=0
for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    ans.append(s)
l=Counter(ans)
c=l.most_common()
for i,j in c:
    tt+=j*(j-1)//2
print(tt)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = []
for _ in range(N):
    s = tuple(sorted(input()))
    S.append(s)
SS = Counter(S)
ans = 0
for v in SS.values():
    if v>=2:
        ans += v*(v-1)//2
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc137/tasks/abc137_c

import math

N = int(input())

s_dic = {}
s_set = set()

for i in range(N):
    s = input()

    s = ''.join(sorted(s))

    if s in s_set:
        s_dic[s] += 1

    else:
        s_set.add(s)
        s_dic[s] = 1


result = 0

for val in s_dic.values():

    if val > 1:
        result += int((val * (val - 1)) / 2)

print(result)

Submission status: Accepted

Solution code:
n = int(input())
dic = dict()
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

element = {}
count = 0
for i in range(n):
    s = ''.join(sorted(input()))
    if s in element:
        element[s] += 1
        count += element[s]
    else:
        element[s] = 0

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]

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

Submission status: Accepted

Solution code:
from collections import Counter
import math
n=int(input())
s=[list(input()) for _ in range(n)]
#print(s)
for i in range(n):
    s[i].sort()
    s[i]=" ".join(s[i])
#print(s)
C=Counter(s)
#print(C)
ans=0
for k,v in C.items():
    ans+=v*(v-1)//2
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    ans = 0
    d = defaultdict(int)
    for s in S:
        s = ''.join(sorted(s))
        if s in d:
            ans += d[s]
        d[s] += 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    d = defaultdict(int)
    for s in S:
        c = [0] * 26
        for l in s:
            c[ord(l) - 97] += 1
        d[tuple(c)] += 1

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s not in d.keys():
        d[s] = 1
    else:
        d[s] += 1
count = 0
for i in d.values():
    count += i * (i-1) // 2
print(count)

Submission status: Accepted

Solution code:
c,a={},0
for _ in range(int(input())):
  s=tuple(sorted(input()))
  c[s]=c.get(s,-1)+1
  a+=c[s]
print(a)

Submission status: Accepted

Solution code:
c={}
for _ in range(int(input())):
  s=tuple(sorted(input()))
  c[s]=c.get(s,0)+1
print(sum(v*(v-1)//2 for v in c.values()))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = sorted(["".join(sorted(input())) for _ in range(n)])
cnt = Counter(s)
print(sum(x*(x-1)//2 for x in cnt.values()))

Submission status: Accepted

Solution code:
import collections
n=int(input())
print(int(sum((i*(i-1)/2)for i in collections.Counter([str(sorted(input()))for i in range(n)]).values())))

Submission status: Accepted

Solution code:
import collections
N=int(input())
ss=['' for i in range(N)]

for i in range(N):
    ss[i]=''.join(sorted(str(input())))

cc=collections.Counter(ss)
ans=0
values, counts = zip(*cc.most_common())
counts=list(counts)

for i in range(len(counts)):
    if counts[i]==1:
        break
    else:
        ans+=counts[i]*(counts[i]-1)/2

print(int(ans))

Submission status: Accepted

Solution code:

def mi(): return map(int,input().split())
def lmi(): return list(map(str,input().split()))
def ii(): return int(input())
def isp(): return input().split()

n=ii()
dic_s={}
for i in range(n):
  s_=list(input())
  s__=sorted(s_)
  #print(s__)
  s=''.join(s__)
  if s in dic_s.keys():
    dic_s[s]+=1
  else:
    dic_s.setdefault(s,1)

  
cnt=0
#print(dic_s)
for i in dic_s.values():
  if i>1:
    cnt+=i*(i-1)//2

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

count = 0
d = defaultdict(int)
for i in range(n):
    s = sorted(input())
    d["".join(s)] += 1

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

print(count)

Submission status: Accepted

Solution code:
N=int(input())
S=[]
for _ in range(N):
  s=list(input())
  s.sort()
  S.append("".join(s))
from math import factorial
def C(n, r):
  return factorial(n)//(factorial(r)*factorial(n-r))
S.sort()
tmp=list(set(S))
tmp.sort()
j=0
num=0
ans=0
S.append("123")
for i in range(N+1):
  if tmp[j]==S[i]:
    num+=1
  else:
    if num>1:
      ans+=C(num,2)
    num=1
    j+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from itertools import groupby

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
sizes = [len(list(v)) for k, v in groupby(sorted(S))]


def combinations_count(n, r):
    if n == 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


ans = sum([combinations_count(size, 2) for size in sizes])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
#n,m=map(int,input().split())
#t=int(input())
#pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
res=0
for i in range(n):
    s=list(input())
    s="".join(sorted(s))
    count=dic.get(s,0)
    if count>0:
        res+=count
    dic[s]=count+1
print(res)

Submission status: Accepted

Solution code:
n = int(input())
dict = {}
for _ in range(n):
    s = [x for x in input()]
    s.sort()
    s = "".join(s)
    dict[s] = dict.get(s, 0) + 1
ans = 0
for k in dict:
    v = dict[k]
    ans += int(v * (v-1) /2)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    d = defaultdict(lambda: 0)
    for _ in range(N):
        d["".join(sorted(list(input())))]+=1

    ans = 0

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

    print(ans)







if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = {}
ans = 0
for i in range(n):
    a = list(input())
    sorted_a = "".join(sorted(a))
    if sorted_a in s:
        s[sorted_a] += 1
    else:
        s[sorted_a] = 0
    ans += s[sorted_a]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


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

c = Counter(s)
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())

d=defaultdict(int)
for i in range(n):
    s=input()
    sorted_list=sorted(s)
    s="".join(sorted_list)
    d[s]+=1
count=0
for i,j in d.items():
    count+=j*(j-1)//2

print(count)

Submission status: Accepted

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

from collections import*
C=Counter(S)

print(sum(v*(v-1)//2 for v in C.values()))

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[str(sorted(input()))for i in range(n)]
c=collections.Counter(s)
l=sum((i*(i-1)/2)for i in c.values())
print(int(l))

Submission status: Accepted

Solution code:
n = int(input())

D = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s not in D:
        D[s] = 1
    else:
        D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
            
print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for i in range(n):
        s1 = list(input())
        d[tuple(sorted(s1))] += 1
    ans = 0
    for i in d.values():
        ans += i*(i-1)//2
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
dic=dict()
for i in range(n):
  s = ''.join(sorted(list(input())))
  if s in dic:
    dic[s] += 1
  else:
    dic[s]=1
res = sum([x*(x-1)//2 for x in dic.values() if x > 1])
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [str(sorted(input())) for i in range(n)]

c = Counter(s)

l = sum((v*(v-1)/2) for v in c.values())
print(int(l))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = [str(sorted(input())) for i in range(n)]

c = Counter(s)

l = sum((v*(v-1)/2) for v in c.values())
print(int(l))

Submission status: Accepted

Solution code:
from collections import Counter

def check(s1, s2):
	for i in range(26):
		if s1[i] != s2[i]:
			return False;
	return True

n = int(input())
stuff = []
for _ in range(n):
	d = list(input())
	cnt = [0 for x in range(26)]
	for i in range(10):
		cnt[ord(d[i])-97] += 1
	stuff.append(cnt)

stuff.sort()
span = 1
ans = 0
for i in range(n-1):
	if check(stuff[i+1], stuff[i]):
		span += 1
	else:
		ans += span*(span-1)//2	
		span = 1
ans += span*(span-1)//2
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = [list(input()) for i in range(n)]
    d = {}
    ans = 0
    for i in s:
        ss = ''.join(sorted(i))
        if ss not in d:
            d.setdefault(ss, 1)
        else:
            d[ss] = d.get(ss) + 1
    for k, v in d.items():
        ans += round(v*(v-1)/2)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
d = {}
c = 0
for i in range(n):
    s = input()
    s = tuple(sorted(s)) #文字列をsort
    if s in d:
        c = c + d[s]
        d[s] = d[s] + 1
    else:
        d[s] = 1
print(c)

Submission status: Accepted

Solution code:
from collections import Counter

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

def LI():
    return list(map(int, input().split()))

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

for s in S:
    tmp = []
    si = Counter(s)
    for l, c in si.items():
        tmp.append((l, c))
    tmp.sort(key = lambda x : x[0])
    cnt.append(tuple(tmp))
 
cnt = Counter(cnt)
ans = 0

for n in cnt.values():
    ans += n * (n - 1) // 2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    s = input()
    ss = sorted(s)
    S.append("".join(ss))
S.sort()
ans = 0
count = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        count += 1
        ans += count
    else:
        count = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

word = {}
for i in range(N):
    t = list(input())
    t.sort()
    t = "".join(t)
    if t not in word:
        word[t] = 1
    else:
        word[t] += 1

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = [''.join(sorted(list(input()))) for x in range(n)]
ans = 0
s_dict = dict()
for v in s:
    if v in s_dict:
      ans += s_dict[v]
      s_dict[v] += 1
    else:
        s_dict[v] = 1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
from collections import Counter
s=[]
for i in range(n):
  read=list(input())
  read.sort()
  s.append("".join(read))

ans=0
dic=Counter(s)
for i in dic:
  ans=ans+dic[i]*(dic[i]-1)//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s = [sorted(list(input())) for _ in range(n)]
s_e = [''] * n

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

s_e.sort()
#print(s_e)

count = 1
ans = 0

for i in range(n-1):
    #print(s_e[i])
    if s_e[i] == s_e[i+1]:
        count += 1
    else:
        ans += (count * (count-1) // 2)
        count = 1

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
dictionary={}
count=0
for i in range(N):
    s="".join(sorted(input()))
    if s in dictionary:
        dictionary[s]+=1
        count+=dictionary[s]
    else:
        dictionary[s]=0
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
d=defaultdict(int)
S=[input() for _ in range(n)]
for i in range(n):
    S[i] = ''.join(sorted(S[i]))
    d[S[i]]+=1

t=0
for v in d.values():
    if v > 1:
        t+=v*(v-1)//2
print(t)

Submission status: Accepted

Solution code:
N = int(input())

sentence_count_dict = {}
for _ in range(N):
    sentence = list(input())
    sentence = ''.join(sorted(sentence))
    if sentence in sentence_count_dict:
        sentence_count_dict[sentence] += 1
    else:
        sentence_count_dict[sentence] = 1

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

print(int(total))

Submission status: Accepted

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

def main():
    N = int(input())
    S = [''.join(sorted(input())) for _ in range(N)]
    counter = {}
    for s in S:
        if s in counter:
            counter[s] += 1
        else:
            counter[s] = 1
    ans = sum([nC2(v) for v in counter.values()])
    print(ans)

main()

Submission status: Accepted

Solution code:
#3問目
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

dictionary = {}
count = 0
N = int(input())
for i in range(N):
    s = input()
    s = ''.join(sorted(s))
    if(s in dictionary):
        dictionary[s] += 1
    else:
        dictionary[s] = 1

for i in dictionary.values():
    if(i >= 2):
        count += combinations_count(i, 2)

print(count)

Submission status: Accepted

Solution code:
N = int(input())
s = sorted([sorted(input()) for _ in range(N)])
total = 0
count = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        total += count * (count - 1) / 2
        count = 1
total += count * (count - 1) / 2
print(int(total))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from math import factorial
def combinations(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
N=int(input())
S=["".join(sorted(input())) for i in range(N)]
s=Counter(S)
ans=0
for key,value in s.items():
    if value>=2:
        ans+=combinations(value,2)
print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())

s = [''] * N

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

c = collections.Counter(s)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
l = []
m = []
for _ in range(N):
    data = input()
    data = list(data)
    data.sort()
    l.append(data)
l.sort()
cnt = 0
for i in range(N-1):
    if l[i] == l[i+1]:
        cnt += 1
    else:
        if cnt == 0:
            pass
        else:
            m.append(cnt+1)
        cnt = 0
if cnt != 0:
    m.append(cnt+1)

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

Submission status: Accepted

Solution code:
n = int(input())
sn = []
ans = 0

for _ in range(n):
    s = sorted(input())
    sn.append("".join(s))

import collections
c = collections.Counter(sn)

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

print(ans)

Submission status: Accepted

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

s.sort()

bef = s[0]
cnt = 1
ans=0
for i in range(1,len(s)):
  if bef == s[i]:
    cnt += 1
  else :
    if cnt > 1:
      ans += (cnt * (cnt -1) )/2
    cnt = 1
  bef = s[i]

if cnt > 1:
  ans += (cnt * (cnt -1) )/2
print(int(ans))

Submission status: Accepted

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

from collections import Counter

L = [''.join(sorted(list(s))) for s in S]
C = Counter(L)
ans = 0
for i in C.values():
    ans += i*(i-1)//2
print(ans)

Submission status: Accepted

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

from collections import Counter

H = [hash(''.join(sorted(list(s)))) for s in S]
C = Counter(H)

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

Submission status: Accepted

Solution code:
n = int(input())
mydict = {}

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

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

cnt = 0
for k in mydict:
	num = mydict[k]
	cnt = cnt + (num*(num-1))//2

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
ans = 0

for i in range(N) :
    s = tuple(sorted(input()))
    if s in dic :
        ans += dic[s]
        dic[s] += 1
    else : 
        dic[s] = 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

from collections import Counter
c = Counter(l)
num = sorted(list(c.values()), reverse = 1)

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

ans = 0
for i in num:
    if i == 1:
        break
    else:
        ans += combinations_count(i, 2)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

from collections import Counter
c = Counter(l)
num = tuple(c.values())

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

ans = 0
for i in num:
    if i > 1:
        ans += combinations_count(i, 2)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = {}
for i in range(N):
    S = list(input())
    S.sort()
    S = ''.join(S)
    A[S] = A.get(S, 0) + 1
 
ans = 0
for i in A.values():
    if i > 1:
        iL = [j for j in range(i)]
        ans += sum(iL)
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
 
dic = {}
ans = 0
for i in range(N):
    s = tuple(sorted(input()))
    if s in dic:
        ans += dic[s]
        dic[s] += 1
    else:
        dic[s] = 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

from collections import Counter
c = Counter(l)
num = list(c.values())

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

ans = 0
for i in num:
    if i > 1:
        ans += combinations_count(i, 2)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

res = 0
d = defaultdict(int)
for list_ in s:
    str_ = str(list_)
    d[str_] += 1
    res += d[str_] - 1

print(res)

Submission status: Accepted

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

res = 0
d = dict()
for list_ in s:
    str_ = str(list_)
    if str_ in d:
        d[str_] += 1
        res += d[str_] - 1
    else:
        d[str_] = 1

print(res)

Submission status: Accepted

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

res = 0
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        res += cnt
        cnt += 1
    else:
        cnt = 1

print(res)

Submission status: Accepted

Solution code:
N=int(input())

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(10)] for i in range(N)]

for i in range(N):
    R=input()
    for j in range(10):
        S[i][j]=R[j]
    S[i].sort()
    
    L=[str(a) for a in S[i]]
    L="".join(L)
    S[i]=L

S.sort()

goukei=0
banpei=S[0]
ncr=1
for i in range(1,N):
    if banpei==S[i]:
        ncr+=1
    else:
        if ncr>=2:
            goukei+=(ncr*(ncr-1))//2
        ncr=1
        banpei=S[i]

if ncr>=2:
    goukei+=(ncr*(ncr-1))//2 
    

print(goukei)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
d = {}
for i in range(N):
    a = list(s[i][:])
    b = ''.join(sorted(a))
    if b in d:
        d[b]+=1
    else:
        d[b]=1
ans = 0
for j in d.values():
    ans+=j*(j-1)//2
print(ans)

Submission status: Accepted

Solution code:
import collections
import math
n = int(input())
a = [0]*n
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(input())
    t.sort()
    m = " ".join(t)
    a[j] = m
c = collections.Counter(a)
d = list(c)
for k in range(len(d)):
    if c[d[k]] > 1:
        b += combinations_count(c[d[k]], 2)
    else:
        continue
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
SS=[]
answer=0
for _ in range(N):
    s=input()
    s=sorted(s)
    S=''
    for a in s:
        S+=a
    SS.append(S)
a=collections.Counter(SS)
for n in a.values():
   answer+=(n-1)*n/2
print(int(answer))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for v in d.values():
            ans += (v*(v-1)) // 2
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for k, v in d.items():
        if v != 1:
            ans += (v*(v-1)) // 2
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = [0]*n
for i in range(n):
    s[i] = list(input())
t = [0]*n
for i in range(n):
    s[i][:] = sorted(s[i][:])
    t[i] = "".join(s[i][:])
import collections
c = collections.Counter(t)
ans = 0
for T in t:
    if c[T] >= 2:
        ans += c[T]-1
print(ans//2)

Submission status: Accepted

Solution code:
import math


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


def main():
    n = int(input())
    d = {}
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        d[ss] = d.get(ss, 0) + 1
        
    for k, v in d.items():
        if v != 1:
            ans += combinations_count(v, 2)
         
    print(ans)
       
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = {}
for i in range(N):
    S = list(input())
    S.sort()
    S = ''.join(S)
    A[S] = A.get(S, 0) + 1

ans = 0
for i in A.values():
    if i > 1:
        iL = [j for j in range(i)]
        ans += sum(iL)
    
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=[list(input()) for i in range(n)]
for i in s:
  i.sort()
s.sort()
cnt=1
ans=0
for i in range(n-1):
  if s[i]==s[i+1]:
    if i!=n-2:
      cnt+=1
    else:
      cnt+=1
      ans+=(cnt*(cnt-1))//2
  else:    
    ans+=(cnt*(cnt-1))//2
    cnt=1
print(ans)

Submission status: Accepted

Solution code:
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())

data = {}
for _ in range(n):
    temp = "".join(sorted(input()))
    # print(temp)
    if temp in data.keys():
        data[temp] += 1
    else:
        data[temp] = 1
# print(data)

answer = 0
for num in data.values():
    answer += (num*(num-1))//2
print(answer)

Submission status: Accepted

Solution code:
n = int(input())
from collections import Counter
cnt= 0
L = []
for i in range(n):
    s = sorted(input())
    L.append(("".join(s)))

L = Counter(L)
for v in L.values():
    cnt +=(v-1)*v//2
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())

dic={}
cnt=0
for i in range(n):
    s=tuple(sorted(input()))
    if s in dic:
        cnt+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(cnt)