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:
x = list(map(str, input().split())) #入力

n = int(x[0]) #最初の文字
z = x[1:] #最初の数字削除

# alphabet（list）をカウントする関数
def word_count(alphabet):
    res_dic = {}
    for i in alphabet:
        test = i in res_dic.keys() 
        if test == False: 
            res_dic[i] = 1
        elif test == True:
            plus = res_dic[i] + 1
            res_dic[i] = plus
    return res_dic

# 全ての文字をカウント
res = []
for i in z:
    alphabet = list(i)
    res.append(word_count(alphabet))

# 全ての組み合わせをチェック
record = []
for i in res:
    for j in res:
        if i == j:
            record.append(1)
        elif i != j :
            record.append(0)
x = list(map(str, input().split())) #入力

n = int(x[0]) #最初の文字
z = x[1:] #最初の数字削除

# alphabet（list）をカウントする関数
def word_count(alphabet):
    res_dic = {}
    for i in alphabet:
        test = i in res_dic.keys() 
        if test == False: 
            res_dic[i] = 1
        elif test == True:
            plus = res_dic[i] + 1
            res_dic[i] = plus
    return res_dic
print(4)

Submission status: Runtime Error

Solution code:
n=int(input())
T=[]
for i in range(n):
  T.append(tuple(sorted(input().split())))
U=set(T)
cnt=[]
for j in range(len(U)):
  cnt.append(T.count(U[j]))
conb=[]
for k in range(len(U)):
  conb.append(cnt[k]*(cnt[k]-1)/2)
print(sum(conb))

Submission status: Runtime Error

Solution code:
n=int(input())
S=[]
for i in range(n):
  S.append(sorted(input().split()))
print(n-len(set(S)))

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
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())
lst_s = ["".join(sorted(input())) for _ in range(N)]
lst_s.sort()

cnt_s = Counter(lst_s)

ans = 0
for v in cnt_s.values():
    if v == 1:
        continue
    else:
        ans += cmb(v, 2)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb


N = int(input())
lst_s = ["".join(sorted(input())) for _ in range(N)]
lst_s.sort()
# print(lst_s)


cnt_s = Counter(lst_s)
# print(cnt_s)

ans = 0
for v in cnt_s.values():
    if v == 1:
        continue
    else:
        ans += comb(v, 2, exact=True)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb


N = int(input())
lst_s = ["".join(sorted(input())) for _ in range(N)]
lst_s.sort()


cnt_s = Counter(lst_s)


ans = 0
for v in cnt_s.values():
    if v == 1:
        continue
    else:
        ans += comb(v, 2, exact=True)
print(ans)

Submission status: Runtime Error

Solution code:
# your code goes here
list1 = []
sum1 = 0
a = int(input())
for i in range(a):
	b = input()
	list1.append(b)
for j in range(a):
	for i in range(j):
		if list1[j].count(a)>=list1[j-1].count(a):
			sum1 += 1
		elif list1[j].count(e)>=list1[j-1].count(e):
			sum1 += 1
print(sum1)

Submission status: Runtime Error

Solution code:
n = int(input())
li = [sorted(list(input())) for a in range(n)]
ans = 0
le = len(li)
while le != 1:
  t = li[0]
  cnt = 0
  for n, w in reversed(list(enumerate(li[1:]))):
    if t == w:
      cnt += 1
      li.pop(n + 1)
  ans += cnt * (cnt + 1) / 2
  li.pop(0)
  le = len(li)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
check = {}
lst = []

for _ in range(n):
  s = list(input())
  s.sort()
  s = "".join(s)
  lst.append(s)
  try:
    check[s]+=1
  else:
    check.update({s:1})
  
cnt=0
check_set = set(lst)
for c in check_set:
  temp_cnt = check[c]
  cnt +=  temp_cnt*(temp_cnt-1)/2
print(int(cnt))

Submission status: Runtime Error

