Symmetric matrix
시간 제한2초메모리 제한256 MB
값이 한 번 또는 두 번씩 나타나는 n x n 행렬이 주어질 때, 대칭 행렬로 만드는 최소 교환 횟수와 교환 과정을 출력한다.
문제
In a square matrix with rows, all elements are integers. You can swap two elements of the matrix at one step. Find out the minimal number of steps necessary to obtain a symmetric matrix from the initial one. A symmetric matrix is a matrix with the same element at the intersection of the th row and th column as that at the intersection of the th row and the th column for any , .
It is guaranteed that in this matrix, elements occur only once, and each of the rest occurs twice.
입력
The first line of the input file contains an integer --- the number of rows in the matrix (). The following lines describe the rows of the matrix. Each of them contains space-separated integers, which are not greater than in absolute value.
출력
In the first line of the output file, print a single integer --- the minimal number of steps to obtain a symmetric matrix. Next, print an example of such steps. For the th step, print four integers , , , into a separate line, which mean that the element located in the th row and the th column must be swapped with the element in the th row and the th column.