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:
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
sl = set(s)
ans=0
for i in sl:
    t = s.count(i)
    ans += t*(t+1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
list1 = [list(input()) for i in range(N)]
for j in range(N):
    list1[j].sort()
list1.sort()
for k in range(0,N-1):
    for l in range(k+1,N):
        if list1[k] == list1[l]:
            ans += 1
        else:
            break
    if list1.count(list1[k])==1:
        break
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
sl = set(s)
ans=0
for i in sl:
    t = s.count(i)
    ans += 1/2*t*(t+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(str(input()) for _ in range(n))
# d = [{} for _ in range(n)]
#
# for m, a in enumerate(l):
#     for p in range(10):
#         d[m][a[p]] = a.count(a[p])
# cnt = 0
# dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
#
# for i in d:
#     pp=[i==k for k in d]
#     kk = [x for x, _ in enumerate(pp) if _]
#     d = dellist(d, kk)
#     cnt += (len(kk)-1)*len(kk)/2
# # for i, j in enumerate(d):
# #     for k in range(i+1, len(d)):
# #         if j == d[k]:
# #             cnt += 1
#
# print(int(cnt))
cnt = 0
l_sort = []
for i in range(n):
    if sorted(l[i]) in l_sort:
        cnt += 1
    l_sort.append(sorted(l[i]))

print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(str(input()) for _ in range(n))
# d = [{} for _ in range(n)]
#
# for m, a in enumerate(l):
#     for p in range(10):
#         d[m][a[p]] = a.count(a[p])
# cnt = 0
# dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
#
# for i in d:
#     pp=[i==k for k in d]
#     kk = [x for x, _ in enumerate(pp) if _]
#     d = dellist(d, kk)
#     cnt += (len(kk)-1)*len(kk)/2
# # for i, j in enumerate(d):
# #     for k in range(i+1, len(d)):
# #         if j == d[k]:
# #             cnt += 1
#
# print(int(cnt))
cnt = 0
l_sort = []
for i in range(n):
    l_sort.append(sorted(l[i]))
    if sorted(l[i]) in l_sort:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]

    for i in range(n):
        s[i] = list(input()).sort()

    print(int(count_anagram(s[0], s[1:], 0)))


def count_anagram(s, str_list, total):
    cnt = 0
    for t in str_list:
        if s == t:
            str_list.remove(t)
            cnt += 1
    if cnt > 0:
        total += (cnt+1) * cnt / 2

    if str_list:
        return count_anagram(str_list[0], str_list[1:], total)
    else:
        return total


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ans = {}
    for i in range(n):
        inp = ''
        for item in sorted(input()):
            inp += item

        one = ans.get(inp)
        if one is None:
            ans[inp] = 0
        else:
            ans[inp] += 1
    print(sum(ans.values()))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import time

ans = 0
s = []
N = int(input())
for i in range(N):
	tmp = []
	string = input()
	for st in string:
		tmp.append(st)
	tmp.sort()
	if tmp in s:
		ans += 1
	else:
		s.append(tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
def count(string, sets):
    return [str(string.count(s)) for s in sets]

N = int(input())
sents = [input() for x in range(N)]
sets = [sorted(list(set(sents[i]))) for i in range(N)]
cnts = [count(sents[i], sets[i]) for i in range(N)]
infer = ["".join(sets[i]) + "".join(cnts[i]) for i in range(N)]
print(N - len(set(infer)))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ans = {}
    for i in range(n):
        inp = str(sorted(input()))

        one = ans.get(inp)
        if one is None:
            ans[inp] = 0
        else:
            ans[inp] += 1
    print(sum(ans.values()))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    A = []
    for _ in range(N):
        a = sorted(list(input()))
        A.append(''.join(a))
    td = {}
    for a in A:
        t = sum([ord(ci) - 97 for ci in a])
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] += 1
    count = 0
    for v in td.values():
        count += v * (v - 1) // 2
    print(count)


main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ans = {}
    for i in range(n):
        inp = str(sorted(input()))
        print(inp)

        one = ans.get(inp)
        if one is None:
            ans[inp] = 0
        else:
            ans[inp] += 1
    print(sum(ans.values()))


def count_letter(string):
    count = {}
    for i in string:
        if count.get(i) is None:
            count[i] = 1
        else:
            count[i] += 1
    return count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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())
s = [" ".join(sorted(list(input()))) for _ in range(N)]
c = collections.Counter(s)
ans = 0
print(c.values())
for i in c.values():
    if i > 1:
        ans += cmb(i, 2)
print(ans)

Submission status: Wrong Answer