Solution code:
import collections

def solve(n, s):
    records = []
    D = {}
    for i in range(n):
        counter = collections.Counter(s[i])
        k = ",".join([f"{k}:{v}" for k, v in sorted(counter.items())])
        if not k in D:
            D[k] = 0
        D[k] += 1
    res = 0
    for k, v in D.items():
        res += v * (v-1) // 2
    return res

n = int(input())
s = [input() for i in range(n)]
print(solve(n, s))

Submission status: Runtime Error

Solution code:
n = int(input())
l = list()
c = 0
for i in range(1,n+1):
  l.append(sorted(input()))
  for j in range(1,i):
    if l[i] == l[j]:
      c = c+1
    else:
      Continue

print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list()
c = 0
for i in range(1,n+1):
  l.append(sorted(input()))
  for j in range(1,i):
    if l[i] == l[j]:
      c = c+1
    else:
      Continue

print(j)

Submission status: Runtime Error

Solution code:
n = int(input())
anagram =[]
ans = 0
for _ in range(n):
    s = ''.join(input())
    anagram.append(s)
count_ana = Counter(anagram)
for v in count_ana.values():
    ans += v * (v + 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for _ in range(N)]
A = []
cnt = 0
for k in S:
   A.append(''.join(sorted(k)))
   print(A)
for i in A[:]:
    cnt += A.count(i) - 1
    A.remove(i)
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[None for i in range(n)]
for i in range(n):
  l[i]=sorted(input())
print(len(set(l)))

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
from scipy.misc import comb
# print(comb(n,r,exact=True))
count = 0
for i in range(len(a)):
    count += comb(a[i],2,True)
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
# スペース区切りの整数の入力
ar = []
for i in range(n):
  ar.append("".join(list(input()).sort()))

count = 0

for i in range(n):
  count = count + ar[i+1:].count(ar[i])

print(count)

Submission status: Runtime Error

Solution code:
import sys
 
a = []
for l in sys.stdin:
    if l == '\n' or l == '\r' or l == '\r\n':
        break
    else :
        a.append(l)
 
target = a[int(a[0])]
num = 0

sortedA = []

for i in a:
    sortedA.append(''.join(sorted(a[i])))
sortedA.pop(0)

for i in range(1, len(a) - 1):
    for j in range(i + 1, len(a)):
        flag = False
        if sortedA[i]==sortedA[j]:
            flag = True
        else:
            flag = False
        if flag:
            num = num + 1
print(num)

Submission status: Runtime Error

Solution code:
n=int(input())
d={}
for i in range(n):
  a=sorted(input())
  if a in d.keys():
    d[a]+=1
  else:
    d[a]=1
l=list(d.values())
c=0
for i in l:
  c+=(i*(i-1))//2
print(c)

Submission status: Runtime Error

Solution code:

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


strings = [''.join(sorted(s)) for s in strings]
strings.sort()

for s in strings:
    print(s)


hashMap = {}
for string in strings:
    if string not in hashMap:
        hashMap[str(string)] = 1
    else:
        hashMap[str(string)] += 1


sum = 0

for key in hashMap:
    v = hashMap[key]
    sum += v * (v - 1) / 2
print(int(sum))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
words = []
for i in range(N):
    words.append(input())
w_s = []
for w in words:
    w1 = w + "あ"
    w1 = list(w1)
    w1.sort()
    l = [0]
    k = ""
    for i in range(1,len(w1)):
        if w1[i] != w1[i-1]:
            l += [i]
            k += str(l[-1]-l[-2]) + w1[i-1]
    w_s += [k] 
n_l = []
for i in list(set(w_s)):
    n = w_s.count(i)
    n_l += [n]
    n_c = [math.factorial(p)/(2*math.factorial(p-2)) for p in n_l]
print(int(sum(n_c)))

Submission status: Runtime Error

