Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]

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

    print(int(count_anagram(s[0], s[1:], 0)))


def count_anagram(s, str_list, total):
    cnt = 0
    tmp = []
    for i, t in enumerate(str_list):
        if s == t:
            cnt += 1
            tmp.append(i)
    if cnt > 0:
        total += (cnt+1) * cnt / 2
        for i in reversed(tmp):
            str_list.pop(i)

    if str_list:
        return count_anagram(str_list[0], str_list[1:], total)
    else:
        return total


if __name__ == '__main__':
    main()


Fixed submission:
import collections

n = int(input())
s = ["".join(sorted(input())) for i in range(n)]

counter = collections.Counter(s)

ans = 0
for i in counter.values():
   if i > 0:
        ans += i * (i - 1) // 2

print(ans)

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]

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

    print(int(count_anagram(s[0], s[1:], 0)))


def count_anagram(s, str_list, total):
    cnt = 0
    tmp = []
    for i, t in enumerate(str_list):
        if s == t:
            cnt += 1
            tmp.append(i)
    if cnt > 0:
        total += (cnt+1) * cnt / 2
        for i in tmp:
            str_list.pop(i)

    if str_list:
        return count_anagram(str_list[0], str_list[1:], total)
    else:
        return total


if __name__ == '__main__':
    main()


Fixed submission:
import collections

n = int(input())
s = ["".join(sorted(input())) for i in range(n)]

counter = collections.Counter(s)

ans = 0
for i in counter.values():
   if i > 0:
        ans += i * (i - 1) // 2

print(ans)

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


def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]
    for i in range(n):
        s[i] = list(input())

    cnt = 0
    for i in range(n):
        cnt += count_anagram(s[i], s[i+1: n])

    print(cnt)


def anagram(list1, list2):
    if not list1:
        return True

    if list1[0] in list2:
        list2.remove(list1[0])
        list1.pop(0)
        return anagram(list1, list2)
    else:
        return False


def count_anagram(s, str_list):
    cnt = 0
    for t in str_list:
        u, v = copy.copy(s), copy.copy(t)
        if anagram(u, v):
            cnt += 1
    return cnt


if __name__ == '__main__':
    main()


Fixed submission:
import collections

n = int(input())
s = ["".join(sorted(input())) for i in range(n)]

counter = collections.Counter(s)

ans = 0
for i in counter.values():
   if i > 0:
        ans += i * (i - 1) // 2

print(ans)

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


def main():
    n = int(input())
    s = [["" for j in range(10)] for i in range(n)]
    for i in range(n):
        s[i] = list(input())

    cnt = 0
    for i in range(n):
        cnt += count_anagram(s[i], copy.copy(s[i+1: n]))

    print(cnt)


def anagram(list1, list2):
    if not list1:
        return True

    if list1[0] in list2:
        list2.remove(list1[0])
        list1.pop(0)
        return anagram(list1, list2)
    else:
        return False


def count_anagram(s, str_list):
    cnt = 0
    for t in str_list:
        u, v = copy.copy(s), copy.copy(t)
        if anagram(u, v):
            cnt += 1
    return cnt


if __name__ == '__main__':
    main()


Fixed submission:
import collections

n = int(input())
s = ["".join(sorted(input())) for i in range(n)]

counter = collections.Counter(s)

ans = 0
for i in counter.values():
   if i > 0:
        ans += i * (i - 1) // 2

print(ans)