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: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial

n = int(input())
strlist = []
for i in range(n):
    strlist.append(set(str(input())))

allcount = 0
while (len(strlist) > 1):
    i = 1
    count = 1
    while True:
        if(strlist[0] == strlist[i]):
            count += 1
            strlist.pop(i)
        else:
            i += 1
        if(i==len(strlist)):
            if(count > 1):
                allcount += int(factorial(count) / factorial(2) / factorial(count-2))
            break
    strlist.pop(0)
print(allcount)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np


def fav(n):
    fav = np.zeros(n+1, dtype=int)

    fav[0] = 1
    for i in range(1, n+1):
        fav[i] = fav[i-1] * i

    return fav


def comb(a, b, fav):
    if a == 0 and b == 0:
        return 1
    if a < 0 or a < b or b < 0:
        return 0

    return int(fav[a] / fav[b] / fav[a-b])


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 = fav(max(valuelist)+1)

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) for v in str_dict.values()]))

Submission status: Runtime Error

Solution code:
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
ptint('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(input()) for i in range(n)]
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        p=[col for col  in a[i] if col not in a[j]]
        if len(lst)==0:
            count+=1
print(count)

Submission status: Runtime Error

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(int(ans/2))

Submission status: Runtime Error

Solution code:
import collections
from math import factorial

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

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += factorial(i) / factorial(2) / factorial(i - 2)

print(int(ans))

Submission status: Runtime Error

Solution code:
N = 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] == current:
            ans += 1
        else:
            pass
print(ans)

Submission status: Runtime Error

Solution code:
"""
https://atcoder.jp/contests/abc137/tasks/abc137_c
"""
import numpy as np


def calc(N: int, sorted_strings: np.ndarray) -> np.ndarray:
    strings_len = sorted_strings.shape[0]
    idx = np.arange(strings_len, dtype="int64")
    xx, yy = np.meshgrid(idx, idx)
    same = sorted_strings[xx] == sorted_strings[yy]
    same2 = same * (1 - np.tri(strings_len))
    return np.sum(same2, dtype="int64")


def main() -> None:
    N = int(input())
    sorted_strings = np.array(["".join(sorted(input())) for _ in range(N)])
    result = calc(N, sorted_strings)
    print(result)


main()

Submission status: Runtime Error

Solution code:
import math

N = int(input())
S = [sorted(input()) for i in range(N)]
S = ["".join(S[i]) for i in range(N)]

S.sort()
S_ = S[:]
S_ = set(S_)

c = 0

for i in S_:
    a = S.count(i)
    if a == 1 :
        continue
    ans = math.factorial(a) / 2 * math.factorial(a-2)
    c += int(ans)

print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["".join(sorted([j for j in input()])) for i in range(n)]
s.sort()
count = 0
key = s[0]
sum = 0
def saiki(i):
    if i == 0:
        return 0

    return i + saiki(i-1)

for i in s:
    if key == i:
        count += 1
    else:
        sum += saiki(count-1)
        key = i
        count = 1
sum += saiki(count-1)
print(sum)

Submission status: Runtime Error

Solution code:
n = int(input());
s = [0]*n;
for i in range(n) :
	s_pre = list(input());
	s_pre.sort();
	s[i] = s_pre;


s.sort(key=lambda x:(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]));

ans = 0;
for i in range(1,n) :
	ok = 1;
	k = 1;
	while s[i-k]==s[i] :
		for j in range(10) :
			if s[i-k][j] != s[i][j] :
				ok = 0;
		if bool(ok) :
			ans += 1;
		k += 1;

print(ans);

Submission status: Runtime Error

Solution code:
import math
N = int(input())

nlist=[""]*N

for i in range(N):
    t=str(input())
    t = ''.join(sorted(t))
    nlist[i] = t

sum=0
tsum=1
nlist=sorted(nlist)
tmpStr=nlist[0]
for i in range(1,N):
    if(tmpStr==nlist[i]):
        tsum+=1
    else:
        tmpStr=nlist[i]
        if(tsum!=1):
                sum+=math.factorial(tsum)/2
                tsum=1