Solution code:
from math import factorial
n=int(input())
count=0
d={}
for i in range(n):
  b=list(input())
  b.sort()
  c=str(b)
  if c in d.keys():
    d[c]+=1
  else:
    d[c]=1
for i in d.values():
  if i>1:
    count+=factorial(i)/factorial(2)/factorial(i-2)
print(int(count))

Submission status: Runtime Error

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

mydict = {}

for i in range(N):
  a[i] = list(a[i])
  b = a[i].sort()
  tmp = ','.join(a[i]).strip(',')

  if tmp in mydict:
    mydict[tmp] += int(mydict[tmp]) + 1
  else:
    mydict[tmp] = 0

  print(mydict)

num = 0

for j in mydict:
  num += int(mydict[j])

print(num)

Submission status: Runtime Error

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

mydict = {}

for i in range(N):
  a[i] = list(a[i])
  b = a[i].sort()
  tmp = ','.join(a[i]).strip(',')

  if tmp in mydict:
    mydict[tmp] += int(mydict[tmp]) + 1
  else:
    mydict[tmp] = 0

  print(mydict)

Submission status: Runtime Error

Solution code:
import sys

a = []
for l in sys.stdin:
    if l == '\n':
        break
    else :
        a.append(l)

target = a[int(a[0])]
num = 0
for i in range(1, len(a) - 1):
    for j in range(i + 1, len(a)):
        flag = False
        iStrSorted = ''.join(sorted(a[i]))
        jStrSorted = ''.join(sorted(a[j]))]
        if iStrSorted==jStrSorted:
            flag = True
        else:
            flag = False
        if flag:
            num = num + 1
print(num)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial
n = int(input())
lst = [input() for _ in range(n)]
for i in range(n):
    lst[i] = str(sorted(lst[i])).replace(', ','').replace("'",'').replace('[','').replace(']','')
numlst = Counter(lst)
ans = 0
for v in numlst.values():
    if v >= 2:
        ans += factorial(v) / factorial(2) / factorial(v-2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial

n = int(input())
lst = [input() for _ in range(n)]
for i in range(n):
    lst[i] = str(sorted(lst[i])).replace(', ','').replace("'",'').replace('[','').replace(']','')

numlst = Counter(lst)

ans = 0
for v in numlst.values():
    if v==1:
        continue
    else:
        ans += factorial(v) / factorial(2) / factorial(v-2)
print(int(ans))

Submission status: Runtime Error

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

def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

def func(x):
    if x < 1:
        return x
    return x + func(x-1)

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 0

for key in words.keys():
    words[key] = func(words[key])

print(sum(words.values()))

Submission status: Runtime Error

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

def my_sort(word):
    sorted_word_list = sorted(word)
    sorted_word = ""
    for letter in sorted_word_list:
        sorted_word += letter
    return sorted_word

def func(x):
    if x < 1:
        return x
    return x + func(x-1)

n = int(input())
words = {}
for i in range(n):
    word = my_sort(input())
    if word in words.keys():
        words[word] += 1
    else:
        words[word] = 0

for key in words.keys():
    words[key] = func(words[key])

print(sum(words.values()))

Submission status: Runtime Error

Solution code:
N = int(input())
S=[]
for n in range(N):
    S.append(input())
Slist = []
for s in S:
    lists = list(s)
    listss = sorted(lists)
    Slist.append(listss)
def isAna2(Sl,sl):
    boolcount = True
    for i,Sli in enumerate(Sl):
        if Sli != sl[i]:
            boolcount = False
            break
    return boolcount
import copy
def countAna(Slist):
    if len(Slist) == 1:
        return 0
    else:
        groupcount = 1
        Sl = Slist[0]
        del Slist[0]
        newSlist = copy.deepcopy(Slist)
        for i,sl in enumerate(Slist):
            if isAna2(Sl, sl) == True:
                groupcount += 1
                del newSlist[i]
        if groupcount == 1:
            count = 0
        else:
            count = int(groupcount*(groupcount-1)/2)
        return count + countAna(newSlist)
print(countAna(Slist))

Submission status: Runtime Error

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

for i in range(n):
  s1 = input()
  
  arr.append(sorted(s1))

sarr = list(set(arr))

cnt = 0

for i in sarr:
  cnt+= arr.count(i)
  
print(cnt)

Submission status: Runtime Error

Solution code:
N=int(input())
word=[]
for i in range(N):
  word.append(input())
  
alphalist=["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"]
numlist=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]


