func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long inf = 1000 * 1000 * 1000;   const long long inf64 = 1ll * inf * inf;   const long long mod = 1e9 + 7;   mt19937 rng(0);   long long binpow(long long a, long long p, long long mod = 998244353) {     if (p == 0) return 1;     if (p % 2 == 0) {       long long t = binpow(a, p / 2);       return t * t % mod;     } else {       return binpow(a, p - 1) * a % mod;     }   }   long long invert(long long x) { return binpow(x, 998244351); }   pair<long long, long long> add(pair<long long, long long> a,                                  pair<long long, long long> b) {     pair<long long, long long> ans;     ans.first = a.first * b.second + b.first * a.second;     ans.second = a.second * b.second;     ans.first %= 998244353;     ans.second %= 998244353;     return ans;   }   pair<long long, long long> multi(pair<long long, long long> a,                                    pair<long long, long long> b) {     return {a.first * b.first % 998244353, a.second * b.second % 998244353};   }   void run() {     long long n;     cin >> n;     vector<vector<long long>> a(n);     vector<vector<long long>> poses(1e6 + 10);     for (long long i = 0; i < n; i++) {       long long k;       cin >> k;       a[i].resize(k);       for (long long j = 0; j < k; j++) {         cin >> a[i][j];         poses[a[i][j]].push_back(i);       }     }     pair<long long, long long> ans = {0, 1};     for (long long i = 0; i < n; ++i) {       pair<long long, long long> t = {1, n};       for (long long k = 0; k < a[i].size(); ++k) {         pair<long long, long long> r = {1, a[i].size()};         pair<long long, long long> e = {poses[a[i][k]].size(), n};         ans = add(ans, multi(multi(t, r), e));       }     }     cout << ans.first * invert(ans.second) % 998244353;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 0; i < t; i++) {       run();     }     return 0;   }   