Lockdown Game -4

0

0 votes
Problem

Alice and Bob are playing a game. They have an integer N. Alice has l distinct intgers and Bob has m distinct integers each of which is between 1 to N1 (both inclusive). The Game starts with a starting integer X. In each turn each player can pick any number from his set of ditinct integers and add it to X. If X becomes greater than N, X is assigned the value XN i.e The integer X is cyclic over N  . (For example if N is 10 and current value of X is 7, and the integer to be added is chosen as 5, then value of X becomes 2)

If the value of X after a player adds an integer from his set, becomes 1 then that player wins the game. Alice goes first and Bob goes second. Both Alice and Bob play ideally and if a player can't win the game he would try to not let other person win the game. Thus there are three possible outcomes Alice wins, Alice loses(or Bob wins), the game continues infinitely and never ends. Alice wants to determine for what starting values of X can she win the game.

Help Alice determine what will be the result of the game for each 2XN.

Note : Each player can chose a integer from his set multiple times (if someone chose integer y for his current turn he can again chose y for his next turn too)

 

INPUT:

    First line contains a single integer N

    Second line contains single integer l

    Third line contains l distinct integers each between 1 and N1

    Fourth line contains a single integer m

    Fifth line contains m distinct integers each between 1 and N1

 

OUTPUT:

    For each 2XN, print 1 if Alice wins the game, 0 if Alice loses the game , 2 if the game continues infinitely

    i.e output N1 intgeres in a single line (0, 1 or 2 ) ith of which should be the result of game for strarting value of X=i+1

 

CONSTARINTS:

    2N5000

    1l,mN1

Sample Input
10
2 
8 5
3 
4 7 5
Sample Output
0 1 2 0 1 0 0 0 0 
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?