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

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

 
for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))

ans = 0

if(i-len(l2) >=2):
    for e in range(i-len(l2)-1):
        n = ll.count(l2[e])
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
    print(int(ans))
else:
    print(i-len(l2))

Submission status: Runtime Error

Solution code:
def for_factorial(n):
    val = 1
    for i in range(2, n + 1):
        val *= i
    return int(val/2)
N = int(input())
l = []
_l = [] #並び替えた文字列の格納
_c = 0 #カウントの総合
#1)リストの作成
for i in range(N):
    l.append(input())
#2)文字列の並び替えを"_l"に格納
for s in l:
    one_l = [c for c in s]
    one_l.sort()
    _one_l = "".join(one_l)
    _l.append(_one_l)
#3)アナグラム判定
for s in _l[:]:
    c = _l.count(s)
    if c > 1:
        #cの組み合わせを考える c C 2 
        _c += for_factorial(c)
        _l.remove(s)
print(_c)

Submission status: Runtime Error

Solution code:
from math import factorial
 
 
i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []
 
 
for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0
#print(l2)
#print(len(l2))
 
if(i-len(l2)==1):
    print(i-len(l2))

if(i-len(l2) >=2):
    for e in range(i-len(l2)-1):
        n = ll.count(l2[e])
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
    print(int(ans))

Submission status: Runtime Error

Solution code:

N = int(input())

cnt_dict = {}

for i in range(N):
    s_str = "".join(sorted(str))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(comb(range(cnt), 2)))

print(total)

Submission status: Runtime Error

Solution code:
from math import factorial
 
 
i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []
 
 
for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0
#print(l2)
#print(len(l2))
 
if(i-len(l2)==1):
 print(i-len(l2))
 
if(i-len(l2) >=2):
    for e in range(i-len(l2)-1):
        n = ll.count(l2[e])
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
    print(int(ans))

Submission status: Runtime Error

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

list_s = []
for j in range(nn):
    #list_s.append(sorted(list(s[j])))
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(nn):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

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)]
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]], 2 )


print(count)

Submission status: Runtime Error

Solution code:
from math import factorial
 
 
i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []
 
 
for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0
#print(l2)
#print(len(l2))

if(i-len(l2)==1):
    print(i)
 
if(i-len(l2) =>2):
    for e in range(i-len(l2)-1):
        n = ll.count(l2[e])
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
    print(int(ans))

Submission status: Runtime Error

Solution code:

N = int(input())

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

cnt_dict = {}

for str in str_list:
    s_str = "".join(sorted(str))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

from math import factorial

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += factorial(cnt) / factorial(2) / factorial(cnt - 2)

print(int(total))

Submission status: Runtime Error

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

list_s = []
for j in range(n):
    #list_s.append(sorted(list(s[j])))
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

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)]
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]], 2 )


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) %10000) * k[i,j] %10000

k = np.zeros(0)
for j in range(N):
    i = 0
    k = np.append(k, np.size(l[l == l[i]]))
    l = l[l != l[i]]
    
    if l.size == 0:
        break

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:
lens = int(input())
hashes = sorted()[''.join(sorted(input())) for _ in range(lens)])
i = 0
j = 0
r = 0
ans = 0
while i < lens - 1:
    i += 1
    if hashes[i] == hashes[j]:
        r += 1
    else:
        ans += (r * (r + 1)) // 2
        r = 0
        j = i
