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=[]
for i in range(n):
    s.append("".join(sorted(input())))

S=set(s)

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 Counter

ans=0
l=Counter(s)
for x in S:
    a=l[x]
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)

Submission status: Accepted

Solution code:
import sys
import collections


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
s = []
ans = 0
for i in range(N):
    s.append(''.join(sorted(S())))

c = collections.Counter(s)

for i in set(s):
    n = c[i]
    ans += n * (n-1) // 2
print(ans)

Submission status: Accepted

Solution code:
from math import factorial
def comb(n,r):
  return factorial(n)//factorial(n-r)//factorial(r)
N=int(input())
S=[]
for i in range(N):
  s=list(input())
  s.sort()
  S+=[s]
S.sort()  
ans=0
anssub=1
for i in range(N-1):
  if S[i]==S[i+1]:
    anssub+=1
  else:
    if anssub!=1:
      ans+=comb(anssub,2)
    anssub=1
  if i==N-2 and anssub!=1:
    ans+=comb(anssub,2)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = [list(input()) for i in range(0,N,1)]
for i in range(0,N,1):
    s[i].sort()
S = ["".join(s[i]) for i in range(0,N,1)]

cnt = Counter(S)
ans =0
for i in set(S):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
S = defaultdict(int)
ans = 0
for _ in range(N):
    s = input()
    sl = []
    for n in s:
        sl.append(n)
    sl.sort()
    s = ''.join(sl)
    S[s] += 1

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

Submission status: Accepted

Solution code:
n = int(input())

dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if not s in dic:
    dic[s] = 1
  else:
    dic[s] += 1

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
s_dic = {}
for _ in range(N):
    s_list = list(input())
    s_list.sort()
    s = ''.join(s_list)

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

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

Submission status: Accepted

Solution code:
import sys
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


def input():
    return sys.stdin.readline()[:-1]


N = int(input())
s_dic = {}
for _ in range(N):
    s_list = list(input())
    s_list.sort()
    s = ''.join(s_list)

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

ans = 0
for k, v in s_dic.items():
    if v >= 2:
        ans += cmb(v, 2)
print(ans)

Submission status: Accepted

Solution code:
import collections

d = {}
n = int(input())
ans = 0
for i in range(n):
    st = list(input())
    st.sort()
    s = ''.join(st)
    m = d.get(s,False)
    if m:
        ans += m
        d[s] = m+1
    else:
        d[s] = 1 
    
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = []
#s = [sorted(input()) for i in range(n)]
for i in range(n):
    temp = sorted(input())
    temp = ''.join(temp)
    s.append(temp)

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

print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# C - Green Bin
# https://atcoder.jp/contests/abc137/tasks/abc137_c

from collections import Counter

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

