#include #include using namespace std; using namespace atcoder; using mint = modint998244353; constexpr int mask = (1 << 19) - 1; constexpr int top = 1 << 19; int main() { vector a(19); for (int i = 0; i < 19; i++) { int l; cin >> l; for (int j = 0; j < l; j++) { int x; cin >> x; x--; a.at(i) ^= 1 << x; } } vector ans(1 << 20); ans.at(0) = 1; for (int i = 0; i < 19; i++) { for (int j = 0; j < 1 << 20; j++) { if (__builtin_popcount(j & mask) != i) continue; for (int k = 0; k < 19; k++) { if ((a.at(i) >> k & 1) and not(j >> k & 1)) { bool flip = __builtin_popcount(j & mask & ~((1 << k) - 1)) % 2 == 1; int t = flip ? top : 0; ans.at(j ^ (1 << k) ^ t) += ans.at(j); } } } } cout << ans.at(mask).val() << ' ' << ans.at(mask ^ top).val() << endl; return 0; }