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 itertools
import collections
 
n = int(input())
lists = [str(input()) for i in range(n)]
 
lists2 = ["".join(sorted(i)) for i in lists]
l = collections.Counter(lists2)
c = l.values()
 
print(sum([i * (i - 1)/ 2 for i in c]))

Submission status: Wrong Answer

Solution code:
import math

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

def c(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

s_list = []
for i in s:
    s_list.append(sorted(i))

s_list = sorted(s_list)

ans = 0
i = 0
while i < n-1:
    count = 0
    while s_list[i] == s_list[i+1]:
        count += 1
        i += 1
        if i == n-1:
            ans += c(count+1)
            break
        elif i+1 < n-1:
            if s_list[i] != s_list[i+1]:
                ans += c(count+1)
                break
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = []
for i in range(n):
    m.append(input())
b = ""
m2 = []
for i in m:
    m1 = sorted(list(i))
    for i in m1:
        b += i 
    m2.append(b)
    b = ""
ans = 0
while m2:
    count_word = m2[0]
    f = m2.count(count_word)
    if f == 2:
        ans += 1
    elif f > 2:
        ans += f
    
    new_words = []
    for word in m2:
        if word != count_word:
            new_words.append(word)

    m2 = new_words
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
#c = 0
#sort_dict = dict()
sort_list = list()
for i in range(n):
  i_sort = "".join(sorted(input()))
  #sort_dict[i] = i_sort
  sort_list.append(i_sort)
  #if not sort_dict[0]:
  #  if sort_dict[i] == sort_dict[i-1]:
  #    c += 1
counts = 0
cc = collections.Counter(sort_list)
#print(cc.most_common())
v, c = zip(*cc.most_common())
#print(c)
for c_ in c:
  if c_ > 2:
    c_ -= 1
  if c_ != 1:
    counts += c_
print(counts)

Submission status: Wrong Answer

Solution code:
import sys

Ans = 0
N = int(input())
S = []
T = []
U = []
for _ in range(N):
  S.append(str(input()))
T = ['a'] * N  
U = ['a'] * N

for i in range(N):
  U[i] = ''.join(sorted(S[i]))

T = sorted(U)

j = 0
while j < N:
  for k in range(1,N):
    if j + k == N - 1:
      if T[j] != T[j + k]:
        Ans = Ans + 2**(k-1) - 1
      else:
        Ans = Ans + 2**k - 1
        
      print(Ans)
      sys.exit()
      
    if T[j] != T[j + k]:
      Ans = Ans + 2**(k-1) - 1
      a = k
      break
  
  j = j + a

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

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

    return result

N = int(input())

nums = [collections.Counter(input()).values() for _ in range(N)]
nums = ["".join(str(list(i))) for i in nums]
ans = 0
for i in collections.Counter(nums).values():
    if i >= 2:
        ans += cmb(i,2)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    td = {}
    for _ in range(N):
        str = [ci for ci in input()]
        str.sort()
        t = ''.join(str)
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] *= 2
    count = 0
    for v in td.values():
        if v > 1:
            count += v - 1
    print(count)


main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
ans = 0
s = []
N = int(input())
for i in range(N):
	tmp = []
	string = input()
	for st in string:
		tmp.append(st)
	s.append(tmp)

for m in s:
	for n in s:
		if Counter(n)==Counter(m):
			ans+=1
			s.remove(n)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
count=0
s=[sorted(input()) for i in range(N)]
s=sorted(s)
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())
strList = []
for i in range(N):
    inStr = input()
    inNum = 0
    for j in range(len(inStr)):
        inNum = inNum + ord(inStr[j])-64
    strList.append(inNum)

anaglam = 0
for i in range(N):
    for j in range(i+1,N):
        if strList[i] == strList[j]:
            anaglam = anaglam + 1
print(anaglam)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[input() for _ in range(n)]
c = 0
for i in range(n):
    s[i] = sum(map(ord,list(s[i])))
    for j in range(i):
        if s[i] == s[j]:
            c+=1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())
aL = [set(Counter(input()).most_common()) for i in range(n)]
count = 0
 
