#include #include #include using namespace std; typedef long long ll; int main(){ vector L(19); vector A(19, 0); for (ll i = 0; i < 19; i++){ cin >> L[i]; assert(L[i] >= 0 && L[i] <= 19); vector a(L[i]); for (ll j = 0; j < L[i]; j++){ cin >> a[j]; assert(a[j] >= 1); assert(a[j] <= 19); if (j >= 1){ assert(a[j] > a[j - 1]); } A[i] += (1LL << (a[j] - 1)); } } /*for (ll i = 0; i < 19; i++){ cout << A[i] << " "; } cout << endl;*/ vector dp1((1 << 19), 0);//奇数 vector dp2((1 << 19), 0);//偶数 dp2[0] = 1; for (ll i = 0; i < (1 << 19) - 1; i++){ ll popcnt1 = __builtin_popcount(i); for (ll j = 0; j < 19; j++){ if ((i >> j) & 1){ continue; } if ((A[j] >> popcnt1) & 1){ ll bitmask = (1 << (j + 1)) - 1; bitmask = bitmask ^ ((1 << 19) - 1); ll popcnt2 = __builtin_popcount(bitmask & i); if (popcnt2 % 2 == 1){ dp1[i | (1 << j)] += dp2[i]; dp2[i | (1 << j)] += dp1[i]; } else{ dp1[i | (1 << j)] += dp1[i]; dp2[i | (1 << j)] += dp2[i]; } } } } cout << dp2[(1 << 19) - 1] << " " << dp1[(1 << 19) - 1] << endl; }