Solution code:

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

    td = {}
    for _ in range(N):
        t = sum([ord(ci) - 97 for ci in input()])
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] += 1
    count = 0
    for v in td.values():
        count += v * (v - 1) // 2
    print(count)


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
from math import factorial
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([ factorial(x+1) / factorial(x+1 - 2) / factorial(x - x + 2) for x in ct[:, ord('z') - ord('a')+1] if x > 0]).sum()
print(count)

Submission status: Wrong Answer

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

#各要素をソート
for i in range(n):
    l[i] = ''.join(sorted(l[i]))
     

#リストをソート
l.sort()

#個数を調べる
flag = 0
for i in range(n-1):
    if l[i] == l[i+1]:
        flag = flag + 1

print(flag)

Submission status: Wrong Answer

Solution code:
import math
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
N = int(input())
a = 0
list2 = []
list3 = []
list1 = [list(input()) for i in range(N)]
for l in range(N):
    list1[l].sort()
list2 = get_unique_list(list1)
for j in range(len(list2)):
    list3.append(int(list1.count(list2[j])))
for k in range(len(list3)):
    if list3[k]==1:
        break
    a += math.factorial(list3[k])//2*math.factorial(list3[k]-2)
print(a)

Submission status: Wrong Answer

Solution code:
from array import array
import math
from collections import defaultdict
import sys

N = int(input())

dd=defaultdict(int)

Sread = sys.stdin.read()


for s in Sread.split('\n'):
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    dd[s]+=1

FAC = {}
FAC[1] = 1

for i in range(2,N+1):
    FAC[i] = FAC[i-1]*i
    
count = 0

for k in dd:
    s_counts = dd[k]
    if s_counts > 1:
        count += FAC[s_counts]//2

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    td = {}
    for _ in range(N):
        t = sum([ord(ci) for ci in input()])
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] += 1

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


main()

Submission status: Wrong Answer

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

num = 0
num_same = 0
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += num_same * (num_same - 1) / 2
        num_same = 1
        break
    num_same += 1
print(num)

Submission status: Wrong Answer

Solution code:
import collections

if __name__ == '__main__':
    n = int(input())
    inputs = [input() for _ in range(n)]

    input_chars = [collections.Counter(s) for s in inputs]
    result = 0
    groups = {}
    for i in input_chars:
        # key = ''.join(sorted(i))
        key = frozenset(i.keys())
        if key not in groups:
            groups[key] = {}

        key2 = frozenset([i[k] for k in sorted(i)])
        if key2 not in groups[key]:
            groups[key][key2] = 0
        else:
            result += 1
    print(result)

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

listStr = [list(input()) for i in range(n)]
listFullStr = []

for i in range(n):
	fullStr = ""
	listStr[i].sort()
	for x in listStr[i]:
		fullStr += x
	listFullStr.append(fullStr)

answer = 0
while(True):
	firstStr = listFullStr[0]
	count = listFullStr.count(firstStr)
	if count != 1:
		answer = answer + combinations_count(count, 2)
	for firstStr in listFullStr:
		listFullStr.remove(firstStr)
	if len(listFullStr) == 0:
		break;

print(answer)

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
a+=b
print(a)

Submission status: Wrong Answer

Solution code:

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

    td = {}
    for _ in range(N):
        t = sum([ord(ci) for ci in input()])
        if t not in td.keys():
            td[t] = 1
        else:
            td[t] += 1

    count = 0
    for v in td.values():
        if v > 1:
            count += v * (v - 1) // 2

    print(count)


main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())

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

line = defaultdict(int)

for anagram in s:
  a = sorted(anagram)
  line[''.join(a)] += 1

_sum = 0

for i in line:
  _sum += line[i]

print(_sum * (_sum-1) / 2)

Submission status: Wrong Answer

Solution code:
import copy


def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]
    for i in range(n):
        s[i] = list(input())

    print(int(count_anagram(s[0], s[1:], 0)))


def anagram(list1, list2):
    list1.sort()
    list2.sort()
    return list1 == list2


def count_anagram(s, str_list, total):
    cnt = 0
    for t in str_list:
        if anagram(s, t):
            str_list.remove(t)
            cnt += 1
    if cnt > 0 :
        total += (cnt+1) * cnt / 2
    
    if str_list:
        return count_anagram(str_list[0], str_list[1:], total)
    else:
        return total
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
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())

s = [ list(input()) for _ in range(N)]
for i in range(N):
    s[i].sort()
    s[i]=''.join(s[i])

s.sort()
s.append('0')
print(s)
ans_tmp = 0
ans = 0
for i in range(N):
    if(s[i]== s[i+1]):
        ans_tmp += 1
    elif(ans_tmp>=1):
        ans+= cmb(ans_tmp+1, 2)
        ans_tmp=0


