line_count = int(input())
birds = []
sums = []
for _ in range(line_count):
    line = input().split()
    bird_count = int(line[0])
    sums.append(bird_count)
    position = {}
    for bird in line[1:]:
        desired_pos = int(bird)
        if desired_pos in position:
            position[desired_pos] += 1
        else:
            position[desired_pos] = 1
    birds.append(position)

all_sums = sum(sums)
collisions = 0
for birds_index, (start, cur_sum) in enumerate(zip(birds, sums)):
    for pos in start.keys():
        collisions += all_sums - cur_sum
        for other_index, other_birds in enumerate(birds):
            if other_index == birds_index:
                continue
            if pos in other_birds:
                collisions -= other_birds[pos]

print(collisions // 2)

