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

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
result_dic = {}

for i in range(0, len(s)):
  sorted_val = ''.join(sorted(s[i]))
  is_contain = False
  for k in result_dic.keys():
    if sorted_val == k:
      result_dic[k] += 1
      is_contain = True
      break
  if not is_contain:
    result_dic[sorted_val] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)


Fixed submission:
# 入力部
N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
# 計算部
result_dic = {}

for i in range(0, len(s)):
  sorted_val = ''.join(sorted(s[i]))
  if sorted_val in result_dic:
    result_dic[sorted_val] += 1
  else:
    result_dic[sorted_val] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Buggy python submission (verdict: Time Limit Exceeded):
def create_anagram_dic(val):
  dic = {}
  for s in val:
    if s not in dic:
      dic[s] = 0
    dic[s] += 1
  
  return dic

def is_anagram(val, dic):
  for k, v in dic.items():
    if val.count(k) != v:
      return False
  return True

N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
result_dic = {}
result_dic[s[0]] = 1

for i in range(1, len(s)):
  is_contain = False
  for k in result_dic.keys():
    dic = create_anagram_dic(k)
    if is_anagram(s[i], dic):
      result_dic[k] += 1
      is_contain = True
      break
  if not is_contain:
    result_dic[s[i]] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Fixed submission:
# 入力部
N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
# 計算部
result_dic = {}

for i in range(0, len(s)):
  sorted_val = ''.join(sorted(s[i]))
  if sorted_val in result_dic:
    result_dic[sorted_val] += 1
  else:
    result_dic[sorted_val] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Buggy python submission (verdict: Time Limit Exceeded):
def create_anagram_dic(val):
  dic = {}
  for s in val:
    if s not in dic:
      dic[s] = 0
    dic[s] += 1
  
  return dic

def is_anagram(val, dic):
  for k, v in dic.items():
    if val.count(k) != v:
      return False
  return True

N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
  
result_dic = {}

while len(s) > 0:
  current_val = s[0]
  result_dic[current_val] = 1
  dic = create_anagram_dic(current_val)
  for i in range(len(s) - 1, 0, -1):
    if is_anagram(s[i], dic):
      result_dic[current_val] += 1
      s.pop(i)
  s.pop(0)

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Fixed submission:
# 入力部
N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
# 計算部
result_dic = {}

for i in range(0, len(s)):
  sorted_val = ''.join(sorted(s[i]))
  if sorted_val in result_dic:
    result_dic[sorted_val] += 1
  else:
    result_dic[sorted_val] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)