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:
N = int(input())
X =[]
LIST = ["0","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"]
B = 0
for i in range(N):
    Y =list(input())
    for i in range(10):
        
        A = LIST.index(Y[i])
        B = B + 10 ** A
    X.append(B)
    B = 0
X.sort()
#print(X)
ans = 0
count = 1 
for i in range(N-1):
    if X[i] == X[i+1]:
        count += 1
    else:
        if count != 1:
            Z = 1/2
            for i in range(1,count+1):
                Z = Z * i
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1/2
    for i in range(1,count+1):
        Z = Z * i
    ans = ans + Z
        
print(int(ans))

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

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:
import math

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
cnt = 0

for c in s:
  if len(s) == 0:
    break
  amnt = len(list(filter(lambda x: x == c, s[s.index(c)+1:])))
  cnt += amnt
  cnt += (sum(range(1, amnt)))
  s = list(filter(lambda x: x != c, s))

print(cnt)

Submission status: Runtime Error

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]

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

cnt=1
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]
        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:
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 += re_factorial(k[i])/2
    
print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from scipy.special import comb
print(sum([comb(anagrams.count(word), 2, exact=True)\
          for word in set(anagrams)]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict
tmp = [defaultdict(int) for i in range(n)]
n = int(input())
s = [input() 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: Runtime Error

Solution code:
import sys
import math

input = sys.stdin.readline


def main():
    n = int(input())
    lines = ["".join(sorted(input().strip())) for _ in range(n)]
    count = 0
    for text in set(lines):
        txt_cnt = lines.count(text)
        count += int(math.factorial(txt_cnt) / math.factorial(txt_cnt - 2)) // 2
    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
s=[list(input()) for _ in range(n)]
for i in s:
    i.sort()
s=["".join(i) for i in s]
count=0
for i,string in enumerate(s):
    l=s[i+1:]
    count+=l.count(string)
    print(s)
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

n = int(input())
s = [input() for _ in range(n)]
ans = 0
while len(s) > 0:
    count = 1
    si = Counter([x for x in s[0]])
    j = 1
    while j < len(s):
        if si == Counter([x for x in s[j]]):
            count += 1
            s.pop(j)
        else:
            j += 1
    ans += math.factorial(count) // (2 * math.factorial(count-2))
    s.pop(0)
print(ans)

Submission status: Runtime Error

Solution code:
#coding: utf-8

from math import factorial
N = int(input())

s_list = []
for i in range(N):
    input_string = list(input())
    input_string.sort()
    input_string = "".join(input_string)
    s_list.append(input_string)

count = 0
s_list.sort()
tmp_count = 0
for i in range(1, len(s_list)):
    if s_list[i-1] == s_list[i]:
        tmp_count = tmp_count + 1
    else:
        if tmp_count == 0:
            pass
        else:
            tmp_count = tmp_count + 1
            count = count + int(factorial(tmp_count) / factorial(2) / factorial(tmp_count - 2))
        tmp_count = 0

if tmp_count == 0:
    pass
else:
    tmp_count = tmp_count + 1
    count = count + int(factorial(tmp_count) / factorial(2) / factorial(tmp_count - 2))

print(count)

Submission status: Runtime Error

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

  tmp = []
  d={}
  for s in S:
    x = Counter(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      tmp.append(x)
      d[tmp.index(x)] = 1 
      
  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: 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) / factorial(2) / factorial(v - 2))

print(cnt)

Submission status: Runtime Error

Solution code:
count = 0
scounts = []
N = int(input())
for n in range(N):
    s = sorted(input())
    found = False
    index = -1
    for i in range(len(scounts)):
        if scounts[i][0] == s:
            found = True
            count += scounts[i][1]
            scounts[i][1] += 1
            break
        elif scounts[i][0] > s:
            index = i
            break
        else: # scounts[i][0] > s:
			pass

    print("index="+str(index))
    if not found:
        if index<0:
            scounts.append([s,1])
        else:
            scounts.insert(index, [s, 1])

        print(str(s))
        print("DONE: "+str(scounts))
    print("===")
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N = int(input())
A = [input() for i in range(N)]
a = []*N
for i in A:
    b = list(i)
    b.sort()
    a.append(b)

a.sort()
c = list(map(list, set(map(tuple, a))))
d=[]
for i in c:
    d.append(a.count(i))
count=0
for i in d:
    count += math.factorial(i) // (math.factorial(i - 2) * math.factorial(2))

print(count)

Submission status: Runtime Error

Solution code:
import collections
import math

inp = int(input())
A = []
for a in range(inp):
    A.append(input())

def charcnt(s):
    cset = {}
    for c in s:
        if c in cset:
            cset[c] += 1
        else:
            cset[c] = 1
    sortedset = sorted(cset.items(), key=lambda x:x[0])
    s = ""
    for k, v in sortedset:
        s += k + str(v)
    return s

sorted = [charcnt(v) for v in A]    

counted = collections.Counter(sorted)
cnt = 0
for v in counted.values():
    if v > 1:
        cnt += math.factorial(v) / 2
print(int(cnt))

Submission status: Runtime Error

Solution code:
N = int(input())
X =[]
for i in range(N):
    Y =list(input())
    Y.sort()
    X.append(Y)
X.sort()
    
ans = 0
count = 1 
for i in range(N-1):
    if X[i] == X[i+1]:
        count += 1
    else:
        if count != 1:
            Z = 1/2
            for i in range(1,count+1):
                Z = Z * i
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1/2
    for i in range(1,count+1):
        Z = Z * i
    ans = ans + Z
        
print(int(ans))

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

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


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

s.sort()

ss = list(set(s))

co = [0]*len(ss)

for i in range(len(ss)):
    co[i] += s.count(ss[i])

ans = 0

for i in co:
    if i != 1:
        ans += cmb(i,2)

print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

n = int(input())
l = [input() for i in range(n)]

res = []
for i in l:
    li = list(i)
    li.sort()
    res.append(''.join(li))

a = list(set(res))
t = 0
for i in a:
    r = res.count(i)
    if r == 2:
        t += 1
    elif r > 2:
        a = factorial(r) / factorial(2) / factorial(r - 2)
        t += a


print(t)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

anagramed = []

def main():
    # n = map(int, input().split(" "))
    n = int(input())
    m = []
    count = 0

    for _ in range(n):
        m.append(input())
        anagramed.append(False)

    for i in range(n):
        shurui = 1
        if anagramed[i]:
            pass
        else:
            for j in range(i+1, n):
                if anagramed[j]:
                    pass
                elif is_anagram(m[i], m[j]):
                    shurui += 1
                    anagramed[i] = True
                    anagramed[j] = True
        if shurui > 1:
            count += int(math.factorial(shurui) / 2)
    print(count)


def check_dp(i, j):
    length_dp2 = len(dp2[i])
    if length_dp2 == 0:
        return False
    else:
        if j in dp2[i]:
            return True


def is_anagram(s1, s2):
    s1_length = len(s1)
    s2_length = len(s2)
    if s1_length != s2_length:
        return False
    else:
        for index in range(s1_length):
            search_char = s1[index: index+1]
            search_result = s2.find(search_char)
            if search_result == -1:
                return False
            else:
                s2 = s2.replace(search_char, "", 1)
    return True

main()

Submission status: Runtime Error

Solution code:
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():
    cnt += factorial(v) / factorial(2) / factorial(v - 2)

print(cnt)

Submission status: Runtime Error

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

n = int(input())

#l = [i for i in range(n)]

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

count = 0
"""
count_l = []

while 1:
    ll = copy.deepcopy(l)
    for i in range(1, len(ll)):
        if Counter(s[ll[0]]) == Counter(s[ll[i]]):
            count += 1
            l.pop(i)
    if count == 0:
        break
    count_l.append(count)
"""
if len(s) > 10000:
    k = 10000
else:
    k = len(s)
    
for i in range(k-1):
    for j in range(i+1, k:
        if Counter(s[i]) == Counter(s[j]):
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
# じゃあ全部保存していってやるよ
n = int(input())
d = {}
arr = []
for _ in range(n):
    x = list(sorted(input()))
    arr.append(x)
    if x not in d:
        d[x] = 1
    else:
        d[x] += 1

c = 0
for a in arr[:0:-1]:
    if d[a] > 0:
        c += d[a] - 1
        d[a] -= 1

print(c)

Submission status: Runtime Error

Solution code:
import sys
p = [r for r in sys.stdin.read().split('\n') if r != '']
n = int(p[0])
s = p[1:]
for i, r in enumerate(s):
    t = list(r)
    t.sort()
    s[i] = ''.join(t)
total = 0
while n:
    a = s.pop(-1)
    count = 0
    for i in reversed(range(0, len(s))):
        if s[i] == a:
            count += 1
            s[i] = None
    total += int((count + 1) * count / 2)
    n -= (count + 1)
print(total)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

n = int(input())
s=[]
m={}
sum=0
for i in range(0,n):
    # print((list(input()))
    tmp = "".join(sorted(input()))
    if tmp in m:
        m[tmp]+=1
    else:
        m[tmp] = 1
for k in m:
    if m[k]>1:
        # print(m[k])
        # print("["+k)
        sum+=cmb(m[k],2)
print(sum)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
s = [0]*N
counter = {}
for i in range(N):
  s[i] = input()
  a = collections.Counter(s[i])
  if a in counter:
    counter[a] += 1
  else:
    counter[a] = 1

ans = 0
for key in counter:
  if counter[key] > 1:
    ans = ans + counter[key] * (counter[key] - 1) / 2
print(ans)

Submission status: Runtime Error

Solution code:
def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return len(arr)

n=int(input())
a=[input() for i in range(n)]
a=list(map(lambda x:list(x),a))
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if intersect_list(a[i],a[j])==len(len(a[i])):
            count+=1
print(count)

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=len(l)-len(list(set(l)))
print(ans)

Submission status: Runtime Error

Solution code:
# 前の提出だとTLEなっちゃった
# じゃあ全部保存していってやるよ
n = int(input())
d = {}
arr = []
for _ in range(n):
    x = list(sorted(input()))
    arr.append(x)
    if x not in d:
        d[x] = 1
    else:
        d[x] += 1

c = 0
for a in arr[:0:-1]:
    if d[a] > 0:
        c += d[a] - 1
        d[a] -= 1

print(c)

Submission status: Runtime Error

Solution code:
mst_l = [chr(i) for i in range(97,97+26)]

n = int(input())
l = ["".join(map(str, [input().count(a) for a in mst_l])) for _ in range(n)]
result = 0
for i in range(n-1):
    result += l[i+1:].count(l[i])
print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [set(input()) for i in range(N)]
 
a = 0
for i in range(N):
  for j in range(i+1,N+1)
    if i==j:
      a+=1
print(a)

Submission status: Runtime Error

Solution code:
from collection import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))

Submission status: Runtime Error

Solution code:
for i in range(n):
    s.append("".join(sorted(input())))
s.sort()

a = 0
r = 0
i = 1
l = len(s)
while i < l:
    if s[i] == s[i-1]:
        r = r+1
    else:
        a = a + sum(range(r+1))
        r = 0
    i = i+1

if r > 0: a = a + sum(range(r+1))
print(a)

Submission status: Runtime Error

Solution code:
n = int(input())
result = []
for i in range(n+1):
    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)
