{"raw_statement":[{"iden":"statement","content":"On the way to school, Karen became fixated on the puzzle game on her phone!\n\n<center>![image](https://espresso.codeforces.com/ddb523e5319d3e419119c3679bdc76340ed480e8.png)</center>The game is played as follows. In each level, you have a grid with _n_ rows and _m_ columns. Each cell originally contains the number 0.\n\nOne move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.\n\nTo win the level, after all the moves, the number in the cell at the _i_\\-th row and _j_\\-th column should be equal to _g__i_, _j_.\n\nKaren is stuck on one level, and wants to know a way to beat this level using the minimum number of moves. Please, help her with this task!"},{"iden":"input","content":"The first line of input contains two integers, _n_ and _m_ (1 ≤ _n_, _m_ ≤ 100), the number of rows and the number of columns in the grid, respectively.\n\nThe next _n_ lines each contain _m_ integers. In particular, the _j_\\-th integer in the _i_\\-th of these rows contains _g__i_, _j_ (0 ≤ _g__i_, _j_ ≤ 500)."},{"iden":"output","content":"If there is an error and it is actually not possible to beat the level, output a single integer _\\-1_.\n\nOtherwise, on the first line, output a single integer _k_, the minimum number of moves necessary to beat the level.\n\nThe next _k_ lines should each contain one of the following, describing the moves in the order they must be done:\n\n*   _row_ _x_, (1 ≤ _x_ ≤ _n_) describing a move of the form \"choose the _x_\\-th row\".\n*   _col_ _x_, (1 ≤ _x_ ≤ _m_) describing a move of the form \"choose the _x_\\-th column\".\n\nIf there are multiple optimal solutions, output any one of them."},{"iden":"examples","content":"Input\n\n3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1\n\nOutput\n\n4\nrow 1\nrow 1\ncol 4\nrow 3\n\nInput\n\n3 3\n0 0 0\n0 1 0\n0 0 0\n\nOutput\n\n\\-1\n\nInput\n\n3 3\n1 1 1\n1 1 1\n1 1 1\n\nOutput\n\n3\nrow 1\nrow 2\nrow 3"},{"iden":"note","content":"In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:\n\n<center>![image](https://espresso.codeforces.com/9725553e228c387c0f12702a054f3a965a7b0805.png)</center>In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required to only have one 1 in the center.\n\nIn the third test case, Karen has a grid with 3 rows and 3 columns. She can perform the following 3 moves to beat the level:\n\n<center>![image](https://espresso.codeforces.com/fd3281c5d83a863405f380c56f861f780a802d8c.png)</center>Note that this is not the only solution; another solution, among others, is _col 1_, _col 2_, _col 3_."}],"translated_statement":[{"iden":"statement","content":"在去学校的路上，Karen 被她手机上的拼图游戏吸引了！\n\n游戏规则如下。在每一关中，你有一个包含 #cf_span[n] 行和 #cf_span[m] 列的网格。每个单元格最初包含数字 #cf_span[0]。\n\n一次操作包括选择一行或一列，并将该行或列中的所有单元格的值增加 #cf_span[1]。\n\n要赢得该关卡，在所有操作完成后，位于第 #cf_span[i] 行和第 #cf_span[j] 列的单元格中的数字必须等于 #cf_span[gi, j]。\n\nKaren 目前卡在某一关，她想知道如何用最少的操作次数通过这一关。请帮她解决这个问题！\n\n输入的第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m ≤ 100]），分别表示网格的行数和列数。\n\n接下来的 #cf_span[n] 行，每行包含 #cf_span[m] 个整数。特别地，第 #cf_span[i] 行中的第 #cf_span[j] 个整数为 #cf_span[gi, j]（#cf_span[0 ≤ gi, j ≤ 500]）。\n\n如果存在错误，实际上无法通过该关卡，请输出一个整数 _-1_。\n\n否则，在第一行输出一个整数 #cf_span[k]，表示通过该关卡所需的最少操作次数。\n\n接下来的 #cf_span[k] 行，每行应描述一个操作（按执行顺序）：\n\n如果存在多个最优解，输出其中任意一个即可。\n\n在第一个测试用例中，Karen 有一个包含 #cf_span[3] 行和 #cf_span[5] 列的网格。她可以通过以下 #cf_span[4] 次操作通过该关卡：\n\n在第二个测试用例中，Karen 有一个包含 #cf_span[3] 行和 #cf_span[3] 列的网格。显然，无法通过该关卡；执行任何操作都会在网格上产生三个 #cf_span[1]，但题目要求中心位置只有一个 #cf_span[1]。\n\n在第三个测试用例中，Karen 有一个包含 #cf_span[3] 行和 #cf_span[3] 列的网格。她可以通过以下 #cf_span[3] 次操作通过该关卡：\n\n请注意，这并非唯一解；其他解之一是 _col 1_、_col 2_、_col 3_。\n\n"},{"iden":"input","content":"输入的第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m ≤ 100]），分别表示网格的行数和列数。接下来的 #cf_span[n] 行，每行包含 #cf_span[m] 个整数。特别地，第 #cf_span[i] 行中的第 #cf_span[j] 个整数为 #cf_span[gi, j]（#cf_span[0 ≤ gi, j ≤ 500]）。"},{"iden":"output","content":"如果存在错误，实际上无法通过该关卡，请输出一个整数 _-1_。否则，在第一行输出一个整数 #cf_span[k]，表示通过该关卡所需的最少操作次数。接下来的 #cf_span[k] 行，每行应描述一个操作（按执行顺序）：\n\n_row_ #cf_span[x]，（#cf_span[1 ≤ x ≤ n]）表示选择第 #cf_span[x] 行的操作。\n_col_ #cf_span[x]，（#cf_span[1 ≤ x ≤ m]）表示选择第 #cf_span[x] 列的操作。\n\n如果存在多个最优解，输出其中任意一个即可。"},{"iden":"examples","content":"输入\n3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1\n输出\n4\nrow 1\nrow 1\ncol 4\nrow 3\n\n输入\n3 3\n0 0 0\n0 1 0\n0 0 0\n输出\n-1\n\n输入\n3 3\n1 1 1\n1 1 1\n1 1 1\n输出\n3\nrow 1\nrow 2\nrow 3"},{"iden":"note","content":"在第一个测试用例中，Karen 有一个包含 #cf_span[3] 行和 #cf_span[5] 列的网格。她可以通过以下 #cf_span[4] 次操作通过该关卡：\n\n在第二个测试用例中，Karen 有一个包含 #cf_span[3] 行和 #cf_span[3] 列的网格。显然，无法通过该关卡；执行任何操作都会在网格上产生三个 #cf_span[1]，但题目要求中心位置只有一个 #cf_span[1]。\n\n在第三个测试用例中，Karen 有一个包含 #cf_span[3] 行和 #cf_span[3] 列的网格。她可以通过以下 #cf_span[3] 次操作通过该关卡：\n\n请注意，这并非唯一解；其他解之一是 _col 1_、_col 2_、_col 3_。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the number of rows and columns, respectively.  \nLet $ G = (g_{i,j}) \\in \\mathbb{Z}^{n \\times m} $ be the target grid, where $ 0 \\leq g_{i,j} \\leq 500 $.  \nLet $ r_i \\in \\mathbb{Z}_{\\geq 0} $ denote the number of times row $ i $ is incremented.  \nLet $ c_j \\in \\mathbb{Z}_{\\geq 0} $ denote the number of times column $ j $ is incremented.  \n\n**Constraints**  \nFor all $ i \\in \\{1, \\dots, n\\} $, $ j \\in \\{1, \\dots, m\\} $:  \n$$\ng_{i,j} = r_i + c_j\n$$\n\n**Objective**  \nMinimize the total number of moves:  \n$$\n\\sum_{i=1}^n r_i + \\sum_{j=1}^m c_j\n$$  \nsubject to the above constraints.  \n\nIf no non-negative integer solution $ (r_1, \\dots, r_n, c_1, \\dots, c_m) $ exists, output $-1$.  \nOtherwise, output the minimal number of moves and a sequence of moves (row or column increments) achieving it.","simple_statement":null,"has_page_source":false}