n = int(input())
arr = []
cnt = 0


for i in range(n):
    inp = list(map(int, input().split(" ")))
    my = sorted(inp[1:])
    for other in arr:
        mi = len(my) -1
        mo = len(other) -1
        r = 1
        while mo >= 0 and mi >= 0:
            if my[mi] >= other[mo]:
                mi -= 1
                continue
            cnt += 1
            mo -= 1
            r += 1
    arr.append(my)
        

print(cnt)


