Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = [input().rstrip() for _ in range(N)]

dict = {}
for s in S:
    s_list = sorted(list(s))
    s_str = "".join(s_list)
    if s_str in dict.keys():
        dict[s_str] += 1
    else:
        dict[s_str] = 1

total = 0
for v in dict.values():
    total += v * (v - 1) // 2

print(total)


# S = ["".join(sorted(input())) for _ in range(N)]
# counter = Counter(S)
#
# ans = 0
# for value in counter.values():
#     if value >= 2:
#         ans += value * (value - 1) // 2
#
# print(ans)


# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
counter = Counter(S)

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

print(ans)

# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = [input().rstrip() for _ in range(N)]
ans = []

for i, s in enumerate(S, start=1):
    if s == NIL:
        continue
    counter = 1
    for j in range(i, len(S)):
        if S[j] == NIL:
            continue
        if is_anag(s, S[j]):
            counter += 1
            S[j] = NIL
    if counter != 1:
        ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
print(sum(ans))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
counter = Counter(S)

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

print(ans)

# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = [input().rstrip() for _ in range(N)]
ans = []

for i, s in enumerate(S, start=1):
    if s == NIL:
        continue
    counter = 1
    for j in range(i, len(S)):
        if S[j] == NIL:
            continue
        if is_anag(s, S[j]):
            counter += 1
            S[j] = NIL
    if counter != 1:
        ans.append(counter)

res = []

for a in ans:
    res.append(a * (a - 1) // 2)
print(sum(res))


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
counter = Counter(S)

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

print(ans)

# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
N, A, B = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = [input().rstrip() for _ in range(N)]

counter = 0
for i, s in enumerate(S, start=1):
    for j in range(i, len(S)):
        if is_anag(s, S[j]):
            counter += 1


print(counter)






# def main():
# if __name__ == '__main__':
#     main()


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = '-1'


def is_anag(a, b):
    return Counter(a) == Counter(b)


N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
counter = Counter(S)

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

print(ans)

# for i, s in enumerate(S, start=1):
#     if s == NIL:
#         continue
#     counter = 1
#     for j in range(i, len(S)):
#         if S[j] == NIL:
#             continue
#         if is_anag(s, S[j]):
#             counter += 1
#             S[j] = NIL
#     if counter != 1:
#         ans.append(counter * (counter - 1) // 2)

# res = []
#
# for a in ans:
#     res.append(a * (a - 1) // 2)
# print(sum(ans))