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:
def main():
    n = int(input())
    a = [input() for i in range(n)]
    num = 0
    for i in range(len(a)):
        a[i] = "".join(sorted(a[i]))
    a.sort()
    for i in range(len(a)):
        e = a[i]
        j = 1
        while i+j < len(a) and e == a[i+j]:
            j = j + 1
        num = num + conb(j)
        i = i+j
    print(num)


def conb(x):
    return x*(x-1)/2


main()

Submission status: Wrong Answer

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

N = int(input())

dd=defaultdict(int)
    
for i in range(N):
    s = input()
    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:
# -*- 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

            first = s[i]
            second = s[k]
            if anagram(first, second) == True:
                count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in 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:
N = int(input())
s = [sorted(input()) for i in range(N)]

s_int = []
a_ord = ord('a')
for _s in s:
    v = list(map(lambda x: ord(x)-a_ord, _s))
    v = sum([v[i]*26**i for i in range(len(v))])
    s_int.append(v)

s_int = sorted(s_int)

cnt = 0
old = -1
for i in s_int:
    _cnt = 1
    if old == i:
        _cnt += 1
    else:
        cnt += _cnt * (_cnt+1)
        _cnt = 1
        old = i

print(cnt)

Submission status: Wrong Answer

Solution code:
num = int(input())
#list_s = []
count = 0
list_a2z = [chr(i) for i in range(97, 97+26)]
dic_ana = {}
for _ in range(num):
    s = input()
    dic_a2z = {}
    for i in s:
        for j in list_a2z:
            if i == j:
                if j in dic_a2z:
                    dic_a2z[j] += 1
                else:
                    dic_a2z[j] = 1
    dic_a2z = str(sorted(dic_a2z))
    if dic_a2z in dic_ana:
        dic_ana[dic_a2z] += 1
    else:
        dic_ana[dic_a2z] = 1
#print(dic_ana)

for k in dic_ana.values():
    count += k * (k - 1) // 2

print(count)

Submission status: Wrong Answer

Solution code:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  print(d)
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

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

Submission status: Wrong Answer

Solution code:
import collections

def main():
    n = int(input())
    c = [[] for i in range(n)]
    count = 0
    lists =[]

    for num in range(n):
        c[num] = input()

    for i in c:
        if i in lists:
            count = count + lists.count(i)
            lists.append(i)
        else:
            lists.append(i)

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Wrong Answer

Solution code:
import sys
a = sys.stdin.readlines()


n = int(a[0])
ans = 0
now = 1

for i in a[1:n]:
    for j in a[(now+1):n]:
        if sorted(i) == sorted(j):
            ans += 1
        now = now + 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
result = []
for i in range(n):
    s = input()
    s = list(s)
    s.sort()
    result.append(s)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
no = get_unique_list(result)
counter = 0
for v in no:
  counter +=result.count(v) - 1
print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
dicts = {}
for _ in range(N):
    s = "".join(sorted(set(input())))
    if s not in dicts:
        dicts[s] = 1
    else:
        dicts[s] += 1
print(int(sum([n*(n-1)/2 for n in list(dicts.values()) if 0<n])))
print("")

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:
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] *= 2
    count = 0
    for v in td.values():
        if v > 1:
            count += v - 1

    print(count)


main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def judge(Si_list, Sj):
    for i in range(10):
        if Si_list[i] in Sj:
            Sj.replace(Si_list[i],"")
        else:
            return 0
    return 1


# 標準入力
N = int(input())

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

count = 0
for i in range(0,len(str_list)):
    Si_list = list(str_list[i])
    for j in range (i+1, len(str_list)):
        count = count + judge(Si_list, str_list[j])
  
print (count)

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,sent in enumerate(str_array):
  for char in sent:
    array[i,alpha2num(char)]+=1
  
count=0
for j in range(N-1):
  count+=np.sum(np.all(array==array[j],axis=1))-1
    
print(count-np.linalg.matrix_rank(array))

Submission status: Wrong Answer

Solution code:



def isAnagram(s, ss):
	i = 0
	while ss != "" and i < len(s):
		ss = ss.replace(str(s[i]), "")
		if len(s) == len(ss):
			return 0
		i += 1
	if ss == "":
		return 1
	else:
		return 0

