Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = [sorted(input()) for i in range(n)]
    cnt = 0
    s.sort()
    sb = []
    while s:
        sa = s.pop()
        cnt += s.count(sa) 
        if sa == sb:
            cnt + 1
        sb = sa
    print(cnt)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = [sorted(input()) for i in range(n)]
    cnt = 0

    while s:
        sa = s.pop()
        cnt += s.count(sa) 
    print(cnt)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = [input() for i in range(n)]
    a = [[0] * 26 for _ in range(n)] 
    al = 'abcdefghijklmnopqrstuvwxyz'
    cnt = 0

    for i in range(n):
        for j in s[i]:
            a[i][al.index(j)] += 1 


    for i in range(n-1):
        for j in range(i+1,n):
            if a[i] == a[j]:
                cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = [input() for i in range(n)]
    a = [[0] * 26 for _ in range(n)] 
    al = 'abcdefghijklmnopqrstuvwxyz'
    cnt = 0

    for i in range(n):
        for j in s[i]:
            a[i][al.index(j)] += 1 


    for i in range(n-1):
        for j in range(i+1,n):
            if a[i] == a[j]:
                cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
a = [[0] * 26 for _ in range(n)] 
al = 'abcdefghijklmnopqrstuvwxyz'
cnt = 0

for i in range(n):
    for j in s[i]:
        a[i][al.index(j)] += 1 


for i in range(n-1):
    for j in range(i+1,n):
        if a[i] == a[j]:
            cnt += 1\

print(cnt)

Fixed submission:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for i in range(n)]
    dic = {}
    cnt = 0

    for i in s:
        if i in dic:
            cnt+=dic[i]
            dic[i]+=1
        else:
            dic[i]=1

    print(cnt)

if __name__ == "__main__":
    main()