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

s = []
for i in range(n):
    tmp = []
    tmp = list(input())
    tmp.sort()
    s.append("".join(tmp))

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if i == j:
            pass
        else:
            if s[i] == s[j]:
                cnt += 1

print(cnt)


Fixed submission:
n = int(input())

s = []
for i in range(n):
    tmp = []
    tmp = list(input())
    tmp.sort()
    s.append("".join(tmp))

s.sort()

cnt = 0
t_cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        t_cnt += 1
    elif s[i] != s[i+1]:
        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

    if i == n-2:

        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

print(cnt)

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

s = []
for i in range(n):
    s.append(input())

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if i == j:
            pass
        else:
            #print(i,j)
            a1 = list(s[i])
            b1 = list(s[j])

            a1.sort()
            b1.sort()

            a2 = "".join(a1)
            b2 = "".join(b1)

            if a2 == b2:
                cnt += 1

print(cnt)


Fixed submission:
n = int(input())

s = []
for i in range(n):
    tmp = []
    tmp = list(input())
    tmp.sort()
    s.append("".join(tmp))

s.sort()

cnt = 0
t_cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        t_cnt += 1
    elif s[i] != s[i+1]:
        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

    if i == n-2:

        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

print(cnt)

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

s = []
for i in range(n):
    s.append(input())

cnt = 0
for i in range(n):
    for j in range(n):
        if i == j:
            pass
        else:
            a1 = list(s[i])
            b1 = list(s[j])

            a1.sort()
            b1.sort()

            a2 = "".join(a1)
            b2 = "".join(b1)

            if a2 == b2:
                cnt += 1

print(cnt//2)


Fixed submission:
n = int(input())

s = []
for i in range(n):
    tmp = []
    tmp = list(input())
    tmp.sort()
    s.append("".join(tmp))

s.sort()

cnt = 0
t_cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        t_cnt += 1
    elif s[i] != s[i+1]:
        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

    if i == n-2:

        if t_cnt > 1:
            t_cnt += 1

            t = 0
            for j in range(t_cnt):
                t += j

            cnt += t
            t_cnt = 0
        else:
            cnt += t_cnt
            t_cnt = 0

print(cnt)