Buggy python submission (verdict: Time Limit Exceeded):

def main():
  from collections import Counter
  N = int(input())
  S = [input() for _ in range(N)]

  tmp = []
  d={}
  for s in S:
    x = Counter(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      tmp.append(x)
      d[tmp.index(x)] = 1 
      
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Fixed submission:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Runtime Error):
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  tmp = []
  d={}
  for s in S:
    x = Counter(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      tmp.append(x)
      d[tmp.index(x)] = 1 
      
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Fixed submission:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Runtime Error):
def main():
  N = int(input())

  d = {}
  tmp = []
  for i in range(N):
    s = input()
    x = sorted(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      d[i] = 1 
      tmp.append(x)
  cnt = 0
  for k, v in d.items():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Fixed submission:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Runtime Error):
def main():
  N = int(input())

  d = {}
  tmp = []
  for i in range(N):
    s = input()
    x = sorted(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      d[i] = 1 
      tmp.append(x)
  cnt = 0
  for k, v in d.items():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(d)
  print(cnt)
if __name__ == "__main__":
  main()

Fixed submission:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from collections import Counter
  N = int(input())
  S = [input() for _ in range(N)]

  tmp = []
  for s in S:
    tmp.append("".join(sorted(s)))
  cnt = 0
  for i, t in enumerate(tmp):
    for j in range(i+1, N):
      if tmp[i] == tmp[j]:
        cnt += 1
  print(cnt)

if __name__ == "__main__":
  main()

Fixed submission:
def main():
  N = int(input())
  S = [input() for _ in range(N)]

  d = {}
  for i, s in enumerate(S):
    x = "".join(sorted(s))
    if x in d:
      d[x] += 1
    else:
      d[x] = 1
  
  cnt = 0
  for v in d.values():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()