alphalist=[]
alpha=[[] for i in range(N)]
for i in range(N):
  word0=word[i]
  for v in range(10):
    alpha[i].append(word0[i])
  alpha[i].sort()
  alphalist.append(alpha[i])


number=0
for i in range(N):
  freq=alphalist.count(alphalist[i])
  if freq!=1:
    number0=(freq*(freq-1))/2
    number0=number0/freq
    number+=number0
  
print(int(number))

Submission status: Runtime Error

Solution code:
n = int(input())
S = ["".join(sorted(input())) for _ in range(n)]
d = []
for i in S:
  d.setdefault(i, 0)
  d[i] += 1
ans = 0
for value in d.values:
  ans = value * (value) / 2
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
word_l = list()
for _ in range(n):
  word = ''.join(sorted(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(word_counter.values()) - n)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
word_l = list()
for _ in range(n):
  word = ''.join(sort(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(word_counter.values()) - n))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
word_l = list()
for _ in range(n):
  word = ''.join(sort(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(word_counter.values()) - n)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for i in range(n)]
s = dict(s)
count = 0
for i in range(len(s)):
    s[i] = "".join(sorted(s[i]))
    if s[i] in s[:i]:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
for _ in range(n):
  word = ''.join(sort(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(word_counter.values()) - n)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = 5
for _ in range(n):
  word = ''.join(sort(list(input())))
  word_l.append(word)
  
word_counter = Counter(word_l)
print('{}'.format(sum(word_counter.values()) - n)

Submission status: Runtime Error

Solution code:
import sys

a = []
for l in sys.stdin:
    if l == '\n':
        break
    else :
        a.append(l)

target = a[int(a[0])]
print(target)

outNum = []
i1 = 0
for item in range(0, int(a[0]) - 1):
    if i1 != 0:
        for i in range(0, len(target) - 1):
            flag = False
            if target.count(target[i]) == item.count(target[i]):
                print(item)
                flag = True
            else:
                break
        if flag:
            outNum.append(item)
    i1 = i1 + 1
    flag = False
print(len(outNum))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from scipy.special import comb

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

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

unique_s = set(s)

output = 0
for k in unique_s:
     if s.count(k) != 1:
        output += int(comb(s.count(k), 2))

print(output)

Submission status: Runtime Error

Solution code:
import collections  

n = int(input())

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

cnt = 0
for (c, m) in collections.Counter(s).items():
    ccnt += m * (m - 1) / 2
    
print(cnt)

Submission status: Runtime Error

Solution code:
import collections  

n = int(input())

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

def f(a):
    if a == 0:
        return 1
    else:
        return a * f(a - 1)

cnt = 0
for (c, m) in collections.Counter(s).items():
    if 1 < m:
        combi = f(m - 1)
        cnt += combi
    
print(cnt)

Submission status: Runtime Error

Solution code:
import collections  

n = int(input())

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

def f(a):
    if a == 0:
        return 1
    else:
        return a * f(a - 1)
  
cnt = 0
for (c, m) in collections.Counter(s):
	combi = f(m - 1)
    if combi != 1:
        cnt += combi
    
print(cnt)

Submission status: Runtime Error

Solution code:
import collections  

n = int(input())

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

def f(a):
  if a == 0:
    return 1
  else:
    return a * f(a - 1)
  
cnt = 0
for (c, m) in collections.Counter(s):
	combi = f(m - 1)
    if combi != 1:
      cnt += combi
    
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())

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

print(n - len(set(s)))

Submission status: Runtime Error

Solution code:
n = int(input())

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

print(n - len(set(s)))

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
cnt = 0

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

for i in range(N):
    for j in range(i+1, N):
        for k in range(len(s[i])):
          	tmp = s[i]
            tmp = s[i].replace(s[j][k], "")
        if tmp == "":
            cnt += 1
        else:
            continue
            
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
ss=[input() for i in range(n)]
d={}
for i in ss:
    a=[c for c in ss]
    a.sort()
    a="".join(a)

    if a in d:
        ans+=d[a]
        d[a]+=1
    
    else:
        d[a]=1

print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

N=int(input())
t=tuple([''.join(sorted(list(input()))) for _ in range(N)])
Dic = {}
ans = 0
for i in range(N):
    if t[i] in Dic:
        Dic[t[i]]+=1
    else:
        Dic[t[i]]=1
for k in tuple(Dic.keys()):
    if Dic[k]==1:
        pass
    else:
        comb(Dic[k], 2, exact=True)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial

N=int(input())
t=tuple([''.join(sorted(list(input()))) for _ in range(N)])
Dic = {}
ans = 0
for i in range(N):
    if t[i] in Dic:
        Dic[t[i]]+=1
    else:
        Dic[t[i]]=1
for k in tuple(Dic.keys()):
    if Dic[k]==1:
        pass
    else:
        ans+=factorial(Dic[k]) / factorial(2) / factorial(Dic[k]-2)

print(int(ans))

Submission status: Runtime Error

Solution code:
count = int(input())

for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0

print(sum(str_data.values()))

Submission status: Runtime Error

Solution code:
count = int(input())
 
str_data = {}
 
for i in range(count):
  judge_str = ''.join(sorted(input()))
  if judge_str in str_data:
    str_data[judge_str] += 1
  else:
    str_data[judge_str] = 0
 
print(sum(str_data.values())

Submission status: Runtime Error

Solution code:
amap = {}
cnt = 0
n = int(input())
for i in range(n):
  s = "".join(sorted(input()))
  if s in amap:
    cnt += amap[s]
  amap[s] += 1

print(cnt)

Submission status: Runtime Error

Solution code:
def solve(string):
    n, *ss = string.split()

    d = defaultdict(int)
    for s in ss:
        s = "".join(sorted(s))
        if s in d.keys():
            d[s] += 1 + d[s]
    return str(sum(d.values()))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())
c = {}
for x in range(n):
    k = ''.join(sorted(input()))
    if k in c: c[k] += 1
    else: c[k] = 1
print(sum([int(factorial(n) / factorial(2) / factorial(n - 2)) for n in c.values() if n != 1]))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)
def intinput():return map(int,input().split())

factmemo={0:1} #階乗
def fact(n):
    if n in factmemo:
        return factmemo[n]
    k = n*fact(n-1)
    factmemo[n]=k
    return k

def comb(a,b): return fact(a)//(fact(a-b)*fact(b)) #組み合わせ


n=int(input())
s={}
for i in range(n):
    t=list(input())
    t.sort()
    t="".join(t)
    try:
        s[t]+=1
    except:
        s[t]=1
ans=0
for i in s.values():
    if i!=1:
        ans+=comb(i,2)
print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())
cnt = 0
b = [input() for i in range(a)]