if(tsum!=1):
        tmpStr=nlist[i]
        sum+=math.factorial(tsum)/2
        
print(int(sum))

Submission status: Runtime Error

Solution code:
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(n):
    S.append(set(input()).sort())
print(n-len(set(S)))

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
N = int(input())
string_list=["".join(sorted(input())) for i in range(N)]

ans = 0
c = Counter(string_list)

for v in c.values():
    ans += comb(v, 2, exact=True)

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        lst = a[i].copy()
        for element in a[j]:
            try:
                lst.remove(element)
            except ValueError:
                pass
        if len(lst)==0:
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
#coding: utf-8
amount = int(input())
strings = list(map(str, [input() for i in range(amount)]))
sum = 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)
	if strings[j] == strings[j+1]:
		sum = sum+1

print(sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial

n = int(input())
strlist = []
for i in range(n):
    strlist.append(list(str(input())))

allcount = 0
while (len(strlist) > 1):
    i = 1
    count = 1
    while True:
        if(set(strlist[0]) == set(strlist[i])):
            count += 1
            strlist.pop(i)
        else:
            i += 1
        if(i==len(strlist)):
            if(count > 1):
                allcount += int(factorial(count) / factorial(2) / factorial(count-2))
            break
    strlist.pop(0)
print(allcount)

Submission status: Runtime Error

Solution code:
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(n):
    S.append(set(input()).sort())
print(n-len(set(S))+1)

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb

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

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():
    ans += comb(i, 2, exact=True)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for i in range(n)]
s = list(map(sorted,s))
score = 0
for j in range(len(ss)-1):
    score += ss[j+1:].count(ss[j])
print(score)

Submission status: Runtime Error

Solution code:
n=int(input())

l=[]
for _ in range(n):
  a=soretd([i for i in input()])
  b=''.join(a)
  l.append(b)

ans=[]
for i in range(n-1):
  for j in range(i+1,n):
    ans.append(l[i]==l[j])
    
print(sum(ans))

Submission status: Runtime Error

Solution code:
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(n):
    S.append(set(input()).sort)
print(n-len(set(S))+1)

Submission status: Runtime Error

Solution code:
N = int(input())
t_dict = {}
for i in range(0, N):
    string = input()
    s_dict = {}
    for s in string:
        if s in s_dict:
            s_dict[s] += 1
        else:
            s_dict[s] = 1
    if s_dict in t_dict:
        t_dict[s_dict] += 1
    else:
        t_dict[s_dict] = 1
        
print(len(t_dict))

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

from math import factorial
import collections

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    #mng = [][]
    sl = []
    for _ in range(N):
        sl.append(str(sorted(sys.stdin.readline().rstrip())))

    c = collections.Counter(sl)
    ans = 0
    for n in c.values():
        r = 2
        if n > 1:
            ans += factorial(n) / factorial(r) / factorial(n - r)

    print(int(ans))

Submission status: Runtime Error

Solution code:
import collections

def total(n):
    if n < 1:
        return 0

    return n + total(n - 1)

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

Submission status: Runtime Error

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_list = []
ans = 0
for _ in range(N):
    s_list.append(sorted(list(input())))
c = collections.Counter(s_list)
for i in range(N):
    m = c.most_common()[i][1]
    if m > 1:
        ans += cmb(m, 2)
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for i in range(N)]
 
from collections import defaultdict
def decode(s):
  d = defaultdict(int)
  for c in sorted(list(s)):
    d[c] += 1
  return d
 
decodes = [decode(s) for s in S]
 
hash_table = defaultdict(int)
for decode in decodes:
  hash_table[tuple(decode.items())] += 1
#print(hash_table)
import math
c_list = [int(math.factorial(v)/math.factorial(2)) for v in hash_table.values()]
#print(c_list)
count = sum(c_list)
 
print(count)

Submission status: Runtime Error

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

    if cache_dict[w1].keys() != cache_dict[w2].keys():
        continue

    if list(cache_dict[w1].values()) != list(cache_dict[w2].values()):
        continue

    cnt += 1


print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(H):
    S.append(set(input()).sort)
print(n-len(set(S))+1)

Submission status: Runtime Error

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