ans += (r ( r + 1))//2
print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[100000];
int main()
{
  int n;
  ll ans = 0;
  cin >> n;
  for(int i = 0; i < n; i++)
  {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  sort(s,s+n);
  int ind=0;
  while(ind < n)
  {
    string t = s[ind];
    ll cnt = 1;
    ind++;
    while(ind < n && s[ind] == t)
    {
      cnt++;
      ind++;
    }
    ans += cnt * (cnt - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
S=[input() for _ in range(n)]
S=[''.join(sorted(i)) for i in S]
d={}
rslt=0
for s in S:
    if s in d:
        rslt+=d
        d+=1
    else:
        d[s]=1
print(rslt)

Submission status: Runtime Error

Solution code:

lens = int(input())
hashes = [''.join(sorted(input())) for _ in range(lens)]
i = 0
j = 0
r = 0
ans = 0
while i < lens - 1:
    i += 1
    if hashes[i] == hashes[j]:
        r += 1
    else:
        ans += (r * (r + 1)) // 2
        r = 0
        j = i
ans += (r ( r + 1))//2
print(ans)

Submission status: Runtime Error

Solution code:
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  print(sum([combinations_count(t, 2) for t in  c.values()]))
 
if __name__ == '__main__':
  main()

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) % 10000) * k[i,j] % 10000

k = np.zeros(0)
for j in range(N):
    i = 0
    k = np.append(k, np.size(l[l == l[i]]))
    l = l[l != l[i]]
    
    if l.size == 0:
        break

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:
n=int(input())
dic={}
for _ in range(n):
  s=input()
  s=sorted(s)
  if s not in dic:
    dic[s]=1
  else:
    dic[s]+=1
ans=0
for val in dic.values():
  ans+=val*(val-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(0)
for j in range(N):
    i = 0
    l = np.append(l, np.size(k[k == k[i]]))
    k = k[k != k[i]]
    
    if l.size == 0:
        break

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
S = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in S.keys():
        S[s] = 0
        continue
    print(S)
    S[s] += 1
    ans += S[s]
print(ans)

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():
    if i == 1:
      continue
    else:
      ans += math.factorial(i)/math.factorial(2)
print(int(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] += (2**(j+1)) * k[i,j]

k = np.zeros(0)
for j in range(N):
    i = 0
    k = np.append(k, np.size(l[l == l[i]]))
    l = l[l != l[i]]
    
    if l.size == 0:
        break

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:
n=int(input())
strings=[]
for i in range(n):
    strings.append(input())

allChars = 'abcdefghijklmnopqrstuvwxyz'
mapList =[]
charMap={}


for string in strings:
    for allChar in allChars:
        for char in list(allChar):
            charMap[char] = 0
    for char in list(string):
        charMap[char] += 1
    #pprint.pprint(charMap)
    charMapCopy = copy.deepcopy(charMap)
    mapList.append(charMapCopy)
#pprint.pprint(mapList)

count = 0
for i in range(len(mapList)):
    #pprint.pprint(mapList[i])
    for j in range(i):
        if mapList[i] == mapList[j]:
            #pprint.pprint(mapList[i])
            #pprint.pprint(mapList[j])
            #print(str(i)+ ' ' +str(j))
            count+=1
print(count)

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)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    s = list(sys.stdin.readlines())
    new_s=sorted(s)
    char_list=[]
    dic ={}
    for i in s:
        i = i.replace('\n','')
        new_s=sorted(i)
        new_s = ''.join(new_s)
        char_list.append(new_s)
        if new_s not in dic:
            dic[new_s] = 1
        else:
            dic[new_s] += 1
    # c = 0
    # for j in range(n):
    #     if char_list[j] in char_list[j+1:]:
    #         c+=char_list[j+1:].count(char_list[j])
    # print(c)

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

    # print(char_list)
    # print(dic)
    c=0
    # print(dic.values())
    for i in dic.values():
        c+=combinations_count(i, 2)
    print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
liss = {}
for i in range(N):
  s = input()
  a = sorted(s)
  if a in liss:
    liss[a] += 1
  else:
    liss[a] = 1

ans = 0
for cc in liss:
  ans = ans + (liss[cc] * (liss[cc] - 1) / 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
ans=0
N = int(input())
A=[]
for i In range(N):
    x=collections.Counter(list(input()))
    for s in A:
        if x==s:
            ans+=1
        else:
            A.append(x)
print(ans)

Submission status: Runtime Error

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

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

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


def count_anagram(s, str_list, total):
    cnt = 0
    tmp = []
    for i, t in enumerate(str_list):
        if s == t:
            cnt += 1
            tmp.append(i)
    if cnt > 0:
        total += (cnt+1) * cnt / 2
        for i in tmp:
            str_list.pop(i)

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
 
n = int(input())
strlist = []
for i in range(n):
    strlist.append(sorted(str(input())))
strlist.sort()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# 通らないのは分かっている

def alpha2num(alpha):
    num=0
    for index, item in enumerate(list(alpha)):
        num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1)
    return num-1

if __name__ == '__main__':
  lis = []
  lis_multi = []

  li = [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,103,107,109,113,127,131,137]
  a=int(input())
  for i in range(a):
    s=list(input())	
    lis.append(s)

  print(lis)


  for i in range(a):
    tmp = 1

    for j in range(10):
      print(tmp)
      tmp = tmp * li[alpha2num('z')]
    lis_multi.append(tmp) 

  print(lis_multi)

Submission status: Runtime Error

Solution code:
cnt = 0
l_sort = []
for i in range(n):
    if sorted(l[i]) in l_sort:
        cnt += 1
    l_sort.append(sorted(l[i]))

print(cnt)

Submission status: Runtime Error

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

from math import factorial


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


for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))

ans = 0
#print(l2)
#print(len(l2))
if(i-len(l2)-1==0):
    print(1)

if(i-len(l2)-1!=0):
    for e in range(i-len(l2)-1):
        n = ll.count(l2[e])
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
    print(int(ans))

#In : a
#Out: {'AA': 3, 'BB': 2}


# print(*l[0])
#print(l, end="")

Submission status: Runtime Error

Solution code:
d = {}
for i in range(n):
    temp = [0 for i in range(26)]
    s = input()
    for c in s:
        t = ord(c)-97
        temp[t]+=1
    for i in range(26):
        temp[i] = str(temp[i])
    txt = ",".join(temp)
    if txt not in d:
        d[txt] = 1
    else:
        d[txt] += 1
ans = 0
for k in d:
    if d[k] != 1:
        ans += d[k]*(d[k]-1)/2
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial
from collections import Counter
 
def conb(n):
    if n == 1:
        return 0
    else:
        return factorial(n) / factorial(2) / factorial(n - 2) 

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

print(int(sum([conb(i) for i in Counter(S).values()])))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = ["".join(sorted(input().split()[0])) for _ in range(n)]
cnt = {}
result = 0
for si in s:
    if si in cnt:
        result += cnt[si]
        cnt[si] += 1
    else:
        cnt[si] = 1
print(result

Submission status: Runtime Error

Solution code:
N=int(input())
dic={}
for i in range(N):
    k="".join(sorted(list(input())))
    if k in dic:
        dic[k]+=1
    else:
        dic[k]=1
c=0
for i in dic:
    c += i*(i-1)

print(c//2)

Submission status: Runtime Error

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

ans = 0
for cc in liss:
  ans = ans + (liss[cc] * (liss[cc] - 1) / 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
liss = []
for i in range(N):
  s = input()
  a = s.sorted()
  if a in liss:
    liss[a] += 1
  else:
    liss[a] = 1

ans = 0
for cc in liss:
  ans = ans + (liss[cc] * (liss[cc] - 1) / 2)
print(int(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())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		
ans = 0
for v in dicS.values():
	ans += cmb(v, 2)
	
print(ans)

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
 
n = int(input())
strlist = []
for i in range(n):
    strlist.append(sorted(str(input())))
strlist.sort()

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

Submission status: Runtime Error

Solution code:

def anagram(list1, list2):

    anagramFlg = 1

    for i in range(len(str)):
        if list1[i] != list2[i]:
            anagramFlg = 0
            break

    return anagramFlg


n = int(input())

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

# print(inputList)

sortedList = []
for i in range(n):
    tmpList = list(inputList[i])
    tmpList.sort()
    sortedList[i] = tmpList

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        if anagram(sortedList[i], sortedList[j]) == 1:
            cnt += 1

print(cnt)

Submission status: Runtime Error

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

ab = "abcdefghijklmnopqrstuvwxyz"
ab_dict = {}
for i,c in enumerate(ab):
    ab_dict[c] = i

def count_c(s):
    count_list = [0]*26
    sum_11 = 0
    for c in s:
        count_list[ab_dict[c]] += 1
    for i in range(26):
        sum_11 += count_list[i] * (11**i)
    return sum_11

sc_list = []
for s in s_list:
    sc = count_c(s)
    # print(sc)
    sc_list.append(sc)


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

ans = 0
sc_list.sort()
current = 0
k = {}
for i,sc in enumerate(sc_list):
    if sc in k.keys():
        k[sc] += 1
    else:
        k[sc] = 1
for k,v in k.items():
    ans += c(v)

print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

N = int(input())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		
ans = 0
for v in dicS.values():
	ans += comb(v, 2, exact=True)
	
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
 
n = int(input())
strlist = []
for i in range(n):
    strlist.append(sorted(str(input())))
strlist.sort()

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
 
n = int(input())
strlist = []
for i in range(n):
    strlist.append(sorted(str(input())))
strlist.sort()

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

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 = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        abs = cmb(aas,2)
        ans += int(abs)
print(ans)

Submission status: Runtime Error

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

from math import factorial


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


for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
print(i-len(l2))

ans = 0

for e in range(i-len(l2)-1):
    n = ll.count(l2[e])
    a = factorial(n) / factorial(2) / factorial(n - 2)
    ans += a

print(int(ans))

Submission status: Runtime Error

Solution code:

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

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

print(count/2)

Submission status: Runtime Error

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

N = int(raw_input())
li = list(map(int, input().split()))

for i in range(N):
    sl.append("".join(sorted(li[i])))

sl.sort()

c = collections.Counter(sl)

print(N - (len(c)-1))

Submission status: Runtime Error

Solution code:
N=int(input())
lst=[]
for i in range(N):
  text=input()
  lst=lst+[sorted(text)]
lst=sorted(lst)      
count=0
i=0
while(i<N):
  j=1
  while(lst[i]==lst[i+j]):
    count=count+j
    j=j+1
    if (i+j >= N):
      break
  i=i+j
print(count)

Submission status: Runtime Error

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

n = int(input())
s = [ input() for i in range(n)]
count = 0
x = [sorted(i) for i in s]
_x = sorted(x)

for i in range(n-1):
  	tmp = -x[i]
    for j in range(i+1,n):
        if tmp == _x[j]:
            count += 1
        else:
            break

print(count)

Submission status: Runtime Error

Solution code:
def hoge(n):
    if n == 1:
        return 1
    else:
        return n * hoge(n-1)

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

count = 0
c = 0
t = []
for i in range(n - 1):
    if i not in t:
        for j in range(n - i - 2):
            if s[i] == s[j]:
                c += 1
                t.append(j)
        count += hoge(c + 1) // 2
        c = 0
    
print(count)

Submission status: Runtime Error

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

total = 0
for i in range(N):
    t = sorted(s[i])

for i in range(N):
    for j in range(N):
        if t[i]  == t[j] and i != j:
            total += 1
print(total)

Submission status: Runtime Error

Solution code:
a=input()
mo="abcdefghijklmnopqrstuvwxyz"
re=[]
ke={]
for i in range(a):
  re.append(input())

for j in range(a):
    ke.append([])
   for k  in range(26):
     co=0
      for l in range(10):
          if re[j][l] ==mo[k]:
            co=co+1
      ke[j].append(co) 

cou=0

for m in range(a):
   for n in range(a):
       if m>n:
         for o in range(26):
            if ke[m][o]!=ke[n][o]:
                break:
            if o==25:
               cou=cou+1

print(count)

Submission status: Runtime Error

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

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

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

    dellist(l, li)

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

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N, M = [int(n) for n in input().split()]
    B = [(0, 0)]*N
    for i in range(N):
        a, b = [int(n) for n in input().split()]
        B[i] = (a, b)
    B = sorted(B, key= lambda x: -x[1])

    result = [0] * M

    for i in range(N):
        a, b = B[i][0], B[i][1]
        while True:
            if result[M-a] == 0:
                result[M-a] = b
                break
            else:
                a += 1
                if a > N:
                    break
    print(sum(result))
main()

Submission status: Runtime Error

Solution code:
import math

num = int(input())
emp = []
for i in range(num):
    emp.append(','.join(sorted(input())))
set_emp = set(emp)
emp2 = []
for i in set_emp:
    emp2.append(emp.count(i))
num = 0
for i in emp2:
     num += int(math.factorial(i) / 2)
print(num)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(raw_input())
li = list(map(int, input().split()))

for i in range(N):
    sl.append("".join(sorted(li[i])))

sl.sort()

c = collections.Counter(sl)

print(N - (len(c)-1))

Submission status: Runtime Error

Solution code:
import collections
from math import factorial

N = int(input())
s_list = []
ans = 0
for _ in range(N):
    s_list.append(''.join(sorted(list(input()))))
c = collections.Counter(s_list)
l = len(c.most_common())
for i in range(l):
    m = c.most_common()[i][1]
    if m > 1:
        a = factorial(m) / factorial(2) / factorial(m - 2)
        ans += a
    else:
        break
print(ans)

Submission status: Runtime Error

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

    return len(result)


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

Submission status: Runtime Error

Solution code:
import math

from collections import Counter


N = int(input())

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

print(sum([math.factorial(i) // math.factorial(i-2) // 2 for i in Counter(S).values()]))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[input() for j in range(n)]
for i in range(n)[:-1]:
	f=l[i]
	for s in range(n)[i1:]:
    	if s != i:
			a=[f[k] for k in range(10)]
            g=l[s]
            b=[g[c] for c in range(10)]
            q +=1 if sorted(a)==sorted(b)
print(q)