Turn All the Lights Off

Eshita is a very ecologically conscious person. She works late and every night before going home she makes sure that all the lights are turned off at her workplace to conserve electricity. The workplace is represented as a 2-dimensional grid. Each square in the grid has 4 neighbors in up, down, left, and right directions. The electrical wiring is such that the sides of the grid wrap around i.e., the leftmost and the rightmost columns are neighbors. Similarly, the top and bottom rows are neighbors. This ensures that each of the squares in the grid has 4 neighbors. To standardize our notation, assume that the upper left-most square of the board is position (0, 0). Rows run horizontally and the top row is row 0. Columns are vertical and column 0 is the left-most column. Any reference to a square is by row then column; thus the square (4, 6) means row 4, column 6. So, in figure 1, the grid has 4 columns and 4 rows (all the grids will have same number of rows and columns). The shaded square is denoted as (2, 3). The four neighbors of the square (2, 3) are squares (1, 3), (3, 3), (2, 2) and (2, 0). Similarly, the four neighbors of the square (0, 0) are squares (3, 0), (1, 0), (0, 1), and (0, 3). Eshita is told that each square of the grid is a switch and a light. When a switch in some square is pushed, the light in that square and its neighboring squares toggle their ON/OFF state. Figure 2 shows a sequence where, starting from a grid with all the lights OFF, switches (1, 1), and (0, 0) have been pushed. The ON lights are shown as shaded. Figure 2 Figure 1 Given a grid with some of the lights ON, Eshita needs to say whether it is possible to turn all the lights OFF by pushing some sequence of button pushes. For example, in the first configuration of the 3×3 grid in figure 3, all the lights can be turned OFF by pushing the switches (0, 0), (1, 1) and (2, 2) (some other lights may be turned ON in the intermediate stages, but at the end of this sequence all the lights will be turned off). But in the second configuration, it is not possible to turn all the lights off by pushing any sequence of switches. Figure 2 Your task is to write a program, which given some arbitrary configuration of a grid will determine whether all the lights can be turned off or not.

2/2 Input The input file contains the descriptions of several grids. Each grid starts with a line containing an integer size, specifying the number of rows and cloumns in the grid (1 ≤ size ≤ 40). Next line has a single integer n, specifying the number of lights that are turned on. The following n lines contain two integers each, namely the row and column of each of ON light. Output For each of the grids output ‘Yes’ or ‘No’ on a line of its own. The output will be ‘Yes’ if all the lights in the configuration can be turned off and ‘No’ if it is not possible. Sample Input 5 11 00 01 02 04 14 21 22 23 32 42 44 3 3 01 02 10 Sample output Yes No