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:
char_num = int(input())
char_length = 10
chars = []
for i in range(char_num):
    chars.append(input())


class CharArrange:
    def __init__(self, char):
        self.char = char

    def char_run(self):
        list_char = self.str2ord_list(self.char)
        for pos in range(1, len(list_char)):
            self.insert_sort(list_char, pos, list_char[pos])
        self.char = self.ordList2Str(list_char)

    def order_run(self, chars):
        for i, char in enumerate(chars):
            chars[i] = self.ord_list2ord_concat(self.str2ord_list(char))
        for pos in range(len(chars)):
            self.insert_sort(chars, pos, chars[pos])
        self.ord_chars = chars

    def str2ord_list(self, char):
        return list(map(ord, char))

    def ordList2Str(self, ordList):
        return ''.join(list(map(chr, ordList)))

    def ord_list2ord_concat(self, ord_list):
        self.ord_concat = ''
        for ord_num in ord_list:
            self.ord_concat += str(ord_num)
        return int(self.ord_concat)

    def insert_sort(self, A, pos, value):
        i = pos - 1
        while (i >= 0 and A[i] > value):
            A[i+1] = A[i]
            i = i - 1
        A[i+1] = value
        return A


counter = 0
hash_table = {}
for i, char in enumerate(chars):
    CA = CharArrange(char)
    CA.char_run()
    if CA.char in hash_table:
        hash_table[CA.char] += 1
    else:
        hash_table[CA.char] = 0
    counter += hash_table[CA.char]


print(counter)

Submission status: Accepted

Solution code:
n = int(input())
 
l = []
for i in range(n):
	l.append(sorted(str(input())))
 
