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
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
        self._fact = [0] * (self._maxNum + 1)
        self._fact[0] = self._fact[1] = 1

        if self._divider != 0:
            self._inv = [0] * (self._maxNum + 1)
            self._finv = [0] * (self._maxNum + 1)
            self._inv[0] = self._inv[1] = self._finv[0] = self._finv[1] = 1

        for i in range(2, self._maxNum + 1):
            self._fact[i] = self._fact[i - 1] * i;
            if self._divider != 0:
                self._fact[i] %= self._divider
                self._inv[i] = self._divider - self._inv[self._divider % i] * (self._divider // i) % self._divider
                self._finv[i] = self._finv[i - 1] * self._inv[i] % self._divider

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
    cmb = Combination(N, 0)
    ans = 0
#    for num in di.values():
#        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
        self._fact = [0] * (self._maxNum + 1)
        self._fact[0] = self._fact[1] = 1

        if self._divider != 0:
            self._inv = [0] * (self._maxNum + 1)
            self._finv = [0] * (self._maxNum + 1)
            self._inv[0] = self._inv[1] = self._finv[0] = self._finv[1] = 1

        for i in range(2, self._maxNum + 1):
            self._fact[i] = self._fact[i - 1] * i;
            if self._divider != 0:
                self._fact[i] %= self._divider
                self._inv[i] = self._divider - self._inv[self._divider % i] * (self._divider // i) % self._divider
                self._finv[i] = self._finv[i - 1] * self._inv[i] % self._divider

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
#    cmb = Combination(N, 0)
    ans = 0
#    for num in di.values():
#        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

List=[''.join(sorted(input())) for i in range(N)]
List.sort()
List.extend("1")
cnt = 0
num = 1

for i in range(N):
  a = List[i]
  b = List[i+1]
  if a != b:   
    cnt = cnt + num * (num-1) / 2
    num = 0 
  else:
    num = num + 1

print(int(cnt))

Submission status: Wrong Answer

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

l = []
for w in range(N):
    l.append("".join(sorted(input())))

print(N - len(set(l)))

Submission status: Wrong Answer

Solution code:
N=int(input())
cnt=0
S= [sorted(input())for i in range(N)]
for i in range(N):
  S[i]="".join(S[i][0:])
cnt=len(S)
print(cnt-len(set(S)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)

N = int(input())
#print(N)
S=[]
for i in range(N):
    #print(i)
    S.append("".join(sorted(input())))
    # print(input())
S.sort()
#print(S)
n = 1
ans=0
for i in range(1,N):
    if S[i] == S[i-1]:
        n = n + 1
    else:
        #print(i,n)
        ans = ans + n * (n-1) //2 
        n = 1
ans = ans + n * (n-1) // 2

Submission status: Wrong Answer

Solution code:
N = int(input())

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

count = {}
ans = 0

for s in S:
    s=str(sorted(s))
    if s in count:
        count[s] += 1
        ans += 1
    else:
        count[s] = 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
s = [input() for i in range(int(input()))]
c = [Counter(i) for i in s]
a = 0
t = []
for i in c:
    if i in t:
        a += 1
    else:
        t.append(i)
print(a)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
	# start from 23:30
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

	N = int(input())
	List = [str(input()) for i in range(N)]

	List_sort = []
	
	for i in range(N):
		List_pre = list(List[i])
		List_pre.sort()
		List_pre = ''.join(List_pre)
		# print(List_pre)
		List_sort.append(List_pre)
	# print(List_sort)

	List_unique = list(set(List_sort))
	# print(List_unique)

	List_ans = []

	for i in range(len(List_unique)):
		# print(i)
		c = List_sort.count(List_unique[i])
		# print(c)
		if c == 1:
			List_ans.append(1)
		else:
			List_ans.append(combinations_count(c,2))

	print(sum(List_ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = sorted(''.join(sorted(list(input()))) for i in range(N))
# N(10+log_2(10)+10)
ans = 0
sep = []
for i in range(N-1): # N*4
    if  S[i] != S[i+1]:
        sep.append(i+1)
sep.append(N)
# print(sep)
count = []
prev = 0
for i in sep: # len(set(N))*2 <= N*2
    count.append(i-prev)
    prev = count[-1]
# print(count)
for i in count: # N*2 (similarly)
    ans += i*(i-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
	import collections
	N = int(input())
	s = list([str(input()) for i in range(N)])
	ans = []
	ans_pre = []
	
	for i in range(N):
		ans_pre.append(collections.Counter(s[i]))
	# print("ans_pre is")
	# print(ans_pre)


	while len(ans_pre) > 0:
		ans_point = ans_pre.count(ans_pre[0])
		# print("ans_point is {}".format(ans_point))
		
		if ans_point == 2:
			ans_point = 1

		ans.append(ans_point)
		ans_pre = [n for n in ans_pre if n!=ans_pre[0]]
		# print(ans_pre)


	print(sum(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
dict={}

for i in range(n):
  a=input()
  newa="".join(sorted(a))
  dict[newa]=dict.get(newa,0)+1

ans=0

for i in dict:
  ans+=dict[i]*(dict[i]-1)/2

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

words = sorted(words)
temp = 0
ans = 0
words.append('pad')

for i in range(n):
    temp = temp + 1
    if words[i] != words[i+1] and temp > 1:
        ans = ans + (math.factorial(temp)//2)
        temp = 0
    elif words[i] != words[i+1]:
        temp = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
d = 0
e = 0
for i in range(n):
    s = sorted(list(input()))
    a.append(s)
a.sort()
for b in a:
    del a[0]
    while b in a:
        del a[0]
        d += 1
        e += 1
    if e > 1:
        d += e - 1
    e = 0
print(d)

Submission status: Wrong Answer

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":3.3,"y":2.3,"z":1.3}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)
ss = sorted(s)

a = 0 # a; pre ans

for i in range(n):
    for j in range(1, n - i):
        if ss[i] == ss[i + j]:
            a += 1
        else:
            break

print(a)

Submission status: Wrong Answer

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":8.3,"x":8.9,"y":9.7,"z":10.1}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)

a = 0 # a; pre ans

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

print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
import math
d={}
for i in range(n):
    a="".join(sorted(input()))
    if a not in d:
        d[a]=1
    else:
        d[a]+=1
lis=list(d.values())
cnt=0
for i in lis:
    i=math.factorial(i)//2
    cnt+=i
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
s = sorted(["".join(sorted(input())) for i in range(n)])
a = 0
b = []
for i in range(n-1):
  if s[i]==s[i+1]:
    a += 1
    if i==n-2:
      b.append(a)
      a = 0
  else:
    b.append(a)
    a = 0
for i in range(len(b)):
  a += math.factorial(b[i])
print(a)

Submission status: Wrong Answer

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

#print(s)

#出現文字列
sdict = {}

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        #組み合わせが増えるので
        sdict[s_i]+= 1
        continue

    else:
        sdict[s_i] = 0

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

Submission status: Wrong Answer

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

#出現文字列
sdict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        #組み合わせが増えるので
        sdict[s_i]+= 1
        continue

    for j in range(i+1,N):
        sdict[s_i] = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [0]*N
count = 0
for i in range(N):
    s[i] = input() #s[i]は長さ10の英小文字
    s[i] = sorted(s[i])
for a in range(1,N):
    for b in range(2,N):
        if s[a] == s[b]:
            count += 1
print(count)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
  for j in range(N):
    if i != j:
      if s[i] == s[j]:
        ans += 1
        
print(ans/2)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list()
d = dict()
for i in range(n):
    b = list(input())
    b.sort()
    moji = "".join(b)
    if (moji in d):
        d[moji] += 1
    else:
        d[moji] = 0
x = 0
for i in d:
    if d[i] > x:
        x = d[i]
print(x)

#非最適化ソート
# for i in range(n):
#     a.append(input())
# for i, youso in enumerate(a):
#     b = list()
#     for j in youso:
#         b.append(j)
#     b.sort()
#     x = str()
#     for j in b:
#         x += j
#         a[i] = x

#TLE ver.
# for i, youso in enumerate(a):
#     for j in range(i, n-1):
#         if youso == a[j+1]:
#             x += 1
# print(x)

#TLE改良版
# a.sort()
# for i in range(n-1):
#     if a[i] == a[i+1]:
#         for j in range(i+1, n):
#             if a[i] == a[j]:
#                 x += 1
#             else:
#                 break
#     else:
#         continue



#いらない処理
# y = 0
# for i in range(1, x+1):
#     y += i

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
L = list()
for i in range(N):
  L.append("".join(sorted(input())))
  
#print(L)
d = collections.Counter(L)
print(sum(d.values()) - len(d))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input() for i in range(n)]
dic={}
l=list()
cnt=0
for i in range(n):
  k=sorted(s[i])
  t=''.join(k)
  l.append(t)
  if l[i] in dic:
    cnt+=1
  else:
    dic[l[i]]=1
print(cnt*(cnt+1)//2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 2019-11-16 14:51:41(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l
# import itertools
# from functools import reduce
# import operator as op
from scipy.misc import comb # float
# import numpy as np
# import heapq
# import array


def main():
    n = int(sys.stdin.readline().rstrip())

    sorted_letters = [''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]
  
    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >= 2:
            count += comb(c, 2)

    print(int(count))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s = [[] for i in range(n)]
ans = -1

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

c = collections.Counter(s)
for i in c.values():
    if i > 1:
        ans += i
if ans > 0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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


print(sum(s.values()))

Submission status: Wrong Answer

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

ss = [''.join(sorted(i)) for i in s]
ans = 0
key_dict = {}

for i in ss:
    if i in key_dict:
        key_dict[i] += 1
    else:
        key_dict[i] = 1

a = key_dict.values()
al = [i * (i-1) / 2 if i > 1 else 0 for i in a]

ans = sum(al)
print(ans)

Submission status: Wrong Answer

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

ss = [''.join(sorted(i)) for i in s]
ans = 0
key_dict = {}
for i in ss:
    if i in key_dict:
        key_dict[i] += key_dict[i] + 1
    else:
        key_dict[i] = 0

ans = sum(key_dict.values())
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[sorted(input()) for _ in range(n)]
count = 0
s.sort()
for i in range(n):
    if s[i*10:(i+1)*10-1] == s[(i+1)*10:(i+2)*10-1]:
        count = count + 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
cnts = []
sorted_set = set()
for s in ss:
	sorted_s = ''.join(sorted(s))
	if not sorted_s in sorted_set:
		sorted_set.add(sorted_s)
		cnts.append(0)
	else:
		i = list(sorted_set).index(sorted_s)
		cnts[i] += 1
		cnt += cnts[i]

print(cnt)

Submission status: Wrong Answer

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

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

count_list = []
for _s in s:
    count_list.append(s.count(_s))

count_count_list = []
for i in range(1,11):
    count_count_list.append(int(count_list.count(i)/i)) 

print(count_count_list)

ans = 0
for i in range(1,11):
    if count_count_list[i-1] != 0:
        ans += count_count_list[i-1] * ((i * (i - 1)) / 2)

print(int(ans))

Submission status: Wrong Answer

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

for i in range(n):
  s.append(''.join(sorted(input())))
s.sort()

cnt = 1
for j in range(0, n-1):
  if s[j] == s[j+1]:
    cnt += 1
    if j == n-2:
      ans += cnt*(cnt-1)/2
  else:
    ans += cnt*(cnt-1)/2
    cnt = 1
    
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  s.append(''.join(sorted(input())))
s.sort()
print(s)

cnt = 1
for j in range(0, n-1):
  if s[j] == s[j+1]:
    cnt += 1
    if j == n-2:
      ans += cnt*(cnt-1)/2
  else:
    ans += cnt*(cnt-1)/2
    cnt = 1
    
print(ans)

Submission status: Wrong Answer

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

for s in S:
  ls = str(sorted(list(s)))
  if ls in count:
    if count[ls] == 1:
      count[ls] = 3
    else:
      count[ls] +=1
  else:
    count[ls] = 0
print(sum(count.values()))

Submission status: Wrong Answer

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

for s in S:
  ls = ("").join(sorted(list(s)))
  if ls in count:
    if count[ls] == 1:
      count[ls] = 3
    else:
      count[ls] +=1
  else:
    count[ls] = 0
print(sum(count.values()))

Submission status: Wrong Answer

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

for s in S:
  ls = ("").join(sorted(list(s)))
  if ls in count:
    if count[ls] == 1:
      count[ls] = 3
    else:
      count[ls] +=1
  else:
    count[ls] = 0
print(count)
print(sum(count.values()))

Submission status: Wrong Answer

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

A=0
for i in range(N):
    for j in range(i+1,N):
        if len(set(s[i]))==len(set(s[j])) and i!=j:
            A+=1

print(A)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
s = [sorted(input()) for _ in range(n)]
s_sort = sorted(s, key = itemgetter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

count = 0
s_count = 0

l = s_sort[0]

print(s_sort)

for i in range(1, n):
    if l == s_sort[i]:
        s_count += 1
        count += s_count
    else:
        l = s_sort[i]
        s_count = 0

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = [str(input()) for i in range(n)]
s_sort = [sorted(i) for i in s]
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        ans += s_sort[j:].count(s_sort[i])

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[0]*N
for i in range(N):
    s[i] = input()
i=0
Co=[]
while s != []:
    counter = 1
    a = s.pop(0)
    for word in s:
        if word == a:
            s.remove(word)
            counter+=1
    Co.append(counter)
summary = 0
for i in range(len(Co)):
    summary+=Co[i]*(Co[i]-1)//2
print(summary)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[0]*N
for i in range(N):
    s[i] = input()
    s[i] = sorted(s[i])
i=0
Co=[]
while s != []:
    counter = 1
    a = s.pop(0)
    for word in s:
        if word == a:
            s.remove(word)
            counter+=1
    Co.append(counter)
summary = 0
for i in range(len(Co)):
    summary+=Co[i]*(Co[i]-1)//2
print(summary)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[list(input()) for i in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        if len(set(s[i])&set(s[j]))==len(set(s[i])):
            c+=1
print(c)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

from collections import Counter
from collections import defaultdict
n = int(input())

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

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[0]*n
ans=0
for i in range(0,n):
  s=input().split()
  li[i]=''.join(sorted(s))
  
for j in range(0,n-1):
  for k in range(j+1,n):
    if li[j]==li[k]:
      ans+=1
    else:
      ans+=0
      
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [str(sorted(input())) for i in range(N)]
count = [0]*N
for i in range(N):
    count[i] = s.count(s[i])-1
print(max(count))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
s = sorted(s)
cnt = 0
for i in range(len(s)):
    for j in s[i + 1:]:
        if s[i] == j:
            cnt += 1
        else:
            print(s[i], j)
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = sorted(["".join(sorted((input()))) for i in range(N)])
count = 0

num=1
for i in range(N-1):
    if(s[i]==s[i+1]):
        num += 1
    elif(num>1):
        count += num*(num-1)/2
        num = 1
    
if(num>1):
    count += num*(num-1)/2
print((count))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = sorted(["".join(sorted((input()))) for i in range(N)])
count = 0

num=1
for i in range(N-1):
    if(s[i]==s[i+1]):
        num += 1
    elif(num>1):
        count += num*(num-1)/2
        num = 1
    
if(num>1):
    count += num*(num-1)/2
print(count)

Submission status: Wrong Answer

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

for i in range(N-1):
    num=1
    if(s[i]==s[i+1]):     
        num += 1
    elif(num>1):
        count += num*(num-1)/2
        num = 1
    
        
print(count)

Submission status: Wrong Answer

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

for i in range(N-1):
    num=1
    if(s[i]==s[i+1]):     
        num += 1
    elif(num>0):
        count += num*(num-1)/2
        num = 1
    
        
print(count)

Submission status: Wrong Answer

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

for i in range(N-1):
    num=0
    if(s[i]==s[i+1]):     
        num += 1
    elif(num>0):
        count += num*(num-1)/2
        count = 0
    
        
print(count)

Submission status: Wrong Answer

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

for i in range(N-1):
    num=0
    if(s[i]==s[i+1]):     
        num += 1
    elif(num>0):
        count += num*(num-1)/2
        
print(count)

Submission status: Wrong Answer

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

for i in range(N-1):
     if(s[i]==s[i+1]):     
        count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = {}
for i in range(N):
    foo = 0
    for j in input():
        j = ord(j) - ord("a")
        foo += 2**j
    try:
        dic[foo] += 1
    except:
        dic[foo] = 1
ans = 0
for n in dic.values():
    ans += n*(n-1)//2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n=int(input())
L = []
for i in range(n):
  a = input()
  a = sorted(a)
  L.append(a)
L = sorted(L)


k=1
sum=0
for i in range(n-1):
  if L[i]==L[i+1]:
    k += 1
  else:
    if k!=1:
      sum += cmb(k,2)
    k=1
if k==1:
  sum += 1
else:
  sum += cmb(k,2)
print(sum)

Submission status: Wrong Answer

Solution code:
import collections as cl

n = int(input())
s = [""]*n
for i in range(0, n):
    s[i] = input()
    s[i] = ''.join(sorted(s[i]))

cs = cl.Counter(s)
num = list(cs.values())
count = 0

for j in range(0, len(num)):
    if num[j] != 1:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from math import factorial
from scipy.misc import comb


# def comb(n, r):
#     if n == 0 or n-r < 0:
#         return 0
#     return int(factorial(n) / factorial(r) / factorial(n-r))


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

S.sort()

count = 0
count_min = 0
tmp = []
for s in S:
    if s == tmp:
        count_min += 1
    else:
        count += comb(count_min+1, 2)
        count_min = 0
    tmp = s
    # print('count:{}, min:{}'.format(count, count_min))
count += int(comb(count_min+1, 2))
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

dic = {}

for i in range(n):
    s = input()
    ss = sorted(s)
    sss = "".join(ss)
    #print(dic)
    #print(sss)
    if (sss in dic):
        val = dic[sss]
        dic[sss] = val + val + 1
        #print(dic[sss])
    else:
        dic.setdefault(sss, 0)

#print(dic)
ans = 0
for i in dic.values():
    ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

dic = {}

for i in range(n):
    s = input()
    ss = sorted(s)
    sss = "".join(ss)
    #print(dic)
    #print(sss)
    if (sss in dic):
        val = dic[sss]
        dic[sss] = val + val + 1
        #print(dic[sss])
    else:
        dic.setdefault(sss, 0)

#print(dic)
print(sum(dic.values()))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
an=[]
count=0
for i in range(n):
    if s[i] not in an:
        an.append(s[i])
    else:
        count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
q=[]  
for i in range(N):
    q+=[list(input())]
    q[i].sort()
    q.sort()
def g(n): #組み合わせ
    if n<=1:
        return 0
    else:
        return n-1+g(n-1)   
i=0
s=0
z=0 #総得点
while i<N-1:
    if q[i]!=q[i+1]:
        z+=g(s+1)
        s=0
    else:
        s+=1
    i+=1
print(z)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        if not array:
            break
        alphabet = array[:][0]
        num = array.count(alphabet)-1
        if num <= 0:
            pass
        elif num <= 1:
            ans += 1
        else:
            ans += (num+1)*num/2
        for j in range(num+1):
            array.remove(alphabet)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

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

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        print(i)
        if not array:
            break
        alphabet = array[:][0]
        num = array.count(alphabet)-1
        if num <= 0:
            pass
        elif num <= 1:
            ans += 1
        else:
            ans += combinations_count(num+1, 2)
        for j in range(num+1):
            array.remove(alphabet)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
S=[]
for i in range(n):
    S.append(sorted(input()))
ans=0
for i in range(n):
    for j in range(n):
        if S[i]==S[j]:
            ans+=1
            
print((ans-n)/2)

Submission status: Wrong Answer

Solution code:
def C(n) :
    if n == 1:
        return 1
    sum = 1
    while (n > 1):
        sum *= n
        n -= 1
    return sum // 2

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
    ans = 0
    for v in dic.values():
        ans += C(v)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def C(n) :
    sum = 1
    while (n > 1):
        sum *= n
        n -= 1
    return sum // 2

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
    ans = 0
    for v in dic.values():
        ans += C(v)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N  = int(input())
from collections import Counter
a = []
for i in range(N):
  a.append(str(sorted(list(Counter(input()).items()))))
  
#print(a)
#print(len(a))
count = Counter(a)
#print(count)
b = 0
for i in (count.values()):
  if i == 1 or i == 2:
    b+=(i-1)
  else:
    b+=(i)
    
#print(sum(b))
print(b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[[]for i in range(n)]
count=0
for i in range(n):
  d[i].append(set(input()))
  d[i].sort()
for i in range(n):
  for j in range(n):
    if i!=j and d[i]==d[j]:
      count+=1
print(int(count/2))

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
for si in S:
  n=C[si]
  ans+=n*(n-1)//2
print(ans)