Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1
    
ln2 = ([i for i in ln2 if i != 1])

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

x = 0

for k in ln2:
    x += cmb(k, 2)
    
print(x)        

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

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

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)    

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

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

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)        

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

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
ans = 0
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

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

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)        

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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [list(str(input())) for _ in range(n)]
ans = 0
for i in p:
    i.sort()
for j in range(n):
    for k in range(j + 1, n):
        if p[j] == p[k]:
            ans += 1
print(ans)

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