for x in range(a):
  c = b[0]
  d = b[1]
  for y in range(10):
    if c[0] in d:
      d.lstrip(c[0])
      if y == 9:
        cnt += 1
    else:
      b.pop(0)
      break

print(cnt)

Submission status: Runtime Error

Solution code:
def z(a,b, c):
    if a==b:c+=1

n=int(input())
ss=[]
ss = [set(list(input())) for i in range(n)]
c=0
[z(ss[i], ss[ii]) for i in range(n) for ii in range(i+1,n,1)]
print(c)

Submission status: Runtime Error

Solution code:

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

word = {}
cnt = 0
for i in s:
    i = sorted(i)
    time = word.get(i, 0)
    cnt += time
    word[i] = time + 1
print(cnt)

Submission status: Runtime Error

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

for l in range(N):
  S[l].sort()
  T[l] = ''.join(S[l])

ans = 0
for j in range(N):
  for k in range(j+1,N):
    if S[j][0] == S[k][0]:
      if S[j][N-1] == S[k][N-1]:
        if T[j] == T[k]:
          ans += 1

print(ans)

Submission status: Runtime Error

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

for l in range(N):
  S[l].sort()
  T[l] = T[l].append(''.join(S[l]))

ans = 0
for j in range(N):
  for k in range(j+1,N):
    if S[j][0] == S[k][0]:
      if S[j][N-1] == S[k][N-1]:
        if T[j] == T[k]:
          ans += 1


          
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)
import collections
from math import factorial
n = int(input())
A = [str(input()) for _ in range(n)]
for i in range(len(A)):
    A[i] = "".join(sorted(A[i]))
