Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []

for _ in range(N):
  a = str(input())
  alist = list(a)
  s.append(sorted(alist))
  
cnt = 0
while len(s) > 1:
  same = 0
  s1 = s.pop()
  same = s.count(s1)
  if same != 0:
    cnt += (same+1) * same / 2
    while s1 in s:
      s.remove(s1)

print(int(cnt))






Fixed submission:
from collections import Counter
N = int(input())
s = []
cnt = 0
for _ in range(N):
  a = str(input())
  alist = sorted(list(a))
  s.append(str(''.join(alist)))
  
l = Counter(s)
for i in l.values():
  if i > 1:
    cnt += (i - 1) * i / 2
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []

for _ in range(N):
  s.append(str(input()))
  
cnt = 0
for i in range(N):
  delete = []
  s1 = s.pop()
  s1list = list(s1)
  same = 1
  
  for j in range(len(s)-1, -1, -1):
    s2 = s[j]
    s2list = list(s2) 
    if sorted(s1list) == sorted(s2list):
      delete.append(s2)
      same += 1
  if same != 1:
    cnt += same * (same - 1) / 2
  for x in delete:
    s.remove(x)
  if not s:
    break
print(int(cnt))




Fixed submission:
from collections import Counter
N = int(input())
s = []
cnt = 0
for _ in range(N):
  a = str(input())
  alist = sorted(list(a))
  s.append(str(''.join(alist)))
  
l = Counter(s)
for i in l.values():
  if i > 1:
    cnt += (i - 1) * i / 2
print(int(cnt))

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
s = []

for _ in range(N):
  s.append(str(input()))
  
cnt = 0
for i in range(N):
  delete = []
  s1 = s.pop()
  s1list = list(s1)
  same = 0
  
  for j in range(len(s)-1, -1, -1):
    s2 = s[j]
    s2list = list(s2) 
    if sorted(s1list) == sorted(s2list):
      delete.append(s2)
      same += 1
  cnt += math.factorical(same)
  for x in delete:
    s.remove(x)
  if not s:
    break
print(cnt)


Fixed submission:
from collections import Counter
N = int(input())
s = []
cnt = 0
for _ in range(N):
  a = str(input())
  alist = sorted(list(a))
  s.append(str(''.join(alist)))
  
l = Counter(s)
for i in l.values():
  if i > 1:
    cnt += (i - 1) * i / 2
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
s = []
for _ in range(N):
  s.append(str(input()))
  
cnt = 0

for i in range(N-1):
  s1 = s[i]
  s1list = list(s1)
  same = 0
  
  for j in range(i+1, N):
    s2 = s[j]
    s2list = list(s2) 
    if sorted(s1list) == sorted(s2list):
      cnt += 1
print(cnt)


Fixed submission:
from collections import Counter
N = int(input())
s = []
cnt = 0
for _ in range(N):
  a = str(input())
  alist = sorted(list(a))
  s.append(str(''.join(alist)))
  
l = Counter(s)
for i in l.values():
  if i > 1:
    cnt += (i - 1) * i / 2
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for _ in range(N):
  s.append(str(input()))
  
cnt = 0

for i in range(N-1):
  s1 = s[i]
  s1list = list(s1)
  for j in range(i+1, N):
    s2 = s[j]
    s2list = list(s2)
    for c in s1list:
      try:
        s2list.remove(str(c))
      except:
        continue
    if not s2list:
      cnt += 1
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
s = []
cnt = 0
for _ in range(N):
  a = str(input())
  alist = sorted(list(a))
  s.append(str(''.join(alist)))
  
l = Counter(s)
for i in l.values():
  if i > 1:
    cnt += (i - 1) * i / 2
print(int(cnt))