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 scipy.special import comb
n = int(input())
s = sorted([''.join(sorted(list(input()))) for i in range(n)])
ans = 0
tmp = 1
for i in range(1, n):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        ans += comb(tmp, 2, exact = True)
        tmp = 1
ans += comb(tmp, 2, exact = True)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [input() for _ in range(n)]
sep=''
b = [sep.join(sorted(a[i])) for i in range(n)]
dic = {letters: b.count(letters) for letters in set(b)}

ans=0
for i in dic.values():
  ans+=i*(i-1)//2
print(ans

Submission status: Runtime Error

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

def comb(n, r):
    def fact(n):
        if n <= 1:
            return 1
        else:
            return n*fact(n-1)
    return fact(n)//(fact(n-r)*fact(r))

ans = 0
count = 1
i = 0
s.sort()
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
    elif s[i] != s[i+1]:
        if count == 1:
            continue
        elif count > 1:
            ans += comb(count, 2)
            count = 1
if count > 1:
    ans += comb(count, 2)
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=sorted(["".join(sorted(input())) for i in range(N)])
ans=0
for p in range(n-1):
  for q in range(p+1,n):
    if s[p]=s[q]:
      ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

N = int(input())
s = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0


for i in range(N):
    s[i]=set(s[i])
    s[i].sort()
s.sort()

for i in range(1,N):

    if s[i]==s[i-1]:
        n += 1
        if i == N-1:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
            n = 0
print(ans)

Submission status: Runtime Error

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions

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 = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0
s.sort()
for i in range(N):
    s[i]=set(s[i])
for i in range(N-1):
    if s[i]==s[i+1]:
        n += 1
        if i == N-2:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
            n = 0
print(ans)

Submission status: Runtime Error

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

from math import factorial

def comb(a:int,b:int)->int:
    return factorial(a) / factorial(b) / factorial(a-b)
def main():
    dic = {}
    ans = 0
    for i in range(N):
        S[i].sort()
        tmp = "".join(S[i])
        S[i] = tmp

    for s in S:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for val in dic.values():
        if val > 1:
            ans += comb(val,2)

    print(int(ans))
    return

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#n = int(input())
#L = list(map(int, input().split()))
import math
import sys
import heapq
import fractions

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 = []
n = 0
for i in range(N):
    s.append(list(input()))
ans = 0
s.sort()
for i in range(N):
    s[i]=set(s[i])
for i in range(N-1):
    if s[i]==s[i+1]:
        n += 1
        if i == N-2:
            ans += cmb(n+1, 2)
    else:
        if n > 0:
            ans += cmb(n+1,2)
        n = 0
print(ans)

Submission status: Runtime Error

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

from scipy.misc import comb

def main():
    dic = {}
    ans = 0
    for s in S:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for val in dic.values():
        if val > 1:
            ans += comb(val,2)
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

from scipy.special import comb

def main():
    dic = {}
    ans = 0
    for s in S:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    for val in dic.values():
        if val > 1:
            ans += comb(val,2)
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

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

n = int(input().strip())

count_by_kw = Counter()
for i in range(n):
    count_by_kw[str(sorted(input().strip()))]+=1
    
c=list(count_by_kw.values())
for i in range(len(c)):
    c[i]=combinations_count(c[i],2)
print(sum(c))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N = int(input())
S = []
for i in range(N):
    S.append("".join(sorted(input())))
S.sort()
C = []
cnt = 1
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        C.append(cnt)
        cnt = 1
C.append(cnt)
ans = 0
for cnt in C:
    ans += int(comb(cnt,2))
print(ans)

Submission status: Runtime Error

Solution code:
N = [int(i) for i in input().split()]
S = []
d = {}
for i in range(N):
    S.append(input())
for s in S:
    new_s = "".join((sorted(s)))
    if new_s in d:
        d[new_s] += d[new_s]
    else:
        d[new_s] = 1
print(max(d.values()))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
li = [input() for x in range(N)]
ans = 0
di = dict()
for k in li:
    word = sorted(list(k))
    if word in di.keys():
        ans += di[word]
        di[word] += 1
    else:
        di[word] = 1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
li = [input() for x in range(N)]
ans = 0
wli = list()
for k in li:
    wli.append(sorted(list(k))
for i in range(N):
    word = wli[i]
    for j in range(i+1, N):
        comp = wli[j]
        if word == comp:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[None]*n
for i in range(n):
  s[i]=sorted(input())
import collections
c=collections.Counter(s)
ans=0
for v in c.valeus():
  ans+=(v*(v-1))//2
print(ans)

Submission status: Runtime Error

Solution code:
d={}
ans=0
for i in range(N):
    s=''.join(sorted(input()))
    if s in d:
        ans+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
s_=[sorted(input()) for i in range(N)]
s_.sort()

l=0
r=1
ans=0
while r < N:
    if s_[l]==s_[r]:
        ans+=math.factorial(r-l)
        r+=1
    else:
        l+=r
        r+=1

print(ans)

Submission status: Runtime Error

Solution code:
N =int(input())
#S = list(map(str, input().split()))
# S = list(map(str, input().split()))
S = []
for _ in range(H):
    S.append(input())

#受け取った文字列をアルファベットに並び替え
S=[''.join(sorted(a)) for a in S]

#バケットを作って、出現回数をカウント
count=[0]*(len(set(S)))
unique_S=list(set(S))
ans=0
for ele in S:
    count[unique_S.index(ele)]+=1
count=sorted(count,reverse=True)

#階乗のコード
def cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
#組み合わせのコード
def combination(n,c):
    a=(cor(n))/(cor(n-c)*cor(c))
    return a

for i in count:
    if i==1:
        break
    else:
        ans+=combination(i,2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
a = []
b = []
c = np.array([[0]*26,[0]*26,[0]*26])
count = 0
for i in range(N):
    a.append(input())

for i in range(N):
    b = a[i]
    for j in range(10):
        if b[j] == 'a':
            c[i][0] +=1
        elif b[j] == 'b':
            c[i][1] +=1
        elif b[j] == 'c':
            c[i][2] +=1
        elif b[j] == 'd':
            c[i][3] +=1
        elif b[j] == 'e':
            c[i][4] +=1
        elif b[j] == 'f':
            c[i][5] +=1
        elif b[j] == 'g':
            c[i][6] +=1
        elif b[j] == 'h':
            c[i][7] +=1
        elif b[j] == 'i':
            c[i][8] +=1
        elif b[j] == 'j':
            c[i][9] +=1
        elif b[j] == 'k':
            c[i][10] +=1
        elif b[j] == 'l':
            c[i][11] +=1
        elif b[j] == 'm':
            c[i][12] +=1
        elif b[j] == 'n':
            c[i][13] +=1
        elif b[j] == 'o':
            c[i][14] +=1
        elif b[j] == 'p':
            c[i][15] +=1
        elif b[j] == 'q':
            c[i][16] +=1
        elif b[j] == 'r':
            c[i][17] +=1
        elif b[j] == 's':
            c[i][18] +=1
        elif b[j] == 't':
            c[i][19] +=1
        elif b[j] == 'u':
            c[i][20] +=1
        elif b[j] == 'v':
            c[i][21] +=1
        elif b[j] == 'w':
            c[i][22] +=1
        elif b[j] == 'x':
            c[i][23] +=1
        elif b[j] == 'w':
            c[i][24] +=1
        elif b[j] == 'z':
            c[i][25] +=1
for i in range(N):
    for j in range(1,N):
        if i != j:
            if (c[i] == c[j]).all():
                count += 1
    
print(count)

Submission status: Runtime Error

Solution code:
import collections 
N = int(input())
dic = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}

ans = []
for i in range(N):
    si = input()
    a = [0]*26
    s = ""
    for j in range(10):
        a[dic[si[j]]] += 1
    for k in range(26):
        s = s + "a"
        s = s + str(a[k])
    ans.append(s)
c = collections.Counter(ans)
b = 0
for v in c.values():
    if v > 1:
        b += v*(v-1)//2
    else:
        pass
print(b)

Submission status: Runtime Error

Solution code:
import collections 
N = int(input())
dic = {"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9,"j":10,"k":11,"l":12,"m":13,"n":14,"o":15,"p":16,"q":17,"r":18,"s":19,"t":20,"u":21,"v":22,"w":23,"x":24,"y":25,"z":26}

ans = []
for i in range(N):
    si = input()
    a = [0]*26
    s = ""
    for j in range(10):
        a[dic[si[j]]] += 1
    for k in range(26):
        s = s + "a"
        s = s + str(a[k])
    ans.append(s)
c = collections.Counter(ans)
b = 0
for v in c.values():
    if v > 1:
        b += v*(v-1)//2
    else:
        break
print(b)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict
import math

N = int(input())
H = defaultdict(int)

for i in range(N):
    s = "".join(sorted(input()))
    H[s] += 1

ret = 0
for v in H.values():
    ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2))
print(ret)

Submission status: Runtime Error

Solution code:
#ABC137_C
N=int(input())
ans=[]
cnt=0
for _ in range(N):
    str_list=input()
    dic={}
    for i in range(10):
        if str_list[i] in dic:
            dic[str_list[i]]+=1
        else:
            dic[str_list[i]]=1
    ans.append(dic)
while len(ans)>1: 
    cnt+=temp=ans.count(ans.pop(0))
print(cnt)

Submission status: Runtime Error

Solution code:
a=0
while True:
    n=input()
    n =n.split(" ")
    b = int(n[0])
    if b>=2 and b<=100000:
        break

for i in range(b):
    for j in range(b):
        f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
        if n[i]==n[j]:
            c=0
        elif f(n[i]) == f(n[j]):
            a += 1
print(a)

Submission status: Runtime Error

Solution code:
from collections import Counter
a=0
while True:
    n=input()
    n =n.split(" ")
    b = int(n[0])
    if b>=2 and b<=100000:
        break

for i in range(b):
    for j in range(b):
        if n[i]==n[j]:
            c=0
        elif Counter(n[i]) == Counter(n[j]):
            a += 1
print(a)

Submission status: Runtime Error

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

    ans = 0
    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        
        if s in di:
            ans += di[s]

        di[s] += 1
    
    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
 
        _fact = [0] * (maxNum + 1)
        _fact[0] = _fact[1] = 1


        if divider != 0:
            _inv = [0] * (maxNum + 1)
            _finv = [0] * (maxNum + 1)
            _inv[0] = _inv[1] = _finv[0] = _finv[1] = 1
        else:
            _inv = []
            _finv = []

        for i in range(2, maxNum + 1):
            _fact[i] = _fact[i - 1] * i;
            if divider != 0:
                _fact[i] %= _divider
                _inv[i] = _divider - _inv[_divider % i] * (_divider // i) % _divider
                _finv[i] = _finv[i - 1] * _inv[i] % _divider

        self._fact = _fact
        self._inv = _inv
        self._finv = _finv

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
    cmb = Combination(max(di.values()), 0)

    ans = 0
    for num in di.values():
#        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())
ans_list = []
num_list = []
for i in range(n):
    s = list(input())
    s.sort()
    ans_list.append("".join(s))
ans_list.sort()
count = 1
for i in range(n-1):
    if ans_list[i] == ans_list[i+1]:
        count += 1
    else:
        num_list.append(count)
        count = 1
num_list.append(count)
ans = 0
for i in range(len(num_list)):
    if num_list[i] != 1:
        ans += factorial(num_list[i]) / factorial(2) / factorial(num_list[i]-2)
print(int(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input().sort() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if s[i]==s[j]:
      cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
	import collections
	import math
	N = int(input())
	s = list([str(input()) for i in range(N)])
	ans = []
	ans_pre = []
	
	for i in range(N):
		ans_pre.append(collections.Counter(s[i]))
	# print("ans_pre is")
	# print(ans_pre)
		def combinations_count(n,r):
			return math.factorial(n)// (math.factorial(n - r) * math.factorial(r))

	while len(ans_pre) > 0:
		ans_point = ans_pre.count(ans_pre[0])
		# print("ans_point is {}".format(ans_point))
		if ans_pre == 1:
			ans_pre = 0
		elif ans_pre == 1:
			ans_pre = 1
		else:
			ans_point = combinations_count(ans_point,2)

		ans.append(ans_point)
		ans_pre = [na for na in ans_pre if na!=ans_pre[0]]
		# print(ans_pre)


	print(sum(ans))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
	import collections
	import math
	N = int(input())
	s = list([str(input()) for i in range(N)])
	ans = []
	ans_pre = []
	
	for i in range(N):
		ans_pre.append(collections.Counter(s[i]))
	# print("ans_pre is")
	# print(ans_pre)
		def combinations_count(n,r):
			return math.factorial(n)// (math.factorial(n - r) * math.factorial(r))

	while len(ans_pre) > 0:
		ans_point = ans_pre.count(ans_pre[0])
		# print("ans_point is {}".format(ans_point))
		if ans_pre == 2:
			ans_pre = 1
		else:
			ans_point = combinations_count(ans_point,2)

		ans.append(ans_point)
		ans_pre = [na for na in ans_pre if na!=ans_pre[0]]
		# print(ans_pre)


	print(sum(ans))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
	import collections
	import math
	N = int(input())
	s = list([str(input()) for i in range(N)])
	ans = []
	ans_pre = []
	
	for i in range(N):
		ans_pre.append(collections.Counter(s[i]))
	# print("ans_pre is")
	# print(ans_pre)
	if ans_pre == 2:
		ans_pre = 1
	else:
		def combinations_count(n,r):
		return math.factorial(n)// (math.factorial(n - r) * math.factorial(r))

	while len(ans_pre) > 0:
		ans_point = ans_pre.count(ans_pre[0])
		# print("ans_point is {}".format(ans_point))
		
		ans_point = combinations_count(ans_point,2)

		ans.append(ans_point)
		ans_pre = [na for na in ans_pre if na!=ans_pre[0]]
		# print(ans_pre)


	print(sum(ans))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
	import collections
	import math
	N = int(input())
	s = list([str(input()) for i in range(N)])
	ans = []
	ans_pre = []
	
	for i in range(N):
		ans_pre.append(collections.Counter(s[i]))
	# print("ans_pre is")
	# print(ans_pre)

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

	while len(ans_pre) > 0:
		ans_point = ans_pre.count(ans_pre[0])
		# print("ans_point is {}".format(ans_point))
		
		ans_point = combinations_count(ans_point,2)	

		ans.append(ans_point)
		ans_pre = [na for na in ans_pre if na!=ans_pre[0]]
		# print(ans_pre)


	print(sum(ans))

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
	import collections
	import math
	N = int(input())
	s = list([str(input()) for i in range(N)])
	ans = []
	ans_pre = []
	
	for i in range(N):
		ans_pre.append(collections.Counter(s[i]))
	# print("ans_pre is")
	# print(ans_pre)

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

	while len(ans_pre) > 0:
		ans_point = ans_pre.count(ans_pre[0])
		# print("ans_point is {}".format(ans_point))
		
		ans_point = combinations_count(ans_point,2)	

		ans.append(ans_point)
		ans_pre = [n for n in ans_pre if n!=ans_pre[0]]
		# print(ans_pre)


	print(sum(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
d = 0
e = 0
for i in range(n):
    s = sorted(list(input()))
    a[i] = s
a.sort()
f = []
for b in a:
    if b in f:
        d += 1
    f.append(b)
print(d)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
d = 0
e = 0
for i in range(n):
    s = sorted(list(input()))
    a[i] = s
a.sort()
for b in a:
    del a[0]
    while b in a:
        del a[0]
        d += 1
        e += 1
    if e > 1:
        d += e - 1
    e = 0
print(d)

Submission status: Runtime Error

Solution code:
import collections
# 再帰制限に引っかかった場合に外す
import sys
sys.setrecursionlimit(100000)

nCr = {}


def cmb(n, r):
    if r == 0 or r == n:
        return 1
    elif r == 1:
        return n
    elif n < r:
        return 0
    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)]


def main():
    n = int(input())
    s_list = []
    for i in range(n):
        temp_s = sorted(list(input()))
        s_list.append(''.join(temp_s))

    counter = collections.Counter(s_list)
    ans = 0
    for key, value in counter.items():
        temp = cmb(value, 2)
        ans += temp


    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input()
ans=0
dic={}
for _ in range(n):
    s=input()
    s=sorted(s)
    s=''.join(s)
    if not s in dic.keys():
      dic[s]=1
    else: dic[s]+=1
for i in dic.values():
  ans+=i*(i-1)//2


print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
dic={}
for i in range(n):
    a=s[i].sort()
    if not a in dic.keys():
      dic[a]=1
    else: dic[a]+=1
for i in dic.values():
  ans+=i*(i-1)//2


print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
dic=dict()
for i in range(n):
    lst=sorted(list(s[i]))
    if dic[lst]:
      dic[lst]=1
    else: dic[lst]+=1
for i in dic.values():
  ans+=i*(i-1)

    
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
t = [input() for i in range(n)]
c_list = []
ans = 0

for i in range(n):
  c = Counter(input())
  ans += c_list.count(c)
  c_list.append(c)
  
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
li = []
for i in range (n):
    li.append(sorted(list(input())))
li.sort()

def comb(x,y):
    d = itertools.combinations(x,y)
    return len(list(d))

cnt = 0
a = []
for i in range(n-1):
    if li[i] == li[i+1]:
        a.append(i+1)
        if i == n-2:
            a.append("1")
            cnt += comb(a,2)
        
    else: 
        a.append("1")
        cnt += comb(a,2)
        a = []
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
S = []
for i in range(N):
	s = list(map(str, input()))
	s.sort()
	S.append(s)
	
count = 0
for i in range(N):
	for j in range(i):
		if S[i] == S[j]:
			count += 1
			
print(ans)

Submission status: Runtime Error

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

def kaijou(X):
  if X==1:
    return 1
  return X*kaijou(X-1)


x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)
ans=[]
for i in range(len(x)):
  if x[i]>1:
    ans.append(kaijou(x[i])/2)
  else:
    ans.append(0)
    
    
print(int(sum(ans)))

Submission status: Runtime Error

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

def kaijou(X):
  if X==1:
    return 1
  return X*kaijou(X-1)


x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)

for i in range(len(x)):
  if x[i]>1:
    x[i]=kaijou(x[i])/2
  else:
    x[i]=0
    
    
print(int(sum(x)))

Submission status: Runtime Error

Solution code:
n=int(input())
d=[]
for i in range(n):
  s=list(input())
  s.sort()
  d.append(s)
d.sort()
def kaijou(X):
  if X==1:
    return 1
  return X*kaijou(X-1)
x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)

for i in range(len(x)):
  if x[i]>1:
    x[i]=kaijou(x[i])/2
  else:
    x[i]=0
print(int(sum(x)))

Submission status: Runtime Error

Solution code:
n=int(input())
d=[]
for i in range(n):
  s=list(input())
  s.sort()
  d.append(s)
d.sort()
def kaijou(X):
  if X==1:
    return 1
  return X*kaijou(X-1)
x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)