count = 0
list1 = []
for i in range(n):
    dic1 = {}
    for k in range(10):
        
        if s[i][k] not in dic1:
            dic1[s[i][k]] = s[i].count(s[i][k])
    list1.append(dic1)
list2 = []
for i in range(n):
    if list1[i] not in list2:
        j = list1.count(list1[i])
        if j >= 2:

            a = factorial(j) / factorial(2) / factorial(j - 2)
            count += a
        list2.append(list1[i])
print(int(count))

Submission status: Runtime Error

Solution code:
N   =   int(input())

counter     =   0


A = []

for i in range(26):
    A.append([])




for i in range(N):
    S   =   input().sort()
    point   =   ord(S[0]) - ord('a')
    
    for j in range(len(A[point])):
        if(A[point][j] == S):
            counter += 1
            continue
    A[point].append(S)

print(counter)

Submission status: Runtime Error

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[len(liss)-1] = 1

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

Submission status: Runtime Error

Solution code:
import numpy as np
import string

a = string.ascii_lowercase

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

for i in range(N):
    s.append(input())
    
k = np.zeros((N,26))

for i in range(N):
    for j in range(26):
        k[i,j] = s[i].count(a[j])

l = np.zeros(26)
for i in range(N):
    for j in range(26):
        l[i] += (11**(j+1)) * k[i,j]

k = np.zeros(0)
while l != np.zeros(0):
    i = 0
    k = np.append(k, np.size(l[l == l[i]]))
    l = l[l != l[i]]

k = np.delete(k, np.size(k)-1)

ans = 0
for i in range(np.size(k)):
    ans += k[i] * (k[i]-1) /2
    
print(int(ans))

Submission status: Runtime Error

Solution code:
list = []

def p(a):
	if (a == 3):
		return 3
	if (a == 2):
		return 1
	if (a == 1):
		return 0
	return p(a - 1) * a

str = input()
N = int(str.split()[0])
d = []
for i in range(N) :
	s = str = input()
	dict = {}
	for j in range(26):
		dict[j] = 0
	for j in range(10) :
		k = ord(s[j]) - ord("a")
		dict[k] = dict[k] + 1
	d.append(dict)
	
E = 0
while(len(d) != 0) :
	deli = []
	for i in range(1, len(d)) :
		f = 0
		for j in range(26):
			if (d[0][j] != d[i][j]) :
				f = 1
				break
		if (f != 1) :
			deli.append(i)
	a = 0
	while(len(deli) != 0) :
		d.pop(deli[0] - a)
		deli.pop(0)
		a = a + 1
	if (len(d) != 0) :
		if (a != 0) :
			E = E + p(a + 1)
		d.pop(0)
print(E)

Submission status: Runtime Error

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

for _ in range(N):
  s.append(str(input()))
  
cnt = 0
for i in range(N):
  delete = []
  s1 = s.pop()
  s1list = list(s1)
  same = 0
  
  for j in range(len(s)-1, -1, -1):
    s2 = s[j]
    s2list = list(s2) 
    if sorted(s1list) == sorted(s2list):
      delete.append(s2)
      same += 1
  cnt += math.factorical(same)
  for x in delete:
    s.remove(x)
  if not s:
    break
print(cnt)

Submission status: Runtime Error

Solution code:

def create_count_dic(text):
    count_dic = {}
    [count_dic[t] +=1 if t in count_dic else count_dic[t] = 1 for t in text]
    for t in text:
        if t in count_dic:
            count_dic[t] += 1
        else:
            count_dic[t] = 1
    return count_dic

def is_anagram(text1, text2):
    text1_dic = create_count_dic(text1)
    text2_dic = create_count_dic(text2)
    if text1_dic == text2_dic:
        return True
    else:
        return False

N = int(input())
S = [input() for x in range(N)]
ans = 0

for i in range(N):
    for j in range(i+1, N):
        if is_anagram(S[i], S[j]):
            ans += 1

print(ans)

Submission status: Runtime Error

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

    if cache_dict[w1].keys() != cache_dict[w2].keys():
        continue

    if cache_dict[w1].values() != cache_dict[w2].values():
        continue

    cnt += 1


