Buggy python submission (verdict: Runtime Error):
import collections
import math

inp = int(input())
A = []
for a in range(inp):
    A.append(input())

def charcnt(s):
    cset = {}
    for c in s:
        if c in cset:
            cset[c] += 1
        else:
            cset[c] = 1
    sortedset = sorted(cset.items(), key=lambda x:x[0])
    s = ""
    for k, v in sortedset:
        s += k + str(v)
    return s

sorted = [charcnt(v) for v in A]    

counted = collections.Counter(sorted)
cnt = 0
for v in counted.values():
    if v > 1:
        cnt += math.factorial(v) / 2
print(int(cnt))


Fixed submission:
import collections
import math

inp = int(input())
A = []
for a in range(inp):
    A.append(input())

def charcnt(s):
    cset = {}
    for c in s:
        if c in cset:
            cset[c] += 1
        else:
            cset[c] = 1
    sortedset = sorted(cset.items(), key=lambda x:x[0])
    s = ""
    for k, v in sortedset:
        s += k + str(v)
    return s

sorted = [charcnt(v) for v in A]    

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


counted = collections.Counter(sorted)
cnt = 0
for v in counted.values():
    if v > 1:
        cnt += cmb(v, 2)
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
inp = int(input())
A = []
for a in range(inp):
    A.append(input())

def charcnt(s):
    cset = {}
    for c in s:
        if c in cset:
            cset[c] += 1
        else:
            cset[c] = 1
    sortedset = sorted(cset.items(), key=lambda x:x[0])
    s = ""
    for k, v in sortedset:
        s += k + str(v)
    return s

sorted = [charcnt(v) for v in A]    

cnt = 0
for i1, s1 in enumerate(sorted[:-1]):
    for s2 in sorted[i1 + 1:]:
        if s1 == s2:
            cnt += 1 
print(cnt)


Fixed submission:
import collections
import math

inp = int(input())
A = []
for a in range(inp):
    A.append(input())

def charcnt(s):
    cset = {}
    for c in s:
        if c in cset:
            cset[c] += 1
        else:
            cset[c] = 1
    sortedset = sorted(cset.items(), key=lambda x:x[0])
    s = ""
    for k, v in sortedset:
        s += k + str(v)
    return s

sorted = [charcnt(v) for v in A]    

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


counted = collections.Counter(sorted)
cnt = 0
for v in counted.values():
    if v > 1:
        cnt += cmb(v, 2)
print(int(cnt))