A = sorted(A)
temp = A[0]
counter = 1
ans = 0
for i in range(1,len(A)):
    if temp != A[i]:
        if counter >= 2:
            ans += factorial(counter) / factorial(2) / factorial(counter-2)
        temp = A[i]
        counter = 1
    else:
        counter += 1
if counter >= 2:
    ans += factorial(counter) / factorial(2) / factorial(counter-2)

print(int(ans))

Submission status: Runtime Error

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

for l in range(N):
  S[l].sort()

ans = 0
for j in range(N):
  for k in range(j+1,N):
    if S[j][0] == S[k][0]:
      if S[j][N-1] == S[k][N-1]:
        if ''.join(S[j]) == ''.join(S[k]):
          ans += 1


          
print(ans)

Submission status: Runtime Error

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

for l in range(N):
  S[l].sort()

ans = 0
for j in range(N):
  for k in range(j+1,N):
    if S[j][0] == S[k][0]:
      if S[j][N-1] == S[k][N-1]:
      if (''.join(S[j]) == ''.join(S[k])):
        ans += 1
           
           
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)
import collections
from math import factorial
n = int(input())
A = [str(input()) for _ in range(n)]
for i in range(len(A)):
    A[i] = "".join(sorted(A[i]))
A = sorted(A)
C = collections.Counter(A)
ans = 0
for c in C.keys():
    if C[c] >= 2:
        ans += factorial(C[c]) / factorial(2) / factorial(C[c]-2)

print(int(ans))

Submission status: Runtime Error

Solution code:

import sys
sys.setrecursionlimit(4100000)
import collections
from math import factorial
n = int(input())
A = [str(input()) for _ in range(n)]
B = []
for a in A:
    B.append("".join(sorted(a)))
B = sorted(B)
C = collections.Counter(B)
ans = 0
for c in C.keys():
    if C[c] >= 2:
        ans += factorial(C[c]) / factorial(2) / factorial(C[c]-2)

print(int(ans))

Submission status: Runtime Error

Solution code:
    def main():
        n = int(input())
        s = [""] * n
        ans = 0
        for i in range(n):
            s[i] = SortString(input())
        s.sort()
        for i in range(n - 1):
            for j in range(i + 1, n):
                if s[i] == s[j]:
                    ans += 1
                else:
                    break
        print(ans)
     
     
    def SortString(text):
        return "".join(sorted(list(text)))
     
     
    if __name__ == '__main__':
        main()

Submission status: Runtime Error