#print(isAnagram("abaaaaaaaa", "aaaaaaaaba"))
c = int(input())
count = 0
strings = []
for i in range(c):
	s = input()
	if strings != []:
		for j in range(len(strings)):
			count += isAnagram(s, strings[j])
	strings.append(s)

print(count)

Submission status: Wrong Answer

Solution code:
A = list(map(sorted,open(0).read().split()))
cnt = 0
N = int(A[0][0])
#print(N,A)
for i in range(1,N):
  #print("i",i,A[i])
  for j in range(i+1,N+1):
    #print("j",j,A[j])
    if A[i]==A[j]:
      cnt+=1
      
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [None for k in range(N)]
for k in range(N):
  a = set(input())
  x[k] = 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:
# -*- coding: utf-8 -*-

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())
s = []
for i in range(n):
  s.append(input())
h = []
b = 'abcdedfhijklmnopqrstuvwyz'
for i in s:
  a = [0] * 27
  for c,d in enumerate(b):
    a[c] = i.count(d)
  ss = ''
  for j in a:
    ss += str(j)
  h.append(ss)
 
ans = 0
c = {}
for i in h:
  if c.get(i, -1) == -1:
    c[i] = 1
  else:
    c[i] += 1
sum = 0
for i in c:
  ans += cmb(c[i],2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s= [input() for i in range(N)]
ans=0
dp = list(range(N))

for i in range(N):
        for k in range(i+1,N):
                if dp[i] == dp[k]:
                        ans += 1
                else:
                        A=list(sorted(s[i]))
                        for j in list(sorted(s[k])):
                                if j in A:
                                        A.remove(j)
                                else:
                                        break
                        if len(A) == 0:
                                ans += 1
                                dp[k]=min(dp[i],dp[k])
                                dp[i]=dp[k]
print(dp)
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 = []
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).sum()==0:
            count += 1
    input_list +=[input_vec]
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
strings = []
for i in range(n):
    s = input()
    s10 = []
    for j in range(10):
        s10.append(s[j])
        s10.sort()
    strings.append(s10)

set_strings = []

for i in range(n):
    if not strings[i] in set_strings:
        set_strings.append(strings[i])

print(n - len(set_strings))

Submission status: Wrong Answer

Solution code:
import math
N = input()
a = []
for i in range(N):
	a.append(raw_input())

count_list=[]

for ii in a:
	count=[0]*26
	for jj in ii:
		count[int(ord(jj)-97)]+=1
	count_list.append(count)

anagram=0
while len(count_list)>0:
	ana_count=0
	buf=count_list.pop()
	for ii in count_list:
		if buf==ii:
			ana_count+=1
			count_list.remove(ii)
	anagram+=math.factorial(ana_count+1)/2
	
print(anagram)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_list = [''.join(sorted(input())) for _ in range(n)]
cnt = 0
cmp_list = list(range(n))
for i in cmp_list:
    cmp_list.remove(cmp_list[0])
    add_cnt = 1
    for j in cmp_list:
        if s_list[i] == s_list[j]:
            cnt += add_cnt
            cmp_list.remove(j)
            add_cnt += 1
    if len(cmp_list) == 1:
        break
print(cnt)

Submission status: Wrong Answer

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

for i in range(0,n):
    m=input()
    y=list(m)
    y.sort()
    m=''.join(y)
    s.append(m)

s.sort()

for j in range(0,n-1):
    if s[j]==s[j+1]:
        d=d+1
    else:
        if d==0:
            continue
        else:
            f=d*(d+1)//2
            z=z+f
            d=0
if d!=0:
    f=d*(d+1)//2
    z=z+f

Submission status: Wrong Answer

Solution code:
import math
import sys
import collections
n = int(input())

s = []
C = []
for i in range(n):                                                                                                                                                                                          
    a = input()                                                                                                                                                                                             
    b = str(a)                                                                                                                                                                                              
    d = sorted(b)                                                                                                                                                                                           
    s.append(d)                                                                                                                                                                                             
    # c = collections.Counter(s[i])                                                                                                                                                                         
    # C.append(c)                                                                                                                                                                                           

