#include using namespace std; int main() { int n; int arr[400000] = {}; int a_size = 0; int cnt = 0; cin >> n; for (int i = 0; i < n; i++) { int c; cin >> c; for(int j = 0; j < c; j++) { int x; cin >> x; if (a_size) { for (int y = 0; y < a_size; y += 2) { if (i > arr[y] && x < arr[y+1] || i < arr[y] && x > arr[y+1]) cnt+=1; } } if (x < i) continue; arr[a_size] =i; arr[a_size +1] = x; a_size+=2; } } cout << cnt << endl; return 0; }