Index Case
문제
The epidemiologist W. Andy wants to find the index case of an ongoing crisis. To do this, he modelled the city of the outbreak and its residents with a cellular automaton. The city is represented by cells numbered from to and each cell has two neighbouring cells, one to its left and one to its right. The left neighbour of cell is cell and the right neighbour is cell . Additionally, the left neighbour of cell is cell and the right neighbour of cell is cell . Thus, the city and the corresponding automaton form a simple cycle.
Each cell contains an integer between and which represents how likely it is that this person is infected. Since the virus can only be transmitted by personal contact, the value in the th cell on day only depends on the values of its neighbours and itself on the previous day. If we denote this value by , then the outbreak can be simulated by a function using the formula: \[s_{d}[i]=f\big(s_{d-1}[i-1],s_{d-1}[i],s_{d-1}[i+1]\big).\] Note that as the city is cyclic both and are calculated modulo .
Andy wants to find the index case, so he first has to find , the state of the city on day zero. This poses a problem, however, as it is not known on which day the crisis started. Right now, Andy believes that he accomplished the task and found the state , but you are not convinced. Therefore, you want to check if there may be a state previous to the initial state proposed by Andy, i.e. whether there exists any state that gets transformed into by applying .
입력
The input consists of:
- One line with two integers and , the number of cells and the number of states.
- lines describing the values ( for each ) of the function modelling the automaton. The values are given in lexicographic order of the arguments: The first value is , the next is , and so on until , followed by and so forth. The last value is .
- One line with integers ( for each ), the initial state that has been proposed by Andy.
출력
Output yes if there exists at least one possible previous state and no otherwise.
예제
예제 1
4 2 1 2 1 2 2 1 2 1 1 2 1 2
yes
예제 2
6 2 1 2 1 2 2 1 2 1 1 2 1 2 1 2
no
예제 3
10 2 1 2 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 2
yes