count = 0
for j in range(n):                                                                                                                                                                                          
    t_count = 0                                                                                                                                                                                             
    if j >= len(s):                                                                                                                                                                                         
        print(count)                                                                                                                                                                                        
        sys.exit()                                                                                                                                                                                          
    for k in range(j+1, n):                                                                                                                                                                                 
        if k >= len(s):                                                                                                                                                                                     
            continue                                                                                                                                                                                        
        if s[j] == s[k]:                                                                                                                                                                                    
            t_count += 1                                                                                                                                                                                    
            s.pop(k)                                                                                                                                                                                        
    if t_count > 1:                                                                                                                                                                                          
        count += math.factorial(t_count + 1) // (math.factorial(t_count - 1) * math.factorial(2))                                                                                                                
    else:                                                                                                                                                                                                   
        count += t_count
    # answer = s.count(s[j])                                                                                                                                                                                

    # count += answer - 1                                                                                                                                                                                   


print(count)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
s = [None]*N
l = [0]*N

for i in range(N):
  s[i] = input()[:-1]
  for j in range(10):
    l[i] += ord(s[i][j])
l = sorted(l)
z=1
ans = 0
for x in range(N-1):

  if l[x] == l[x+1]:
    z += 1
  else:
    ans += (z*(z-1))//2
    z = 1

