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())
s=[input() for i in range(n)]
ans=0
word={}
for j in s:
  a=''.join(sorted(list(j)))
  if a in word:
    ans+=word[a]
    word[a]+=1
  else:
    word[a]=1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = Counter(''.join(sorted(input())) for i in range(n))#文字列をsortedした時点でlistになる
print(sum(map(lambda x : x * (x-1) // 2, s.values())))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = Counter("".join(sorted(input())) for i in range(n))#文字列をsortedした時点でlistになる
print(sum(map(lambda x : x * (x-1) // 2, s.values())))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s =  Counter("".join(sorted(input())) for i in range(n))

print(sum(map(lambda x : x * (x - 1) // 2, s.values())))

Submission status: Accepted

Solution code:
n = int(input())

li1 = []
for _ in range(n):
    s = list(input())
    li1.append(sorted(s))

cnt = 0
li2 = sorted(li1)
li3 = []
for i in range(1, len(li2)):
    if li2[i] == li2[i-1]:
        cnt += 1
    else:
        li3.append(cnt)
        cnt = 0
    if i == len(li2)-1:
        li3.append(cnt)

cnt1 = 0
for i in li3:
    cnt1 += (i*(i+1))//2
    
print(cnt1)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s =  Counter("".join(sorted(input())) for i in range(n))

print(sum(map(lambda x : x * (x - 1) // 2, s.values())))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

i  = lambda: int(input())
s  = lambda: input()

str_m = {}
for _ in range(i()):
  S = ''.join(sorted(s()))
  if S in str_m:
    str_m[S] += 1
  else:
    str_m[S] = 1

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

print(count)

Submission status: Accepted

Solution code:
import collections
import math

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

for val in range(n):
    s = input()
    s_L = [i for i in s]
    s_L.sort()
    s = "".join(s_L)
    str_L.append(s)


c = collections.Counter(str_L)

str_L = list(set(str_L))


ans = 0
r = 2

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

for val in str_L:
    n = c[val]
    #print(n,r)
    ans = ans + combinations_count(n,r) #comb(n, r, exact=True)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import collections 
 
N=int(input())
l=[]
 
for i in range(N):
    l.append(list(input()))
    l[i].sort()
    l[i]="".join(l[i])
    
clist=list(collections.Counter(l).values())

count=0
for c in clist:
    count+=int(c*(c-1)//2)
    
print(count)

Submission status: Accepted

Solution code:
N = int(input())

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

ans = sorted(ans)

voc = "a"
A = 0
c = 0
for i in range(N):
    if voc == ans[i]:
        c += 1
    else:
        A += c * (c + 1) // 2
        c = 0
    voc = ans[i]

A += c * (c + 1) // 2

print(A)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
c = collections.Counter(S).values()
cand = list(c)
cand = [i for i in cand if i > 1]
for i in range(len(cand)):
    cand[i] = cand[i]*(cand[i]-1)//2
print(sum(cand))

Submission status: Accepted

Solution code:
import collections

N = int(input())

A = []

for i in range(N):
  A.append("".join(list(sorted(list(input())))))

C = list(collections.Counter(A).values())

s = 0

for c in C:
  s += int(((c-1)*c)//2)
  
print(s)

Submission status: Accepted

Solution code:

N = int(input())
anagram_dict = {}
ans = 0

for i in range(N):
    s= ''.join(sorted(list(input())))
    if s in anagram_dict:
        ans += anagram_dict[s]
        anagram_dict[s] += 1
    else:
        anagram_dict[s]=1

print(ans)

Submission status: Accepted

Solution code:
def comb(n):
    return n * (n - 1) // 2

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

w_list = []

for ss in S:
    s = sorted([i for i in ss])
    w_list.append("".join(s))
    
w_list.sort()

ans = 0
anagram = 1
temp = w_list[0]

for i in range(1, N):
    if temp == w_list[i]:
        anagram += 1
    else:
        ans += comb(anagram)
        anagram = 1
        temp = w_list[i]

ans += comb(anagram)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
counter = 0
tmp = {}
for _ in range(n):
    s = str(sorted(input()))
    if s in tmp:
        counter += tmp[s]
        tmp[s] += 1
    else:
        tmp[s] = 1
print(counter)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
d={}
s=0
for _ in range(int(input())):
  l=input()
  l=str(sorted(l))
  f=d.keys()
  if l not in f:
    d[l]=0
  else:
    d[l]+=1
    s+=d[l]
print(s)

Submission status: Accepted

Solution code:
d={}
s=0
for i in range(int(input())):
    j=str(sorted(input()))
    if j in d:
        d[j]+=1
        s+=d[j]
    else:
        d[j]=0
print(s)

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:
n = int(input())

sample = {}
sam = 0

for i in range(n):
    s = sorted(input())
    s = ''.join(s)
    if s in sample:
        sample[s] += 1
        sam += sample[s] -1
    else:
        sample[s] = 1
print(sam)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
c = 0
c_dict = {}
l = []
for i in range(n):
    s_listed = sorted(list(input()))
    s = ''.join(s_listed)
    if s in c_dict.keys():
        c_dict[s] += 1
        c += c_dict[s] - 1
    else:
        c_dict[s] = 1
print(int(c))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

N = int(input())
dic = {}
count = 0
for _ in range(N):
    x = "".join(sorted(input()))
    if x in dic:
        count += dic[x]
        dic[x] += 1
    else:
        dic[x] = 1

print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=["".join(sorted(input())) for _ in range(n)]
s.sort()
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 = [''.join(sorted(input())) for _ in range(N)]

ans = 0
dic ={} 
#print(S)
for s in  S:
   if s in dic:
      ans+=dic[s]
      dic[s]+=1
   else:
      dic[s] = 1

#print(dic)
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

N = int(input())
hash = {}
count = 0
for _ in range(N):
    x = "".join(sorted(input()))
    if x in hash:
        count += hash[x]
    else:
        hash[x] = 0
    hash[x] += 1

print(count)

Submission status: Accepted

Solution code:
from math import factorial

def comb(n, r):
    if n == 1:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

N = int(input())
S = [input() for _ in range(N)]
str_dict = {}
for s in S:
    sorted_s = "".join(sorted(s))
    if sorted_s not in str_dict:
        str_dict[sorted_s] = 0
    str_dict[sorted_s] += 1
ans = sum([comb(v, 2) for v in str_dict.values()])
print(int(ans))

Submission status: Accepted

Solution code:
def main(): 
    n = int(input())
    s = [''.join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for si in s:
        if si in dic:
            ans += dic[si]
            dic[si] += 1
        else:
            dic[si] = 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def anagram(n,s):
    count = 0
    dic = {}
    for s in S:
        if s in dic:
            count += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    return count

N = int(input())
S = []
for i in range(N):
    li = sorted(input())
    li = ''.join(li)
    S.append(li)
print(anagram(N,S))

Submission status: Accepted

Solution code:
N = int(input())
d = dict()

for i in range(0, N):
    si = input()
    si_sorted = "".join(sorted(list(si)))
    if si_sorted in d:
        d[si_sorted] = d[si_sorted] + 1
    else:
        d[si_sorted] = 1

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

print(res)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())

s = set()
res = Counter([tuple(sorted(input())) for _ in range(n)])
print(sum((x*(x-1))//2 for x in res.values()))

Submission status: Accepted

Solution code:
n = int(input())
dict = {}
ans = 0
for _ in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = ''.join(tmp)
    if tmp in dict:
        dict[tmp] += 1
        ans += dict[tmp]
    else:
        dict[tmp] = 0
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
dict = {}
for i in range(n):
    s = list(input())
    s.sort()
    s2 = "".join(s)
    if s2 in dict:
        dict[s2] += 1
    else:
        dict[s2] = 1
ans = 0
for k in dict:
    ans += dict[k]*(dict[k]-1)//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N = int(input())
lists = []
result = 0
tempres = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        result += tempres
        continue

    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            tempres += 1
        else:
            break
    result += tempres

print(result)

Submission status: Accepted

Solution code:
N = int(input())
letter_list = []
letter_dic = {}
ans = 0
for _ in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    if tmp in letter_dic:
        letter_dic[tmp] += 1
        ans += letter_dic[tmp]
    else:
        letter_dic[tmp] = 0

print(ans)

Submission status: Accepted

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

for i in range(n):
  lists = list(input())
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    k = ''.join(sorted(list(input())))
    if k in dic:
        cnt += dic[k]
        dic[k] += 1
    else:
        dic[k] = 1

print(cnt)

Submission status: Accepted

Solution code:
import collections

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = sum(x*(x-1)//2 for x in c.values())
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)
print(sum([k*(k-1)//2 for k in c.values()]))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dict = defaultdict(int)
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        dict[str] += 1

    ans = 0
    for val in list(dict.values()):
        if 1 < val:
            ans += val*(val-1)//2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dp = {}
    ans = 0
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        if str in dp:
            ans += dp[str]
            dp[str] += 1
        else:
            dp[str] = 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r==0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  

from collections import defaultdict
dic = defaultdict(int)
N = int(input())
for n in range(N):
  s = list(input())
  s.sort()
  k = tuple(s)
  dic[k] += 1
ans = 0
for k in dic.keys():
  if dic[k]<2:
    continue
  ans += cmb(dic[k],2)
print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby
from math import factorial


N = int(input())
words = [input() for _ in range(N)]
groups = groupby(sorted([''.join(sorted(list(word))) for word in words]))

res = 0
for k, vs in groups:
    l = len(list(vs))
    if l >= 2:
        res += factorial(l) // (factorial(l - 2) * 2)

print(res)

Submission status: Accepted

Solution code:
A ={}
c = 0
for i in range(int(input())):
    a = str(sorted(input()))
    if a in A:
        A[a] += 1
        c += A[a]
    else:
        A[a] = 0
print(c)

Submission status: Accepted

Solution code:
import math
import sys


sys.setrecursionlimit(10**7)

N = int(input())
words = [input() for _ in range(N)]
patterns = sorted([''.join(sorted(list(word))) for word in words])

def count_list_duplicates(arr):
    dup, prev, c = [], '', 0
    for l in arr:
        if prev == l:
            c += 1
        else:
            dup.append(c)
            c = 1
        prev = l
    else:
        dup.append(c)

    return dup

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

res = 0
for d in count_list_duplicates(patterns):
    if d >= 2:
        res += combinations_count(d, 2)
        
print(res)

Submission status: Accepted

Solution code:
# -*- coding:utf8 -*-
import collections

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = collections.Counter(s)
t = [range(i) for i in list(c.values()) if i != 1]
a = [sum(i) for i in t]
print(sum(a))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [input() for i in range(n)]
st = []
ans = 0
for i in range(n):
    st.append(list(tuple(s[i])))
    st[i].sort()
    st[i] = str(st[i])
st.sort()
count = Counter(st)
for v in count.values():
    if v != 1:
        for n in range(1, v):
            ans += n
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = sorted(["".join(sorted(stdin.readline().rstrip())) for _ in range(n)])

gr = groupby(sary)

res = 0

for k, g in gr:
    num = len(list(g))
    if  num >= 2:
        res += num * (num - 1) // 2

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = dict()
count = 0
for i in range(n):
    t = "".join(sorted(list(input())))

    if not t in s.keys():
        s[t] = 1
    else:
        s[t] += 1
        count += s[t] - 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list()
for i in range(n):
    s.append(list(input()))

t = dict()
l = 0

for i in range(len(s)):
    s[i].sort()
    k = "".join(s[i])
    if not k in t.keys():
        t[k] = 1
    else:
        t[k] += 1
        l += t[k] - 1

print(l)

Submission status: Accepted

Solution code:
def slove():
    import sys, collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]
    s = collections.Counter(s).most_common()
    t = 0
    for i, v in s:
        for j in range(1, v):
            t += j
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
d = {}
c = 0

for i in s:
  tmp = "".join(sorted(i))
  if tmp not in d:
    d[tmp] = 0
  else:
    d[tmp] += 1
  c += d[tmp]
  
print(c)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = [input() for i in range(n)]
s = map(list,s)
lst = []
for i in s:
  i.sort()
  lst.append(''.join(i))
ans = collections.Counter(lst)
ctr = 0
for v in ans.values():
  if v != 1:
    for n in range(1,v):
      ctr+=n
      
print(ctr)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    count = 0
    d = {}
    for _ in range(N):
        s = ''.join(sorted(input()))
        try:
            d[s]
        except KeyError:
            d[s] = 0
        d[s] += 1
        if d[s] > 1:
            count += d[s] - 1
    print(count)

Submission status: Accepted

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

ans, d = 0, {}
for i in range(n):
    if s[i] in d.keys():
        ans += d[s[i]]
        d[s[i]] = d[s[i]] + 1
    else:
        d[s[i]] = 1
print(ans)

Submission status: Accepted

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

cnt = {}
ans = 0

for Si in S:
    x = "".join(sorted(list(Si)))
    if x not in cnt:
        cnt[x] = 0
    ans += cnt[x]
    cnt[x] += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ctr = Counter()
ans = 0
for Si in S:
    x = "".join(sorted(list(Si)))
    if x in ctr:
        ans += ctr[x]
    ctr[x] += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
 
ctr = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in ctr:
        ans += ctr[a]
    ctr[a] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())

s = defaultdict(str)

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

print(ans)

Submission status: Accepted

Solution code:
#17:37
n = int(input())
can = []
for _ in range(n):
  raw = input()
  made = []
  for k in range(10):
    made.append(ord(raw[k])-97)
  made.sort()
  can.append(made)
can.sort()
ans = 0
combo = 0
for i in range(1,n):
  if can[i-1] == can[i]:
    combo += 1
  else:
    combo = 0
  ans += combo
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s_arr = []
for i in range(n):
    s = sorted(input())
    s_arr.append(''.join(s))
s_arr.sort()

from collections import Counter
c = Counter(s_arr)
cnt = 0
for i in c:
    cnt += c[i]*(c[i]-1)//2
print(cnt)

Submission status: Accepted

Solution code:
A ={}
c = 0
for i in range(int(input())):
    a = str(sorted(input()))
    if a in A:
        A[a] += 1
        c += A[a]
    else:
        A[a] = 0
print(c)

Submission status: Accepted

Solution code:
import math
N = int(input())
L = [input() for i in range(N)]
L = sorted(list(map("".join, list(map(sorted, list(map(list, L)))))))
c = 0
ans = 0
for j in range(1,N):
    if not L[j] == L[j - 1]:
        ans += (j - c)*(j - c - 1)/2
        c = j
    elif j + 1 == N:
        ans += (j + 1 - c)*(j - c)/2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

string_list = [''.join(sorted(input())) for i in range(n)]

word_dict = dict()

counter = 0

for i in range(n):
  word_dict.setdefault(string_list[i], 0)
  word_dict[string_list[i]] += 1
  if word_dict[string_list[i]] != 1:
    counter += word_dict[string_list[i]] - 1
  
print(counter)

Submission status: Accepted

Solution code:
N = int(input())
Dictionary = {}
for i in range(N):
        string = "".join(sorted(input()))
        if string in Dictionary:
                Dictionary[string] += 1
        else:
                Dictionary[string] = 1

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

print(int(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 = sum(sum(range(i)) for i in c.values())
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    dp = {}
    ans = 0
    for _ in range(N):
        str = ''.join(sorted(input().rstrip()))
        if str in dp:
            ans += dp[str]
            dp[str] += 1
        else:
            dp[str] = 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n_str = int(input().strip())

str_dict = {}

for i in range(n_str):
    string = input().strip()
    sorted_str = ''.join(sorted(string))
    if sorted_str in str_dict:
        str_dict[sorted_str] += 1
    else:
        str_dict[sorted_str] = 1

num_pairs = 0
for value in str_dict.values():
    num_pairs += (value - 1) * value // 2

print(num_pairs)

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]
    s = collections.Counter(s).most_common()
    t = 0
    for i, v in s:
        for j in range(v-1, 0, -1):
            t += j
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = collections.Counter(["".join(sorted(input())) for _ in range(n)]).most_common()
#print(s)
cnt = 0
for i in s:
    for j in range(1, i[1]):
        cnt += j
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = [0]*n
count = 0
each_count = {}

for i in range(n):
    tmp = list(str(input()))
    tmp.sort()
    s[i] = "".join(tmp)

for si in s:
    if each_count.setdefault(si, 0) == 0:
        each_count[si] = 1
    else:
        count += each_count[si]
        each_count[si] += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
ans = {}
for i in range(n):
    s = input()
    t = []
    for i in range(len(s)):
        t.append(s[i])
    t.sort()
    k = "".join(t)
    if k in ans:
        ans[k] = ans[k]+1
    else:
        ans[k] = 0
answer = 0
for i in ans:
    j = ans[i]
    answer += j*(j+1)//2
print(answer)

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

Submission status: Accepted

Solution code:
N = int(input())
S = []

dic = dict()

for _ in range(N):
	s = ''.join(sorted(input()))
	
	if not s in dic:
		dic[s] = 1
	else:
		dic[s] += 1
	
ans = 0

for key, val in dic.items():
	if val > 1:
		ans += (val * (val - 1)) / 2
		
print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
count = {}
res = 0
for i in range(n):
  si = input()
  sortedSi = sorted(si)
  tSi = tuple(sortedSi)
  if tSi not in count:
    count[tSi] = 0
  res += count[tSi]
  count[tSi] += 1
print(res)

Submission status: Accepted

Solution code:
from math import factorial

N = int(input())
strings = {}
for _ in range(N):
    string = str(sorted(list(input().rstrip('\n'))))
    if string in strings:
        strings[string] += 1
    else:
        strings[string] = 1

count = 0
for value in strings.values():
    if value >= 2:
        count += factorial(value) // 2 // factorial(value - 2)

print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
  s = list(input())
  s.sort()
  S.append(s)
S.sort()
ans = 0
snt = 1
for i in range(N-1):
  if S[i]==S[i+1]:
    snt += 1
  else :
    ans += (snt*(snt-1))//2 if snt>1 else 0
    snt = 1
ans += (snt*(snt-1))//2 if snt>1 else 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

dic = dict()
for i in range(N):
    S = input()
    new = ''.join(sorted(S))
    
    if not new in dic:
        dic[new] = 0
        
    dic[new] += 1

ans = 0

for key,val in dic.items():
    if val > 1:
        ans += (val*(val-1)) // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
lis=sorted([sorted([f for f in input()]) for i in range(a)])
lis+=["w"]
kari=""
ans=0
cou=1
for i in lis:
  if kari!=i:
    ans+=cou*(cou-1)/2
    cou=1
    kari=i
  else:
    cou+=1
print(int(ans))

Submission status: Accepted

Solution code:
from collections import Counter

count = Counter()
for i in range(int(input())):
	s = sorted(input())
	count[''.join(s)] += 1
	
ans = 0

for n in count.values():
	if n >= 2:
		ans += (n**2 - n) // 2 
		
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [input() for i in range(0, N)]

ans = 0
A = {}

for i in range(0, N):
    S[i] = sorted(S[i])
    S[i] = ''.join(S[i]) 
    if S[i] in A.keys():
        ans += A[S[i]]
        A[S[i]] += 1
    else:
        A[S[i]] = 1
    
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
ss = ["".join(sorted(input())) for _ in range(n)]
counter = collections.Counter(ss)
count = 0
for k, v in counter.items():
    count += v * (v - 1) // 2
print(count)

Submission status: Accepted

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

Dict = {} # 空の辞書を用意(集合ともみれるが)
ans = 0

for i in range(N):
    s[i] = ''.join(sorted(s[i])) # 文字列をソートすると配列になる
    if s[i] in Dict:
        ans += Dict[s[i]] # あったら過去にあった個数をansに代入
        Dict[s[i]] += 1 # 値に1追加
    else:
        Dict[s[i]] = 1 # なかったら辞書にキー(文字列)と値1を格納

print(ans)

Submission status: Accepted

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

d = defaultdict(int)
for s in S:
    d[''.join(sorted(s))] += 1
    
ans = 0
for v in d.values():
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = []
l = 1
z = 0
s = [input() for _ in range(N)]
for i in range(0,N):
    s[i] = ''.join(sorted(s[i]))
s.sort()
for i in range(0,N-1):
    if s[i] == s[i+1]:
        l += 1
    else:
        z += l*(l-1)/2
        l = 1
z += l*(l-1)/2
print(int(z))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
  A_temp = input()
  A[i]= sorted([c for c in A_temp])
count = 0

B = sorted(A)
A_unique_count = 1

for i in range(N-1):
  if B[i] == B[i+1]:
    A_unique_count += 1
  else:
    count += A_unique_count * (A_unique_count -1) /2
#    print('i' + str(i))
#    print(count)
    A_unique_count = 1

count += A_unique_count * (A_unique_count -1) /2
print(int(count))

Submission status: Accepted

Solution code:
#16:15
n = int(input())
can = []
for _ in range(n):
  raw = input()
  made = []
  for k in range(10):
    made.append(raw[k])
  made.sort()
  can.append(made)
can.sort()
ans = 0
combo = 0
for i in range(1,n):
  if can[i] == can[i-1]:
    combo += 1
  else:
    combo = 0
  ans += combo
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = [input() for _ in range(n)]
ans_dict = {}

for s in arr:
    samp = sorted(s)
    tmp = ""
    for i in samp:
        tmp = tmp + i
    if tmp in ans_dict:
        ans_dict[tmp] += 1
    else:
        ans_dict[tmp] = 1

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