CF237B.Young Table

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got table aa , consisting of nn rows, numbered from 1 to nn . The ii -th line of table aa contains cic_{i} cells, at that for all ii (1<i<=n) holds ci<=ci1c_{i}<=c_{i-1} .

Let's denote ss as the total number of cells of table aa , that is, . We know that each cell of the table contains a single integer from 11 to ss , at that all written integers are distinct.

Let's assume that the cells of the ii -th row of table aa are numbered from 1 to cic_{i} , then let's denote the number written in the jj -th cell of the ii -th row as ai,ja_{i,j} . Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions:

  1. for all i,ji,j (1<i<=n; 1<=j<=c_{i}) holds a_{i,j}>a_{i-1,j} ;
  2. for all i,ji,j (1<=i<=n; 1<j<=c_{i}) holds a_{i,j}>a_{i,j-1} .

In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap.

Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than ss . You do not have to minimize the number of operations.

输入格式

The first line contains a single integer nn (1<=n<=50)(1<=n<=50) that shows the number of rows in the table. The second line contains nn space-separated integers cic_{i} (1<=ci<=50; ci<=ci1)(1<=c_{i}<=50; c_{i}<=c_{i-1}) — the numbers of cells on the corresponding rows.

Next nn lines contain table аа . The ii -th of them contains cic_{i} space-separated integers: the jj -th integer in this line represents ai,ja_{i,j} .

It is guaranteed that all the given numbers ai,ja_{i,j} are positive and do not exceed ss . It is guaranteed that all ai,ja_{i,j} are distinct.

输出格式

In the first line print a single integer mm (0<=m<=s)(0<=m<=s) , representing the number of performed swaps.

In the next mm lines print the description of these swap operations. In the ii -th line print four space-separated integers xi,yi,pi,qix_{i},y_{i},p_{i},q_{i} (1<=xi,pi<=n; 1<=yi<=cxi; 1<=qi<=cpi)(1<=x_{i},p_{i}<=n; 1<=y_{i}<=c_{xi}; 1<=q_{i}<=c_{pi}) . The printed numbers denote swapping the contents of cells axi,yia_{xi},y_{i} and api,qia_{pi},q_{i} . Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed.

输入输出样例

  • 输入#1

    3
    3 2 1
    4 3 5
    6 1
    2
    

    输出#1

    2
    1 1 2 2
    2 1 3 1
    
  • 输入#2

    1
    4
    4 3 2 1
    

    输出#2

    2
    1 1 1 4
    1 2 1 3
    
首页