Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(10):
            c = 1
            if s[i][k] != s[j][k]:
                c = 0
                break
        if c == 0:
            break
        if c == 1:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        start = i
        end = N-1
        while start != end:
            center = (start + end) // 2
            if s[center] == s[i]:
                if s[center+1] == s[i]:
                    start = center+1
                else:
                    start = end = center
            else:
                end = center
        ans += start - i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i] == s[j]:
            ans += 1
        else:
            break
print(ans)

Fixed submission:
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        start = i
        end = N-1
        while start != end:
            center = (start + end) // 2
            if s[center] == s[i]:
                if s[center+1] == s[i]:
                    start = center+1
                else:
                    start = end = center
            else:
                end = center
        ans += start - i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
s = [collections.Counter(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        c = 1
        for k in s[i].items():
            if k not in s[j].items():
                c = 0
                break
        if c == 1:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        start = i
        end = N-1
        while start != end:
            center = (start + end) // 2
            if s[center] == s[i]:
                if s[center+1] == s[i]:
                    start = center+1
                else:
                    start = end = center
            else:
                end = center
        ans += start - i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
s = [collections.Counter(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if s[i] == s[j]:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
s = [sorted(input()) for i in range(N)]
s.sort()
ans = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        start = i
        end = N-1
        while start != end:
            center = (start + end) // 2
            if s[center] == s[i]:
                if s[center+1] == s[i]:
                    start = center+1
                else:
                    start = end = center
            else:
                end = center
        ans += start - i
print(ans)