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:
n=int(input())
d=dict()
a=0
for _ in range(n):
    s=''.join(sorted(input()))
    if s in d:
        a+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(a)

Submission status: Accepted

Solution code:
from functools import reduce

N = int(input())
Sn = [''.join(sorted(list(input()))) for _ in range(N)]
dic = {}
for k in range(len(Sn)):
  if Sn[k] in dic:
    dic[Sn[k]] += 1
  else:
    dic[Sn[k]] = 1

ans = list(map(lambda x:x*(x-1)//2, list(dic.values())))
ans = sum(ans)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
count=0
dic={}
ppp=""
for i in range(n):
  s=list(input())
  s.sort()
  s=ppp.join(s)
  if s in dic:
    dic[s]+=1
  else:
    dic[s]=1
kouho=0
for j in range(len(dic)):
  kk=dic.popitem()
  c=kk[1]
  kouho+=(c*(c-1))//2
print(kouho)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
#import numpy as np

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

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

s = {}
ans = 0

for i in range(n):
    l = list(str(stdin.readline().rstrip()))
    l.sort()
    l = str(l)
    if l in s:
        s[l] += 1
        ans += s[l] -1
    else:
        s[l] = 1

print(ans)

Submission status: Accepted

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

from collections import defaultdict as dl
n  =ii()
s = []
for _ in range(n):
    ss = input()
    a = sorted(ss)
    a = "".join(a)
    s.append(a)
dic = dl(int)
for i in range(n):
    dic[s[i]] += 1

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

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
def sort_string(st):
  res = list(st)
  res.sort()
  return "".join(res)

s = [sort_string(input()) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for n in c.values():
  ans += n*(n-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import math
n = int(input())
s_list = ["".join(map(str,sorted(input()))) for i in range(n)]
s_counter = Counter(s_list)
s_len = len(s_counter)
s_most = s_counter.most_common()
#print(s_counter)
ans = 0
for i in range(s_len):
    if s_most[i][1] != 1:
        dum = s_most[i][1]
        ans += (dum * (dum-1)) // 2
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N=int(input())
S=[input() for i in range(N)]
d={}
#10*N
for i in S:
  s="".join(sorted(i))
  if s in d:
    d[s]+=1
  else:
    d[s]=1  
ans=0
for v in d.values():
  if v>=2:
    ans+=cc(v,2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [str(sorted(input())) for _ in range(N)]
print(sum(map(lambda x: x * (x - 1) // 2, Counter(S).values())))

Submission status: Accepted

Solution code:
N=int(input())
S={}
c={}
for i in range(N):
    s=''.join(sorted(input()))  
    if s in S:
        c[s]+=1
        if c[s]>=2:
            S[s]=S[s]+c[s]
        else:
            S[s]+=1

    else:
        S[s]=0
        c[s]=0
print(sum(S.values()))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n, *S = sys.stdin.read().split()
n = int(n)

def main():
    t = [''.join(sorted(t)) for t in S]
    c = Counter(t)
    cnt = 0
    for v in c.values():
        cnt += v*(v-1)
    print(cnt//2)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    N = int(input())
    s = ["".join(sorted(input())) for _ in range(N)]
    S = Counter(s)
    ans = 0
    for a in S.values():
        ans += sigma(a)
    print(ans)


def sigma(x):
    sum = 0
    for i in range(1, x):
        sum += i
    return sum


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())

result=[]

for item in range(n):
  s=list(input())
  #print(s)
  s.sort()
  result.append("".join(s))

tmp_cnt=0
count=0
temp=""
result.sort()
result.append("")


for item in result:
    if temp!=item:
        count+=tmp_cnt*(tmp_cnt-1)//2
        tmp_cnt=1
        temp=item
    else:
        tmp_cnt+=1

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N = int(input())
    counter = defaultdict(int)
    for _ in range(N):
        s = ''.join(sorted(input()))
        counter[s] += 1
    answer = 0
    for c in counter.values():
        answer += c * (c - 1) // 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
s_dict = {}
ans = 0
for _s in s:
  _s = sorted(_s)
  _s = ''.join(_s)
  s_dict.setdefault(_s, 0)
  ans += s_dict[_s]
  s_dict[_s] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    if n <= 1:
        return 0
    return P(n, r)//math.factorial(r)
N = int(input())
d = defaultdict(int)
for i in range(N):
    d[','.join(sorted(input()))] += 1
ans = 0
for value in d.values():
    ans += C(value,2)
print(ans)

Submission status: Accepted

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

c=Counter(s)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools

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

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    T = [tuple(sorted(iss())) for _ in range(N)]
    S = collections.Counter(T)
    print(sum(v*(v-1)//2 for v in S.values()))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s_lsit = {}
cnt = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    if s in s_lsit:
        cnt += s_lsit[s]
        s_lsit[s] += 1
    else:
        s_lsit[s] = 1
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        mul=(T*(T-1))//2
        cnt+=mul
    else:
        continue
print(int(cnt))

Submission status: Accepted

Solution code:

n=int(input())
st=dict()
for i in range(n):
    si=list(input())
    si.sort()
    si="".join(si)
    if si in st:
        st[si]+=1
    else:
        st[si]=1
        
icnt=0
for i in st.values():
    if i>1:
        icnt+=i*(i-1)//2
        
print(icnt)

Submission status: Accepted

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

l = [""] * n
for i in range(n):
    temp = input()
    l[i] = "".join(sorted(temp))

c = dict(collections.Counter(l))

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

a = [input() for i in range(n)]

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

a = sorted(a)

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

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

Submission status: Accepted

Solution code:
n = int(input())

cnt = 0
anagrams = {}
for _ in range(n):
    s = input()
    sorted_s = ''.join(sorted(s))
    if sorted_s in anagrams:
        anagrams[sorted_s] += 1
        cnt += anagrams[sorted_s]
    else:
        anagrams[sorted_s] = 0

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
N = int(input())
S = [sorted(list(input())) for _ in range(N)]
s = sorted(S)
s.append(["X"])
sum = 0
num = 1
for i in range(N):
  if s[i] == s[i+1]:
    num += 1
  else:
    sum += num*(num-1)//2
    num = 1
print(sum)

Submission status: Accepted

Solution code:
import collections
from math import factorial

def combinations_count(n, r): #組み合わせ
    return factorial(n) // (factorial(n - r) * factorial(r))

n = int(input())
li = []
ans = 0

for i in range(n):
    s = list(input())
    s.sort()
    li.append(''.join(s))

c = list(collections.Counter(li).values())
c.sort(reverse=True)

for i in c:
    if i == 1:
        break
    ans += combinations_count(i, 2)

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
from scipy.misc import comb
n = int(input())

dic = {}
for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1
sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += comb(num, 2,exact=True)
print(math.floor(sum))

Submission status: Accepted

Solution code:
import math
n = int(input())

dic = {}


def twoKimuawaseSum(num):
    result = 0
    for i in range(1, num):
        result += i
    return result


for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1
sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += twoKimuawaseSum(num)
print(math.floor(sum))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
#from collections import Counter


def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    N = int(input())
    combi = {}
    for i in range(N):
        t = ''.join(sorted(input()))
        #print(t)
        if t not in combi.keys():
            #combi.append(t)
            combi[t] = 1
        else:
            combi[t] += 1

    ans = 0
    for v in combi.values():
        ans += combinations_count(v,2)
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter as counter
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,s):
    res = 0
    for i in counter(s).values():
        if 1 < i :
            res += int(i*(i-1)/2)
    print(res)

n = ii()
s = list("".join(sorted(input())) for _ in range(n))
main(n,s)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
sn = [None] * n
for i in range(n):
    sn[i] = ''.join(sorted(list(input().strip())))

c = Counter(sn)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
ANS = {}
for i in range(N):
  si = input()
  new_str_list = sorted(si)
  s = "".join(new_str_list)
  if s not in ANS.keys():
    ANS[s] = 1
  else:
    ANS[s] += 1
  ans += ANS[s]
      
print(ans-N)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N=II()
S=[''.join(sorted(SR())) for _ in range(N)]
C=Counter(S)
ans = 0
for c in C.values():
    if c>1:
        ans+=c*(c-1)/2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
#文字を最初から数えていって、辞書に入れていき、同じになるかどうかを確認する
#nこ分の文字列があるってことは、nこ分の辞書が生まれる可能性があるってこと
#文字列を小さい順に書き換えた時に、全くもって一致すれば良い
slist = []
countdic = {}
# ss = sorted(input())
# ss = input()
snum = ''.join(sorted(input()))
# print(snum)

# ss.sort()
# print(ss)
# slist.append(snum)
# print(slist)
countdic[snum] = 0
# print(countdic)

for i in range(n-1):
    snum = "".join(sorted(input()))
    if snum not in countdic:
        countdic[snum] = 0
        # print(countdic)
    else:
        countdic[snum] += 1
        # print(countdic)
count_values =list(countdic.values())
# print(count_values)
count_values_len = len(count_values)
# print(count_values_len)

count_sum = 0
numtemp = 0

for i in range(count_values_len):
    count_values[i] = count_values[i] * (count_values[i]+1) / 2
# print(count_values)
print(int(sum(count_values)))

Submission status: Accepted

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

d = defaultdict(int)
ans = 0
for i in range(N):
  if s[i] in d.keys():
    ans += d[s[i]]
    d[s[i]] += 1
  else:
    d[s[i]] += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    S = [("").join(sorted(input().rstrip())) for i in range(N)]
    DICT = {}
    ans = 0
    for i in range(N):
        if S[i] in DICT:
            DICT[S[i]][1] += DICT[S[i]][0]
            DICT[S[i]][0] += 1
        else:
            DICT.setdefault(S[i], [1,0])
    for dicts in DICT:
        ans += DICT[dicts][1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    S = [("").join(sorted(input().rstrip())) for i in range(N)]
    DICT = {}
    ans = 0
    for i in range(N):
        if S[i] in DICT:
            DICT[S[i]] += 1
            ans += DICT[S[i]]
        else:
            DICT.setdefault(S[i], 0)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

slist.sort()
slist += ['x']
a = slist[0]
ans = 0
count = 1
for s in slist[1:]:
  if a == s:
    count += 1
  else:
    if count > 1:
      ans += int(count*(count-1)/2)
    count = 1
    a = s
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
strs = (input() for _ in range(0,N))

ans = {}
for string in strs:
    key = ''.join(sorted(string))
    if key not in ans:
        ans[key] = 0
    else:
        ans[key] += 1
print(sum([x*(x+1)//2 for x in ans.values()]))

Submission status: Accepted

Solution code:
from collections import Counter as CC
N = int(input())
L = [str(sorted(list(input()))) for i in range(N)]
C = CC(L)
print(sum([C[i] * (C[i] - 1) // 2 for i in C if C[i] > 1]))

Submission status: Accepted

Solution code:
n = int(input())

dic = {}

for i in range(n):
    s = sorted(input())
    temp = "".join(s)
    if temp not in dic:
        dic[temp] = 1
    else:
        dic[temp] += 1
    
ans = 0
for i in dic.values():
    ans += i*(i-1)/2

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
a=int(input())
l=[]
l1=[]
p=0
for i in range(a):
    b=input()
    b=list(b)
    b=sorted(b)
    b="".join(map(str,b))
    l.append(b)
d=Counter(l)
for j in d:
        if d[j]<=2:
            p+=d[j]//2
        else:
            c=d[j]-1
            p+=(c*(c+1))//2
print(p)

Submission status: Accepted

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

ans = 0
cnt = 1
for i in range(N - 1):
    if strings[i] == strings[i + 1]:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt * (cnt - 1) // 2
        cnt = 1
print(ans) if cnt <= 1 else print(ans + cnt * (cnt - 1) // 2)

Submission status: Accepted

Solution code:
from collections import defaultdict
def main(): 
    N = int(input())
    words = [ "".join(sorted(list(input()))) for i in range(N)]
    w = defaultdict(int)

    for word in words:
        w[word] += 1
        
    pair = 0
    for k, v in w.items():
        if v >= 2:
            pair += v*(v-1)//2
    
    print(pair)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 初期入力

import sys
input = sys.stdin.readline
N = int(input())
S = [input().strip() for i in range(N)]

from collections import Counter
c =[]
for i_s in S:
    i_sorted =sorted(i_s) #各文字列をソート
    i="".join(i_sorted)
    c.append(i)

from collections import Counter
ans_colle =Counter(c) #ソートした後の文字列の数
ans =0
for i in ans_colle.values():
    ans +=i*(i-1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = ''.join(sorted(input()))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = sorted([''.join(sorted(input())) for _ in range(n)])
t = len(set(S))
cnt = [1] * t
loop = 0

for i in range(0, t):
    for j in range(loop, n - 1):
        if S[j] == S[j + 1]:
            cnt[i] += 1
        else:
            loop = j + 1
            break
# print(cnt)

ans = 0
for i in range(0, t):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
strings = sorted(str(sorted(input())) for _ in range(N))

ans = 0
cnt = 1
for i in range(N - 1):
    if strings[i] == strings[i + 1]:
        cnt += 1
    else:
        if cnt > 1:
            ans += cnt * (cnt - 1) // 2
        cnt = 1
print(ans) if cnt <= 1 else print(ans + cnt * (cnt - 1) // 2)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = str(sorted(input()))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = str(sorted(input()))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter


N = int(input())
dic = defaultdict(int)
ans = 0
for _ in range(N):
    elem = [(k, v) for k, v in Counter(input()).items()]
    elem = tuple(sorted(elem))
    ans += dic[elem]
    dic[elem] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
input=sys.stdin.readline
N=int(input())

s_dic=defaultdict(int)
for i in range(N):
  s=list(input().rstrip())
  s.sort()
  s_str="".join(s)
  s_dic[s_str]+=1
#print(s_dic)

answer=0
for val in s_dic.values():
  answer+=(val*(val-1))//2

print(answer)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=collections.Counter(["".join(sorted(input())) for _ in range(n)])
v=list(s.values())
res=0
for u in v:
	if u!=1:
		res += u*(u-1)//2
print(res)

Submission status: Accepted

Solution code:
P=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]
n=int(input())
A=[1]*n

for i in range(n):
	s=input()
	for j in range(10):
		A[i] *= P[ord(s[j])-97]

res=0
A.sort()
cnt=0

for i in range(n-1):
		if A[i]==A[i+1]:
			cnt += 1
		else:
			res += cnt*(cnt+1)//2
			cnt=0
if cnt != 0:
	res += cnt*(cnt+1)//2
print(res)

Submission status: Accepted

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

N = int(input())
s = [sorted(input()) for _ in range(N)]
s.sort()
sum = 0
i = 1

for j in range(1,N):
  if s[j] == s[j-1]:
    i += 1
  else:
    if i > 1:
      sum += combinations_count(i, 2)
    i = 1
if i > 1:
      sum += combinations_count(i, 2)
    
  
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
s.sort()
tmp = s[0]
t = 0
ans = 0
for x in s[1:]:
    if x == tmp:
        t += 1
    else:
        ans += t * (t + 1) // 2
        t = 0
        tmp = x
ans += t * (t + 1) // 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(["".join(sorted(input())) for _ in range(n)])
ans = 0
for w in c:
    ans += c[w] * (c[w] - 1)
print(ans // 2)

Submission status: Accepted

Solution code:
from collections import Counter
from scipy import misc
N = int(input())
c = []
for i in range(N):
    a = list(input())
    c.append(''.join(sorted(a)))
d = Counter(c)
print(sum([misc.comb(v,2,exact=True) for v in d.values() if v > 1]))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
S = defaultdict(int)

for i in range(N):
  s = sorted(input())
  w = "".join(s)
  S[w] += 1

ans = sum([(i*(i-1))//2 for i in list(S.values())])

print(ans)

Submission status: Accepted

Solution code:
import math
from collections import Counter
n=int(input())
s = [str(sorted(list(input()))) for i in range(n)]
c = Counter(s)
#l=[]
#for si in set(s):
#    l.append(s.count(si))
ans=0
for i in c.values():
    if i>=2:
        x = (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
        ans+=x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [0]*n
L = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	L[i] = ''.join(sorted(list(s[i])))
D = collections.Counter(L)
for i in D.values():
	ans += i*(i-1)//2
print(ans)

Submission status: Accepted

Solution code:
import collections
import math
n = int(input())
s = [0]*n
T = [0]*n
L = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	T[i] = sorted(list(s[i]))
	L[i] = ''.join(T[i])
D = collections.Counter(L)
for i in D.values():
	ans += i*(i-1)/2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = [str(input()) for _ in range(n)]
e = []
for i in range(n):
    e.append("".join(sorted(s[i])))
e.sort()
g = [1]
for i in range(n-1):
    if e[i] != e[i+1]:
        g.append(1)
    else:
        g[-1] += 1
ans = 0
for i in g:
    ans += (i*(i-1)//2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

print(res)

Submission status: Accepted

Solution code:
n = int(input())
a = [sorted(input()) for i in range(n)]
from collections import Counter
b = []
for i in range(n):
    b.append(''.join(a[i]))
count = Counter(b)
ans = 0
for i in set(b):
    ans += count[i]*(count[i]-1)/2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

standard = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    
    if s in standard:
        standard[s] += 1
    else:
        standard[s] = 1

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

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
#a, b, x = list(map(int, input().split()))
#b = list(map(int, input().split()))
s_dic = {}
ans = 0
for i in range(n):
    s = input()
    s = ''.join(sorted(list(s)))
    if s in s_dic:
        # 辞書のキーで管理
        ans += s_dic[s]
        s_dic[s] += 1
    else:
        s_dic[s] = 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

d = dict()
for i in range(n):
  s = "".join(sorted(list(input())))
  d[s] = d.get(s, 0) + 1
  
ans = 0
for key in d:
  ans += d[key] * (d[key]-1) // 2
  
print(ans)

Submission status: Accepted

Solution code:
def f(n):
  return (n**2-n)//2
N=int(input())
A=[]
for i in range(N):
  S=sorted(input())
  A.append("".join(S))
A=sorted(A)
A.append("")
ans=0
n=1
for i in range(N):
  if A[i]==A[i+1]:
    n+=1
  else:
    ans+=f(n)
    n=1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from scipy import misc
n = int(input())
s = [list(input()) for _ in range(n)]

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

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] >= 2:
        ans += round(float(misc.comb(ss[i],2)))
print(int(ans))

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
s = []
for _ in range(n):
    s.append(''.join(sorted(input())))
s.sort()
ans = 0
cnt = 0
for i in range(1, n):
    if s[i - 1] == s[i]:
        cnt += 1
    else:
        ans += (cnt * (cnt + 1) // 2)
        cnt = 0
else:
    ans += (cnt * (cnt + 1) // 2)
print(ans)

Submission status: Accepted

Solution code:
# C - Green Bin

from collections import defaultdict

d = defaultdict(int)
n = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
ans = 0

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

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

print(ans)