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

input_patterns = []

patterns = {}

a_max = ord('z')
a_min = ord('a')


def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

#input_patterns = ['acornistnt', 'peanutbomb', 'constraint']
count = 0
for inp in input_patterns:
    key = init_key()
    for j in range(len(inp)):
        # make [0, 0, 1, 0, 2, 3, ...]
        #       a  b  c  d  e  f  
        for k in range(26):
            if inp[j] == chr(ord('a') + k):
                key[k] = key[k] + 1

    skey = ''
    for k in range(26):
        skey = skey + str(key[k])

    if skey in patterns:
        patterns[skey] = patterns[skey] + 1
    else:
        patterns[skey] = 1

    if patterns[skey] > 1:
        count = count + patterns[skey] - 1

        
result = 0

#for skey in patterns:
#    if patterns[skey] > 1:
#        for i in range(1, int(patterns[skey])):
#            result = result + i

print('{}'.format(count))


Fixed submission:
n = int(input())

input_patterns = []

patterns = {}

def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

count = 0
for inp in input_patterns:
    key = sorted(inp)
    skey = ''

    for k in range(len(key)):
        skey = skey + key[k]

    if skey in patterns:
        patterns[skey] = patterns[skey] + 1
    else:
        patterns[skey] = 1

    if patterns[skey] > 1:
        count = count + patterns[skey] - 1
    
print('{}'.format(count))

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

input_patterns = []

patterns = {}

a_max = ord('z')
a_min = ord('a')


def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

#input_patterns = ['acornistnt', 'peanutbomb', 'constraint']
    
for inp in input_patterns:
    key = init_key()
    for j in range(len(inp)):
        # make [0, 0, 1, 0, 2, 3, ...]
        #       a  b  c  d  e  f  
        for k in range(26):
            if inp[j] == chr(ord('a') + k):
                key[k] = key[k] + 1

    skey = ''
    for k in range(26):
        skey = skey + str(key[k])

    if skey in patterns:
        patterns[skey] = patterns[skey] + 1
    else:
        patterns[skey] = 1

result = 0

for skey in patterns:
    if patterns[skey] > 1:
        for i in range(1, int(patterns[skey])):
            result = result + i

print('{}'.format(result))


Fixed submission:
n = int(input())

input_patterns = []

patterns = {}

def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

count = 0
for inp in input_patterns:
    key = sorted(inp)
    skey = ''

    for k in range(len(key)):
        skey = skey + key[k]

    if skey in patterns:
        patterns[skey] = patterns[skey] + 1
    else:
        patterns[skey] = 1

    if patterns[skey] > 1:
        count = count + patterns[skey] - 1
    
print('{}'.format(count))

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

input_patterns = []

patterns = []

a_max = ord('z')
a_min = ord('a')


def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

#input_patterns = ['acornistnt', 'peanutbomb', 'constraint']
    
for inp in input_patterns:
    key = init_key()
    for j in range(len(inp)):
        # make [0, 0, 1, 0, 2, 3, ...]
        #       a  b  c  d  e  f  
        for k in range(26):
            if inp[j] == chr(ord('a') + k):
                key[k] = key[k] + 1

    patterns.append(key)

result = 0

for i in range(len(patterns) - 1):
    for j in range(i+1, len(patterns)):
#        print('comparing s{} s{}'.format(i, j))
        if patterns[i] == patterns[j]:
            result = result + 1

print('{}'.format(result))


Fixed submission:
n = int(input())

input_patterns = []

patterns = {}

def init_key():
    ini_key = []
    for i in range(26):
        ini_key.append(0)
    return ini_key

for i in range(n):
    val = input()
    input_patterns.append(val)

count = 0
for inp in input_patterns:
    key = sorted(inp)
    skey = ''

    for k in range(len(key)):
        skey = skey + key[k]

    if skey in patterns:
        patterns[skey] = patterns[skey] + 1
    else:
        patterns[skey] = 1

    if patterns[skey] > 1:
        count = count + patterns[skey] - 1
    
print('{}'.format(count))