print(ans+(z*(z-1))//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    s.append(sin)

c = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            c += 1
            break
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
s=[]
answer=0
for i in range(n):
  t=Counter(input())
  s.append(t)
for j in range(n):
  if len(s)==0:
    break
  else:
    h=s[0]
    g=s.count(h)
    if g>1:
      answer+=g*(g-1)//2
    for k in range(g):
      s.remove(h)
  print(answer)
print(answer)

Submission status: Wrong Answer

Solution code:
import math

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

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s_l.append(input())

for i in range(n):
        a = ''
        for x in sorted(s_l[i]):
                a += x
        s_l[i] = a

cnt = 0

# set_s_l = set(s_l)
# if len(s_l) == len(set_s_l):
#         print(0)
# else:
#         l = []
#         for val in set_s_l:
#                 l.append(s_l.count(val))
#         for i in l:
#                 if i > 1:
#                         if i == 2:
#                                 cnt += 1
#                         elif i == 3:
#                                 cnt +=i
#                         else:
#                                 cnt += c(i,2)
#         print(cnt)
set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        for i in range(n):
                for j in range(1,n-i):
                        if s_l[i] == s_l[i+j]:
                                cnt += 1
                                print(cnt)
# 0 1 2 3 4
#     2

Submission status: Wrong Answer

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

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 range(len(s)):
	for n in range(len(s)):
		if Counter(s[n])==Counter(s[m]) and s[m] != s[n]:
			ans+=1
print(ans/2)

Submission status: Wrong Answer

Solution code:
import json
n = int(input())
S = list()

A = list()
for _ in range(n):
  S.append(input())

for i in range(len(S)):
  hash = dict()
  for a in range(len(S)):
    for b in range(len(S[i])):
      hash[S[a][b]] = 0
  for j in range(len(S[i])):
    
    hash[S[i][j]] += 1
    
  A.append(hash)
  
count = 0

unique_list = list(map(json.loads, set(map(json.dumps, A))))
ans = len(A)-len(unique_list)
print(ans)

Submission status: Wrong Answer

Solution code:



def isAnagram(s, ss):
	i = 0
	while ss != "" and i < len(s):
		ss = ss.replace(str(s[i]), "")
		i += 1
	if ss == "":
		return 1
	else:
		return 0

#print(isAnagram("abaaaaaaaa", "aaaaaaaaba"))
c = int(input())
count = 0
strings = []
for i in range(c):
	s = input()
	if strings != []:
		for j in range(len(strings)):
			count += isAnagram(s, strings[j])
	strings.append(s)

print(count)

Submission status: Wrong Answer

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

for k, x in enumerate(s):
    for j in range(k+1, N):
        if set(x) == set(s[j]):
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math

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

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s_l.append(input())

for i in range(n):
        a = ''
        for x in sorted(s_l[i]):
                a += x
        s_l[i] = a

cnt = 0

# set_s_l = set(s_l)
# if len(s_l) == len(set_s_l):
#         print(0)
# else:
#         l = []
#         for val in set_s_l:
#                 l.append(s_l.count(val))
#         for i in l:
#                 if i > 1:
#                         if i == 2:
#                                 cnt += 1
#                         elif i == 3:
#                                 cnt +=i
#                         else:
#                                 cnt += c(i,2)
#         print(cnt)
set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        for i in range(n):
                for j in range(1,n-i):
                        if s_l[i] == s_l[i+j]:
                                cnt += 1

Submission status: Wrong Answer

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

for i in range(0,n):
    m=input()
    y=list(m)
    y.sort()
    m=''.join(y)
    s.append(m)

s.sort()

for j in range(0,n-1):
    if s[j]==s[j+1]:
        d=d+1
    else:
        if d==0:
            continue
        else:
            f=d*(d+1)/2
            z=z+f
            d=0
if d!=0:
    f=d*(d+1)//2
    z=z+f
                

print(z)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
s_dict = {}
for i in range(N):
    s=input()
    s0 = [0]*26
    for j in range(10):
        s0[ord(s[j])-ord('a')] += 1
    s0 = ''.join(map(str,s0))
    if s0 in s_dict:
        s_dict[s0] += 1 + s_dict[s0]
    else:
        s_dict[s0] = 0
print(sum(s_dict.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list()
num = 0
for i in range(n):

    s = input()
    s = list(s)
    s.sort()
    lst.append(s)

lst.sort()

for i in range(n-1):
    if (lst[i] == lst[i+1]):
        num = num + 1
print(num)

Submission status: Wrong Answer

Solution code:
n=input()
n=int(n)
l=[]
for i in range(n):
  s=input()
  f=[""]*10
  for j in range(10):
    f[j]=s[j]
  f.sort()
  if f not in l:
    l.append(f)
print(n-len(l))

Submission status: Wrong Answer

Solution code:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    S = [INPUT() for _ in range(N)]
    check = []
    alphabet = ['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']
    count = 0

    for i in range(N):
        check.append([0] * 26)
        for j in range(10):
            for k in range(26):
                if S[i][j] == alphabet[k]:
                    print(check)
                    check[i][k] += 1

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

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

res = 0
ns = S[0]
c = 1
for i in range(1, N):
    if S[i] == ns:
        c += c
    else:
        res += c
        c = 1
        ns = S[i]

if c != 1:
    res += c

print(res)

Submission status: Wrong Answer

Solution code:
_, *S=open(0).read().split()
a={}
for s in S:
    x = sum([ord(c) for c in s])
    if x in a:
        a[x] += 1
    else:
        a[x] = 1

from operator import mul
from functools import reduce
def aaa(n,r):
    if n == 1:
        return 0
    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

print(sum(map(lambda x:aaa(x, 2), a.values())))

Submission status: Wrong Answer

Solution code:


import math


def str_sort(s):
    return ''.join(sorted(s))
    
def combinations_count(n, r):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def is_anagram(s_1, s_2):
    for c in set(s_1):
        char_count_1 = s_1.count(c)
        char_count_2 = s_2.count(c)
        if char_count_1 != char_count_2:
            return False

    return True





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



S = [str_sort(s) for s in S]

ans = 0
done_list = []
for s in S:
    if s in done_list: continue
    count = S.count(s)
    ans += combinations_count(count, 2)
    done_list.append(done_list)




print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from array import array
import math

N = int(input())

S = []

for i in range(N):
    s = input()
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    S.append(s)

#N_FAC_MAX = math.factorial(10)
#FAC = array('l', [0]*(N+1))
#FAC = array('q', [0]*(N_FAC_MAX+1))
FAC = {}
FAC[1] = 1

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

prev = S.pop(0)
s_counts = 1

for s in S:
    if s == prev:
        s_counts += 1
    else:
        if s_counts > 1:
            count += FAC[s_counts]//2
        prev = s
        s_counts = 1

if s_counts > 1:
    count += FAC[s_counts]//2

print(count)

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np


global mod
mod = 10 ** 9 + 7


def mpow(x, n):  # x^nをmod取りながら返す
    ans = 1
    while n != 0:
        if n & 1:
            ans = ans * x % mod
        x = x * x % mod
        n = n >> 1

    return ans


def fav(n):  # nまでの階乗とその逆元を返す
    fav, ifav = np.zeros(n+1, dtype=int), np.zeros(n+1, dtype=int)

    fav[0] = 1
    ifav[0] = 1
    for i in range(n):
        fav[i + 1] = fav[i] * i % mod
        ifav[i + 1] = ifav[i] * mpow(i + 1, mod - 2)

    return fav, ifav


def comb(a, b, fav, ifav):  # aCbの計算
    if a == 0 and b == 0:
        return 1
    if a < 0 or a < b or b < 0:
        return 0

    temp = ifav[b] * ifav[a-b] % mod
    return temp * fav[a] % mod


n = int(input())

inputlist = []

for i in range(n):
    inputlist.append("".join(sorted(list(input()))))

counter = collections.Counter(inputlist)

counter = dict(counter)
valuelist = list(map(int, counter.values()))

fav, ifav = fav(max(valuelist))

ans = 0

for i in valuelist:
    if i == 1:
        continue
    if i == 2:
        ans += 1
        continue
    if i == 3:
        ans += 3
        continue
    ans += comb(i, 2, fav, ifav)

print(ans)

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
key = s[0]
flag = 0
for i in range(n-1):
    if key == s[i] and s[i] == s[i+1]:
        cnt += 1
        flag = 1
    elif s[i] != s[i+1]:
        if flag == 1:
            cnt += 1
        key = s[i+1]
        flag = 0
if s[n-2] == s[n-1]:
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import collections


n = int(input())

inputlist = []

for i in range(n):
    inputlist.append("".join(sorted(list(input()))))

counter = collections.Counter(inputlist)

counter = dict(counter)
valuelist = list(map(int, counter.values()))

ans = 0

for i in valuelist:
    if i == 1:
        continue
    if i == 2:
        ans += 1
        continue
    if i == 3:
        ans += 3
        continue
    #ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)
print(ans)

Submission status: Wrong Answer

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

res = 0
ns = S[0]
c = 1
for i in range(1, N):
    if S[i] == ns:
        c += c
    else:
        res += c
        c = 1
        ns = S[i]

print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
s = [input() for i in range(n)]
tmp = [defaultdict(int) for i in range(n)]

for j in range(len(s)):
    for k in s[j]:
        tmp[j][k] += 1
        
ans = 0
for i in range(0,len(s)):
    for j in range(i+1,len(s)):
        if(tmp[i]==tmp[j]):
            print(s[i])
            print(s[j])
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    input()
    num = 0
    a = [input().split() for i in range(num)]
    for i in range(len(a)):
        a[i] = "".join(sorted(a[i]))
    a.sort()
    for i in range(len(a)):
        e = a[i]
        j = 1
        while i+j < len(a) and e == a[i+j]:
            num = num + 1
            j = j + 1
    print(num)


main()

Submission status: Wrong Answer

Solution code:
def main():
    input()
    num = 0
    a = [input().split() for i in range(num)]
    for i in range(len(a)):
        a[i] = "".join(sorted(a[i]))
    a.sort()
    for i in range(len(a)):
        e = a[i]
        j = 1
        while i+j < len(a) and e == a[i+j]:
            num = num + 1
            j = j + 1
    print(num)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
for i in range(n):
  word = str(input())
  lis.append({letter:word.count(letter) for letter in word})
counter = 0
while True:
  d=lis[0]
  m = lis.count(d)
  counter += (m*(m-1))//2
  for i in range(m):
    lis.remove(d)
  print(lis)
  print(counter)
  if len(lis) == 0:
    break
print(counter)

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

            first = s[i]
            second = s[k]
            if anagram(first, second) == True:
                count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in b:
            a.replace(i, '')

        else:
            return False
    return True


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
seen = []
notseen = []
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    if s not in notseen:
        notseen.append(s)
    else:
        ans += 1
        if s in seen:
            ans += 1
            seen.append(s)
        else:
            seen.append(s)

print(ans)