Today is Yeongseon's birthday. Her friends prepared one rectangular birthday cake.
The top of the cake is divided into n×m cells. The top left cell is (1,1), the top right cell is (n,1), and the bottom right cell is (n,m). In a coordinate (x,y), x is the column counted from the left and y is the row counted from the top.
Seven cells carry one decoration each.
- A candle sits on (x1,y1).
- Cherries sit on (x2,y2), (x3,y3), (x4,y4).
- Strawberries sit on (x5,y5), (x6,y6), (x7,y7).
Yeongseon wants to cut the cake into four pieces. She eats one piece and her three friends eat the other three.
Every piece is made of cells, and every cell belongs to exactly one piece. Every piece must also be connected. Two cells that share a side are neighbours, and a piece is connected when you can travel between any two of its cells by stepping only on neighbouring cells of that same piece.
Yeongseon eats the piece that holds the candle, and each of the other three pieces must hold one strawberry and one cherry.
Given n, m, and the positions of the candle, the cherries and the strawberries, write a program that decides whether the cake can be cut this way.