print(cnt)

Submission status: Runtime Error

Solution code:
import collections
from math import factorial

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

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

c = collections.Counter(S)
values, counts = zip(*c.most_common())
counts = [i for i in counts if i > 1]

ans = 0
for c in counts:
    ans += factorial(c) / factorial(2) / factorial(c - 2)
print(int(ans))

Submission status: Runtime Error

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 = [input() for i in range(N)]
ans = 0

for i in range(len(strings)):
  anagrams_index = []
  anagrams_num = 0
  for j in range(i+1, len(strings)):
    if i > len(strings) or j > len(strings):
      break
    if is_anagram(strings[i], strings[j]):
      anagrams_num += 1
      strings.pop(j)
  
  if anagrams_num == 1:
    ans +=1
  elif anagrams_num > 1:
    ans += int(math.factorial(anagrams_num+1)/math.factorial(anagrams_num)) 
print(ans)

Submission status: Runtime Error

Solution code:
import collections

m = dict()
def f(n):
    if n <= 1:
        return 0
    else:
        if n in m:
            return m[n]
        else:
            m[n] = (n-1) + f(n-1)
            return m[n]

n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = 0
for k, v in collections.Counter(s).items():
    if v <= 1:
        continue
    c += f(v)

print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["".join(sorted([j for j in input()])) for i in range(n)]
s.sort()
count = 0
jump = 0
count_i = 0
def saiki(i):
    if i == 0:
        return 0

    return i + saiki(i-1)

for i in range(0,len(s)):
    s_count = s.count(s[i])
    if jump != i:
        continue

    if s_count != 1:
        count += saiki(s_count-1)
        jump = i + s_count
    else:
        jump = i+1
print(count)

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())
s = ["".join(sorted(input())) for i in range(n)] 
l = []
count = 0
for i in range(n-1):
  if s[i] in s[i+1:]:
    l.append(s[i])
for k in set(l):
  num = s.count(k)
  if num > 2:
    count += factorial(num) / factorial(2) / factorial(num-2)
  elif num ==2:
    count += 1
  else:
    pass
    
print(int(count))

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())

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

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: Runtime Error

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 = [input() for i in range(N)]
ans = 0

for i in range(len(strings)-1):
  anagrams_index = []
  anagrams_num = 0
  for j in range(i+1, len(strings)):
    if i > len(strings) or j > len(strings):
      break
    if is_anagram(strings[i], strings[j]):
      anagrams_num += 1
      strings.pop(j)
  
  if anagrams_num == 1:
    ans +=1
  elif anagrams_num > 1:
    ans += int(math.factorial(anagrams_num+1)/math.factorial(anagrams_num)) 
print(ans)

Submission status: Runtime Error

Solution code:
import collections
import itertools
import math

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

def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())

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

Submission status: Runtime Error

Solution code:
N = int(input())
t_dict = {}
for i in range(0, N):
    string = input()
    s_dict = {}
    for s in string:
        if s in s_dict:
            s_dict[s] += 1
        else:
            s_dict[s] = 1
    if s_dict in t_dict:
        s_dict[t_dict] += 1
    else:
        t_dict = 1
print(len(t_dict))

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
s = [input() for i in range(n)]
x = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        for k in range(10):
            if s[i].count(s[j][i]) != s[j].count(s[j][i]):
                break
        if k == 9:
            x = x + 1
print(x)

Submission status: Runtime Error

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

import math

N = int(input())

type_dict = {}
for _ in range(N):
    s = input()
    counts = (
        s.count('a'), s.count('b'), s.count('c'), s.count('d'),
        s.count('e'), s.count('f'), s.count('g'), s.count('h'),
        s.count('i'), s.count('j'), s.count('k'), s.count('l'),
        s.count('m'), s.count('n'), s.count('o'), s.count('p'),
        s.count('q'), s.count('r'), s.count('s'), s.count('t'),
        s.count('u'), s.count('v'), s.count('w'), s.count('x'),
        s.count('y'), s.count('z')
    )
    if counts in type_dict:
        type_dict[counts] = type_dict[counts] + 1
    else:
        type_dict[counts] = 1


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


