import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeMap;

public class Ornithology {

    static Scanner sc = new Scanner(System.in);

    static ArrayList<Path> paths = new ArrayList<>();
    static TreeMap<Integer, ArrayList<Path>> mapPaths = new TreeMap<>();

    public static void main(String[] args) {

        int n = sc.nextInt();
        int res = 0;

        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();

            for (int j = 0; j < p; j++) {
                int des = sc.nextInt();
                Path cp = new Path(i, des);

                for (Integer key : mapPaths.keySet()) {
                    if (key < des) {
                        continue;
                    }
                    for (Path op : mapPaths.get(key)) {
                        if (cp.crosses(op)) {
                            res++;
                        }
                    }
                }

                if (mapPaths.containsKey(des)) {
                    mapPaths.get(des).add(cp);
                } else {
                    ArrayList<Path> t = new ArrayList<>();
                    t.add(cp);
                    mapPaths.put(des, t);
                }

            }
        }
        System.out.println(res);
    }


    static class Path {
        int start;
        int end;

        public Path(int start, int end) {
            this.start = start;
            this.end = end;
        }

        public boolean crosses(Path other) {
            int difStart = other.start - this.start;
            int difEnd = other.end - this.end;
            if (difStart == 0 || difEnd == 0) {
                return false;
            }

            if (difStart < 0) {
                return difEnd > 0;
            } else {
                return difEnd < 0;
            }
        }
    }

}