Solution code:
N=int(input())
equal=0
ans=0
s=[list(input()) for _ in range(N)]
s10 = [i for i in range(10)]
i=0
t=['x' for i in range(N)]
for i in range(N):
    s10 = [x for x in range(10)]
    ti = [['xx',0] for x in range(10)]
    for j in range(10):
        if j in s10:
            ti[j][0]=s[i][j]
            ti[j][1]=1
            for k in range(j+1,10):
                if s[i][j]==s[i][k]:
                    ti[j][1]=ti[j][1]+1
                    s10.remove(k)
                else:
                    pass

        else:
            pass
        j=j+1
    ti = [[ti[a][0],ti[a][1]] for a in range(10) if not ti[a][1]==0]
    t[i] =ti
    i+=1

for i in range(N):
    for j in range(i+1,N):
        equal = 0
        for k in range(len(t[i])):
            if t[i][k][0]==t[j][k][0] and t[i][k][1]==t[j][k][1]:
                equal +=1
            else:
                pass
        if equal == len(t[i]):
            ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
equal=0
ans=0
s=[list(input()) for _ in range(N)]
s10 = [i for i in range(10)]
i=0
t=['x' for i in range(N)]
for i in range(N):
    s10 = [x for x in range(10)]
    ti = [['xx',0] for x in range(10)]
    for j in range(10):
        if j in s10:
            ti[j][0]=s[i][j]
            ti[j][1]=1
            for k in range(j+1,10):
                if s[i][j]==s[i][k]:
                    ti[j][1]=ti[j][1]+1
                    s10.remove(k)
                else:
                    pass

        else:
            pass
        j=j+1
    ti = [[ti[a][0],ti[a][1]] for a in range(10) if not ti[a][1]==0]
    t[i] =ti
    i+=1

for i in range(N):
    for j in range(i+1,N):
        equal = 0
        for k in range(len(t[i])):
            if t[i][k][0]==t[j][k][0] and t[i][k][1]==t[j][k][1]:
                equal +=1
            else:
                pass
        print(equal)
        if equal == len(t[i]):
            ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
str = [input().sort for i in range(N)]
dict = {}
count = 0

print(str)

Submission status: Runtime Error

Solution code:
n  = int(input())
def s(i):
    s = input()
    a = []
    for m in range(0,10):
        a.append(s[m])
    a.sort()
    return a
k = 0
for i in range (0, n - 1):
    for j in range (i + 1, n):
        if s (i) == s(j):
            k = k + 1

print (k)

Submission status: Runtime Error

Solution code:
import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

f2 = sorted(["".join(sorted(list(f1[i]))) for i in range(len(f1))])
f3 = list(map(str, set(f2)))
f4 = [[i for i, e in enumerate(f2) if e == f3[j]] for j in range(len(f3))]
f5 = sum([math.factorial(len(f4[i]))for i in range(len(f4))])/2
print(round(f5))

Submission status: Runtime Error

Solution code:
import math
n1 = int(input())
#f1 = [list(map(int, input().split())) for _ in range(n1)]
f1 = [str(input()) for _ in range(n1)]

f2 = sorted(["".join(sorted(list(f1[i]))) for i in range(len(f1))])
f3 = list(map(str, set(f2)))
f4 = [[i for i, e in enumerate(f2) if e == f3[j]] for j in range(len(f3))]
f5 = sum([math.factorial(len(f4[i]))for i in range(len(f4))])/2
print(round(f5))

Submission status: Runtime Error

Solution code:
new_a = []

for k in range(n):
    a.append(str(input()))

for k in range(n):
    new_a.append( ''.join(list(sorted(a[k]))))

new_a.sort()

b = 0

for k in range(n-1):
    for m in range(k+1, n):
        if(new_a[k] == new_a[m]):
            b = b +1

print(b)

Submission status: Runtime Error

Solution code:
n = map(int, input())
a = []
new_a = []

for k in n:
    a[k] = map(str, input())

for k in n:
    new_a[k] = ''.join(list(reversed(a[k])))

sorted(new_a)

b = 0

for k in n:
    if(new_a[k] == new_a[k+1]):
        b = b +1
        
print(b)