print(ans)

Submission status: Wrong Answer

Solution code:
import collections

l = sorted([''.join(sorted(input())) for i in range(int(input()))])
s = [int(i) for i in collections.Counter(l).values()]
a=0
b=0
for i in range(max(s)):
    print(i)
    b+=i
    a+=s.count(i+1)*b
print(a)

Submission status: Wrong Answer

Solution code:
import collections as col
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
N = int(input())
l = [input() for _ in range(N)]
a = []
for i in range(N):
    c = col.Counter(str(l[i]))
    a.append(sorted(c.most_common()))

ans = [a.count(x) for x in a if a.count(x) > 1]
if len(ans) == 0:
    print(0)
    quit()
count = ans[0]-1
bais = ans[0]
for i in range(len(ans)):
    if bais != ans[i]:
        if ans[i] in ans[i:]:
            count += ans[i:].count(ans[i])-1
    bais = ans[i]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0

l = [sorted(input()) for _ in range(n)]
dellist = lambda items, indices: [item for idx, item in enumerate(items) if idx not in indices]

while True:
    if not l:
        break
    a = l.pop(0)
    li = []
    for i in range(len(l)):
        if l[i] == a:
            li.append(i)

    dellist(l, li)

    ans += sum(range(len(li) + 1))

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
slist=[]
ans=0
for s in range(N):
	slist+=[set(input())]
for s in range(N):
	ans+=slist.count(slist[0])-1
	slist.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = []
for _ in range(N):
    d.append(sorted(str(input())))
count = 0

for i in range(N):
    for j in range(N):
        if d[i] == d[j]:
            count +=1
        else:
                break

print(count)

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
    m2 = [word for word in m2 if word != m2[0]]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [None for k in range(N)]
ans = 0
for p in range(N):
  a = input()
  b = 0
  for t in a:
  	b += ord(t)
  x[p]=b
  for q in range(p-1):
    if x[p] == x[q]:
      ans += 1
print(ans)

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 + (k*(k-1))/2
      else:
        Ans = Ans + (k*(k+1))/2
        
      print(Ans)
      sys.exit()
      
    if T[j] != T[j + k]:
      Ans = Ans + (k*(k-1))/2
      a = k
      break
  
  j = j + a

Submission status: Wrong Answer

Solution code:
import collections

l = sorted([''.join(sorted(input())) for i in range(int(input()))])
s = [int(i) for i in collections.Counter(l).values()]
a=0
b=0
print(s)
for i in range(max(s)):
    print(i)
    b+=i
    a+=s.count(i+1)*b
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())

s = []
for i in range(n):
    tmp = []
    tmp = list(input())
    tmp.sort()
    s.append("".join(tmp))

s.sort()

cnt = 0
t_cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        t_cnt += 1
    elif s[i] != s[i+1]:
        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for i in range(t_cnt):
                t += i

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt

    if i == n-2:
        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for i in range(t_cnt):
                t += i

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt

print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
#k=hoge[0]
#x=hoge[1]

list = [[0 for i in range(26)] for j in range(n)]
#list[0][1]=1
#print(list)

hash=[]
for i in range(0,26):
	hash.append([])

for i in range(0,n):
	tmp=input()
	hoge=0
	for j in range(0,10):
		list[i][ord(tmp[j])-ord("a")]+=1
		hoge+=ord(tmp[j])-ord("a")
	hoge=hoge%26
	hash[hoge].append(i)
#print(hash)

sum=0

for i in range(0,26):
	for j in range(0,len(hash[i])-1):
		for k in range(j,len(hash[i])):
			#print(i)
			#print(hash[i][j])
			#print(hash[i][k])
			for m in range(0,26):
				if(list[hash[i][j]][m]!=list[hash[i][k]][m]):
					break
				elif(m==25):
					sum+=1


#for i in range(0,n-1):
#	for j in range(i+1,n):
#		for k in range(0,26):
#			if(list[i][k]!=list[j][k]):
#				break
#			elif(k==25):
#				sum+=1

print(sum)

#print(list)
#print(list[0][:])

Submission status: Wrong Answer

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


print(int(sum(ccr)))

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

ss = []
counts_id = []
counts = []
answer = 0

chars = [x for x in "abcdefghijklmnopqrstuvwxyz"]
num = len(chars)

