This problem is about the Braindead card game which is invented on 21 February 2019 and is loosely based on some other unspecified card game. It is fairly easy to guess though.
There are cards of n suits and m ranks. Some suits are trumps. Note that there may be multiple trumps or none at all. Unlike most actual card games multiple cards may share both rank and suit.
There are two players. Each of them has some non-empty set of cards. This set of cards is called the hand. Both players know each other's hands. The cards in the hand of some player are called his cards.
A card of suit s_1 with rank r_1 beats a card of suit s_2 and rank r_2 if one of the following conditions hold:
One of the player is the attacker and the other is the defender. The following steps happen
A player can not play the same card twice.
How many starting attacks are there, such that the attacker wins the game from there assuming players play optimally afterwards (after the starting attack)? Starting attacks which play different cards with the same rank and suit are considered different starting attacks.
The first line contains two integers n and m (1≤n,m≤18), the number of suits and ranks, respectively.
The second line contains n integers t_i (0≤t_i≤1). t_i is equal to 1 if the i-th suit is a trump and to 0 if it is a regular suit (not a trump).
Next n lines describe the hand of the attacker. i-th of them contains m integers a_i,j (0≤a_i,j≤1012). a_i,j is equal to the number of cards of suit i with rank j the attacker has.
Next n lines describe the hand of the defender in the same format.
It is guaranteed that both players hands are non-empty.
Output a single integer --- the number of winning first attacks.