Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]

count = 0
for j in range(N):
    # print(j, s.count(s[j])-1)
    count += (s.count(s[j])-1)
print(count//2)


Fixed submission:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]

from collections import Counter
counter = Counter(s)
ans = sum(n*(n-1)//2 for n in counter.values())
print(ans)

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

s = []
for i in range(N):
    x = sorted(input())
    s.append(x)

count = 0
for j in range(N):
    if s.count(s[j]) > 1:
        count += s.count(s[j])-1

print(count//2)

Fixed submission:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]

from collections import Counter
counter = Counter(s)
ans = sum(n*(n-1)//2 for n in counter.values())
print(ans)

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

s = []
for i in range(N):
    x = sorted(input())
    s.append(x)

count = 0
start = 0
while(start<N):
    for j in range(len(s)):
        if j <= start:
            pass
        else:
            if s[start] == s[j]:
                count += 1

    start += 1

    if s==False:
        break

print(count)

Fixed submission:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]

from collections import Counter
counter = Counter(s)
ans = sum(n*(n-1)//2 for n in counter.values())
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]

from scipy.misc import comb
print(sum([comb(anagrams.count(word), 2, exact=True)\
          for word in set(anagrams)]))

Fixed submission:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from scipy.special import comb
print(sum([comb(anagrams.count(word), 2, exact=True)\
          for word in set(anagrams)]))

Fixed submission:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
import pandas as pd
import math

print(sum([math.factorial(i-1) for i in pd.DataFrame(anagrams, columns=["word"]).groupby("word")["word"].count().values]))

Fixed submission:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
print(sum([math.factorial(i-1) for i in pd.DataFrame(anagrams, columns=["word"]).groupby("word")["word"].count().values]))

Fixed submission:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
anagrams = [sorted(input()) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1, n):
        if anagrams[i] == anagrams[j]:
            cnt+=1
print(cnt)

Fixed submission:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)