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 collections
import string

def s_to_hist(s):
    hist = collections.Counter()
    for c in s:
        hist[c] += 1
    hist_list = []
    for al in string.ascii_letters:
        hist_list.append(str(hist[al]))
    return " ".join(hist_list)

s_hist = collections.Counter()

N = int(input())
for n in range(N):
    s = input().strip()
    s_hist[s_to_hist(s)] += 1

ans = 0
#for key in s_hist:
#    ans += s_hist[key]*(s_hist[key]-1)/2
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

anum = {}
ans = 0

N = int(input())
strings = [''.join(sorted(input())) for i in range(N)]

for i in strings:
    if i in anum:
        ans += anum[i]
    else:
        anum[i] = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

anum = {}
ans = 0

N = int(input())
strings = [''.join(sorted(input())) for i in range(N)]

for i in range(N):
    if strings[i] in anum:
        ans += anum[strings[i]]
    else:
        anum[strings[i]] = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

anum = {}
ans = 0

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

for i in range(N):
    strings.append(input())

for i in range(N):
    if strings[i] in anum:
        ans += anum[i]
    else:
        anum[strings[i]] = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

anum = {}

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

for i in range(N):
    strings.append(input())

for i in range(N):
    temp = [s for s in strings[i]]
    temp.sort()
    strings[i] = ''.join(temp)
    if strings[i] in anum.keys():
        anum[strings[i]] += anum[strings[i]] + 1
    else:
        anum[strings[i]] = 0

print(sum(anum.values()))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    n = int(input())
    s = [''.join(sorted(list(input()))) for _ in range(n)]

    ans = 0

    print(s)
    for a in range(len(s) - 1):
        for b in range(a + 1, len(s)):
            if s[a] == s[b]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N =int(input())
#横文字数、縦N行の行列を作成
s = [list(input()) for i in range(N)]

#文字列をアルファベット順に並び替える
for i in range(len(s)):
    s[i].sort()
   
ans = 0 
cnt = 1
for i in range(1,N):
    for j in range(10):
        #1文とその次の文の文字を比較
        #異なっていた場合はbreak
        if(s[i][j] != s[i-1][j]):
            break
    else:
        cnt +=1
        continue
    ans += cnt*(cnt-1)//2
    cnt =1
