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

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]

S_ = set(S)

a = [math.factorial(S.count(i)) // (math.factorial(S.count(i) - 2) * math.factorial(2)) for i in S_ if not S.count(i) == 1]

print(int(sum(a)))


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

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

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

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]

S_ = set(S)

a = [combinations_count(S.count(i), 2) for i in S_ if not S.count(i) == 1]

print(int(sum(a)))

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

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

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

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]

S_ = S[:]
S_ = set(S_)

a = [combinations_count(S.count(i), 2) for i in S_ if not S.count(i) == 1]

print(int(sum(a)))


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

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

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

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]

S_ = S[:]
S_ = set(S_)

a = [int(combinations_count(S.count(i), 2)) for i in S_ if not S.count(i) == 1]

print(sum(a))


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

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

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

N = int(input())
S = [sorted(input()) for i in range(N)]
S = ["".join(S[i]) for i in range(N)]

S_ = S[:]
S_ = set(S_)

c = 0

for i in S_:
    a = S.count(i)
    if a == 1 :
        continue
    ans = combinations_count(a, 2)
    c += int(ans)

print(c)


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
S = [sorted(input()) for i in range(N)]
S = ["".join(S[i]) for i in range(N)]

S.sort()
S_ = S[:]
S_ = set(S_)

c = 0

for i in S_:
    a = S.count(i)
    if a == 1 :
        continue
    ans = math.factorial(a) / 2 * math.factorial(a-2)
    c += int(ans)

print(c)


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [sorted(input()) for i in range(N)]

a = ["a" for i in range(N) for j in range(N-i-1) if S[i] == S[i+j+1]]
print(len(a))


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [sorted(input()) for i in range(N)]
c = 0
for i in range(N):
    for j in range(N-i-1):
        if S[i] == S[i+j+1]:
            c+=1
print(c)


Fixed submission:
n = int(input())
s = [input() for i in range(n)]
existed = {}
c = 0
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))

  if sorted_s in existed:
    c += existed[sorted_s]
    existed[sorted_s] += 1
  else:
    existed[sorted_s] = 1
print(c)