print(d)
print(x)

for i in range(len(x)):
  if x[i]>1:
    x[i]=kaijou(x[i])/2
  else:
    x[i]=0
print(sum(x))

Submission status: Runtime Error

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

ans = 0
aDict = {}
for i in s:
  if str(i) not in aDict:
    aDict[str(i)] = 1
  else
  	aDict[str(i)] += 1
    
for n in aDict.values():
    ans += (n*(n-1)//2)
print(ans)

Submission status: Runtime Error

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

ans = 0
aDict = {}
for i in s:
  i.sort()
  if str(i) not in aDict:
    aDict[str(i)] = 1
  else:
    ans += aDict[str(i)] 
    aDict[str(i)] += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys

from scipy.special import comb

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = read().split()
    S = list(map(lambda x: sorted(x.decode('UTF-8')), S))

    A = defaultdict(int)
    for i in range(N):
        s = ''.join(S[i])
        A[s] += 1

    cnt = 0
    for i in A.values():
        cnt += comb(i, 2)
    print(int(cnt))


main()

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input() for i in range(1,n+1)]
dic={}
l=list()
cnt=0
for i in range(n):
  s[i].sort()
  s=''.join(s[i])
  l.append(s)
  if l[i] in dic:
    cnt+=1
  else:
    dict[l[i]]=1
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
from collections import defaultdict as dd