ans +=cnt*(cnt-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

abcs = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
pnum = [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]
anum = 0

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

for i in range(N):
    idnum = 1
    for j in range(10):
        for k in range(26):
            if strings[i][j] == abcs[k]:
                idnum *= pnum[k]
    ids.append(idnum)

for i in range(N-1):
    for j in range(i,N):
        if ids[i] == ids[j]:
            anum += 1

print(anum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    s = list(map(lambda s: ''.join(sorted(s)), s))
    hash = {}

    count = 0
    print(s[0])
    for i in range(0, n):
        if s[i] in hash:
            hash[s[i]] += 1
        else:
            hash[s[i]] = 1
        count += hash[s[i]] - 1
    return count


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = [sorted(input()) for i in range(n)]
cnt = 0
dic = {}
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, *s = open(0).read().split()
s_sorted = []
s_sorted = [''.join(sorted(c)) for c in s]
count = 0
for s in s_sorted:
  count += s_sorted.count(s)-1
  s_sorted.pop(0)
print(count)

Submission status: Wrong Answer

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

if len(distincts) == len(s):
    print(0)
else:
    answer = 0
    for elem in distincts:
        number = s.count(elem)
        patterns = number * (number - 1)
        answer += patterns
    print(answer)

Submission status: Wrong Answer

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

if len(distincts) == len(s):
    print(0)
else:
    answer = 0
    for elem in distincts:
        answer += s.count(elem)
    print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
seq_s = "".join(s)
ans = 0
start_i = 0
used_s = set()
for i in range(n):
    if not s[i] in used_s:
        cnt = seq_s.count(s[i],start_i) - 1
        while cnt > 0:
            ans += cnt
            cnt -= 1
        used_s.add(s[i])
        start_i += len(s[i])

print(ans)

Submission status: Wrong Answer

Solution code:
# 整数の入力
N = int(input())
# 改行区切りの整数の入力
S = []
for k in range(N):
  S.append(input())
#初期値
n = 0
#繰り返し
for i in range(len(S)):
    for j in range(len(S)-i):
      if i < j:
        if sorted(list(S[i])) == sorted(list(S[i+j])):
          n += 1
print(n)

Submission status: Wrong Answer

Solution code:
import collections
N =int(input())
A = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(A)
ANS=0
for d in c:
  ans = c[d]
  if ans>=2:
    ANS +=ans
if ANS != 0:
  print(ANS-1)
else:
  print(ANS)

Submission status: Wrong Answer

Solution code:
N =int(input())
s = ["".join(sorted(input())) for _ in range(N)]
cnt = 0
i = 0
while i <= N-1:
    grnm=(s[i+1:]).count(s[i])
    if grnm == 0:
        i+=1
    else:
        cnt += int(grnm*(grnm+1)/2)
        i+=(grnm+1)
print(cnt)

Submission status: Wrong Answer

Solution code:
N =int(input())
s = list(sorted(input()) for i in range(N))

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if s[i]==s[j]:
            cnt+=1
        else: break
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
set_lists = set(lists)
for i in range(len(set_lists)):
    n = c[str(lists[i])]
    Sum += n * (n - 1) // 2
lists.sort()
print(Sum)

Submission status: Wrong Answer

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

for _ in range(N):
    s.append(input())

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

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

print(counter)

Submission status: Wrong Answer

Solution code:
import collections
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
set_lists = set(lists)
for i in range(len(set_lists)):
    cnt = c[str(lists[i])]
    if cnt <= 1:
        pass
    else:
        Sum += nCr(cnt,2)
print(Sum)

Submission status: Wrong Answer

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

for _ in range(N):
    s.append(input())

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

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

print(counter)

Submission status: Wrong Answer

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

for _ in range(N):
    s.append(input())
s

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

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

print(counter)

Submission status: Wrong Answer

Solution code:
import collections
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
set_lists = set(lists)
for i in range(len(set_lists)):
    cnt = c[str(lists[i])]
    if cnt == 1:
        pass
    else:
        Sum += nCr(cnt,2)
print(Sum)

Submission status: Wrong Answer

Solution code:
N =int(input())
s = list(sorted(input()) for i in range(N))
cnt = 0
for i in range(N):
    for j in range(N):
        if s[i]==s[j]:
            cnt+=1
print((cnt-N)/2)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
N = int(input())
dic = {}
for i in range(N):
    s = ''.join(sorted(str(input())))
    if s in dic:
      dic[s] += 1
    else:
      dic[s] = 0
print(sum(dic.values()))

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
ans=0
for i in c:
  if c.count(i) >=2 :
    ans+=1
anss =ans-1
if anss == -1:
  anss=0
print(anss)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
ans=0
for i in c:
  if c.count(i) >=2 :
    ans+=1
print(ans-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
str_list = list()
for _ in range(n):
  tar_str = input()
  str_list.append(sorted(list(tar_str)))

count = 0
for j in range(len(str_list)):
  t_list = str_list.pop()
  if t_list in str_list:
    num = str_list.count(t_list)
    for l in range(num):
      count += l + 1
    str_list.remove(t_list)
  if not str_list:
    break
print(count)

Submission status: Wrong Answer

Solution code:
n =  int(input())

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

d = {}

for e in s:
    if e in d:
        d[e] += d[e] + 1
    else:
        d[e] = 0

ans = 0
for k, v in d.items():
    ans += v

print(ans)

Submission status: Wrong Answer

Solution code:
# Green Bin
n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(list)

Submission status: Wrong Answer

Solution code:
import copy
import math
import sys

sys.setrecursionlimit(10 ** 7)

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


def split(word):
    return [char for char in word]


normalized_s_list = sorted([''.join(sorted(split(s))) for s in s_list])

uniqued_s_list = sorted(list(set(normalized_s_list)))

j = 0
counter = 0
result = 0
for s in normalized_s_list:
    print(j)
    if s == uniqued_s_list[j]:
        counter += 1
    else:
        result += (1 / 2) * counter * (counter - 1)
        j += 1
        counter = 1  # このとき s と uniqued_s_list[j] は同じはずなので

result += (1 / 2) * counter * (counter - 1)
print(int(result))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
ans = list(map(lambda x: s.count(x)-1, set(s)))
ans = list(filter(lambda x: x!= 0, ans))

print(sum(ans) if len(ans)<2 else sum(ans)+len(ans)-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_s = []
for i in range(1,N+1):
    list_s.append(str(input()))

cnt =0
result_cnt =0

for i in list_s[0]:
    for j in list_s:
        if list_s.index(j) == 0:
            pass
        if i in j:
            cnt +=1
            if len(list_s[0]) == cnt:
                 result_cnt+=1
print(result_cnt)

Submission status: Wrong Answer

Solution code:
# Green Bin
n = int(input())
s = [input() for i in range(n)]
m = 0
list = {}
for i in s:
  i = ' '.join(sorted(i))
  print(i)
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
for i in list.values():
  l = i -1
  m = m + int(((l * (l + 1)) / 2))
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
m = 0
for i in s:
  i = ' '.join(sorted(i))
for k in range(n):
  m += s[:k].count(s[k])
print(m)

Submission status: Wrong Answer

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

word_dict={}
for word in S:
  word=''.join(sorted(word))
  if word in word_dict.keys() and word_dict[word]==0:#2nd
    word_dict[word] = word_dict[word]+1
  elif word in word_dict.keys() and word_dict[word]==1:#3rd
    word_dict[word]= word_dict[word]+2
  elif word in word_dict.keys() and word_dict[word]==3:#4th
    word_dict[word]= word_dict[word]+3
  elif word in word_dict.keys() and word_dict[word]==6:#5th
    word_dict[word]= word_dict[word]+4
  elif word in word_dict.keys() and word_dict[word]==10:#6th
    word_dict[word]= word_dict[word]+5
  elif word in word_dict.keys() and word_dict[word]==15:#7th
    word_dict[word]= word_dict[word]+6
  else:
    word_dict[word] = 0
print(sum(word_dict.values()))

Submission status: Wrong Answer

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

#word_list=list(map(lambda x: ''.join(sorted(x)),S))
word_dict={}
for word in S:
  word=''.join(sorted(word))
  if word in word_dict.keys():
    word_dict[word] = word_dict[word]+(word_dict[word]+1)
  else:
    word_dict[word] = 0
print(sum(word_dict.values()))

Submission status: Wrong Answer

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

#word_list=list(map(lambda x: ''.join(sorted(x)),S))
word_dict={}
for word in S:
  word=''.join(sorted(word))
  if word in word_dict.keys():
    word_dict[word] = word_dict[word]+(word_dict[word]+1)
  else:
    word_dict[word] = 0
print(word_dict)

Submission status: Wrong Answer

Solution code:
N_number = int(input())
strings = []
count = 0
for i in range(N_number):
  string = "".join(sorted(input()))
  if string in strings:
    count += 1
  strings.append(string)
  
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input() for i in range(N)]
word_list=[]
for w in S:
  sort_word=''.join(sorted(w))
  word_list.append(sort_word)

word_set = set(word_list)
for i in range(len(word_set)):
  word_list.remove(list(word_set)[i])
print(len(word_list))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

# スペース区切りの整数の入力
ar = []
for i in range(N):
  l = list(input())
  l.sort()
  ar.append("".join(l).__hash__())

# 数を数える
list = {}
for i in ar:
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1
  
count = 0
for i in list.values():
  n = i - 1
  count = count + ((n * (n + 1)) / 2)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input() for i in range(N)]
ans ={}
num = 0

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

print(num)

Submission status: Wrong Answer

Solution code:
dic = { c: i for i, c in enumerate('abcdefghijklmnopqrstuvwxyz')}

n = int(input())
strs = [tuple(sorted(map(lambda x: dic[x], input())))  for _ in range(n)]

a = {}
for s in strs:
  if s not in a:
    a[s] = 1
  else:
    a[s] += 1

print(a)
print(sum(item[1]*(item[1]-1)//2 for item in a.items()))

Submission status: Wrong Answer

Solution code:
import itertools
ans = 0
n = int(input())
ls = [input() for i in range(n)]
for i in range(len(ls)):
    tmp = sorted(list(ls[i]))
    ls[i] =  ''.join(tmp)

print(len(ls) -len(set(ls)))

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = {}
for _ in range(N):
    s = "".join(sorted(input()))
    if s in dic:
        dic[s] = dic[s] + dic[s] + 1
    else:
        dic.setdefault(s, 0)
print(sum(dic.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list()
for i in range(N):
    l.append(sorted(input()))
count = 0
for i, j in zip(range(len(l)), l):
    for k, m in zip(range(len(l)), l):
        if i != k:
            if j == m:
                count+=1
print(count/2)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def comb(x):
    a = 1
    for i in range(1, x+1):
        a *= i
    return a//2


def main():
    N = int(input())
    M = {}
    for _ in range(N):
        s = ''.join(sorted(input()))
        if (s in M.keys()):
            M[s] += 1
            continue
        M[s] = 1

    print(sum([comb(m) for m in M.values()]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    N = int(input())
    S = [sorted(input()) for _ in range(N)]
    S.sort()

    ans = 0
    x = 1
    a = S[0]
    for s in S[1:]:
        if a == s:
            x += 1
        else:
            ans += reduce(lambda k, l: k*l, range(1, x+1))//2
            a = s
            x = 1
    if x != 1:
        ans += reduce(lambda k, l: k*l, range(1, x+1))//2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = []
out = 0

for i in range(N):
	s_in =''.join(sorted(list(input())))
	if s_in in s_list:
		out +=1
	else:
		s_list.append(s_in)
    
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=0
for i in range(n):
    z=input()
    a.append(z)
for i in range(len(a)):
	c=set(a[i])
	for j in range(i+1,len(a)):
		d=set(a[j])
		if(c==d):
			b+=1
			break
print(b)

Submission status: Wrong Answer

Solution code:
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]
p=[ i for i in range(n)]
con=dict()
con.update(zip(texts,p))
print(n-len(con))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
string_list=[Counter(input()) for i in range(n)]
cnt=0
for i in range(n):
  si = string_list[i]
  for j in range(i, n):
    sj = string_list[j]
    if si==sj:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
string_list=[sorted(Counter(input()), key=lambda x:x[0]) for i in range(n)]
cnt=0
for i in range(n):
  si = string_list[i]
  for j in range(i, n):
    sj = string_list[j]
    if si==sj:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

mydic = {}

for i in range(N):
    mystr = "".join(sorted(input()))
    if mystr in mydic:
        mydic[mystr] += 1
    else:
        mydic[mystr] = 1
#print(mydic)
mycnt = 0
for i in mydic.values():
    if i > 2:
        mycnt += i
    elif i == 2:
        mycnt += 1
print(mycnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_anagram = [''.join(sorted(str(input()))) for i in range(N)]

list_anagram.sort()
ans = 0

print(list_anagram)

x = 1

for i in range(1, N):
    if i != N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
    elif i != N - 1 and list_anagram[i] != list_anagram[i - 1]:
        ans = ans + x * (x - 1) // 2
        x = 1
    elif i == N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
        ans = ans + x * (x - 1) //2
    else:
        ans = ans + x * (x - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_anagram = [''.join(sorted(str(input()))) for i in range(N)]

list_anagram.sort()
ans = 0

print(list_anagram)

x = 1

for i in range(1, N):
    if i != N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
        print(ans)
    elif i != N - 1 and list_anagram[i] != list_anagram[i - 1]:
        ans = ans + x * (x - 1) // 2
        x = 1
        print(ans)
    elif i == N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
        ans = ans + x * (x - 1) //2
    else:
        ans = ans + x * (x - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_anagram = [''.join(sorted(str(input()))) for i in range(N)]

list_anagram.sort()
ans = 0

x = 1

for i in range(1, N):
    if i != N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
    elif i != N - 1 and list_anagram[i] != list_anagram[i - 1]:
        ans = ans + x * (x - 1) // 2
        x = 1
    elif i == N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
        ans = ans + x * (x - 1) // 2
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_anagram = [''.join(sorted(str(input()))) for i in range(N)]

list_anagram.sort()
ans = 0

x = 1

for i in range(1, N):
    if i != N - 1 and list_anagram[i] == list_anagram[i - 1]:
        x += 1
    elif i != N - 1 and list_anagram[i] != list_anagram[i - 1]:
        ans = ans + x * (x - 1) // 2
        x = 1
    else:
        x += 1
        ans = ans + x * (x - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections,functools
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]
#print(texts)
c=collections.Counter(texts)
ans=functools.reduce(lambda x,y:x+y,c.values())
ans-=len(c)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
texts=[''.join(sorted(input())) for i in range(n)]
#print(texts)
c=collections.Counter(texts)
print(sum(c.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = set()
for _ in range(N):
    b = list(input())
    b.sort()
   
    s.add(''.join(b))
    
print(N - len(s))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import factorial

N = int(input())
st = set()
d = defaultdict(int)
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if s_sorted in st:
        d[s_sorted] += 1
    else:
        st.add(s_sorted)

ans = 0
for _, v in d.items():
    x = factorial(v + 1) // 2
    ans += x

print(round(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import factorial

N = int(input())
st = set()
d = defaultdict(int)
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if s_sorted in st:
        d[s_sorted] += 1
    else:
        st.add(s_sorted)

ans = 0
# for _, v in d.items():
#     x = factorial(v + 1) / factorial(2)
#     ans += x

print(round(ans))

Submission status: Wrong Answer

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

#make dic from input parameters
for component in inlist :
    dic = []
    for n in component:
        dic.append(n)
    dic.sort()
    dic2 = "".join(dic)
    result.append(dic2)
print(result)

counter = 0
for k1, v1 in enumerate(result):
    for k2, v2 in enumerate (result):
        if v1 == v2 and k1 > k2:
            counter += 1

print (counter)

Submission status: Wrong Answer

Solution code:
N=int(input())

string=list()
for i in range(N):
  c=list(input())
  c.sort()
 # print(''.join(c))
  string.append(''.join(c))
  
#print(string)

count=0
M=N
for j in range(N):
  c=string.count(string[0])
  string.remove(string[0])
  M=M-c
  count=count +int(c*(c-1)/2)
  if j+1>M-1:
    break
  
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())

string=list()
for i in range(N):
  c=list(input())
  c.sort()
 # print(''.join(c))
  string.append(''.join(c))
  
#print(string)

count=0
M=N
for j in range(N):
  c=string.count(string[j])
  string.remove(string[j])
  M=M-c
  count=count +int(c*(c-1)/2)
  if j+1>M-1:
    break
  
print(count)

Submission status: Wrong Answer

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

def main():
    num = int(input())
    s = []
    count = 0
    for i in range(num): 
        s_c = []
        for c in input():
            s_c.append(c)
        s_c.sort()
        s.append(s_c)

        for j in range(i-1):
            if (s[i] == s[j]):
                count = count + 1 
                #print("equal: {}, {}".format(i,j))
    print(count)
    
if __name__ == "__main__" :
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
 
kintama = 0
for i in range(len(S)-1):
    A = list(S[i])
    for j in range(i+1,len(S)):
        B = list(S[j])
        if set(A)==set(B):
            kintama += 1
 
print(kintama)

Submission status: Wrong Answer

Solution code:
n=int(input())
Lists=sorted([sorted(list(map(str, input()))) for i in range(n)])
Lists=list(map(list, set(map(tuple, Lists))))
print(n-len(Lists))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [input() for i in range(N)]
mydict = {}
count = 0
value = 1
for i in range(N):
    l[i] = ''.join(sorted(l[i]))
    if l[i] in mydict.keys():
        count += 1
    else:
        mydict[l[i]] = value
        value += 1
print(count)
print(mydict)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
sl = []
for i in range(n):
  S = ''.join(sorted(input()))
  sl.append(S)
print(sl)
count = 0
dict ={}

for s in sl:
  if s in dict:
    count += dict[s]
    dict[s] += 1
  else:
    dict[s] = 1
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[]
for i in range(N):
    S.append(input())
uniq=[]
for i in range(N):
    uniq.append(sorted(set(s for s in S[i])))

pair=[]
for i in range(N):
    for j in range(i+1,N):
        if(uniq[i]==uniq[j]):
            pair.append([i,j])

#print(uniq)
#print(pair)

counter=0
for p in pair:
    cnti=[]
    for u in uniq[p[0]]:
        cnti.append(S[i].count(u))
    cntj=[]
    for u in uniq[p[1]]:
        cntj.append(S[j].count(u))

    if(cnti==cntj):
        counter=counter+1

print("{}".format(counter))

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

in_str = []
for _ in range(n):
    i = input()
    in_str.append(''.join(sorted(i)))


def cmb(n, r):
    """
    組み合わせ数
    https://qiita.com/derodero24/items/91b6468e66923a87f39f
    :param n:
    :param r:
    :return:
    """
    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


if __name__ == '__main__':
    count = 0
    for k, g in itertools.groupby(sorted(in_str)):
        n = sum(1 for _ in g)
        if n == 0:
            continue
        count += cmb(n, 2)
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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