d = sorted(l)
c = 0
ans = 0
for i in range(n-1):
	if d[i] == d[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Submission status: Accepted

Solution code:
import math
def cmb(n, r):
        if r > n: 
                return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 
 
import collections
N = int(input())
s= [input() for i in range(N)]
ans=0
#各文字列文字列をソート
s=list(map(sorted,s))
 
s.sort()        #リストをソート
s=list(map(''.join,s))  #リストになっていたものを文字列に変換
clist = collections.Counter(s) #リスト内の各要素の数を数え上げ
kaisu=list(clist.values())
 
for i in kaisu:
        ans += cmb(i,2)
 
print(ans)

Submission status: Accepted

Solution code:
import math
def cmb(n, r):
        if r > n: 
                return 0
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


import collections
N = int(input())
s= [input() for i in range(N)]
ans=0
#各文字列文字列をソート
s=list(map(sorted,s))

s.sort()        #リストをソート
s=list(map(''.join,s))  #リストになっていたものを文字列に変換
clist = collections.Counter(s) #リスト内の各要素の数を数え上げ
kaisu=list(clist.values())

for i in kaisu:
        ans += cmb(i,2)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
a = int(input())
dic = defaultdict(int)
l = []
for i in range(a):
    l.append("".join(sorted(list(input()))))
    dic[l[-1]]+=1
s = 0
L = set(l)
for j in L:
    i = dic[j]
    s+=i*(i-1)/2
print(int(s))

Submission status: Accepted

Solution code:
n = int(input())

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = Counter()
for i in range(N):
    s[''.join(sorted(input()))] += 1
ans = 0
for kw, count in s.most_common():
    for i in range(1, int(count)):
        ans += i
    if int(count) < 2:
        break
print(ans)

Submission status: Accepted

Solution code:
#from Collections import Counter

N = int(input())
count = 0
word = {}
def str_sort(str):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(str)
for _ in range(N):
    sorted_str = str_sort(input())
    if sorted_str not in word:
        word[sorted_str] = [0]
        word[sorted_str].append(1)
    else:
        if word[sorted_str] == 0:
            word[sorted_str][0] = 1
        else:
            word[sorted_str][0] += word[sorted_str][1]
            word[sorted_str][1] += 1
            #word[sorted_str] = word[sorted_str][0] + word[sorted_str][1]
total = sum(
    v[0] for v in word.values()
)
#print(word)
print(total)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [list(input()) for i in range(n)]
l = [''.join(sorted(i)) for i in s]
c = list(collections.Counter(l).values())
x = sum([sum([i for i in range(i)]) for i in c if i != 1])
print(x) if 0 < x else print(x)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
N = int(input())
words = {}
while N > 0:
    word = ''.join(sorted(input().rstrip()))
    if word in words:
        words[word] += 1
    else:
        words[word] = 1
    N -= 1

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

print(count)

Submission status: Accepted

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

    
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
strings = [raw_input() for _ in xrange(n)]
hashes = {}
for s in strings:
  h = ''.join(sorted(s))
  hashes[h] = hashes.get(h, 0) + 1
total = 0
for c in hashes.itervalues():
  total += c * (c-1)
print total/2 # not sure why I need to /2

Submission status: Accepted

Solution code:
n = int(input())
S = [input() for i in range(n)]

ans = 0
cnt = {}

for s in S:
    s = "".join(sorted(s))
    if s in cnt:
        ans += cnt[s]
        cnt[s] += 1
    else:
        cnt[s] = 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = [''.join(sorted(raw_input())) for _ in range(n)]
d = {}
ans = 0
for si in s:
    if si in d:
        ans += d[si]
        d[si] += 1
    else:
        d[si] = 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
d = {}
ans = 0
for i in range(n):
    si = ''.join(sorted(raw_input()))
    if si in d:
        ans += d[si]
        d[si] += 1
    else:
        d[si] = 1
print(ans)

Submission status: Accepted

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

for s in S:
    s.sort()
S.sort()

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    tmp = list(input())
    tmp.sort()
    S.append(''.join(tmp))
cnt = 0

mydict = {}

for i in range(N):
    if (S[i] in mydict.keys()) == False:
        mydict[S[i]] = 0
    else:
        cnt += mydict[S[i]]+1
        mydict[S[i]] += 1

print(cnt)

Submission status: Accepted

Solution code:
ROW = int(input())
LIST = [input() for i in range(ROW)]

dic={}
ans=0
for i in LIST:
    j = " ".join(sorted(i))

    if j in dic:
        ans+= dic[j]
        dic[j] += 1
    else:
        dic[j] = 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

s = []
ans = 0
count = 1

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

s.sort()

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(int(ans))

Submission status: Accepted

Solution code:
N=int(input())
l=[]
for x in range(0,N):
    l.append(input())
for x in range(N):
    k=list(l[x])
    k.sort()
    k=''.join(k)
    l[x]=k
l.sort()
k=1
ans=0
for i in range(N-1):
    if l[i]==l[i+1]:
        k+=1
    else:
        ans+=k*(k-1)//2
        k=1
ans+=k*(k-1)//2
print(ans)

Submission status: Accepted

Solution code:
import collections
import itertools
ans = 0

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

d = {}
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l2.sort()
    a = ""
    for i in l2:
        a += i
    if a in d:
        ans+=d[a]
        d[a]+=1
    else:
        d[a] = 1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

H=[]
c=0
t=0
for i in range(N):
    h=list(input())
    h.sort(reverse=False)
    H.append(h)

H.sort(reverse=False)

for j in range(N-1):
    
    if H[j]==H[j+1]:
        c+=1

    else:
        t+=int((c)*(c+1)/2)
        c=0

if c:
    t+=int(((c)*(c+1)/2))
        

print(t)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
 
dic = {}
ans = 0
 
for ss in s:
    #temp = [ch for ch in ss]
    #temp.sort()
    
   # sss = "".join(temp)
    sss="".join(sorted(ss))
  
    if sss in dic:
        ans += dic[sss]
        dic[sss] += 1
    else:
        dic[sss] = 1
 
print(ans)

Submission status: Accepted

Solution code:
n =int(input())

S=[]
ans = 0
count=1

for i in range(n):
    tmp=input()
    S.append(sorted(tmp))

S.sort()

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

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

print(int(ans))

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for _ in range(N)]
 
import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())
 
import sys
sys.setrecursionlimit(100000000)
 
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
count = 0
memo = [0]*10**6
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]
        
print(count)

Submission status: Accepted

Solution code:
N=int(input())
C=[]
dic={}
ans=0
for i in range(N):
  a=str(input())
  C.append(a)
for i in C:
  ab=[j for j in i]
  ab.sort()
  aaa="".join(ab)
  #print(aaa)
  if aaa in dic:
    ans+=dic[aaa]
    dic[aaa]+=1
  else:
    dic[aaa]=1
print(ans)
#print(dic)

Submission status: Accepted

Solution code:
# collection.Counterを使わなくても同じようにできる
n=int(input()) 
s = []
for i in range(n):
    s.append(list(input()))
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)

Submission status: Accepted

Solution code:
from collections import Counter

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

    # Counterは要素を数え上げる
cnt = Counter()
ans = 0
for s in S:
    # 単語をアナグラムの判別がしやすように並び替え
    a = ''.join(sorted(list(s)))
    # cntの中に同じものがあればカウント 
    if a in cnt:
        # ans += 1 じゃダメ ここがcollection.Counterを使うキモな気がする　 
        ans += cnt[a]
    # アナグラム判定後にcntに要素を加える
    cnt[a] += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lst = []
dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if s not in dic.keys():
        dic[s] = 1
    else:
        dic[s] += 1

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

print(ans)

Submission status: Accepted

Solution code:
import collections
from scipy.misc import comb

N = int(input())

diclist = []

i=0
while i < N:
  temp = list(input())
  temp.sort()
  tmp_el = ''.join(temp)
  diclist.append(tmp_el)
  i += 1
  
c = collections.Counter(diclist)
clist = list(c.values()) 
ccomb = [comb(clist[i], 2, exact = True) for i in range(0,len(clist))]

print(sum(ccomb))

Submission status: Accepted

Solution code:
N = int(input())

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

count = 0
d = {}
for elm in s:
    if elm in d:
        count += d[elm]
        d[elm] += 1
    else:
        d[elm] = 1

print(count)

Submission status: Accepted

Solution code:
n,*sl, = map(lambda x:''.join(sorted(x)),open(0).read().split())
count = 0
dict = {}
for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Submission status: Accepted

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

dic = {}
ans = 0

for ss in s:
    temp = [ch for ch in ss]
    temp.sort()
    sss = "".join(temp)
    
    if sss in dic:
        ans += dic[sss]
        dic[sss] += 1
    else:
        dic[sss] = 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
readline = sys.stdin.readline
C = defaultdict(int)
N = int(readline())
ans = 0
for i in range(N):
    *s, = readline()
    s.sort()
    t = tuple(s)
    ans += C.get(t, 0)
    C[t] += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

import collections

c = collections.Counter(s)


ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s = []
for _ in range(n):
    s += [''.join(map(str, (sorted(list(str(input()))))))]

import collections

c = collections.Counter(s)

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
s=["".join(sorted(stdin.readline().rstrip())) for _ in range(n)]
t=Counter(s).values()
ans=0
for i in t:
    ans+=sum(range(1,i))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
words = {}

ans = 0
for _ in range(N):
    w = list(input())
    w.sort()
    w = "".join(w)
    if w not in words:
        words[w] = 1
    else:
        ans += words[w]
        words[w] += 1
print(ans)

Submission status: Accepted

Solution code:
num = int(input())
arr = []
d = {}

for i in range(num):
    s = sorted(list(input()))
    ss = ''.join(s)
    arr.append(ss)

#print(arr)
ans = 0

for i in range(num):
    if arr[i] in d:
        ans += d[arr[i]] 
        d[arr[i]] += 1
    else:
        d[arr[i]] = 1

print(ans)

Submission status: Accepted

Solution code:
def f_c():

    n = int(input())
    d = {}
    dc = {}
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in d:
            dc[s] += d[s]
            d[s] += 1
        else:
            d[s] = 1
            dc[s] = 0
    print(sum(dc.values()))

if __name__ == "__main__":
    f_c()

Submission status: Accepted

Solution code:
N = int(input())

s = ''.join(sorted(input()))
h = {s: 1}
count = 0
for i in range(N - 1):
    # 比較がしやすいようにソートしたものを追加
    s = ''.join(sorted(input()))
    if s in h:
        count += h[s]
        h[s] += 1
    else:
        h[s] = 1

print(count)

Submission status: Accepted

Solution code:
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n=int(input())
s=["".join(sorted(input())) for _ in range(n)]
t=Counter(s).values()
ans=0
for i in t:
    ans+=sum(range(1,i))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
#N = 100000
#S = [input() for i in range(N)]
S = [input() for i in range(N)]
#S = ['zabcdefghi']*100000

#groups = {i: [] for i in range(26)}
sort_str = {}

counter = 0
for i in range(N):
    s = ''.join(sorted(S[i]))
    if s in sort_str:
        counter += sort_str[s]
        sort_str[s] += 1 
    else:
        sort_str[s] = 1
print(counter)
#
#
#    groups[int(s[0], 36) - 10].append(s)
#
#counter = 0
#for group in groups.values():
#    for i in range(len(group)):
#        for j in range(i+1, len(group)):
#            print(i, j)
#            if group[i] == group[j]:
#                counter += 1
#
#print(counter)
#
#

Submission status: Accepted

Solution code:
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for i in [0]*N]
words = {}
cnt = 0
for i in s:
    i = "".join(sorted(i))
    time = words.get(i,0)
    cnt += time
    words[i] = time + 1
print(cnt)

Submission status: Accepted

