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:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
S_counter = Counter(S)
ans = 0
for i in S_counter.values():
    if i > 1:
        ans += (i-1)*i/2
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d = dict()
for i in range(n):
  S = ''.join(sorted(list(input())))
  if S in d.keys():
    d[S] +=1
  else:
    d[S] = 1

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

Submission status: Wrong Answer

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

for i in range(len(cnt_dic)):
    sum_cnt += int((cnt_dic[str(s[i])] * (cnt_dic[str(s[i])] - 1) )/ 2)



print(sum_cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# N=10^5より、O(N)で解く
for i in range(N):
  s[i] = sorted(s[i])

for i in range(N):
  tmp = ''
  for j in range(10):
    tmp += s[i][j]
  s[i] = tmp

print(N-len(set(s)))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# N=10^5より、O(N)で解く
for i in range(N):
  s[i] = Counter(s[i]).most_common()

Submission status: Wrong Answer

Solution code:
n=int(input())
mozi=[]
for i in range(n):
    mozi.append(sorted(input()))
mozi.sort()

def hantei(x,y):
    for i in range(10):
        if x[i]!=y[i]:
            return False
    return True

def conbi(n,r,mod):
    ue=1
    for i in range(n-r+1,n+1):
        ue*=i
        ue%=mod
 
    sita=1
 
    for i in range(1,r+1):
        sita*=i
        sita%=mod
 
    sita=pow(sita,mod-2,mod)
 
    return (ue*sita)%mod
i=0
ans=0
while i<n-1:
    c=1
    while i<n-1 and hantei(mozi[i],mozi[i+1]):
        c+=1
        i+=1
    ans+=conbi(c,2,10**9+7)
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
cnt = 0

for i in range(n):
  s = sorted(list(input()))
  arr.append(s)

for i in range(n):
  for j in range(i, n):
    if i != j and arr[i] == arr[j]:      
      cnt += 1

print(cnt//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
cnt = 0

for i in range(n):
  s = sorted(list(input()))
  arr.append(s)

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

print(cnt//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
word_list = []
count = 0
for word in s:
    if sorted(word) in word_list:
        count += 1
    else:
        word_list.append(sorted(word))
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 10 00:32:19 2020

@author: liang
"""

N = int(input())
d = dict()
for i in range(N):
    S = input()
    S = ''.join(sorted(list(S)))
    print(S)
    if S in d.keys():
        d[S] += 1
    else:
        d[S] = 1

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

def sum_stair(n):
    num = 0
    for i in range(1, n + 1):
        num += i
    return num

def main():
    N = int(input())
    s = [input() for _ in range(N)]

    t = []
    for i in s:
        c = 0
        for j in range(len(i)):
            c += ord(i[j])
        t.append(c)
    u = list(set(t))

    ans = 0
    for i in u:
        ans += max(0, sum_stair(t.count(i) - 1))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

while True:
    if l.count(l[-1]) >= 2:
        n = l.count(l[-1])
        r = l.count(l[-1])-1
        ans += factorial(n) // factorial(r) // factorial(n - r)
    l = [s for s in l if s != l[-1]]
    
    if len(l) == 0:
        break

if ans != 0:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    b=list(input())
    b.sort()
    b=str(b)
    s.append(b)

c=collections.Counter(s)

for i in c.values():
    if i>1:
        a+=i-1

print(a)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import copy

n = int(input())
S = [stdin.readline()[:-1] for i in [0]*(n-1)]
S.append(stdin.readline())
s = []
for i in S:
    s.append("".join(sorted(i)))
s.sort()
arr = []
temp = 1
for i in range(n-1):
    if temp>1 and s[i]!=s[i+1]:
        arr.append(temp)
        temp = 1
    if s[i]==s[i+1]:
        temp += 1
if temp>1:
    arr.append(temp)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[set(input()) for i in range(n)]
res=0
for i in range(n):
    for j in range(i+1,n):
        if li[i]==li[j]:
            res+=1
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = [tuple(sorted(list(input()))) for _ in range(n)]
ans = 0
st = []
count = {}

for i in range(n):
    if not s[i] in st:
        st += [s[i]]
        count[s[i]] = 0

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

Submission status: Wrong Answer

Solution code:
n = int(input())

dic = []
cnt = 0

for i in range(n):
  word = sorted(list(input()))
  word = ''.join(word)
  if word in dic:
    cnt += 1
  else:
    dic.append(word)

print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = list(''.join(sorted(input())) for i in range(n))
cnt = 0

for i in set(s):
    n = s.count(i)
    if n >= 2:
        cnt += (math.factorial(n)//2*math.factorial(n-2))
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = list(''.join(sorted(input())) for i in range(n))
cnt = 0
print(s)
for i in set(s):
    n = s.count(i)
    if n >= 2:
        cnt += math.factorial(n)
print(cnt)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
dict_a = {}

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

print(dict_a)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
count =0
store_list=[]
ans_list=[1]*n
for _ in range(n):
    s = input()
    dict_s =Counter(s)
    #print(dict_s)
    if dict_s in store_list:
        a = store_list.index(dict_s)
        #print(a)
        #print(dict_s)
        ans_list[a] += 1
    else:
        store_list.append(dict_s)
#print(ans_list)
sum = 0
for i in range(n):
    b = ans_list[i]
    sum += b*(b-1)/2
       
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
count =0
store_list=[]
for _ in range(n):
    s = input()
    s_list =[s[i] for i in range(10)]
    s_list.sort()
    if s_list in store_list:
        count +=1
    else:
        store_list.append(s_list)
print(count)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(S)
ans = 0
print(S)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [set(input())for _ in range(N)]
m = 0
for i in S:
    m += S.count(i)
    
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
S = set()
ans = 0
for i in s:
    if "".join(sorted(i)) in S:
        ans +=1
    else:
        S.add("".join(sorted(i)))
print(ans)

Submission status: Wrong Answer

Solution code:
def get( s ):
    sum=0
    s = sorted(s) 
    for i in range(len(s)):
        sum += int(ord(s[i])*(1<<i))
    return sum

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

H=[0]*n
for i in range(n):
    H[i]=get(S[i])

H.sort()
c=0
ans=0
for i in range(n-1):
    if H[i]==H[i+1]:
        c+=1
    else:
        ans += c*(c+1)//2
        c=0
ans += c*(c+1)//2

# print(H)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
List=[list(input()) for i in range(n)]
ans=0
for i in range(n-1):
    List1=Counter(List[i])
    for j in range(1,n):
        List2=Counter(List[j])
        if List1==List2:
            ans+=1
print(int(ans/2))

Submission status: Wrong Answer

Solution code:
class Combination:                                      # 計算量は O(n_max + log(mod))
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):                     # 階乗(= n_max !)の逆元を生成
            f = f * i % mod                             # 動的計画法による階乗の高速計算
            fac.append(f)                               # fac は階乗のリスト
        f = pow(f, mod-2, mod)                          # 階乗から階乗の逆元を計算。フェルマーの小定理より、　a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
                                                        # python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):                   # 上記の階乗の逆元から階乗の逆元のリストを生成（＝ facinv ）
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()


    def __call__(self, n, r):  # self.C と同じ
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def C(self, n, r):
        if not 0 <= r <= n: return 0                    # 範囲外という事はすなわち、そのような場合の数は無いはずなので、0を出力すればよい。（これが無いとREになる）
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

##############################################################################################

from collections import Counter
N = int(input())
S = [[0]*26 for _ in range(N)]
for i in range(N):
    for s in input():
        S[i][ord(s)-ord("a")] += 1
    S[i] = tuple(S[i])
C = Combination(N)
res = 0
for value in Counter(S).values():
    res += C(value,2)

print(res)

Submission status: Wrong Answer

Solution code:
import collections


def main():
    N = int(input())
    S = [input() for i in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            cnt = [0] * 10
            for k in range(10):
                if S[i][k] in S[j]:
                    cnt[k] += 1
            if 0 not in cnt:
                ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections


def main():
    N = int(input())
    S = [input() for i in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            cnt = 0
            for k in range(10):
                if S[i][k] in S[j]:
                    cnt += 1
            if cnt == 10:
                ans += 1

    print(ans)





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
s.sort()
cnt=0
for i in range(n-1):
    if s[i]==s[i+1]:
        cnt +=1
print(cnt)

Submission status: Wrong Answer

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

cnt=0
for i in range(n):
    if s.count(s[i])!=1:
        cnt += s.count(s[i])/s.count(s[i])
print(cnt-n)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(input())
alp = [chr(i) for i in range(97, 97+26)]
L = []
for i in range(N):
    s = list(set(list(input())))
    L.append(s)
for i in range(N):
    L[i].sort()
L.sort()

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

Submission status: Wrong Answer

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

import collections
li = []
li2 = []
for i in range(n):
    cou = collections.Counter(list(s[i]))
    if cou in li:
        li2 += [str(cou)[8:-1]] 
    li += [cou]

li3 = collections.Counter(li2)
li4 = list(li3.values())
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

counter={}
ans=0
for i in range(n):
	ss = sorted(s[i])
	ss=("").join(ss)
	if ss not in counter:
		counter[ss]=0
	else:
		counter[ss]+=counter[ss]+1
for k,v in counter.items():
	if v>0:
		ans+=v
print(ans)

Submission status: Wrong Answer

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

counter={}
ans=0
for i in range(n):
	ss = sorted(s[i])
	ss=("").join(ss)
	if ss not in counter:
		counter[ss]=0
	else:
		counter[ss]+=counter[ss]+1
print(counter)
for k,v in counter.items():
	if v>0:
		ans+=v
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
sl = []
for i in range(n):
    s = list(input())
    s.sort()
    sl.append(s)
sl.sort()
ans = 0
for i in range(n - 1):
    j = i + 1
    if sl[i] == sl[j]:
        cnt = 0
        while sl[i] == sl[j + cnt]:
            cnt += 1
            if j + cnt == n:
                break
        ans += cnt
        j += cnt
        if j == n:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
dict={}
for _ in range(int(input())):
  s=''.join(sorted(input()))
  if s not in dict: dict[s]=1
  else:
    dict[s]+=dict[s]
print(sum(dict.values())-2)

Submission status: Wrong Answer

Solution code:
dict={}
for _ in range(int(input())):
  s=''.join(sorted(input()))
  if s not in dict: dict[s]=0
  else: dict[s]+=dict[s]+1
print(sum(dict.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
ans = 0
for _ in range(n):
    s = ''.join(sorted(input()))
    print(s) 
    if s in d.keys():
        d[s] += 1;
        ans += d[s]
    else:
        d.setdefault(s,0)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


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


def z():
    return int(sys.stdin.readline())


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


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def nck(n, k, mod=10**9+7):
    bunbo = bunshi = 1
    for i in range(k):
        bunshi = (bunshi * (n-i)) % mod
        bunbo = (bunbo * (i+1)) % mod
    return (bunshi * pow(bunbo, mod-2, mod)) % mod


N = z()
str_lis = ['']*N
ans_dic = defaultdict(int)
for i in range(N):
    tmp = S()
    tmp = tuple(sorted(tmp))
    ans_dic[tmp] += 1
ans = 0
for key in ans_dic:
    ans += nck(ans_dic[key], 2)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
d={}
C=[]
i=0
for x in range(N):
  s="".join(sorted(input()))
  if s not in C:
    C.append(s)
    d[s]=1
  else:
    d[s]*=2
ans=0
for y in range(len(C)):
  ans += d[C[y]]-1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[]
for x in range(N):
  s=sorted(input())
  S.append(s)
a=0
for y in range(N):
  t=S.count(S[y])
  if t>a:
    a=t
print(a)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
slist = []
for _ in range(N):
    s = sorted(input())
    s = ''.join(s)
    slist.append(s)
slist = Counter(slist)
ans = 0
for i in slist.values():
    if i == 1:
        break
    ans += (i*(i-1)+2)//2-1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
slist = []
for _ in range(N):
    s = sorted(input())
    s = ''.join(s)
    slist.append(s)
slist = Counter(slist)
ans = 0
for i in slist.values():
    if i == 1:
        break
    ans += (i*(i-1))//2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
lsS = []
for i in range(N):
    lsS.append(''.join(sorted(input())))

counter = collections.Counter(lsS)
n=0
for i in counter.values():
    if i > 1:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
import collections
import copy
N = int(input())
lsS = []
for i in range(N):
    lsS.append(collections.Counter(list(input())))
n=0
lsS2 = copy.copy(lsS)
for i in range(N):
    lsS2.remove(lsS[i])
    if lsS[i] in lsS2:
        n += 1
        print(lsS2)
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

d = dict()
for x in a:
  s = ''.join(sorted(x))
  if s not in d.keys():
    d[s] = 0
  else:
    d[s] += 1

print(sum(d.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
Dic = {}
for _ in range(N):
  st = input()
  st=''.join(sorted(st))
  if st not in Dic:
    Dic[st]=0
  else:
    Dic[st]+=Dic[st]+1
print(sum(Dic.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
Dic = {}
for _ in range(N):
  st = input()
  st=''.join(sorted(st))
  if st not in Dic:
    Dic[st]=0
  else:
    Dic[st]=Dic[st]+1
print(sum(Dic.values()))

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    import math
    N = int(input())
    Ss = [sorted([item for item in input()]) for _ in range(N)]
    
    sss = []
    for line in Ss:
        sss.append(''.join(line))
    line_cnt = collections.Counter(sss)

    cnt = -1
    for letter, num in line_cnt.most_common():
        if num >=2:
            cnt += math.comb(num, 2)

    print(cnt) if cnt != -1 else print(0)
if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    Ss = [sorted([item for item in input()]) for _ in range(N)]
    
    sss = []
    for line in Ss:
        sss.append(''.join(line))
    line_cnt = collections.Counter(sss)

    cnt = -1
    for letter, num in line_cnt.most_common():
        if num >=2:
            cnt += num

    print(cnt) if cnt != -1 else print(0)
if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    Ss = [sorted([item for item in input()]) for _ in range(N)]
    
    sss = []
    for line in Ss:
        sss.append(''.join(line))
    line_cnt = collections.Counter(sss)

    cnt = 0
    for letter, num in line_cnt.most_common():
        if num >=2:
            cnt += num

    print(cnt)
if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

count_by_kw = Counter()

n=int(input())
l=[]
dict={}
ans=0
for x in range(n):
  a=sorted(input())
  b=''.join(a)
  if not b in dict:
    dict[b]=x
    l.append(b)
    count_by_kw[b]+=0
  else:
    d=count_by_kw[b]
    count_by_kw[b]+=(d+1)
    
for y in range(len(l)):
  r=l[y]
  ans+=count_by_kw[r]

print(ans)

Submission status: Wrong Answer

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

split_abc = [list(a[i]) for i in range(n)]

count = 0
split = [sorted(split_abc[i]) for i in range(n)]

count = 0
for i in range(n-1):
  for s in range(n-1):
    if i!=s and i<s:
      if split[i]==split[s+1]:
        count += 1
      
print(count)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = [sorted(input()) for i in range(N)]
SS = []
for i in S:
    SS.append("".join(i))
count = 0

c = collections.Counter(SS)

for i in c.values():
    A = SS.count(i)
    count += (A*(A-1)) // 2

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

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

n = readInt()
d = defaultdict(int)
for i in [input() for i in range(n)]:
  t = defaultdict(int)
  for j in i:
    t[j]+=1
  d[str(sorted(t))]+=1
ans = 0
#print(d)
for i in d:
  ans+=comb(d[i],2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
prm = [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]
alp = {chr(i):p for i,p in zip(range(97, 97+26),prm)}
n = int(input())
d = defaultdict(int)
nums = set([])
for _ in range(n):
  s = input()
  m = 1
  for l in s:
    m = m*alp[l]%10**9
  d[m] += 1

def comb(n, r):
  if n<r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 0
for k in d.values():
  ans += comb(k,2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
n = int(input())
d = defaultdict(int)
nums = set([])
for _ in range(n):
  s = input()
  m = 1
  for l in s:
    m *= ord(l)-95
  d[m] += 1

def comb(n, r):
  if n<r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 0
for k in d.values():
  ans += comb(k,2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
n = int(input())
d = defaultdict(int)
nums = set([])
for _ in range(n):
  s = input()
  m = 1
  for l in s:
    m *= ord(l)-96
  d[m] += 1

def comb(n, r):
  if n<r:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans = 0
for k in d.values():
  ans += comb(k,2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = [list(input()) for S in range(n)]
cnt = 0
for i in range(n):
	s[i].sort()
duplicated_data = [tuple(d) for d in s]
unique_data = set(duplicated_data)
s_set = [list(d) for d in unique_data]
print(s_set)
for j in range(len(s_set)):
	if s.count(s_set[j]) >= 2:
		k = s.count(s_set[j])
		cnt += math.factorial(k)//(math.factorial(k-2)*math.factorial(2))
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
a = [0]*n
for i in range(n):
    for j in range(10):
        a[i] += 10**(ord(s[i][j])-97)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

alist = []
count = 0

for i in range(n):
    a = Counter(s[i]) 
    if a not in alist:
        alist.append(a)
    else:
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
S = [''.join(sorted(input())) for _ in range(n)]
d = [v-1 if v%2==0 else v for v in collections.Counter(S).values() if v > 1]
print(sum(d))

Submission status: Wrong Answer

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
S = []
for i in range(N):
	S.append(rs())

import collections
h = collections.defaultdict(int)
for s in S:
	l = [0] * 26
	for c in s:
		n = ord(c)-ord('a')
		l[n] = 1
	h[tuple(l)] += 1

def comb(n, k):
	p, q = 1, 1
	for i in range(1, k+1):
		p = p * (n-i+1)
		q = q * i
	return p // q

ans = 0
for k, v in h.items():
	if v > 1:
		ans += comb(v, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections
import fractions
import itertools
import functools
import  operator

def solve():
    n = int(input())
    s = [sorted(list(set(input()))) for _ in range(n)]
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if s[i] == s[j]:
                cnt += 1
    print(cnt)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

ls = []
ans = 0

for s in sn:
    s = ''.join(sorted(s))
    if s in ls:
        ans += 1
    else:
        ls.append(s)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math

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

def main():
    N = int(input())
    S = defaultdict(int)
    for _ in range(N):
        s = ''.join(sorted(list(input())))
        if s in S:
            S[s] += 1
        else:
            S.update({s:0})
    cnt = 0
    for k,v in S.items():
        if v == 0:
            continue
        elif v == 1:
            cnt += v
        else:
            cnt += combinations_count(v+1,v)
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    S = defaultdict(int)
    for _ in range(N):
        S[''.join(sorted(list(input())))] += 1
    # print(S)
    cnt = 0
    for k,v in S.items():
        if v == 1:
            continue
        cnt += v
    if cnt > 0:
        print(cnt-1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
print(len(set([''.join(sorted(i)) for i in [input() for i in range(n)]])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=set()
tt=0
for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    if s not in ans:
        ans.add(s)
    else:
        tt+=1
print(tt)

Submission status: Wrong Answer

Solution code:
n = int(input())
o = [0]*251
ans = 0
for i in range(n):
    s = input()
    ind = 0
    for j in range(10):
        ind += (ord(s[j])-97)
    if o[ind] != 0:
        ans += o[ind]
    o[ind] += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
o = [0]*251

for i in range(n):
    s = input()
    ind = 0
    for j in range(10):
        ind += (ord(s[j])-97)
    o[ind] += 1

ans = 0
for i in range(251):
    ans += o[i]*(o[i]-1)//2

print(ans)

Submission status: Wrong Answer

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

count = 0

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

    moji.append("".join(s))

result = []
for i in range(n):
    if moji[i] in result:
        count += 1
    else:
        result.append(moji[i])

print(count)

Submission status: Wrong Answer

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

count = 0

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

    moji.append("".join(s))

print(moji)
result = []
for i in range(n):
    if moji[i] in result:
        count += 1
    else:
        result.append(moji[i])

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
 
def andgram(s):
  dictnary=defaultdict(list)
  
  for i in s:
    dictnary["".join(sorted(i))].append(i)
  
  li=[]
  li2=0
    # Print all anagrams together
  for key,value in dictnary.items():
        li.append(key)
        for item in value:
            li2 += 1

  print(li2-len(li))

n=int(input())
s=[]
for i in range(n):
  s.append(input())
  
andgram(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input()for i in range(n)]
d=dict()
for i in s:
 i="".join(sorted(list(i)))
 try:d[i]+=d[i]+1
 except:d[i]=0
print(sum(d.values()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    if set(S[i]) != set(S[j]):
      pass
    else:
      if S[i].sort() == S[j].sort():
        ans += 1
      else:
        pass
print(ans)