C = Counter(S)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter
def main():
    n = int(readline())
    S = []
    for i in range(n):
        S.append(''.join(sorted(readline().rstrip().decode())))
    ans = 0
    for v in Counter(S).values():
        ans += v*(v-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
c = collections.Counter(s)

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

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for _ in range(n):
    s = str(input())
    s = ''.join(sorted(s))
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
cnt = 0
for k, v in d.items():
    if v != 1:
        cnt += v * (v - 1) // 2
print(cnt)

Submission status: Accepted

Solution code:
import itertools
import collections
from collections import Counter
n=int(input())
k=[]
t=0
for i in range(n):
    p=input()
    k.append(tuple(sorted(p)))
k=Counter(k)
v,c=zip(*k.most_common())
c=list(c)
for i in range(len(c)):
    n=c[i]
    t+=n*(n-1)/2
print(int(t))

Submission status: Accepted

Solution code:
import itertools
import collections
from collections import Counter
n=int(input())
k=[]
t=0
for i in range(n):
    p=input()
    k.append(sorted(p))
for i in range(n):
    k[i]=tuple(k[i])
k=Counter(k)
v,c=zip(*k.most_common())
c=list(c)
for i in range(len(c)):
    n=c[i]
    t+=n*(n-1)/2
print(int(t))

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
dic_sorted_s = defaultdict(int)
count = 0
for i in range(n):
    s = input()
    str_sorted_s = ''.join(sorted(s))
    count += dic_sorted_s[str_sorted_s]
    dic_sorted_s[str_sorted_s] += 1
print(count)

Submission status: Accepted

Solution code:
N=int(input())
mem={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    s=str(s)
    if s in mem:
        ans+=mem[s]
        mem[s]+=1
    else:
        mem[s]=1

print(ans)

Submission status: Accepted

Solution code:
import math

n=int(input())

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

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


print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
cnt = {}
for _ in range(n):
    sorted_s = "".join(sorted(input()))
    cnt.setdefault(sorted_s, 0)
    cnt[sorted_s] += 1
ans = 0
for v in cnt.values():
    if v < 2: continue
    ans += int(v * (v - 1) / 2)
print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
d = DD(int)

for _ in range(N):
  k = list(S())
  k.sort()
  k = tuple(k)
  d[k] += 1

keys  = [k for k in d]
print(sum(d[k]*(d[k]-1)//2 for k in keys))

Submission status: Accepted

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

Submission status: Accepted

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

d = {}
ans = 0
for i in range(n):
    s = S[i]
    s = list(s)
    s.sort()
    s = ''.join(s)
    if s in d:
        ans += d[s]
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import math
def combination2(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

N = int(input())
l = []
for _ in range(N):
    tmp = input()
    tmp = sorted(tmp)
    l.append(''.join(tmp))

l = Counter(l)
ans = 0
for key, value in l.items():
    if value >= 2:
        ans += combination2(value)
print(ans)

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

dic = defaultdict(int)

N = int(input())
ans = 0
for i in range(N):
    s = list(input())
    s.sort()
    ans += dic[''.join(s)]
    dic[''.join(s)] += 1

print (ans)

Submission status: Accepted

Solution code:
n=int(input())
d={}
for i in range(n):
    si=''.join(list(sorted(input())))
    d[si]=d.get(si, 0)+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())
C = {}
for i in range(N):
    s = input().strip()
    s = "".join(sorted(s))
    if s not in C:
        C[s] = 0
    C[s] += 1
cnt = 0
for x in C:
    n = C[x]
    cnt += (n*(n-1))//2
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
from collections import defaultdict
dic = defaultdict(int)
for i in range(n):
    s = "".join(list(sorted(input())))
    dic[s] += 1
#print(dic)
cnt = 0
for k,v in dic.items():
    cnt += v*(v-1)//2
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = {}
for i, si in enumerate(s):
    cnt_tmp = {}
    for j, sij in enumerate(si):
        key = str(sij)
        cnt_tmp.setdefault(key, 0)
        cnt_tmp[sij] += 1
    #
    key_si = ''
    for key, val in sorted(cnt_tmp.items()):
        key_si += '{0}_{1}/'.format(key, val)
    #
    cnt.setdefault(key_si, 0)
    cnt[key_si] += 1

ans = 0
for key, val in cnt.items():
    ans += val * (val - 1) // 2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
from collections import Counter
ctr = Counter()
for i in range(N):
    s = input()
    h = hash(tuple(sorted(s)))
    ctr[h] += 1
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N, *S = open(0).read().split()
S = [''.join(sorted(s)) for s in S]
C = Counter(S)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
cnt = defaultdict(int)
ans = 0

for _ in range(N):
    s = input()[:-1]
    s = list(s)
    s.sort()
    s = ''.join(s)
    ans += cnt[s]
    cnt[s] += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
counter = Counter()

for i in range(N):
    s = input()
    lst = []
    for c in s:
        lst.append(c)
    lst.sort()
    lst = "".join(lst)
    counter[lst] += 1

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
def main():
    word = {}
    n = int(input())
    for _ in range(n):
        s = "".join(sorted(input()))
        if s in word:
            word[s] += 1
        else:
            word[s] = 1
    answer = 0
    for cnt in word.values():
        answer += cnt * (cnt - 1) // 2
    print(answer)


if __name__ == '__main__':
    main()

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:
n = (int)(input())
s = sorted([sorted(list(input())) for i in range(n)])
 
ans = 0
temp = 1
for i in range(n - 1):
  if s[i] == s[i + 1]:
    temp += 1
  else:
    if temp != 1:
      ans += temp * (temp - 1) // 2
      temp = 1
else:
  if temp != 1:
    ans += temp * (temp - 1) // 2
    temp = 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [''.join(sorted(list(input()))) for _ in range(N)]
import collections
c = collections.Counter(a)
c_ls = list(c.values())
ans = 0
for i in range(len(c_ls)):
  ans += c_ls[i] * (c_ls[i]-1)//2
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x={}
ans=0
for j in range(n):
    s=list(input())
    s.sort()
    p=''.join(s)
    if p not in x:
        x[p]=1
    else:
        ans+=x[p]
        x[p]+=1
print(ans)

Submission status: Accepted

Solution code:
def green_bin(n, sli):

    ans = 0
    count = {}

    for i in sli:
        i.sort()
        if ''.join(i) in count:
            ans += count[''.join(i)]
            count[''.join(i)] += 1

        else:
            count[''.join(i)] = 1

    return ans

def main():
    n = int(input())
    sli = [list(str(input()))for i in range(n)]
    print(green_bin(n, sli))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
s = defaultdict(lambda:0)
count=0

for i in range(N):
  a = "".join(sorted(input()))
  s[a] +=1
  
  if s[a] >1:
    count += s[a]-1
print(count)

Submission status: Accepted

Solution code:
import sys, collections
n = int(input())
uq = ["".join(sorted(x.rstrip())) for x in sys.stdin.readlines()]
chk = collections.Counter(uq)
ans = 0
for x in chk:
    if chk[x] != 1:
        ans += chk[x]*(chk[x]-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


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


N = int(input())
counter = Counter()

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

print(sum([nc2(count) for count in counter.values() if count > 1]))

Submission status: Accepted

Solution code:
from collections import Counter
from math import factorial


def nc2(n):
    return factorial(n) // 2 // factorial(n - 2)


N = int(input())
counter = Counter()

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

print(sum([nc2(count) for count in counter.values() if count > 1]))

Submission status: Accepted

Solution code:
N = int(input())
S = []
Y = {}
c = 0
for i in range(N):
  s = input()
  t = [s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]]
  t.sort()
  u = t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+t[7]+t[8]+t[9]
  if u not in Y:
    Y[u] = 1
  else :
    c += Y[u]
    Y[u] += 1
    


print(c)

Submission status: Accepted

Solution code:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
s.sort()
ans = 0
now = ''
cnt = 0
for si in s:
    if si == now:
        ans += cnt
        cnt += 1
    else:
        now = si
        cnt = 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
sl = [input() for nesya in range(n)]
sm = []
for s in sl:
  t = list(s)
  t.sort()
  sm.append(''.join(t))
d = dict()
for m in sm:
  if m in d:
    d[m] += 1
  else:
    d[m] = 1
c = 0
for v in d.values():
  c += v*(v-1)//2
print(c)

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:
n = int(input())
d = {}
for i in range(n):
    s = sorted(list(input()))   
    s = ''.join(s)
    d[s] = d.get(s, 0) + 1

cnt = 0
for k,v in d.items():
    if v >= 2:
        cnt += v * (v - 1) // 2 # 組の個数

print(cnt)

Submission status: Accepted

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

for i in range(n):
    s[i] = ''.join(sorted(s[i]))
# print(s)
t = {}
for i in range(n):
    if s[i] in t:
        t[s[i]] += 1
    else:
        t[s[i]] = 1
# print(t)
print(sum(t[k]*(t[k]-1)//2 for k in t))

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    s = sorted(list(input()))   
    s = ''.join(s)
    d[s] = d.get(s, 0) + 1

cnt = 0
for k,v in d.items():
    if v >= 2:
        cnt += v * (v - 1) // 2 # 組の個数

print(cnt)

Submission status: Accepted

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

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
cnt = 0
for k in s_sorted:
    if k in s_dict:
        cnt += s_dict[k]
        s_dict[k] += 1
    else:
        s_dict[k] = 1

#cnt = 0
# for k in s_dict:
#    cnt += sum(range(s_dict[k]))
#cnt = sum([sum(range(s_dict[k])) for k in s_dict])

print(cnt)

Submission status: Accepted

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

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
for k in s_sorted:
    if k in s_dict:
        s_dict[k] += 1
    else:
        s_dict[k] = 1

#cnt = 0
# for k in s_dict:
#    cnt += sum(range(s_dict[k]))
cnt = sum([sum(range(s_dict[k])) for k in s_dict])

print(cnt)

Submission status: Accepted

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

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
for k in s_sorted:
    if k in s_dict:
        s_dict[k] += 1
    else:
        s_dict[k] = 1

cnt = 0
for k in s_dict:
    cnt += sum(range(s_dict[k]))

print(cnt)

Submission status: Accepted

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

s.sort()
ans = 0
lcnt = 1
for i in range(1,len(s)):
    if s[i] == s[i-1]:
        lcnt += 1
    else:
        ans += lcnt * (lcnt-1)//2
        lcnt=1

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

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    ans = 0
    chk = {}
    for tmp in s:
        d1 = "".join(sorted(list(tmp)))
        if d1 in chk.keys():
            ans += chk[d1]
            chk[d1] += 1
        else:
            chk[d1] = 1
    print(ans)


resolve()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

n, *lst = sys.stdin.read().split()
n = int(n)
c = defaultdict(int)
for i in lst:
  tmpi = ''.join(sorted(i))
  c[tmpi] += 1
res = 0
for key in c:
  res += c[key] * (c[key] - 1) // 2
print(res)

Submission status: Accepted

Solution code:
import math

n = int(input())


def cho(i):
    return (i * (i - 1)) // 2


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

_ans = 0
for k, v in d.items():
    if v == 0: continue
    _ans += cho(v + 1)

print(_ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
t = list(["".join(sorted(list(input()))) for i in range(N)])

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

print(counter)

Submission status: Accepted

Solution code:
import collections

dic = collections.defaultdict(lambda:0)

N = int(input())
ans = 0
for _ in range(N):
  s = "".join(sorted(input()))
  dic[s] += 1
  if dic[s] > 1:
    ans += dic[s] - 1

print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [0] * n
c = [0] * n

count = 0
for i in range(n):
    s[i] = input()
    c[i] = ''.join(sorted(s[i]))
for i in collections.Counter(c).values():
    count += i*(i-1)//2
print(count)

Submission status: Accepted

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

# 全てをソートして、一致するものを探すのが早い？
s = [0] * n
for i in range(n):
    IN = input()
    inSort = sorted(IN)
    # リストの要素を結合
    s[i] = ''.join(inSort)

count = Counter(s)
most = count.most_common()
# print(count)
inSet = set(s)
loop = list(inSet)


ans = 0
for i in most:
    # for i in count:
    # print(i)
    aa = i[1]
    if (aa == 1):
        pass
    else:
        ans += aa * (aa - 1) / 2


print(int(ans))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
l = ["".join(sorted(input())) for _ in range(n)]
lcnt = Counter(l)
ls = set(l)
ans = 0
for i in ls:
    #iC2を足していく
    ans += (lcnt[i]*(lcnt[i]-1))//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
sc = Counter(s)
ss = set(s)
ans = 0

for k in ss:
    ans += (sc[k]*(sc[k]-1))//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
ans = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        cnt +=1
        ans += cnt
    else:
        cnt = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = []
count = 0
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    if li[i] == li[i+1]:
        f += 1
    else:
        count += (f*(f-1))//2
        f = 1
count += (f*(f-1))//2
print(count)

Submission status: Accepted

Solution code:
# ABC137C

from math import factorial
 
def unique(w):
    d = {}
    for c in w:
        if c in d.keys():
            d[c] += 1
        else:
            d.setdefault(c, 1)
    return list(d.values())
 
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()
# s = sorted([''.join(sorted(list(t))) for t in s])
s = [''.join(sorted(list(t))) for t in s]
values = unique(s)
count = 0
for i in values:
    if i > 1:
        count += factorial(i) // factorial(2) // factorial(i - 2)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

n = int(input())

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

l_2 = collections.Counter(l)
ans = 0
for j in l_2.values():
    ans += int((j*(j-1))/2)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

ans = 0    

for k, v in d.items():
    if v > 1:
        ans += v * (v - 1) // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
#dic ={}

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = list(''.join(sorted(input())) for i in range(n))
c = collections.Counter(s)
num = 0

for i in set(s):
  n = c[i]
  num += (n * (n - 1)//2)
print(num)

Submission status: Accepted

Solution code:
n = int(input())
si = [0]*n
for i in range(n):
    si[i] = input()

listarr = []
for s in si:
    arr = list(s)
    arr.sort()
    arr = tuple(arr
    )
    listarr.append(arr)
from collections import Counter

cont = Counter(listarr)
ans = 0
for i in cont.values():
    if i >= 2:
        num = (i*(i-1))//2
        ans += num

print(ans)

Submission status: Accepted

Solution code:
## from collections import Counter
from collections import Counter

N=int(input())
Word_List=[]

for i in range(N):
    Temp_Word=''.join(sorted(input()))
    Word_List.append(Temp_Word)

Word_Count=Counter(Word_List)
Word_PairCount_List = []

for i in Word_Count.values():
    if i > 1 :
        Word_PairCount_List.extend(range(i))

print(sum(Word_PairCount_List))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]
c = Counter(s)
ans = 0
for k, v in c.items():
    ans += v*(v-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import math
def combination(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
n = int(input())
S =[input() for _ in range(n)]
S =[''.join(sorted(s)) for s in S]
ans = 0
c = Counter(S)
for i in c.values():
    if i >= 2:
        ans += combination(i, 2)
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
n = int(input())
s = []
for i in range(n):
    string = sorted(input())
    s.append(''.join(string))

hist = {}
for i in range(n):
    current = hist.get(s[i],0)
    hist[s[i]] = current + 1

count = 0
for i in hist:
    count += (hist[i]*(hist[i]-1))//2

print(count)