Buggy python submission (verdict: Time Limit Exceeded):
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

#from math import factorial

if __name__ == "__main__":
	n=int(input())
	string_list=[]

	for _ in range(n):
		rel = sorted(list(input()))
		string_list.append(''.join(rel))
	    
	string_distinct = set(string_list)
	idx = 0
	for item in string_distinct:
		s_count = string_list.count(item)
		if s_count > 1:
			idx += cmb(s_count,2)
	print(idx)




Fixed submission:
N = int(input())

def sort_alpabetical(s):
	
	s_list = list(s)
	s_list.sort()
	return ''.join(s_list)

list_s = []
for n in range(N):
	list_s.append(input())

list_s = [sort_alpabetical(s) for s in list_s]

dict_s = {s : 0 for s in set(list_s)}

n_of_pairs = 0


for s in list_s:
	
	n_of_pairs += dict_s[s]
	dict_s[s] +=1
	
print(n_of_pairs)

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

n=int(input())
string_list=[]

for _ in range(n):
	rel = sorted(list(input()))
	string_list.append(''.join(rel))
    
string_distinct = set(string_list)
idx = 0
for item in string_distinct:
	s_count = string_list.count(item)
	if s_count > 1:
		idx += factorial(s_count) // factorial(2) // factorial(s_count - 2)
print(idx)

Fixed submission:
N = int(input())

def sort_alpabetical(s):
	
	s_list = list(s)
	s_list.sort()
	return ''.join(s_list)

list_s = []
for n in range(N):
	list_s.append(input())

list_s = [sort_alpabetical(s) for s in list_s]

dict_s = {s : 0 for s in set(list_s)}

n_of_pairs = 0


for s in list_s:
	
	n_of_pairs += dict_s[s]
	dict_s[s] +=1
	
print(n_of_pairs)

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

n=int(input())
string_list=[]

for _ in range(n):
	rel = sorted(list(input()))
	string_list.append(''.join(rel))
    
string_distinct = set(string_list)
idx = 0
count_list=[]
for item in string_distinct:
	
	
	s_count = string_list.count(item)
	if s_count > 1:
#		idx += (2 * s_count - 1)
		idx += factorial(s_count) // factorial(2) // factorial(s_count - 2)
		count_list.append(item)
print(idx)

Fixed submission:
N = int(input())

def sort_alpabetical(s):
	
	s_list = list(s)
	s_list.sort()
	return ''.join(s_list)

list_s = []
for n in range(N):
	list_s.append(input())

list_s = [sort_alpabetical(s) for s in list_s]

dict_s = {s : 0 for s in set(list_s)}

n_of_pairs = 0


for s in list_s:
	
	n_of_pairs += dict_s[s]
	dict_s[s] +=1
	
print(n_of_pairs)

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial

n=int(input())
string_list=[]

for _ in range(n):
	rel = sorted(list(input()))
	string_list.append(''.join(rel))
    
#string_distinct = set(string_list)
#print(len(string_list) - len(string_distinct))
idx = 0
count_list=[]
for item in string_list:
	
	if item in count_list:
		continue
	
	s_count = string_list.count(item)
	if s_count > 1:
#		idx += (2 * s_count - 1)
		idx += factorial(s_count) // factorial(2) // factorial(s_count - 2)
		count_list.append(item)
print(idx)

Fixed submission:
N = int(input())

def sort_alpabetical(s):
	
	s_list = list(s)
	s_list.sort()
	return ''.join(s_list)

list_s = []
for n in range(N):
	list_s.append(input())

list_s = [sort_alpabetical(s) for s in list_s]

dict_s = {s : 0 for s in set(list_s)}

n_of_pairs = 0


for s in list_s:
	
	n_of_pairs += dict_s[s]
	dict_s[s] +=1
	
print(n_of_pairs)