Solution code:
import glob
import numpy as np
import heapq


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\137\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):

        N = int(self.input_data())
        problem = ["" for i in range(N)]

        for i in range(N):
            tmp = self.input_data()
            tmp = list(tmp)[0:10]
            tmp.sort()
            for j in range(10):
                problem[i] += tmp[j]

        problem.sort()
        con_num = 1
        now = ""
        result = 0

        for s in problem:
            if now == s:
                con_num += 1
            else:
                result += int(con_num * (con_num-1) / 2)
                con_num = 1
                now = s
        result += int(con_num * (con_num - 1) / 2)

        print(str(result))


solver = C(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

Solution code:
n = int(input())
sl = [''.join(sorted(input())) for _ in [0]*n]
count = 0
dict = {}
for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
sl = [input() for _ in [0]*n]
count = 0
dict = {}
for s_raw in sl:
  s = ''.join(sorted(s_raw))
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
sl = [input() for _ in [0]*n]
count = 0
dict = {}
for s_raw in sl:
  s = ''.join(sorted(s_raw))
  if s in dict:
    #count += dict[s]
    dict[s] += 1
  else:
    dict.setdefault(s, 1)
for s in dict:
  count += dict[s]*(dict[s]-1)//2
print(count)

Submission status: Accepted

Solution code:
import sys
import collections
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(sys.stdin.readline().rstrip())
SList=[]
for i in range(N):
  S=sys.stdin.readline().rstrip()
  SList.append("".join(sorted(S)))
  
c = collections.Counter(SList)

ans=0
for v in c.values():
  if v<=1:
    continue
  ans+=combinations_count(v, 2)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  a.append(input())
for i in range(n):
  k = list(a[i])
  k.sort()
  k = ''.join(k)
  a[i] = k
a.sort()
k = 1
s = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    k += 1
  else:
    s += k*(k-1)/2
    k = 1
s += k*(k-1)/2
print(int(s))

Submission status: Accepted

Solution code:
n = int(input())
sl = [input() for _ in [0]*n]
count = 0
dict = {}
for s_raw in sl:
  s = ''.join(sorted(s_raw))
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict.setdefault(s, 1)
print(count)

Submission status: Accepted

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


from collections import Counter
counter = Counter(S)
answer = sum(x * (x - 1) // 2 for x in counter.values())
print(answer)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
S = [''.join(sorted(list(str(input())))) for i in range(N)]

countDict = defaultdict(int)
ans = 0
for s in S:
    ans += countDict[s]
    countDict[s] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin
 
def main():
    n = int(input())
    S = ["".join(sorted(input())) for _ in range(n)]

    ans = 0
    dd = defaultdict(int)
    for s in S:
        ans += dd[s]
        dd[s] += 1
    print(ans)
 
input = lambda: stdin.readline().rstrip()
main()

Submission status: Accepted

Solution code:

n = int(input())
lista= [''.join(sorted(input())) for _ in range(n)]
 
dic = {}
ans = 0
for word in lista:
    if word not in dic:
        dic[word] = 1
    else:
        ans += dic[word]
        dic[word] += 1
 
print(ans)

Submission status: Accepted

Solution code:
Ncount = input()
strings = []
count_flag = 0
letters = {}
for i in range(int(Ncount)):
  strings.append(''.join(sorted(input())))

for i in strings:
  if i not in letters:
    letters[i] = 0
  else :
    letters[i] += 1
    count_flag += letters[i]

print(count_flag)

Submission status: Accepted

Solution code:
from collections import Counter
from sys import stdin


def main():
    n = int(input())
    anas = Counter(''.join(sorted(stdin.readline())) for _ in range(n))

    result = sum(sum(range(anas[a])) for a in anas)
    print(result)


main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import collections

n = int(input())
s = np.array([[str(i) for i in input().split()] for i in range(n)])
s = np.ravel(s)
ans = 0
sorted_list = [''.join(sorted(e)) for e in s]
# dict
c = collections.Counter(sorted_list)
for i in c.values():
  for j in range(0, i):
    ans += j

print(ans)

Submission status: Accepted

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

dic = {}
ans = 0
for word in SList:
    if word not in dic:
        dic[word] = 1
    else:
        ans += dic[word]
        dic[word] += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
ls=[sorted(list(input())) for _ in range(N)]
ls.sort()

l=[]
for i,s in enumerate(ls):
    if i == 0:
        l.append(1)
        continue
    
    if ls[i-1] == s:
        l[-1]+=1
    else:
        l.append(1)
sol=0
for e in l:
    if e==1:
        continue
    
    sol+=int(0.5*(e-1)*e)

print(sol)

Submission status: Accepted

Solution code:
N=int(input())
#ls=[]
ds={}
for i in range(N):
    s=input()
    #dc={}
    #for ss in s:#sを辞書化
        #if ss in dc.keys():
            #dc[ss]+=1
        #else:
            #dc[ss]=1
    #s=sorted(s)
    s="".join(sorted(s))#sを比較できる形へ

    #ls.append(dc)
    #if dc in ds:#文字列がそれぞれ何個重複しているかわかる
    #_TypeError: unhashable type: 'dict'
    #_辞書のキーはイミュータブルでなければならない
    #    ds[dc]+=1
    #else:
    #    ds[dc]=1"""

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

ans=0
for i in ds:
    ans+=ds[i]*(ds[i]-1)/2
#print(ls)
#for i in range(N):
    #for j in range(i+1,N):
        #if ls[i]==ls[j]:
        #    ans+=1

    #dc=ls[i]
    #del ls[i]
    #if dc in ls:
print(int(ans))

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	s = [input() for _ in range(n)]
	a = defaultdict(int)
	for i in s:
		t = ''
		for j in sorted(i):
			t += j
		a[t] += 1
	ans = 0
	for v in a.values():
		ans += v * (v-1) // 2
	print(ans)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    n = int(input())
    anas = Counter(''.join(sorted(input())) for _ in range(n))

    result = sum(sum(range(anas[a])) for a in anas)
    print(result)


main()

Submission status: Accepted

Solution code:
import math
from collections import Counter


N = int(input())

def sort_string(s):
    s = list(s)
    s.sort()
    
    return ''.join(s)

S = [sort_string(input()) for _ in range(N)]
c = Counter(S)

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

count = 0
for s in c.values():
    if s > 1:
        count += combinations_count(s, 2)

print(count)

Submission status: Accepted

Solution code:
n = int(input())
d = dict()
for _ in range(n):
  l = "".join(sorted(list(input()))) 
  if l not in d:
    d[l] = 0
  d[l] += 1
ans = 0
for x in d.values():
  ans += x*(x-1)//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = []
s = [input() for i in range(N)]
count = 0
a = []
sortdict = {}
for i in range(N):
    a = str(sorted(s[i]))
    if a in sortdict:
        sortdict[a] += 1
    else:
        sortdict[a] = 0
sort_list = list(sortdict.values())
for i in range(len(sort_list)):
    sort_list[i] = int((sort_list[i])*(sort_list[i] + 1)/2)
 

print(sum(sort_list))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    d = {}
    ans = 0
    for _ in range(N):
        s = "".join(sorted(list(input())))
        if s in d:
            ans += d[s]
            d[s] += 1
        else:
            d[s] = 1
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    c = list(input())
    c.sort()
    a.append(''.join(c))
a.sort()
sol = 0
i = 0
while i < len(a):
    j = i + 1
    temp = 1
    while j < len(a) and a[j] == a[i]:
        j += 1
        temp += 1
    i = j
    if temp == 0 or temp == 1: continue
    if temp == 2:
        sol += 1
        continue
    if temp == 3:
        sol += 3
        continue
    else:
        sol += (temp * (temp - 3) // 2 + temp)
print(sol)

Submission status: Accepted

Solution code:
N = int(input())
ss = ["".join(sorted(list(input()))) for _ in range(N)]

from collections import Counter
d = Counter(ss)

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

print(int(cnt))

Submission status: Accepted

Solution code:
def main():
    n = int(input())

    count = 0
    found = {}
    for _ in range(n):
        strs = list(input())
        strs.sort()
        str = ''.join(strs)
        if str in found:
            count += found[str]
            found[str] += 1
        else:
            found[str] = 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())

    count = 0
    found = {}
    for _ in range(n):
        str = ''.join(sorted(input()))
        if str in found:
            count += found[str]
            found[str] += 1
        else:
            found[str] = 1

    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
S = []
for i in range(N):
    t = input()
    l = []
    for a in t:
        l.append(ord(a)-ord('a'))
    l.sort()
    v = 0
    for a in l:
        v = v * 26 + a
    S.append(v)

S.sort()
S.append(-1)

P = -1
C = 0
Ans = 0
for v in S:
    if P != v:
       Ans += int(C * (C - 1) / 2)
       C = 1
    else:
        C += 1
    P = v

print(Ans)

Submission status: Accepted

Solution code:
#C'
from collections import Counter

n=int(input())  #数値入力 「N」だけの入力のとき
count_by_kw = Counter()
for i in range(n):
    count_by_kw[''.join(sorted(input()))]+=1

cnt=0
for val in count_by_kw.values():
    cnt+=val*(val-1)//2    
    
print(cnt)