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


N = int(input())
s = []
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    if t:
        del s[:t]
    ans += (t * (t + 1)) // 2
print(ans)

Fixed submission:
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

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


N = int(input())
s = []
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    del s[:t]
    ans += (t * (t + 1)) // 2
print(ans)

Fixed submission:
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

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


N = int(input())
s = []
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    del s[:t]
    ans += (t * (t + 1)) // 2
print(ans)

Fixed submission:
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

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


N = int(input())
s = []
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    ans += t
print(ans)

Fixed submission:
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    for ss in si:
        if ss not in memo[i]:
            memo[i][ss] = 1
        else:
            memo[i][ss] += 1
for j in range(N):
    for k in range(j, N):
        if j != k:
            if memo[j] == memo[k]:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    for ss in si:
        if ss not in memo[i]:
            memo[i][ss] = 1
        else:
            memo[i][ss] += 1
for j in range(N):
    for k in range(j, N):
        if j != k:
            if memo[j] == memo[k]:
                ans += 1
print(ans)

Fixed submission:
N = int(input())
memo = {}
ans = 0
for i in range(N):
    si = list(input())
    si.sort()
    si = ('').join(si)
    if si not in memo:
        memo[si] = 1
    else:
        memo[si] += 1
        ans += memo[si] - 1
print(ans)