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: Wrong Answer

Solution code:
import math
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 i <= 1 : break
        res += ncr(i,2)
    print(res)

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for i in range(n-1):
	if A[i]==A[i+1]:
		res += 1

print(res)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
count = 0
lis = [0]*N

for i in range(N):
  s = input()
  for j in range(10):
    count += ord(s[j])
  lis[i] += count
  count = 0

dic = collections.Counter(lis)
newlis = list(dic.values())
ans = sum([(i*(i-1))//2 for i in newlis]) 

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
s = [0]*n
c = {}
T = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	c[i] = collections.Counter(list(s[i]))
	T[i] = str(c[i])
D = collections.Counter(T)
for i in D.values():
	ans += i*(i-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
s = [0]*n
c = {}
T = [0]*n
ans = 0
for i in range(n):
	s[i] = input()
	c[i] = collections.Counter(list(s[i]))
	T[i] = str(c[i])
D = collections.Counter(T)
for i in D.values():
	ans += i*(i-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
s = [0]*n
c = {}
T = [0]*n
for i in range(n):
	s[i] = input()
	c[i] = collections.Counter(list(s[i]))
	T[i] = str(c[i])
D = collections.Counter(T)
ans = 0
for i in D.values():
	ans += i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
list1 = []
ans = 0
for i in range(n):
    a = list(input())
    a.sort()
    a = "".join(a)
    if a not in list1:
        list1.append(a)
    else:
        ans+=1
print(ans)

Submission status: Wrong Answer

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)
print(x)

Submission status: Wrong Answer

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


for i in range(n):
    for j in range(i,):
        if s[i] == s[j]:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
T = []

cnt = 0
for i in range(N):
    t = Counter(list(S()))
    if i == 0:
        T.append(t)
      
    if t in T:
        cnt += 1
    if i != 0:
        T.append(t)

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = [[0]*10 for _ in range(n)]
ans = 0
for i in range(n):
    str_s = input()
    for j in range(10):
        s[i][j] = str_s[j]

dict_s = {}
for i in range(n):
    s[i].sort()
    si = "".join(s[i])
    if si in dict_s.keys():
        dict_s[si] += dict_s[si]
    else:
        dict_s[si] = 1
print(sum(dict_s.values()) - len(dict_s.items()))

Submission status: Wrong Answer

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

l.sort()
cnt=0
tmp=0

for i in range(1,len(l)):
    if l[i]==l[i-1]:
        tmp += 1
    else:
        cnt += tmp+1*(tmp)//2
        tmp=0
cnt += tmp+1*(tmp)//2
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=0
total=0
l=[]
for i in range(n):
            l_i=list(input())
            l_i.sort()
            l.append(l_i)
            l.sort()
#print(l)
for j in range(n-1):
            if l[j]==l[j+1]:
                        cnt+=1
                        #print('l[j]',l[j],'l[j+1]',l[j+1],'cnt',cnt)
                        if cnt>=2:
                                    total+=((cnt+1)*cnt)//2
                                    #print('total1',total)
                        else:
                                    total+=cnt
                                    #print('total2',total)
            else:
                        j=j+2
                        cnt=0
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

# [[1, 1], [0, 1], [0, 0], [1, 0]]
for i in range(n):
    s[i] = sorted(s[i])
print(len(get_unique_list(s)))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
dic = {}
for i in range(n):
    s = input()
    t = 0
    for x in s:
        t += ord(x)
    dic.setdefault(t, 0)
    dic[t] += 1
ans = 0
for x in dic.values():
    ans += x * (x - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = []
cnt = []
for i in range(N):
    S.append(input())
    S[i] = set(S[i])

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            ans += 1

print(ans)
#print("cnt = {}".format(cnt))

Submission status: Wrong Answer

Solution code:
from math import factorial
n = int(input())
d = {}
for i in range(n):
    s = input()
    ns = ''.join(sorted(s))
    if ns not in d.keys():
        d[ns] = 1
    else:
        d[ns] += 1
ans = 0
for i, v in d.items():
    if v != 1:
        ans += factorial(v) /(factorial(v-2)*2)
print(str(ans)[:-2])

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [sorted(list(input())) for _ in range(N)]
i = 0
A = []
for a in S:
    A.append("".join(a))


print(len(A) - len(set(A)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
list1 = [str(input()) for  _ in range(N)]
list2 =  ["".join(sorted(list1[i])) for i in range(N)]
print(len(list2)-len(set(list2)))

Submission status: Wrong Answer

Solution code:
from math import factorial

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

count=0
count_1=0
for k in range(len(S)):
  count=S.count(S[k])
  if count!=1:
    T = factorial(count) / factorial(2) / factorial(count-2)
    count_1 +=T/count
print(count_1//1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    s = ["".join(sorted(input())) for i in range(N)]
    # print(s)
    S = set(s)
    # print(S)
    print(len(s)-len(S))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def countPairs(str_arr):
	count = 0
	for i in range(N):
		for j in range(i+1,N):
			if str_arr[i] == str_arr[j]:
				count += 1
	return count


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

for i in range(N):
	str = input()
	str_arr.append(str)

print(countPairs(str_arr))

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
count = 0
ans = 0
lis = [0]*N

for i in range(N):
  s = input()
  for j in range(10):
    count += ord(s[j])
  lis[i] += count
  count = 0

dic = collections.Counter(lis)
newlis = list(dic.values())

for i in newlis:
  ans += i*(i-1)/2

print(int(ans))

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    dic = {}
    for i in range(n):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1

    def comb(n,r,p = mod):
        r = min(r,n-r) # nCr
        res = 1
        div = 1 # nCr := n*n-1*...n-r+1 // 1*2*3...r
        for i in range(n-r+1,n+1):
            res *= i
            res %= p
        for i in range(1,r+1):
            div *= i
            div %= p
        res *= pow(div,p-2,p) # 掛け算に
        res %= p
        return res
    ans = 0
    for k,v in dic.items():
        if v != 1:
            ans += comb(v,2)
    print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]

for i in range(n):
  b=sorted(input())
  a.append(b)

cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    flag=True
    for k in range(9):
      if a[i][k]!=a[j][k]:
        flag=False
        break
    if flag==True:
      cnt+=1
print(cnt)

Submission status: Wrong Answer

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

Solution code:
n=int(input())
L=[]
for i in range(n):
    a=sorted(list(input()))
    L.append(a)
L=[tuple(d) for d in L]
unL=set(L)
unL=[list(d) for d in unL]
print(n-len(unL)+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[]
for i in range(n):
    a=sorted(list(input()))
    L.append(a)
L=[tuple(d) for d in L]
unL=set(L)
unL=[list(d) for d in unL]
print(n-len(unL))

Submission status: Wrong Answer

Solution code:

n = int(input())
import collections
chk = collections.deque([])
for i in range(n):
  s = input()
  s = sorted(s)
  chk.append(''.join(s))
#chk = list(chk)
c = collections.Counter(chk)
c = dict(c)
ans = 0
for i in c.values():
  if i == 1:
    break
  else:
    ans += i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
import collections
chk = collections.deque([])
for i in range(n):
  s = input()
  s = sorted(s)
  chk.append(''.join(s))
#chk = list(chk)
c = collections.Counter(chk)
c = dict(c)
ans = 0
for i in c.values():
  if i == 1:
    break
  else:
    ans += i*(i-1)//2
print(ans)

Submission status: Wrong Answer

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

N = int(input())
S = []
for i in range(N):
    S.append(collections.Counter(list(input())))
#print(S)
cnt = 0
for i in range(N):
    for k in range(N-i):
        if S[i] == S[i+k]:
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=int(input())
l=[]
k=0
for i in range(a):
    c=input()
    c=sorted(c)
    c="".join(map(str,c))
    l.append(c)
if len(set(l))==len(l):
    print(k)
else:
 for j in set(l):
    if l.count(j)%2==0 and l.count(j)!=1:
        k+=l.count(j)//2
    if l.count(j) % 2 != 0 and l.count(j) != 1:
        k+=l.count(j)
 print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    i = tuple(sorted(input()))
    A.append(i)

B = set(A)

print(len(A)-len(B))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = [input().rstrip() for _ in range(N)]
#S = ["".join(sorted(input())) for _ in range(N)]
# counter = Counter(S)
#
# ans = 0
# for value in counter.values():
#     if value >= 2:
#         ans += value * (value - 1) // 2
#
# print(ans)

dict = {}
for s in S:
    s_list = sorted(list(s))
    s_str = "".join(s_list)
    if s_str in dict.keys():
        dict[s_str] += dict[s_str] + 1
    else:
        dict[s_str] = 0

print(sum(dict.values()))




# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[list(input()).sort() for _ in range(n)]
print(n-len(set(s))+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[]
t=[]
for i in range(n):
  t.append([str(c) for c in input()])
  s.append(sorted(set(t[i])))

l=[] 
m=[[0 for i in range(10)] for j in range(n)] 
for i in range(n):  
  l.append(len(s[i]))
  for j in range(l[i]):
    m[i][j]=t[i].count(s[i][j])

lm=len(m)
c=[]
for i in range(lm):
  if not m[i] in c:
    c.append(m[i])
lc=len(c)
d=[0]*lc
for i in range(lm):
  for j in range(lc):
    if m[i]==c[j]:
      d[j]+=1
x=0
for i in range(lc):
  x+=d[i]*(d[i]-1)//2
print(str(x))

Submission status: Wrong Answer

Solution code:
import collections
from math import factorial
A = int(input())
listA = []
total = 0
listB = {}
for i in range(A):
    B = list(input())
    B.sort()
    listA.append("".join(B))
for i in listA:
    if i in listB:
        listB[i] += 1
    else:
        listB[i] = 1
listC = listB.values()
listC = [i for i in listC if i > 1]
for i in listC:
    total += factorial(i) // 2
print(total)

Submission status: Wrong Answer

Solution code:
import math
import collections
A = int(input())
listA = []
total = 0
listB = {}
for i in range(A):
    B = list(input())
    B.sort()
    listA.append("".join(B))
for i in listA:
    if i in listB:
        listB[i] += 1
    else:
        listB[i] = 1
for i in listB.values():
    if i > 1:
        total += math.factorial(i) // 2
print(total)

Submission status: Wrong Answer

Solution code:
import math
import collections


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


n = int(input())
c = [collections.Counter(str(sorted(list(input())))) for _ in range(n)]

i = 0
anagram = []
while i < len(c):
    anagram += [c.count(c[i])]
    c.remove(c[i])
    i += 1

print(sum(comb(a, 2) for a in anagram if a > 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
dic = defaultdict(int)
for _ in range(N):
  s = input()
  s_list = list(s)
  s_list.sort()
  s = ''.join(s_list)
  dic[s] += 1
print(sum(dic.values())-len(dic))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = 0
prev = None
cnt = 0
for i in range(N):
  s = SS[i]
  if s == prev:
    if not cnt:
      cnt = 2
    else:
      cnt += 1
  else:
    ans += cnt
    cnt = 0
  prev = s
  
ans += cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = 0
prev = None
for i in range(N):
  s = SS[i]
  if s == prev:
    ans += 1
  prev = s
  
print(ans)

Submission status: Wrong Answer

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

STR_IN_S = [[[] for _ in range(11)] for _ in range(26)]

for i in range(N):
  S = SS[i]
  c = Counter(S)
  for j in range(26):
    s = chr(97+j)
    STR_IN_S[j][c[s]].append(i)
    
SAME = [set(range(N)) for _ in range(N)]

for i in range(26):
  for j in range(11):
    l = STR_IN_S[i][j]
    nl = set(l)
    for x in l:
      SAME[x] &= nl
  
ans = 0
for i in range(N):
  ans += len(SAME[i]) - 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations as c
n, *d = map(sorted, open(0).read().split())
print(sum(d[i[0]] == d[i[1]] for i in c(range(int("".join(n))), 2)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
d=defaultdict(int)
n,*s=open(0).read().split()
for i in s:d["".join(sorted(list(i)))]+=1
print(max(d.values()))

Submission status: Wrong Answer

Solution code:
import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip())) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


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

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
#import math
import collections
#from collections import deque
#from bisect import bisect_left
N = int(input())
#S = input()[:-1]
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
l = {}
for i in range(N):
    if i == N-1:
      S = list(input())
    else:
      S = list(input()[:-1])
    S.sort()
    S = tuple(S)
    if S in l.keys():
      l[S] += 1
    else:
      l[S] = 1
ans = 0
for j in l.values():
  ans += j*(j-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
s_list = list()
for _ in range(N):
    s_list.append(''.join(sorted(input())))
    
count = 0
for k, v in Counter(s_list).items():
    count += v - 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
import collections
n = int(input())
l = []
ans = 0
for i in range(n):
  a = list(input())
  a.sort()
  a = str(a)
  l.append(a)
c = collections.Counter(l)
for j in c.values():
  if j >= 2:
    j = math.factorial(j)//2
    ans += j
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    t = "".join(s)
    if t in dic.keys():
        dic[t] += dic[t] + 1
    elif t not in dic.keys():
        dic[t] = 0
print(sum(dic.values()))

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

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

r=1
ans=0

print(S)
for i in range(1,N):
    if(S[i-1]==S[i]):
        r+=1
    elif(r>1):
        ans+=math.factorial(r)//(math.factorial(r-2)*math.factorial(2))
        r=1

if(r>1):
    ans+=math.factorial(r)//(math.factorial(r-2)*math.factorial(2))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

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

r=1
ans=0

for i in range(1,N):
    if(S[i-1]==S[i]):
        r+=1
    elif(r>1):
        ans+=math.factorial(r)//(math.factorial(r-2)*math.factorial(r))
        r=1

if(r>1):
    ans+=math.factorial(r)//(math.factorial(r-2)*math.factorial(r))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
ans = 0
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) 
    
    return result

x = 0

for k in ln2:
    x += cmb(k, 2)
    
print(x)

Submission status: Wrong Answer

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

from collections import Counter
a=Counter(S)

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N = int(input())
S = [list(input()) for i in range(N)]
X = [i for i in range(N)]

x = combinations(X, 2)
list_x = list(x)


ans = 0
for i in range(len(list_x)):
  if set(S[list_x[i][0]]) == set(S[list_x[i][1]]):
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = sorted(input())
count = 0
for i in range(n-1):
    if s == sorted(input()):
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
slist = [""]*n
for i in range(n):
	slist[i] =sorted(input())
sslist=sorted(slist)
count=0
for i in range(n-1):
	if sslist[i]==sslist[i+1]:
		count = count +1
#	print(sslist[i])
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = [""] * n
t = [""] * n

cnt = 0

for i in range(n):
    s[i] = input()
    t[i] = sorted(s[i])

t = sorted(t)

for i in range(n - 1):
    if t[i] == t[i + 1]:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N        = int( input() )
dict_all = {}
for nn in range(N):
    text = ''.join( sorted( str( input() ) ) )
    if( text in dict_all ):
        dict_all[text] += dict_all[text] + 1
    else:
        dict_all[text] = 0
        
count = 0
for key in dict_all:
    count += dict_all[key]    

print(count)

Submission status: Wrong Answer

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  clist = []
  for i in range(n):
    s = ''.join(sorted(input()))
    clist.append(s)
  d = {}
  for v in clist:
    if v in d:
      d[v] += 1
    else:
      d[v] = 1
  print(d)
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=[list(input()) for i in range(N)]
x=[]
for i in S:
  a=collections.Counter(i)
  a=sorted(a)
  x.append(a)
x=list(map(list,set(map(tuple,x))))
print(N-len(x))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
S=[list(input()) for i in range(N)]
x=[]
for i in S:
  a=collections.Counter(i)
  a=sorted(a)
  x.append(a)
x=list(map(list,set(map(tuple,x))))
print(N-len(x)+1)

Submission status: Wrong Answer

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

ans = 0
for v in s.values():
  ans += v
  if v > 1: ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
print(s)
for v in s.values():
  ans += v
  if v > 1: ans += 1
print(ans)

Submission status: Wrong Answer

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

C = []
sum_ana = 0
for _ in range(N):
  s = list(input())
  c = Counter(s)
  sum_ana = C.count(c)
  C.append(c)
  
print(sum_ana)

Submission status: Wrong Answer

Solution code:
li = []
l_dic={}
counter = 0
n = int(input())
for i in range(n):
    l = "".join(sorted(list(input())))
    if l in l_dic.keys():
        l_dic[l] += 1
        
    else:
        l_dic[l] =1
    
for d in l_dic.values():
    counter+=(d-1)*d*0.5
print(d)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(a)
an = c.values()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
slist = []
cnt = 0
for i in range(n):
  s = input()
  if slist:
    for i in range(len(slist)):
      for j in range(len(s)):
        if s[j] not in slist[i]:
          break
        else:slist[i] = slist[i].replace(s[j],'',1)
      else:cnt += 1
  slist.append(s)
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
slist = []
cnt = 0
for i in range(n):
  s = input()
  if slist:
    for i in range(len(slist)):
      for j in range(len(s)):
        if s[j] not in slist[i]:
          break
      else:cnt += 1
  slist.append(s)
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input() for i in range(n)]
for i in range(n):
  s[i]=sorted(s[i])
s=sorted(s)
counta=1
ans=0
for i in range(n-1):
  if s[i]==s[i+1]:
    counta+=1
  else:
    ans+=counta*(counta-1)
    counta=0
ans+=counta*(counta-1)
print(ans)

Submission status: Wrong Answer

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

N = int(input())
d = defaultdict(int)
for _ in range(N):
    s = list(input().rstrip("\r\n"))
    s.sort()
    if d["".join(s)] == 0:
        d["".join(s)] += 1
    else:
        d["".join(s)] += d["".join(s)]
ans = 0
for k in d:
    ans += d[k]-1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np 

N = int(input())
S = []
res = 0
for i in range(N):
    s = sorted(input())
    if s in S:
        res += 1 
    else:
        S.append(s)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())

S = []
for n in range(N):
  s = ''
  for _s in sorted(input()):
    s += _s
    
  S.append(s)
  
print(N-len(set(S)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
ans = 0
check_box = []
for s in S:
  s = sorted(s)
  s = ''.join(s)
  check_box.append(s)
C = Counter(check_box)
for i in C:
  if C[i] > 2:
    ans += C[i]
  elif C[i] == 1:
    pass
  else:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
ans = 0
check_box = []
for s in S:
  s = sorted(s)
  s = ''.join(s)
  check_box.append(s)
C = Counter(check_box)
for i in C:
  ans += C[i]
print(ans-1)