Symmetric matrix

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

In a square matrix with nn 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 iith row and jjth column as that at the intersection of the jjth row and the iith column for any ii, jj.

It is guaranteed that in this matrix, nn elements occur only once, and each of the rest occurs twice.

입력

The first line of the input file contains an integer nn --- the number of rows in the matrix (1n5001\le n \le 500). The following nn lines describe the rows of the matrix. Each of them contains nn space-separated integers, which are not greater than 10910^9 in absolute value.

출력

In the first line of the output file, print a single integer mm --- the minimal number of steps to obtain a symmetric matrix. Next, print an example of mm such steps. For the iith step, print four integers a_ia\_i, b_ib\_i, c_ic\_i, d_id\_i into a separate line, which mean that the element located in the a_ia\_ith row and the b_ib\_ith column must be swapped with the element in the c_ic\_ith row and the d_id\_ith column.