for i in range(n-1):
    for j in range(i+1, n):
        if aL[i] == aL[j]:
          tmp = aL.count(aL[i])
          count += (tmp-1)*(tmp-2)//2
          aL[j] = 0
 
print(count)

Submission status: Wrong Answer

Solution code:
H = int(input())
S = []
for _ in range(H):
    S.append(input())

sorted_S = []    
for i in range(H):
  sorted_S.append("".join(sorted(S[i])))

cnt = 0
for i in range((H//2)+1):
  for j in range(i+1, H):
   if sorted_S[i] == sorted_S[j]:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())

str_array = [input() for i in range(N)]
  
alpha2num = lambda c: ord(c) - ord('a')

array=np.zeros((N,26))

for i in range(N):
    for char in str_array[i]:
        array[i,alpha2num(char)]+=1

print(np.linalg.matrix_rank(array)**2)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [sorted(input()) for _ in range(n)]
s.sort()
count = 0
array = [0] * (n - 1)

for i in range(1, n):
    count = 0
    for k in range(len(s[0])):
        if s[i - 1][k] == s[i][k]:
            count += 1
            if count == len(s):
                array[i - 1] += 1
        else:
            break

for i in range(1, n - 1):
    if array[i - 1] == 1 and array[i] == 1:
        array[i - 1] += 1

print(sum(array))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
amount = int(input())
strings = list(map(str, [input() for i in range(amount)]))
sum = 0
sum2 = 0

for i in range(len(strings)):
	# print(strings[i])
	abc = list(strings[i])
	abc.sort()
	strings[i] = ''.join(abc)
	# print(strings[i])

strings.sort()

for j in range(len(strings)-1):
	# print(j+1)
	# print(strings[j]+strings[j+1])
	if strings[j] == strings[j+1]:
		sum2 = sum2+1
	else:
		sum = sum + sum2 * (sum2+1) / 2
		sum2 = 0

sum = sum + sum2 * (sum2+1) / 2
print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [None for k in range(N)]
ans = 0
for p in range(N):
  a = list(input())
  a.sort()
  x[p] = ''.join(a)
  for q in range(p-1):
    if x[p] == x[q]:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
countr = []
liss = []
for i in range(N):
  s = input()
  a = collections.Counter(s)
  if a in liss:
    ind = liss.index(a)
    countr[ind] += 1
  else:
    liss.append(a)
    countr.append(1)

ans = 0
for cc in countr:
  if cc > 1:
    ans = ans + (cc * (cc - 1) / 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n   = input()
dic = {chr(j):i for i,j in enumerate(range(97, 97+26))}
input_list = np.ones((int(n),26)) * 100
count = 0
for i in range(int(n)):
    input_vec   = np.zeros(26)
    for j in input():
        input_vec[dic[j]] += 1
#     for text in input_list:
#         if ((text - input_vec)**2).sum()==0:
#             count += 1
    count = ((input_list - input_vec)**2).sum(1).astype(np.bool).sum()
    input_list[i] = input_vec
print(int((int(n)**2 -int(n) )/2 -count))

Submission status: Wrong Answer

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

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

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

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

    return result

def getNumbers(str_input):
    Numbers = ""
    for i in alfa:
        Numbers += str(str_input.count(i))
    return Numbers

N = int(input())
s = [input() for _ in range(N)]
alfa = ["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"]

ans = []
ans_point = [1] * N
for i in range(N):
    s_s = getNumbers(s[i])
    if (s_s in ans) == False:
        ans.append(s_s)
    else:
        ans_point[ans.index(s_s)] += 1

ans_count = 0
for i in range(N):
    if ans_point[i] != 1:
        ans_count += cmb(ans_point[i],2)
    else:
        print(ans_count)
        exit()

print(ans_count)

Submission status: Wrong Answer

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

t=l[0]
a,b=0,0
for s in l[1:]:
    if t==s:
        b+=b+1
    else:
        a+=b
        b=0
    t=s
    print(b)
a+=b
print(a)

Submission status: Wrong Answer

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

print(sum(S.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())

arr0 = []
arr = []

for i in range(n):
    arr0.append(list(input()))

for i in range(n):
    arr0[i].sort()
    arr.append(''.join(arr0[i]))

print(arr)

anag = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    # 省略できるかどうか判定
    flg = 0
    for x in range(i):
        if(anag[x][i] == 1):
            flg = 1
            prev = x
            break
    if(flg == 1):
        anag[i][i+1:] = anag[prev][i+1:]
        break

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

# print(anag)

count = 0

for a in anag:
    count += sum(a)

print(count)

Submission status: Wrong Answer

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

N=int(input())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
sorteds.sort()
print(sorteds)
sums=0
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
sets = []
for i in range(N):
  sets.append(set(list(input())))

cnt = 0
for i,r in enumerate(itertools.combinations(sets,2)):
  if r[0]==r[1]:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())

str_array = [input() for i in range(N)]
  
alpha2num = lambda c: ord(c) - ord('a')

array=np.zeros((N,26))

for i in range(N):
    for char in str_array[i]:
        array[i,alpha2num(char)]+=1

print(N-np.linalg.matrix_rank(array)+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations

N = int(input())
c = ["".join(sorted(str(input()))) for x in range(N)]
cs = Counter(c)

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
def checkAnagram(str1, str2):
    value = 0

    for i in range(0,len(str1)):
        value = value ^ ord(str1[i])
        value = value ^ ord(str2[i])
  
    return value == 0

N = int(input())

# V = dict()
# for i in range(N):
# 	s = sum(map(ord, input()))
# 	if s not in V.keys():
# 		V[s]=1
# 	else:
# 		V[s]+=1

# result = 0
# for key in V.keys():
# 	result += ((V[key]-1)*(1+V[key]-1))//2

# print(result)

V = []
count = 0
for i in range(N):
	s = input()
	for v in V:
		if(checkAnagram(v, s)):
			count+=1
	V.append(s)

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [None for k in range(N)]
for k in range(N):
  a = list(input())
  a.sort()
  x[k] = ''.join(a)
ans = 0
for p in range(N):
  for q in range(p-1):
    if x[p] == x[q]:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [input() for i in range(n)]
char = [chr(97+i) for i in range(26)]
char_list = [[m.count(c) for c in char] for m in l]

t = list(map(list, set(map(tuple, char_list))))
print(n - len(t) + 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def anagrams(word1,word2):
    def counter(s):
        return Counter(s.upper().replace(' ',''))
    return counter(word1) == counter(word2)

N=int(input())

count=0
cnt=0

list=[]

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

for i in list:
    list.remove(i)
    if len(list)==2:
        if anagrams(list[0],list[1])==True:
            count+=1
        break
    for j in list:
        if anagrams(i,j)==True:
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math

N = int(input())

List=[input() for i in range(N)]
count = 0

ct = np.zeros((N, ord('z') - ord('a')+1+1))
for i, s1 in enumerate(List):
  for x in s1:
    ct[i, ord(x)-ord('a')]+=1
  k = ct[i,:ord('z') - ord('a')+1]
  for p in range(i) :
    if (k == ct[p, :ord('z')-ord('a')+1]).all():
      ct[p, ord('z') - ord('a')+1] += 1
      break
count = np.array([math.factorial(x) for x in ct[:, ord('z') - ord('a')+1] if x != 0]).sum()

print(count)

Submission status: Wrong Answer

Solution code:
import collections

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

cnt=0

for i in range(N):
  li = collections.Counter(S[i])
  if li[0] == li[i+1]:
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = [input() for i in range(N)]

line = []

for anagram in s:
  a = sorted(anagram)
  line.append(''.join(a))

line
after = list(set(line))

_sum = 0
for i in after:
  c = line.count(i)
  if c == 2:
    _sum += 1
  elif c == 1:
    continue
  else:
    _sum += c

print(_sum)

Submission status: Wrong Answer

Solution code:
num = int(input())
arr = [input() for i in range(num)]
lines = []
count = 0

for i in arr:
  l = []
  for j in range(len(i)):
    l.append(i[j:(j+1)])
  l.sort()
  lines.append(l)
  
for k in range(len(lines)):
    if k == 0:
        x = lines[0]
        if x == lines[k+1]:
            count += 1
    elif k == (len(lines)-1):
        pass
    else:
        x = lines[k-1]
        if x == lines[k]:
            continue
        else:
            if x == lines[k+1]:
                count += 1
        
  
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
t = []
cnt = 0
for i in s:
    t.append(sorted(list(i)))
t.sort()
for i in t:
    t.remove(i)
    for j in t:
        for k in range(10):
            if i == j:
                cnt+=1
            else:
                break
print(cnt//10)

Submission status: Wrong Answer

Solution code:
num = int(input())
dic = [input() for i in range(num)]

sdic = ["".join(sorted(dic[i])) for i in range(num)]
ans = 0
while len(sdic) > 0:
    now = sdic[0]
    cnt = sdic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for now in sdic:
        sdic.remove(now)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

#辞書を準備
alpha_dict = {}
for i,c in enumerate(range(ord('a'),ord('z')+1)):
    alpha_dict[chr(c)] = i
    
result = []
for words in s:
    result_list = np.zeros(26,dtype=int)
    for i in range(len(words)):
        number = words[i]
        result_list[alpha_dict[number]] +=1
    result.append(result_list)
result_2 = set(list(map(tuple,result)))
final_result = len(result) - len(result_2) 
print(final_result)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

num = int(input())
n = num - 1

a = []
b = []
c = 0

for i in range(num):

    a.append(input())

#for i in range(num):
#    print(a[i])

#print(a[0][0])

for i in range(num):
    new_str = sorted(a[i])
    b.append(new_str)

for i in range(num):
    for j in range(i):
        if  (b[i] == b[j+1]):
            c += 1

#for i in range(num):
#    print(b[i])

print(c-3)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
l = [input() for _ in range(n)]
mst = [x[0] for x in Counter(list("".join(l))).most_common(5)]
l = [[x.count(a) for a in mst] for x in l]
result = 0
for i in range(n-1):
    result += l[i+1:].count(l[i])
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
t = []
cnt = 0
for i in s:
    t.append(sorted(list(i)))
t.sort()
for i in t:
    t.remove(i)
    for j in t:
        for k in range(10):
            if i[k] == j[k]:
                if k == 9:
                    cnt+=1
            else:
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
def sig(s):
  ls = list(s)
  work = 0
  for c in ls:
    work += ord(c)
  return work

def norm_str(s):
  ls = list(s)
  return "".join(sorted(ls))
  
ans = 0
pool = set()
n = int(input())
for i in range(n):
  s = input()
  #signature = sig(s)
  norm = norm_str(s)
  
  if norm in pool:
    ans += 1
  else:
    pool.add(norm)
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = [input() for i in range(N)]

line = []

for anagram in s:
  a = sorted(anagram)
  line.append(''.join(a))

line
after = list(set(line))

_sum = 0
for i in after:
  if line.count(i) == 2:
    _sum += 1
  elif line.count(i) == 1:
    continue
  else:
    _sum += line.count(i) 

print(_sum)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import math

n=int(input())
s=[]
li=[]
ans=0
cnt=1

for i in range(n):
  s.append(sorted(input()))
s.sort(key=itemgetter(1,0))
s=s+['0']

for i in range(n):
  if s[i]==s[i+1]:
    cnt+=1
  elif cnt>1:
    li.append(cnt*(cnt-1)/2)
    cnt=1
print(int(sum(li)))

Submission status: Wrong Answer

Solution code:
n = input()
n = int(n)
total = 0
word = []

for i in range(n):
    word.append(input())

i = 0
count = 0
while i < len(word):    
    master = list(word[i])
    j = i + 1
    while j < len(word):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while l < len(target):
                if master[k] == target[l]:
                    target.pop(l)
                    break
                l += 1
        if len(target) == 0:
            word.pop(j)
            count += 1
        i += 1
        j += 1
    for i in range(1, count):
    	total += i
print(total)

Submission status: Wrong Answer

Solution code:
import math
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

N = int(input())
strings = []
anagrams_num = []
for i in range(N):
  string = ''.join(sorted(input()))
  if string in strings:
    anagrams_num[strings.index(string)] += 1
  else:
    strings.append(string)
    anagrams_num.append(0)

ans = 0
for anagram_num in anagrams_num:
  if anagram_num == 1:
    ans +=1
  elif anagram_num > 1:
    ans += int(math.factorial(anagram_num+1)/math.factorial(anagram_num)) 
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
lst = []
lstn = [0] *10**5
cnt = 0
j = 0

def nCr(n,r):
    r = min(r,n-r)
    numerator = 1
    for i in range(n,n-r,-1):
        numerator *= i
    denomination = 1
    for i in range(r,1,-1):
        denomination *= i
    return numerator // denomination


for i in range(n):
    s = input()
    c = Counter(s)
    if c not in lst:
        lst.append(c)
        lstn[j] = 1
        j += 1
    else:
        k = lst.index(c)
        lstn[k] += 1

for x in lstn:
    if x != 0:
        cnt += nCr(x,2)
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

# 長さが10で英小文字の文字列リスト
str_list = [input() for i in range(N)]

import itertools as iter
comb_list = list(iter.combinations(str_list, 2))

def from_cache(cache_dict, word):
    if word in cache_dict.keys():
        return cache_dict

    cnt_dict = {}
    for s in list(word):
        if s not in cnt_dict.keys():
            cnt_dict[s] = 0
        cnt_dict[s] += 1
    # cache_dict[word] = sorted(cnt_dict.items(), key=lambda x:x[0])
    cache_dict[word] = cnt_dict
    return cache_dict


cache_dict = {}
cnt = 0
for comb_str in comb_list:
    w1, w2 = comb_str[0], comb_str[1]

    cache_dict = from_cache(cache_dict, w1)
    cache_dict = from_cache(cache_dict, w2)

    keys1 = sorted(list(cache_dict[w1].keys()))
    keys2 = sorted(list(cache_dict[w2].keys()))
    if keys1 != keys2:
        continue

    for k in keys1:
        if cache_dict[w1][k] != cache_dict[w2][k]:
            continue
    cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
num = int(input())
count = 0
dic_ana = {}
for _ in range(num):
    s = input()
    dic_a2z = {}
    for i in s:
        for j in [chr(i) for i in range(97, 97+26)]:
            flg = 0
            if i == j:
                flg = 1
                if j in dic_a2z:
                    dic_a2z[j] += 1
                else:
                    dic_a2z[j] = 1
            if flg == 1:
                break
    dic_a2z = str(sorted(dic_a2z))
    if dic_a2z in dic_ana:
        dic_ana[dic_a2z] += 1
    else:
        dic_ana[dic_a2z] = 1
for k in dic_ana.values():
    count += k * (k - 1) // 2
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

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

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

    return result

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
    count += cmb(c, 2)

print(count)

Submission status: Wrong Answer

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


alpha = ["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"]

s_li = []
for i in range(n):
    s = input()
    buf_li = []
    for j in range(len(alpha)):
        buf_li.append(0)
    for j in range(10):
        for k in range(len(alpha)):
            if s[j] == alpha[k]:
                buf_li[k] += 1
    
    s_i = ""
    for j in range(len(alpha)):
        s_i += alpha[j] + str(buf_li[j])
    s_li.append(s_i)
"""
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

"""
ans = 0
s_li.sort()
for i in range(n):
    for j in range(n):
        if i >= j :
            continue

        if s_li[i] == s_li[j]:
            ans += 1
        else:
            break
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

def getNumbers(str_input):
    Numbers = ""
    for i in alfa:
        Numbers += str(str_input.count(i))
    return Numbers

N = int(input())
s = [input() for _ in range(N)]
alfa = ["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"]

ans = []
ans_point = [1] * N
for i in range(N):
    if (getNumbers(s[i]) in ans) == False:
        ans.append(getNumbers(s[i]))
    else:
        ans_point[ans.index(getNumbers(s[i]))] += 1

ans_count = 0
for i in range(N):
    if ans_point[i] != 1:
        ans_count += cmb(ans_point[i],2)
    else:
        print(ans_count)
        exit()

print(ans_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rslt=0
rl=[]
for i in range(n):
    for c in sl[i]:
        tmp=[0]*26
        tmp[ord(c)-ord('a')]+=1
    if tmp in rl: rslt+=1
    else: rl.append(tmp)
print(rslt)

Submission status: Wrong Answer

Solution code:
a=int(input())
f=["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"]
g=[]
for p in range (0,a):
    b=input()
    h=[0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0]
    for q in range (0,10):
        c=b[q]
        for r in range (0,26):
            if c==f[r]:
                h[r]+=1
    g.append(h)

i=tuple(g)


x=0
for s in range (0,a):
    g=list(i)
    k=g[s]
    l=g[s+1:]
    if k in l:
        x+=1
print(x)

Submission status: Wrong Answer

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

def uniGram(sentences_String):
    return([sentences_String[0+i:1+i] for i in range(len(sentences_String)-1+1)])

sUniGramed = list(map(uniGram, s))
sSetted = list(map(set, sUniGramed))
sLength = len(sSetted)

ans = 0
for i in range(sLength-1):
    current = sSetted[i]
    for j in range(sLength-i-1):
        if current - sSetted[i+j+1] == set():
            ans += 1
        else:
            pass
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())

    td = {}
    strs = []
    for _ in range(N):
        strs.append(sum([ord(ci) for ci in input()]))
    strs.reverse()

    for t in strs:
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] *= 2
    count = 0
    for v in td.values():
        if v > 0:
            count += v - 1
    print(count)


main()

Submission status: Wrong Answer

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

count = 0
for i in range(n - 1):
    for j in range(n - i - 2):
        if s[i] == s[j]:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
num = int(input())
dic = [input() for i in range(num)]

dic = ["".join(sorted(dic[i])) for i in range(num)]
ans = 0
while len(dic) > 0:
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for now in dic:
        dic.remove(now)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

mat = np.zeros(N)
alphabet = "abcdefghijklmnopqrstuvwxyz"

ans_dic = {}

for i in range(N):
    word = input()
    tmp = 0
    for s in word:
        tmp += 2**alphabet.index(s)

    if tmp in ans_dic:
        ans_dic[tmp] += 1
    else:
        ans_dic[tmp] = 1
ans = 0
for k, v in ans_dic.items():
    ans += v * (v-1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

slist = []
for h in range(n):
  slist.append(input())

newlist = []
word=[]
wordy = ""
for i in range(n):
  word = list(slist[i])
  word.sort()
  for jk in range(len(word)):
	  wordy = wordy+word.pop()
  newlist.append(wordy)
  wordy=""
new2list = sorted(newlist)

print(new2list)
count= 0
for j in range(n-1):
  k = j+1
  while (new2list[j] == new2list[k]):
    count += 1
    k += 1
    if k == n:
      break

print(count)

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):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            if i == k:
                continue
            if anagram(s[i], s[k]) == True:
                count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in b:
            b = b.replace(i, '')
            continue
        else:
            return False
    return True

# def anagram(a, b):
#     a = ''.join(sorted(a))
#     b = ''.join(sorted(b))
#     return a == b


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

mat = np.zeros(N)
alphabet = "abcdefghijklmnopqrstuvwxyz"

ans_dic = {}

for i in range(N):
    word = input()
    tmp = 0
    for s in word:
        tmp += 2**alphabet.index(s)

    if tmp in ans_dic:
        ans_dic[tmp] += 1
    else:
        ans_dic[tmp] = 1
ans = 0
print(ans_dic)
for k, v in ans_dic.items():
    ans += v * (v-1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

V = dict()
for i in range(N):
	s = sum(map(ord, input()))
	if s not in V.keys():
		V[s]=1
	else:
		V[s]+=1

result = 0
for key in V.keys():
	result += ((V[key]-1)*(1+V[key]-1))//2

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for i in range(n)]
s_sorted = []
c=0
for w in s:
    w_list = [c for c in w]
    w_list.sort()
    s_sorted.append(w_list)
for w2 in s_sorted:
    if s_sorted.count(w2) > 1:
        c += 1
if c-1 > 0:
    print(c-1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = [input() for i in range(N)]

line = []

for anagram in s:
  a = sorted(anagram)
  line.append(''.join(a))

before = line
after = list(set(line))

_sum = 0
for i in after:
  if before.count(i) == 2:
    _sum += 1
  elif before.count(i) == 1:
    continue
  else:
    _sum += before.count(i) 

print(_sum)