시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB17101090.909%

문제

We are given a board of n × n squares, where n is an odd integer meeting the inequality 3 ≤ n < 50, and a set of k = (n2 - 3)/2 stones. Each stone has the shape of a rectangle covering exactly 2 squares of the board. The board squares are numbered consecutively by rows - the squares in the first row (from left to right) are numbered from 1 to n, the squares in the second row from n+1 to 2n, and so on until we reach the bottom right corner square whose number is n2.

We cut any three squares out of the board, and next we want to cover it with the stones. We require that every square not removed should be covered with exactly one stone (covering also one adjacent square) and that cut out squares remain uncovered.

Is it always possible?

Write a program that:

  • reads from the standard input the dimension of the board n and numbers of three board squares that have been cut out,
  • examines whether such a board can be covered with stones. If not, the program writes the answer NIE ("no") in the standard output.
    If so, it writes in the standard output a sequence of k = (n2 - 3)/2 pairs of integers indicating the positions of stones covering the given board.

If there are many ways to cover the board with stones, your program should write only one (arbitrary) of them.

입력

In the only line of the standard input there are written four numbers separated by single spaces. The first number is the dimension of the board n, and the three other are the numbers of the cut out squares. The last number is followed by the end of the line.

The data in the standard input are written correctly, and your program need not verify that.

출력

The standard output should contain:

  • either one word NIE
  • or in each of k consecutive lines two numbers separated by a space, i.e. the numbers of two adjacent squares covered with one stone.

예제 입력 1

7 17 25 40

예제 출력 1

18 19
20 21
8 9
10 11
12 13
14 7
6 5
4 3
1 2
15 22
16 23
29 36
30 37
24 31
32 39
43 44
38 45
46 47
48 49
41 42
33 34
35 28
26 27

예제 입력 2

7 25 32 40

예제 출력 2

NIE

출처

Olympiad > Polish Olympiad in Informatics > POI 1994/1995 > Stage 2 4번

  • 스페셜 저지를 만든 사람: koosaga