Problem: There are lamps on a line, numbered from to . Each one has an initial state off () or on ().
You're given subsets of , such that the intersection of any three subsets is empty. In other words, for all , .
In one operation, you can choose one of these subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.
Let be the minimum number of operations you have to do in order to make the first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between and ), they can be either off or on.
You have to compute for all .
Input Format: The first line contains two integers and ().
The second line contains a binary string of length , representing the initial state of each lamp (the lamp is off if , on if ).
The description of each one of the subsets follows, in the following format:
The first line of the description contains a single integer () — the number of elements in the subset.
The second line of the description contains distinct integers () — the elements of the subset.
It is guaranteed that:
- The intersection of any three subsets is empty;
- It's possible to make all lamps be simultaneously on using some operations.
Output Format: You must output lines. The -th line should contain a single integer — the minimum number of operations required to make the lamps to be simultaneously on.
Note: In the first example:
- For , we can just apply one operation on , the final states will be ;
- For , we can apply operations on and , the final states will be ;
- For , we can apply operations on , and , the final states will be .
In the second example:
- For , we can just apply one operation on , the final states will be ;
- For , we can apply operations on , the final states will be .