import collections



n=int(eval(input()))

s=[(eval(input())) for _ in range(n)]



lis=[list(s[i]) for i in range(n)]

lis_sort = [sorted(lis[i]) for i in range(n)]

lis_sort = [''.join(lis_sort[i]) for i in range(n)]

lis_sort.sort()



c = collections.Counter(lis_sort)

values, counts = list(zip(*c.most_common(len(c))))

cnt=0

for i in range(len(counts)):

    if counts[i]==2: cnt+=1

    elif counts[i]>2: cnt+=counts[i]*(counts[i]-1)//2

print(cnt)
n = int(eval(input()))

d = {}

for i in range(n):

    s = sorted(list(eval(input())))   

    s = ''.join(s)

    d[s] = d.get(s, 0) + 1



cnt = 0

for k,v in list(d.items()):

    if v >= 2:

        cnt += v * (v - 1) // 2 # 組の個数



print(cnt)
import collections

n = int(eval(input()))
s = [(eval(input())) for _ in range(n)]
lis = [list(s[i]) for i in range(n)]
lis_sort = [sorted(lis[i]) for i in range(n)]
lis_sort = ["".join(lis_sort[i]) for i in range(n)]
lis_sort.sort()
c = collections.Counter(lis_sort)
values, counts = list(zip(*c.most_common(len(c))))
cnt = 0
for i in range(len(counts)):
    if counts[i] == 2:
        cnt += 1
    elif counts[i] > 2:
        cnt += counts[i] * (counts[i] - 1) // 2
print(cnt)

n = int(eval(input()))
d = {}
for i in range(n):
    s = sorted(list(eval(input())))
    s = "".join(s)
    d[s] = d.get(s, 0) + 1
cnt = 0
for k, v in list(d.items()):
    if v >= 2:
        cnt += v * (v - 1) // 2  # 組の個数
print(cnt)

-import collections - -s = [(eval(input())) for _ in range(n)] -lis = [list(s[i]) for i in range(n)] -lis_sort = [sorted(lis[i]) for i in range(n)] -lis_sort = ["".join(lis_sort[i]) for i in range(n)] -lis_sort.sort() -c = collections.Counter(lis_sort) -values, counts = list(zip(*c.most_common(len(c)))) +d = {} +for i in range(n): +    s = sorted(list(eval(input()))) +    s = "".join(s) +    d[s] = d.get(s, 0) + 1 -for i in range(len(counts)): -    if counts[i] == 2: -        cnt += 1 -    elif counts[i] > 2: -        cnt += counts[i] * (counts[i] - 1) // 2 +for k, v in list(d.items()): +    if v >= 2: +        cnt += v * (v - 1) // 2  # 組の個数