hsh = dd(int)

for i in range(n):
  s = input()
  s = sorted(s)
  hsh[s] += 1

x = 0
for i in hsh:
  x += (hsh[i]*(hsh[i]-1))//2

print(x)

Submission status: Runtime Error

Solution code:
n = int(input())
A = []
for i in range(n):
  s = input()
  A.append(sorted(s))
x = 0
for i in range(n):
  for j in range(i+1, n):
  	if A[i] == A[j]:
      x+=1
print(x)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())

s = [",".join(sorted(input())) for i in range(n)]

c = collections.Counter(s)

ans = 0
for i in c.valuses():
  ans += i*(i-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
# 2019-11-16 14:51:41(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l
# import itertools
# from functools import reduce
# import operator as op
from scipy.special import comb # comb(n, r, exact=True)
# import numpy as np
# import heapq
# import array


def main():
    n = int(sys.stdin.readline().rstrip())

    sorted_letters = [''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]
  
    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >= 2:
            count += comb(c, 2, exact=True)

    print(count)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# coding: utf-8

n = int(input())
words = {}
ans = 0

for i in range(n):
  t = ''.join(sorted(input()))
  if t in words:
    ans += words[t]
    words[t] += 1
  else:
    words[t] += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[sorted(input()) for _ in range(n)].sort()
count = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            count = count + 1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[sorted(input()).sort() for _ in range(n)]
s.sorted()
count = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        count = count + 1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[input().sort() for _ in range(n)]
count = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            count = count + 1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
s_sort = [sorted(i) for i in s]
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        b = 0
        for k in range(10):
            if ss[i][k] != ss[j][k]:
                b = 1
                break
        if b == 0:
            ans += 1
                
print(ans)

Submission status: Runtime Error

Solution code:
i = lambda : int(input())

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

ans = 0
cnt = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt+=1
        if i == n-2:
            ans += cnt*(cnt-1)/2
    else:
        ans += cnt*(cnt-1)/2
        cnt = 1

print(int(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
v=0
for i in range(n):
  d=input()
  d.sort()
  a.append(d)
for j in range(n-1):
  for k in range(i+1,n):
    if a[j]==a[k]:
      v+=1
      
print(v)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))
unique_S = list(set(S))

ans = 0
for s in unique_S:
    n = S.count(s)
    if n > 1:
        ans += comb(n, 2, exact=True)
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))
unique_S = list(set(S))

ans = 0
for s in unique_S:
    n = S.count(s)
    if n > 1:
        ans += factorial(n) / factorial(2) / factorial(n - 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
def factorial(n):
    res = 1
    for i in range(1, n+1):
        res *= i
    return res

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

for i in s:
    i.sort()

s.sort()
s.append('a')

tmp = 'a'
total = 0
cnt = 1
for i in s:
    if i == tmp:
        cnt += 1
    elif cnt >= 2:
        total += factorial(cnt)*factorial(cnt-2)/2
        cnt = 1
    tmp = i

print(int(total))