print(len(result) - len(no))

Submission status: Runtime Error

Solution code:
import math
n = input()
list1 = []
count = 0
for i in range(int(n)):
  list1.append(input())
  b=[]
  for x in list1[i]:
  	b.append(x)
  b.sort()
  list1[i] = ''
  for x in b:
    list1[i] += x
list1.sort()
sum = 0
count=1
for i in range(int(n)-1):
  if(list1[i] == list1[i+1]):
    count+=1
  else:
    sum += math.factorial(count)/2
    count=1
if(count != 1):
  sum += math.factorial(count)/2
count=1
print(int(sum))

Submission status: Runtime Error

Solution code:
import collections

m = dict()
def f(n):
    if n == 0:
        return 1
    elif n in m:
        return m[n]
    else:
        m[n] = n * 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():
    c += (f(v) // 2)

print(c)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

n = int(input())
s=[]
m={}
sum=0
for i in range(0,n):
    # print((list(input()))
    tmp = "".join(sorted(input()))
    if tmp in m:
        m[tmp]+=1
    else:
        m[tmp] = 1
for k in m:
    if m[k]>1:
        # print(m[k])
        # print("["+k)
        sum+=cmb(m[k],2)
print(sum)

Submission status: Runtime Error

Solution code:

import math

def combain(X, Y):
    return int(math.factorial(X) / math.factorial(Y))

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

ans = 0

for i in range(N):
    S.append(sorted(input()))

S.sort()

ans = 0

X = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        X += 1
    elif X > 1:
        C = combain(X, 2)
        X = 1
        ans += C

if X > 1:
    C = combain(X, 2)
    X = 1
    ans += C

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[input() for i in range(n)]
a=list(map(lambda x:list(x),a))
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if intersect_list(a[i],a[j])==len(col):
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
s = []
for i in range(n):
    s.append(sorted(list(input())))
cnt_ans = 0
s.sort()

while len(s):
    cnt = 0
    for i in range(1, len(s)):
        if s[0] == s[i]:
            cnt += 1
        else:
            break
    cnt = int((cnt+1) * (cnt) / 2)
    cnt_ans += cnt
    s = s[cnt+1:]
print(cnt_ans)

Submission status: Runtime Error

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
# for i in range(n):
#         for j in range(1,n-i):
#                 if s_l[i] == s_l[i+j]:
#                         cnt += 1
set_s_l = set(s_l)
l = []
for val in set_s_l:
        l.append(s_l.count(val))
for i in l:
        cnt += c(i,2)
print(cnt)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
ss = []
for i in range(1,N+1):
  ss.append(input())

sorted_ss     = []
sorted_ss_uni = []
for s in ss:
  sorted_s = []
  for char in s:
    sorted_s.append(char)
  sorted_s.sort()
  sorted_ss.append(sorted_s)
  if sorted_s not in sorted_ss_uni:
    sorted_ss_uni.append(sorted_s)
    
n_anagrams = 0
for sorted_s_uni in sorted_ss_uni:
  nana     = sorted_ss.count(sorted_s_uni)
  if nana > 1:
      nanapair = cmb(nana,2)
      n_anagrams += nanapair
print(int(n_anagrams))

Submission status: Runtime Error

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

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    s = defaultdict(int)
    for _ in range(N):
        si = tuple(sorted(input()))
        s[si] += 1

    from functools import lru_cache

    @lru_cache(maxsize=None)
    def c(n,k): 
        return 1 if(k<=0 or n<=k) else ( c(n-1, k-1) + c(n-1, k) ) %4

    ans = 0
    for i in s.values():
        if i == 1:
            continue
        ans += c(i, 2)
    
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = input()
s = list(map(str,input().split()))
ans=0
def anagram(si,sj):
    for si_i in si:
        sj = sj.replace(si_i,"",1)
    if sj=="":
        return 1
    else:
        return 0
for i in range(int(N)):
    for j in range(i+1,int(N)):
        if anagram(s[i],s[j]):
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N; cin >> N;
    string tmp;
    string s[N]; REP(i, N) {
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        s[i] = tmp;
    }

    ll ans = 0;
    for (ll i = 0; i<N; ++i) {
        for (ll j = 0; j<N; ++j) {
            if (j<=i) continue;
            if (s[i] == s[j]) ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Submission status: Runtime Error

Solution code:
n=int(input())

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

ans=len(l)-len(list(set(l)))
print(ans)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
ss = []
for i in range(1,N+1):
  ss.append(input())

sorted_ss     = []
sorted_ss_uni = []
for s in ss:
  sorted_s = []
  for char in s:
    sorted_s.append(char)
  sorted_s.sort()
  sorted_ss.append(sorted_s)
  if sorted_s not in sorted_ss_uni:
    sorted_ss_uni.append(sorted_s)

print(sorted_ss)
print(sorted_ss_uni)
    
n_anagrams = 0
for sorted_s_uni in sorted_ss_uni:
  nana     = sorted_ss.count(sorted_s_uni)
  if nana > 1:
      nanapair = a = cmb(nana,2)
      n_anagrams += nanapair
print(int(n_anagrams))

Submission status: Runtime Error

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

counter     =   0

for i in range(N):
    S   =   sorted(input())
    for j in range(len(A)):
        if(A[j] == S):
            counter += 1
            continue
    A.append(S)
print(counter)

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)
    xx, yy = np.meshgrid(idx, idx)
    same = sorted_strings[xx] == sorted_strings[yy]
    same2 = np.all(same, axis=2) * (1 - np.tri(strings_len))
    return int(np.sum(same2))


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


main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n=input()
strings = []
for i in range(n):
    strings.append(input())
dic = {}
for l in [Counter(s) for s in strings]:
    ll = str(l)
    if ll in dic:
        dic[ll] += 1
    else:
        dic[ll] = 0
res = 0
for k , v in dic.items():
    res += v * (v + 1)/2
print(res)

Submission status: Runtime Error

Solution code:
from math import factorial
import collections

n = int(input())

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

cs = collections.Counter(ss)
l = list(cs.values())
l.sort(reverse=True)

c = 0
for i in l:
	if i > 1:
		a = factorial(i) / factorial(2) / factorial(i - 2)
		c+=a
	elif i == 1:
		print(int(c))
		exit()
print(int(c))

Submission status: Runtime Error

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

import collections
import math

c = collections.Counter(S)
ans = 0
for i in c.values():
    ans += math.factorial(i)/math.factorial(2)
print(int(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)):
        if intersect_list(a[i],a[j])==len(col):
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    n = int(input())
    dict_list = []
    for i in range(n):
        dict = {}
        s = input()
        for i in s:
            if i in dict:
                dict[i] = dict[i] + 1
            else:
                dict[i] = 1
        dict_list.append(dict)

    count = 0
    check = [0]*n
    for i in range(n):
        tmp=0
        for j in range(i,n):
            if j > i and check[j] ==0:
                if dict_list[i] == dict_list[j]:
                    check[j]=1
                    tmp=tmp+1
        if tmp >0:
            count = count + math.factorial(tmp)
    print(count)

Submission status: Runtime Error

Solution code:
def conv(s):
  return ord(s) - 97

n = int(input())

ls = []
for i in range(n):
    ls.append(input())

lss = []
for i in range(n):
    ll = [0] * 25
    lss.append(ll)

for i in range(n):
    for j in range(10):
        lss[i][conv(ls[i][j])]+=1

ans = 0
for i in range(n):
    for j in range(n-i-1):
        if lss[i] == lss[i+j+1]:
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

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


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

s.sort()

ans = 0

mae = s[0]
count = 0

for i in range(1,N):
    if mae == s[i]:
        count += 1
    else:
        if count != 0:
            ans += cmb(count+1, 2)
        else:
            pass
        count = 0
    mae = s[i]

if count != 0:
    ans += cmb(count+1,2)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    a="".join(a)
    sortlist.append(a)
    
def kaijyo(n):
    ans=1
    for i in range(2,n+1):
        ans*=i
    return ans

count=0
sortlist.sort()


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    count+=kaijyo(times)*kaijyo(times-2)/2
    
print(count/2)