import sys from collections import defaultdict def main(): # Read input A = [] for _ in range(19): parts = list(map(int, sys.stdin.readline().split())) L_i = parts[0] A_i = parts[1:] if L_i > 0 else [] A.append(A_i) # Precompute mask_gt for x from 1 to 19 mask_gt = [0] * 20 # x ranges from 1 to 19 for x in range(1, 20): mask_gt[x] = ((1 << 19) - 1) ^ ((1 << x) - 1) # Initialize DP with a dictionary to track active masks and their even/odd counts prev = {0: (1, 0)} # mask: (even_count, odd_count) for step in range(19): current_A = A[step] if not current_A: prev = {} break curr = defaultdict(lambda: [0, 0]) # key: mask, value: [even, odd] for mask in prev: even_prev, odd_prev = prev[mask] for x in current_A: if (mask & (1 << (x - 1))) != 0: continue # x is already used mg = mask_gt[x] k = (mask & mg).bit_count() new_mask = mask | (1 << (x - 1)) # Process even_prev if even_prev > 0: new_parity = (0 + k) % 2 if new_parity == 0: curr[new_mask][0] += even_prev else: curr[new_mask][1] += even_prev # Process odd_prev if odd_prev > 0: new_parity = (1 + k) % 2 if new_parity == 0: curr[new_mask][0] += odd_prev else: curr[new_mask][1] += odd_prev # Update prev to curr, filtering out masks with zero counts new_prev = {} for m in curr: even, odd = curr[m] if even + odd > 0: new_prev[m] = (even, odd) prev = new_prev full_mask = (1 << 19) - 1 X_even, X_odd = prev.get(full_mask, (0, 0)) print(X_even, X_odd) if __name__ == "__main__": main()