for i in range(N):
  ss.append(input().strip())
  _count = [0 for _ in range(num)]
  for _s in ss[i]:
    _count[chars.index(_s)] += 1
  
  flag = True
  if i == 0:
    counts_id = [_count]
    counts = [0]
  else:
    for k, id in enumerate(counts_id):
      if id == _count:
        #answer += 1
        counts[k] += 1
        flag = False
        break
    if flag:
      counts_id.append(_count)
      counts.append(0)
    
for c in counts:
  answer += c
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]

c = 0
c1 =  0
p = sorted(q)
for i in range(n-1):
	if p[i] == p[i+1]:
		c+=1
	else:
		if i != 0:
			if p[i] == p[i-1] or i == n-2:			
				for j in range(c+1):
					c1+=j
		c=0



print(c1+1)

Submission status: Wrong Answer

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

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

ans = 0

for i in range(len(str)-1):
    list1 = list(set(list(str[i])))
    list1.sort()
    for j in range(i+1,len(str)):
        list2 = list(set(list(str[j])))
        list2.sort()
        if len(list1) != len(list2):
            continue
            
        count = 0
        for k in range(len(list1)):

            if list1[k] == list2[k]:
                count = count + 1
            else:
                break
            
        if count == len(list1):
            ans = ans + 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
ss = input().split()
sett = set()
ans = 0
flg = True
for s in ss:
    if flg:
        flg = False
    else:
        l = list(s)
        sl = l.sort()
        if sl in sett:
            ans += 1
        else:
            sett.add(sl)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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


def eratosthenes_sieve(n):
    primes = [2]
    for odd in range(3, n + 1, 2):
        for p in primes:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                primes.append(odd)
                break
    return primes


era = eratosthenes_sieve(150)
ans = 0
n = int(input())
array = [0] * n
for i in range(n):
    new = input()
    var = 1

    for j in range(10):
        h = chars.index(new[j])
        var *= era[h]

    array[i] = var

print(collections.Counter(array))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
S = [0 for i in range(N)]
S2 = [0 for i in range(N)]
for i in range(N):
    S[i] = input()
    for j in range(len(S[0])):
        S2[i] += ord(S[i][j])
ans = 0
S3= list(set(S2))
for j in range(len(S3)):
    x = S2.count(S3[j])
    if x != 1:
        ans += x * (x - 1) / 2
print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(strList)
for i in c.keys():
    anaglam = anaglam + c[i]*(max(1,c[i]-1))/2
    
print(str(anaglam)[:-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s)
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())

S = [0 for i in range(N)]

for i in range(N):
  S[i] = input()
  
ans = 0

for i in range(N):
  for j in range(i+1,N):
    if S[j].count(S[i][0]) == 0:
      break
    if S[j].count(S[i][1]) == 0:
      break
    if S[j].count(S[i][2]) == 0:
      break
    if S[j].count(S[i][3]) == 0:
      break
    if S[j].count(S[i][4]) == 0:
      break
    if verify_anagrams(S[i],S[j]) == True:
      ans += 1

print(ans)

Submission status: Wrong Answer

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


print(int(sum(ccr)))

Submission status: Wrong Answer

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

def main():
    n = int(input())
    s = sorted([sorted(input()) for i in range(n)])
    ans = 0
    for i in s:
        cnt = 1
        for k in range(0, len(s) - 1):
            if s[k] == s[k + 1]:
                cnt += 1
            else:
                break
        del s[0:cnt]
        if cnt > 1:
            ans += (cnt * (cnt - 1)) // 2
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter                 
                                                
n = int(input())                                
s = [input() for i in range(n)]                 
s_sorted = []                                   
for w in s:                                     
    w_list = [c for c in w]                     
    w_list.sort()                               
    s_sorted.append(''.join(w_list))            
counter = Counter(s_sorted)                     
a = counter.most_common()[0]                    
c = a[1]                                        
if c > 0:                                       
    print(c)                                    
else:                                           
    print(0)

Submission status: Wrong Answer

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

c = 0

let_dic = {}
for k in range(26) :
    let_dic[chr(97+k)] = k

ls = []
for i in range(n) :
    d = 0
    for l in range(len(ls_str[i])) :
        d += 11**(let_dic[ls_str[i][l]] -1)
    ls.append(d)
    
ls.sort()

while ls != [] :
    i = 1
    while True :
        if len(ls) > i+1 and ls[i] == ls[0] :
            i += 1
        else :
            c += i*(i-1)//2
            for j in range(i) :
                ls.pop(0)
            break

print(c)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ls = []
    for i in range(n):
        inp = count_letter(input())

        tf = False
        for item in ls:
            tf = all(inp[key] == item[0].get(key) for key in inp)
            if tf:
                item[1] += 1
        if not tf:
            ls.append([inp, 0])
    print(sum(map(lambda x: x[1], ls)))


