#define IB ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#include <bits/stdc++.h>
#define ll long long
#define loop(i, n) for(int i=0;i<n;i++)
#define loopi(i, j, n) for(int i=j;i<n;i++)
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
const int MAX = 1e9, MOD = 1e9 + 7, N = 1e5 + 5;
const double eps = 1e-10;
// L-R-U-D-DL-DR-UL-UR
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
vector<vector<int>> cells;
int n;
int sol() {
int unstable = 0;
for (int i = 0; i < n; ++i) {
int adj1 = (i + 1 == n ? 0 : i + 1);
int adj2 = (i - 1 == -1 ? n - 1 : i - 1);
for (int j = 1; j < cells[i].size(); ++j) {
int e_adj1 = upper_bound(all(cells[adj1]), cells[i][j]) - cells[adj1].begin();
int e_adj2 = upper_bound(all(cells[adj2]), cells[i][j]) - cells[adj2].begin();
int s_adj1 = lower_bound(all(cells[adj1]), cells[i][j - 1]) - cells[adj1].begin();
int s_adj2 = lower_bound(all(cells[adj2]), cells[i][j - 1]) - cells[adj2].begin();
if (e_adj1 - s_adj1 != e_adj2 - s_adj2) unstable++;
}
}
return unstable;
}
void solve() {
int _ = 1;
//cin >> _;
while (_--) {
int k;
cin >> n;
cells.resize(n);
loop(i, n) {
cin >> k;
cells[i].resize(k);
loop(j, k) cin>>cells[i][j];
sort(all(cells[i]));
}
cout << sol() << endl;
}
}
void Hema() {
IB
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
solve();
}
int main() {
Hema();
}
628. Maximum Product of Three Numbers | 1526A - Mean Inequality |
1526B - I Hate 1111 | 1881. Maximum Value after Insertion |
237. Delete Node in a Linked List | 27. Remove Element |
39. Combination Sum | 378. Kth Smallest Element in a Sorted Matrix |
162. Find Peak Element | 1529A - Eshag Loves Big Arrays |
19. Remove Nth Node From End of List | 925. Long Pressed Name |
1051. Height Checker | 695. Max Area of Island |
402. Remove K Digits | 97. Interleaving String |
543. Diameter of Binary Tree | 124. Binary Tree Maximum Path Sum |
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts | 501A - Contest |
160A- Twins | 752. Open the Lock |
1535A - Fair Playoff | 1538F - Interesting Function |
1920. Build Array from Permutation | 494. Target Sum |
797. All Paths From Source to Target | 1547B - Alphabetical Strings |
1550A - Find The Array | 118B - Present from Lena |