Matrix Inversion
시간 제한1초메모리 제한1024 MB
1부터 N^2까지를 N×N 격자에 채워 행 우선 순열의 역전 개수가 X, 열 우선 순열의 역전 개수가 Y가 되게 만든다.
문제
You have an by grid board, which is initially empty. You will write an integer to each cell, using each integer from to exactly once. Let be the integer written on the cell in the -th row from the top and the -th column from the left.
Let's define sequences and as follows:
For example, when the board looks like this,
1 3 4
2 7 6
9 8 5
and are defined as follows.
You are given integers . Find a way to fill in the cells so that the inversion numbers of and are and respectively, or report that it is impossible to do so.
Note: an inversion number of a sequence is the number of pairs s.t. both and are satisfied.
입력
Input is given from Standard Input in the following format:
출력
If there is no solution, print 'No'.
Otherwise, print the answer in the following format:
Yes
If there are multiple solutions, you can print any of them.