def count_letter(string):
    count = {}
    for i in string:
        if count.get(i) is None:
            count[i] = 1
        else:
            count[i] += 1
    return count


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#各要素をソート
for i in range(n):
    l[i] = ''.join(sorted(l[i]))
     

#リストをソート
l.sort()

#個数を調べる
flag = 0
for i in range(n-1):
    if l[i] == l[i+1]:
        flag == flag + 1

print(flag)

Submission status: Wrong Answer

Solution code:
import math
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
N = int(input())
a = 0
list2 = []
list3 = []
list1 = [list(input()) for i in range(N)]
for l in range(N):
    list1[l].sort()
list2 = get_unique_list(list1)
for j in range(len(list2)):
    list3.append(int(list1.count(list2[j])))
for k in range(len(list3)):
    if list3[k]==1:
        break
    a += math.factorial(list3[k])//2*math.factorial(list3[k]-2)
print(a)
print(list2)
print(list3)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
s = [input() for i in range(n)]
for i in range(len(s)):
    s0 = sorted(s[i])
    s[i] = ''.join(s0)
# ans = [s.count(a) for a in set(s) if s.count(a) > 1]
ans = []
for a in list(set(s)):
    if s.count(a) > 1:
        ans.append(s.count(a))
for i in range(len(ans)):
    if ans[i] == 2:
        ans[i] -= 1
print(sum(ans))

Submission status: Wrong Answer

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


def is_anagram(s_i, s_j):
    for k in range(10):
        found = False
        for l in range(10):
            if s_i[k] == s_j[l]:
                found = True
                break
        if not found:
            return False
    return True


num = 0
for i in range(n):
    for j in range(i + 1, n):
        if is_anagram(s[i], s[j]):
            num += 1
print(num)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
s = [str(input()) for s in range(N)]

S = []
for i in range(len(s)):
    foo = list(reversed(s[i]))
    foo.sort()
    S.append(''.join(foo))
ans = []
c = collections.Counter(S)
keys = list(c.keys())
for s in keys:
    ans.append(c[s])
n = len(ans) - 1
print(sum(ans) - n)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = []
count = 0
st = []

for i in range(N):
  if i==0:
    in_pu = input()
    l = list(in_pu)
    lst.append(in_pu)
    st.append(set(l))
    continue
    
  in_pu = input()
  l = list(in_pu)
  lst.append(list(in_pu))
  
  if set(l) in st:
    count = count + 1 
print(count+1)

Submission status: Wrong Answer

Solution code:
import itertools
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return len(result)


n=int(input())
a=[list(input()) for i in range(n)]
count=0
a=list(itertools.permutations(a))
for i in range(len(a[1])):
    if list_difference(a[i][0],a[i][1])==0:
        count+=1
print(count)

Submission status: Wrong Answer

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

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

i = 0

while i < len(word):   
    count = 0
    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)
                else:
                    l += 1
        if len(target) == 0:
            word.pop(j)
            count += 1
        else:
            j += 1
    i += 1
    if count != 0:
    	total += 1
    for a in range(count):
        total += a
print((total + 1) // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]

c = 0
c1 =  0
p = sorted(q)
for i in range(n-1):
	if p[i] == p[i+1]:
		c+=1
	else:
		if i != 0 or i == n-2:
			if p[i] == p[i-1] or i == n-2:			
				for j in range(c+1):
					c1+=j
		c=0



print(c1+1)

Submission status: Wrong Answer

Solution code:
num = int(input())

strs = [[] for i in range(num)]
for i in range(num):
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
shorten_strs = list(set(new_strs))

cnt = 0

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

for str in shorten_strs:
    nums = new_strs.count(str)
    if nums > 2:
        cnt += comb_count(nums, 2)

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())

F    = [None] * (N+1)
F[0] = 1

for i in range(1, N+1):
    F[i] = F[i-1] * i

S = [''.join(sorted(list(input()))) for i in range(N)]

Submission status: Wrong Answer

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

print(len(s) - len(set(s)) + sum(range(1, len(set(s)))))

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections

alpha2num = lambda c:ord(c) - ord('a')

N = int(input())
D = np.ones([26,N])*100
SUM = 0

for n in range(N):
  s = input()
  c = collections.Counter(s)
  for _c in c.keys():
    i = alpha2num(_c)
    D[i, n] = c[_c]
    
  d = D[:,n]
  d = d.reshape(len(d),1)
  diff = D - d
  count = np.max(diff,axis=0)
  k = np.count_nonzero(count==0)
  SUM = SUM + k
  
print('%d' % (SUM-N))