print(sum([combinations_count(x, 2) for x in type_dict.items() if x > 1]))

Submission status: Runtime Error

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: Runtime Error

Solution code:
num = int(input())
tmp = {}
for i in range(num):
  if i in tmp: tmp[i]=1
  else: tmp[i]+=1
for k, v in tmp.items():
  if v > 1: print(k)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial
N=int(input())
S=[]
for i in range(N):
    s="".join(sorted(list(input())))
    S.append(s)
c=Counter(S).most_common()
ans=0
for i in range(len(c)):
    if c[i][1]>1:
        ans+=factorial(c[i][1]) / factorial(2) / factorial(c[i][1] - 2)
print(int(ans))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

word_list = []
for i in range(N):
    S = list(input())
    words, count = np.unique(S, return_counts=True)
    word_list.append(''.join(words)+str(count))

S, ans_count = np.unique(word_list, return_counts=True)
temp = ans_count[ans_count>1]
ans = int(sum([t*(t-1)/2 for t in temp]))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for i in range(N)]
 
from collections import defaultdict
def decode(s):
  d = defaultdict(int)
  for c in list(sorted(s)):
    d[c] += 1
  return d
 
decodes = [decode(s) for s in S]
 
hash_table = defaultdict(int)
for decode in decodes:
  hash_table[tuple(decode.items())] += 1
#print(hash_table)
import math
c_list = [int(math.factorial(v)/math.factorial(2)) for v in hash_table.values()]
#print(c_list)
count = sum(c_list)
 
print(count)

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb
N = int(input())
string_list=["".join(sorted(input())) for i in range(N)]

ans = 0
c = collections.Counter(string_list)

for v in c.values():
    ans += comb(v, 2, exact=True)

print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())
s = []
for i in range(n):
    s.append(input())
count = 0
#---ここまでok
for i in range(n):
    s[i] = ''.join(sorted(s[i]))
set_s = list(set(s))
if len(set_s) != len(s):
    for i in set_s:
        if s.count(i) >= 2:
            count += int(factorial(s.count(i)) / factorial(2) / factorial(s.count(i) - 2))
print(count)

Submission status: Runtime Error

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 = {}
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)

    if cache_dict[w1].keys() != cache_dict[w2].keys():
        continue

    if cache_dict[w1].values() != cache_dict[w2].values():
        continue

    cnt += 1


print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(input()) for i in range(n)]
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        for element in a[j]:
             try:
                    a[i].remove(element)
                    if len(a[i])==0:
                        count+=1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())

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

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[j+1:]==array[j],axis=1))
    
print(count)

Submission status: Runtime Error

Solution code:
from math import factorial

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

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1

for v in count_dict.values():
    if v >= 2:
        cnt += int(factorial(v)) / int(factorial(2)) / int(factorial(v - 2))

print(int(cnt))

Submission status: Runtime Error

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

from collections import defaultdict
def decode(s):
  d = defaultdict(int)
  for c in list(sorted(s)):
    d[c] += 1
  return d

decodes = [decode(s) for s in S]

hash_table = defaultdict(int)
for decode in decodes:
  hash_table[tuple(decode.items())] += 1
print(hash_table)
import math
c_list = [int(math.factorial(v)/math.factorial(2)) for v in hash_table.values()]
#print(c_list)
count = sum(c_list)

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import string

a = string.ascii_lowercase

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

for i in range(N):
    s.append(input())
    
k = np.zeros((N,26))

for i in range(N):
    for j in range(26):
        k[i,j] = s[i].count(a[j])

l = np.zeros(26)
for i in range(N):
    for j in range(26):
        l[i] += (11**(j+1)) * k[i,j]

k = np.zeros(0)
while l != np.zeros(0):
    i = 0
    k = np.append(k, np.size(l[l == l[i]]))
    l = l[l != l[i]]

k = np.delete(k, np.size(k)-1)
    
def re_factorial(n):
    if n < 2:
        return 1
    return n * re_factorial(n-1)

ans = 0
for i in range(np.size(k)):
    if k[i] > 1:
        ans += k[i] * (k[i]-1)/2
    
print(int(ans))