description: A subarray of array a from index l to the index r is the array [a_l, a_{l+1}, ..., a_{r}]. The number of occurrences of the array b in the array a is the number of subarrays of a such that they are equal to b.
  
  You are given n arrays A_1, A_2, ..., A_n; the elements of these arrays are integers from 1 to k. You have to build an array a consisting of m integers from 1 to k in such a way that, for every given subarray A_i, the number of occurrences of A_i in the array a is not less than the number of occurrences of each non-empty subarray of A_i in a. Note that if A_i doesn't occur in a, and no subarray of A_i occurs in a, this condition is still met for A_i.
  
  Your task is to calculate the number of different arrays a you can build, and print it modulo 998244353.
  
  Input
  
  The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 3 ⋅ 10^5) — the number of the given arrays, the desired length of the array a, and the upper bound on the values in the arrays.
  
  Then n lines follow. The i-th line represents the array A_i. The first integer in the i-th line is c_i (1 ≤ c_i ≤ m) — the number of elements in A_i; then, c_i integers from 1 to k follow — the elements of the array A_i.
  
  Additional constraint on the input: ∑_{i=1}^n c_i ≤ 3 ⋅ 10^5; i. e., the number of elements in the given arrays in total does not exceed 3 ⋅ 10^5.
  
  Output
  
  Print one integer — the number of different arrays a you can build, taken modulo 998244353.
  
  Examples
  
  Input
  
  
  2 4 3
  2 1 2
  1 3
  
  
  Output
  
  
  5
  
  
  Input
  
  
  2 4 3
  2 1 2
  3 3 2 1
  
  
  Output
  
  
  0
  
  
  Input
  
  
  1 42 1337
  2 13 31
  
  
  Output
  
  
  721234447
solution: #include <bits/stdc++.h>
  template <class t>
  inline void read(t &s) {
    s = 0;
    register long long f = 1;
    register char c = getchar();
    while (!isdigit(c)) {
      if (c == '-') f = -1;
      c = getchar();
    }
    while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
    ;
    s *= f;
  }
  template <class t, class... A>
  inline void read(t &x, A &...a) {
    read(x);
    read(a...);
  }
  template <class t>
  inline void write(t x) {
    if (x < 0) putchar('-'), x = -x;
    static long long buf[21], top = 0;
    while (x) buf[++top] = x % 10, x /= 10;
    if (!top) buf[++top] = 0;
    while (top) putchar(buf[top--] ^ '0');
  }
  inline void setIn(std::string s) {
    freopen(s.c_str(), "r", stdin);
    return;
  }
  inline void setOut(std::string s) {
    freopen(s.c_str(), "w", stdout);
    return;
  }
  inline void setIO(std::string s = "") {
    setIn(s + ".in");
    setOut(s + ".out");
    return;
  }
  template <class t>
  inline bool ckmin(t &x, t y) {
    if (x > y) {
      x = y;
      return 1;
    }
    return 0;
  }
  template <class t>
  inline bool ckmax(t &x, t y) {
    if (x < y) {
      x = y;
      return 1;
    }
    return 0;
  }
  inline long long lowbit(long long x) { return x & (-x); }
  const long long MaxN = 3e5 + 50;
  const long long p = 998244353;
  std::map<long long, long long> F[MaxN];
  long long n, m, K;
  long long f[MaxN], ideg[MaxN], odeg[MaxN];
  std::vector<long long> nd[MaxN];
  inline long long getf(long long x) { return f[x] == x ? x : f[x] = getf(f[x]); }
  inline void merge(long long x, long long y) {
    long long a = getf(x), b = getf(y);
    if (a != b) f[b] = a;
  }
  inline void add(long long x, long long y) {
    if (!F[x].count(y)) F[x][y], ++odeg[x], ++ideg[y], merge(x, y);
  }
  long long g[MaxN];
  signed main(void) {
    read(n, m, K);
    for (long long i = 1; i <= K; ++i) f[i] = i;
    while (n--) {
      long long x, y, lst = 0;
      read(x);
      while (x--) {
        read(y);
        if (lst) add(lst, y);
        lst = y;
      }
    }
    for (long long i = 1; i <= K; ++i) nd[getf(i)].push_back(i);
    for (long long i = 1; i <= K; ++i)
      if (getf(i) == i) {
        long long c0 = 0, c2 = 0, C0 = 0, C2 = 0;
        for (auto j : nd[i]) {
          if (!ideg[j])
            ++c0;
          else if (ideg[j] >= 2)
            ++c2;
          if (!odeg[j])
            ++C0;
          else if (odeg[j] >= 2)
            ++C2;
        }
        if (!c2 && c0 == 1 && !C2 && C0 == 1) ++g[(long long)nd[i].size()];
      }
    std::vector<std::pair<long long, long long> > G;
    for (long long i = 1; i <= K; ++i)
      if (g[i]) G.push_back(std::make_pair(i, g[i]));
    std::memset(f, 0, sizeof f), f[0] = 1;
    for (long long i = 0; i < m; ++i)
      for (auto j : G)
        if (i + j.first <= m) (f[i + j.first] += f[i] * j.second) %= p;
    write(f[m]), putchar('\n');
    return 0;
  }
  