High Card Duel
Two players are engaged in a card game. Initially, each player receives a certain number of cards, denoted as (n_1) and (n_2) respectively. During each turn, both players select one card from their hand and reveal it simultaneously. The player with the weaker card discards it, while the player with the stronger card retrieves theirs. If both cards are of equal strength, both are discarded. The game continues until at least one player has no cards left. If one player still has cards remaining, they earn (1) point, while the other scores (0). If both players run out of cards, each scores (0.5) points. There are (N) different types of cards in total. The strength relationship between the cards is potentially non-transitive and is specified by the matrix (A). The element (A_ij) is (1) if card (i) defeats card (j), and (0) otherwise. The goal is to calculate the maximum average score for the first player, assuming the second player plays optimally.
**Constraints**
- (1 n_1, n_2, N 8). - (A_ij + A_ji = 1) for (i j), (A_ii = 0).
**Input**
The first line contains the number (N). The next (N) lines each contain (N) numbers, defining the matrix (A). The following line contains the number (n_1) followed by (n_1) numbers, each indicating the type of card for the first player. The subsequent line provides the cards for the second player in the same format.
**Output**
Output the value of the game for the first player with a precision of at least (10^-8).