N = 19 bit_count = lambda x: bin(x).count("1") exist_table = [[False] * N for _ in range(N)] for i in range(N): L, *A = map(int, input().split()) for a in A: exist_table[i][a - 1] = True dp0 = [0] * (1 << N) dp1 = [0] * (1 << N) dp0[0] = 1 for b in range(1 << N): sign = True for i in range(N): n = bit_count(b) if (b >> i) & 1: continue sign = not sign if not exist_table[n][i]: continue c = b | (1 << i) if sign: dp1[c] += dp0[b] dp0[c] += dp1[b] else: dp0[c] += dp0[b] dp1[c] += dp1[b] print(dp0[-1], dp1[-1])