CF1236D Alice and the Doll

Description

Alice got a new doll these days. It can even walk! Alice has built a maze for the doll and wants to test it. The maze is a grid with $ n $ rows and $ m $ columns. There are $ k $ obstacles, the $ i $ -th of them is on the cell $ (x_i, y_i) $ , which means the cell in the intersection of the $ x_i $ -th row and the $ y_i $ -th column. However, the doll is clumsy in some ways. It can only walk straight or turn right at most once in the same cell (including the start cell). It cannot get into a cell with an obstacle or get out of the maze. More formally, there exist $ 4 $ directions, in which the doll can look: 1. The doll looks in the direction along the row from the first cell to the last. While moving looking in this direction the doll will move from the cell $ (x, y) $ into the cell $ (x, y + 1) $ ; 2. The doll looks in the direction along the column from the first cell to the last. While moving looking in this direction the doll will move from the cell $ (x, y) $ into the cell $ (x + 1, y) $ ; 3. The doll looks in the direction along the row from the last cell to first. While moving looking in this direction the doll will move from the cell $ (x, y) $ into the cell $ (x, y - 1) $ ; 4. The doll looks in the direction along the column from the last cell to the first. While moving looking in this direction the doll will move from the cell $ (x, y) $ into the cell $ (x - 1, y) $ . .Standing in some cell the doll can move into the cell in the direction it looks or it can turn right once. Turning right once, the doll switches it's direction by the following rules: $ 1 \to 2 $ , $ 2 \to 3 $ , $ 3 \to 4 $ , $ 4 \to 1 $ . Standing in one cell, the doll can make at most one turn right. Now Alice is controlling the doll's moves. She puts the doll in of the cell $ (1, 1) $ (the upper-left cell of the maze). Initially, the doll looks to the direction $ 1 $ , so along the row from the first cell to the last. She wants to let the doll walk across all the cells without obstacles exactly once and end in any place. Can it be achieved?

Input Format

N/A

Output Format

N/A

Explanation/Hint

Here is the picture of maze described in the first example: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1236D/a446f23c7b4fc0fe67d2e36e4d38a412a7a5c518.png)In the first example, the doll can walk in this way: - The doll is in the cell $ (1, 1) $ , looks to the direction $ 1 $ . Move straight; - The doll is in the cell $ (1, 2) $ , looks to the direction $ 1 $ . Move straight; - The doll is in the cell $ (1, 3) $ , looks to the direction $ 1 $ . Turn right; - The doll is in the cell $ (1, 3) $ , looks to the direction $ 2 $ . Move straight; - The doll is in the cell $ (2, 3) $ , looks to the direction $ 2 $ . Move straight; - The doll is in the cell $ (3, 3) $ , looks to the direction $ 2 $ . Turn right; - The doll is in the cell $ (3, 3) $ , looks to the direction $ 3 $ . Move straight; - The doll is in the cell $ (3, 2) $ , looks to the direction $ 3 $ . Move straight; - The doll is in the cell $ (3, 1) $ , looks to the direction $ 3 $ . The goal is achieved, all cells of the maze without obstacles passed exactly once.