1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
#define pii pair<int, int>
#define For(i, l, r) for (int i=l;(l<=r?i<=r:i>=r);(l<=r?i++:i--))
#define DEBUG
#ifdef DEBUG
auto operator<<(auto &o,auto p)->decltype(p.first,o){return o<<'('<<p.first<<", "<<p.second<<')';}
auto operator<<(auto &o,auto x)->decltype(x.end(),o){o<<'{';int i=2;for(auto &e:x)o<<(", ")+i<<e,i=0;return o<<'}';}
#define LOG(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X);
#else
#define LOG(x...)(void)0
#endif
//#define int long long
using namespace std;

const int inf=1e9+1, M = 1LL << 40;

void solve(){
    int k, n1;
    cin >> k >> n1;
    vector<vector<int>> m(k);
    m[0] = vector<int>(n1, 1);
    int res = n1, last = n1;
    for (int i = 1; i < k; i++){
        int n;
        cin >> n;
        m[i] = vector<int>(n);
        vector <int> c(last + 1, 0);
        for (int j = 0; j < n; j++){
            cin >> m[i][j];
        }
        last = n;
    }
    vector<int> c(m[k - 1].size(), 1);
    for (int i = k - 1; i > 0; i--){
        int cur = 0;
        int pren = m[i - 1].size();
        vector<int> c2(pren, 0);
        for (int j = 0; j < c.size(); j++){
            cur += c[j];
            if (m[i][j] > 0)
                c2[m[i][j] - 1] += c[j];
        }
        for (int j = 0; j < pren; j++)
            c2[j] = max(c2[j], 1);
        res = max(res, cur);
        c = c2;
    }
    int s = 0;
    for (auto el: c)
        s += el;
    res = max(res, s);
    cout << res << '\n';
}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}