On the way to school, Karen became fixated on the puzzle game on her phone! [Image] 

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.

One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.

To 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.

Karen 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!


-----Input-----

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.

The 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).


-----Output-----

If there is an error and it is actually not possible to beat the level, output a single integer -1.

Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level.

The next k lines should each contain one of the following, describing the moves in the order they must be done:  row x, (1 ≤ x ≤ n) describing a move of the form "choose the x-th row".  col x, (1 ≤ x ≤ m) describing a move of the form "choose the x-th column". 

If there are multiple optimal solutions, output any one of them.


-----Examples-----
Input
3 5
2 2 2 3 2
0 0 0 1 0
1 1 1 2 1

Output
4
row 1
row 1
col 4
row 3

Input
3 3
0 0 0
0 1 0
0 0 0

Output
-1

Input
3 3
1 1 1
1 1 1
1 1 1

Output
3
row 1
row 2
row 3



-----Note-----

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: [Image] 

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.

In 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: [Image] 

Note that this is not the only solution; another solution, among others, is col 1, col 2, col 3.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Complete search

Implementation

Greedy algorithms


Solutions:
(n, m) = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
r = [a[i][0] - a[0][0] for i in range(n)]
c = [a[0][i] - a[0][0] for i in range(m)]
t = min(r)
r = [x - t for x in r]
t = min(c)
c = [x - t for x in c]
p = a[0][0] - r[0] - c[0]
if n < m:
	r = [x + p for x in r]
else:
	c = [x + p for x in c]
for i in range(n):
	for j in range(m):
		if r[i] + c[j] != a[i][j]:
			print(-1)
			quit()
print(sum(r) + sum(c))
for (i, x) in enumerate(r):
	for j in range(x):
		print('row', i + 1)
for (i, x) in enumerate(c):
	for j in range(x):
		print('col', i + 1)


def isNullified():
	for i in range(n):
		if max(matrix[i]) != 0:
			return False
	return True

def processRows():
	for i in range(n):
		minValue = min(matrix[i])
		if minValue != 0:
			content = 'row ' + str(i + 1)
			result.extend(minValue * [content])
			for j in range(m):
				matrix[i][j] -= minValue

def processCols():
	for i in range(m):
		column = [row[i] for row in matrix]
		minValue = min(column)
		if minValue != 0:
			content = 'col ' + str(i + 1)
			result.extend(minValue * [content])
			for j in range(n):
				matrix[j][i] -= minValue
inpt = input().split()
n = int(inpt[0])
m = int(inpt[1])
matrix = []
result = []
for i in range(n):
	row = list(map(int, input().split()))
	matrix.append(row)
if n < m:
	processRows()
	processCols()
else:
	processCols()
	processRows()
if isNullified():
	print(len(result))
	print('\n'.join(result))
else:
	print(-1)


import logging
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
logger.addHandler(ch)

def solve(n, m, grid):
	logger.debug('\n'.join([str(x) for x in grid]))
	a = [grid[i][0] for i in range(n)]
	b = [grid[0][i] - grid[0][0] for i in range(m)]
	if any((grid[i][j] != a[i] + b[j] for i in range(n) for j in range(m))):
		logger.debug('Not possible ....')
		return [-1]
	(best_move, best) = (None, float('inf'))
	for z in range(501):
		a = [grid[i][0] - z for i in range(n)]
		b = [z + grid[0][i] - grid[0][0] for i in range(m)]
		logger.debug('z = %s', z)
		logger.debug('a = %s', a)
		logger.debug('b = %s', b)
		if any((x < 0 for x in a + b)):
			logger.debug('Non-positives on z %s', z)
			continue
		current = sum(a) + sum(b)
		if current < best:
			best_move = z
			best = current
	if best_move is None:
		return [-1]
	logger.debug('Best move is %s', best_move)
	res = []
	res.append(best)
	a = [grid[i][0] - best_move for i in range(n)]
	for (i, times) in enumerate(a):
		if not times:
			continue
		res.extend(['row {}'.format(i + 1)] * times)
	b = [best_move + grid[0][i] - grid[0][0] for i in range(m)]
	for (i, times) in enumerate(b):
		if not times:
			continue
		res.extend(['col {}'.format(i + 1)] * times)
	return res

def main():
	(n, m) = list(map(int, input().strip().split()))
	grid = [list(map(int, input().strip().split())) for _ in range(n)]
	result = solve(n, m, grid)
	print('\n'.join(map(str, result)))

def __starting_point():
	main()
__starting_point()


(r, c) = map(int, input().split(' '))
arr = []
ops = []
num_ops = 0
for i in range(r):
	arr.append(list(map(int, input().split(' '))))
(s1, s2) = ('row ', 'col ')
if r > c:
	arr1 = []
	for i in range(c):
		arr1.append([0] * r)
	for i in range(r):
		for j in range(c):
			arr1[j][i] = arr[i][j]
	(r, c) = (c, r)
	(s1, s2) = (s2, s1)
	arr = arr1
for i in range(r):
	m = min(arr[i])
	if m > 0:
		arr[i] = [x - m for x in arr[i]]
		ops.append((0, i, m))
		num_ops += m
possible = True
for i in range(c):
	a = arr[0][i]
	for j in range(1, r):
		if arr[j][i] != a:
			possible = False
			break
	if possible == False:
		break
	if a > 0:
		ops.append((1, i, a))
		num_ops += a
if possible:
	print(num_ops)
	for i in ops:
		if i[0] == 0:
			for k in range(i[2]):
				print(s1 + str(i[1] + 1))
		else:
			for k in range(i[2]):
				print(s2 + str(i[1] + 1))
else:
	print(-1)


(n, m) = map(int, input().split())
M = [list(map(int, input().split())) for i in range(n)]
M1 = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		M1[i][j] = M[i][j]
l = []
l1 = []
c = 0
for i in range(n):
	V = min(M[i])
	if n > m:
		c = 1
		break
	for j in range(V):
		l.append(['row', i + 1])
	for j in range(m):
		M[i][j] = M[i][j] - V
	for j in range(m):
		V = M[i][j]
		for j1 in range(V):
			l.append(['col', j + 1])
		for j1 in range(n):
			M[j1][j] = M[j1][j] - V
for i in range(n):
	if c == 1:
		break
	if M[i].count(0) != m:
		print(-1)
		exit()
if n <= m:
	print(len(l))
	for i in range(len(l)):
		print(*l[i])
	exit()
for i in range(m):
	ma = 100000
	for j in range(n):
		if ma > M1[j][i]:
			ma = M1[j][i]
	for j in range(ma):
		l1.append(['col', i + 1])
	for j in range(n):
		M1[j][i] = M1[j][i] - ma
	for j in range(n):
		V = M1[j][i]
		for j1 in range(V):
			l1.append(['row', j + 1])
		for j1 in range(m):
			M1[j][j1] = M1[j][j1] - V
for i in range(n):
	if M1[i].count(0) != m:
		print(-1)
		exit()
print(len(l1))
for i in range(len(l1)):
	print(*l1[i])


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(r, c) = value()
a = []
for i in range(r):
	a.append(array())
row = [0] * r
col = [0] * c
steps = inf
final_row = []
final_col = []
for r1 in range(501):
	row[0] = r1
	ok = True
	for i in range(c):
		col[i] = a[0][i] - row[0]
		if col[i] < 0:
			ok = False
	for i in range(1, r):
		row[i] = inf
		for j in range(c):
			here = a[i][j] - col[j]
			if row[i] == inf:
				row[i] = here
			elif row[i] != here:
				ok = False
		if row[i] < 0:
			ok = False
	if ok:
		ans = sum(row)
		ans += sum(col)
		if ans < steps:
			steps = ans
			final_row = row[:]
			final_col = col[:]
if steps == inf:
	print(-1)
else:
	print(steps)
	for i in range(r):
		for j in range(final_row[i]):
			print('row', i + 1)
	for i in range(c):
		for j in range(final_col[i]):
			print('col', i + 1)


class CodeforcesTask815ASolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.board = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[0]):
			self.board.append([int(y) for y in input().split(' ')])

	def process_task(self):
		columns = []
		for x in range(self.n_m[1]):
			column = []
			for y in range(self.n_m[0]):
				column.append(self.board[y][x])
			columns.append(column)
		left_board_moves = [min(row) for row in self.board]
		bottom_board_moves = [min(column) for column in columns]
		reduce1 = min(bottom_board_moves)
		reduce2 = min(left_board_moves)
		if reduce1 * self.n_m[0] > reduce2 * self.n_m[1]:
			left_board_moves = [x - reduce1 for x in left_board_moves]
		else:
			bottom_board_moves = [x - reduce2 for x in bottom_board_moves]
		moves = sum(left_board_moves) + sum(bottom_board_moves)
		board_score = sum(left_board_moves) * self.n_m[1] + sum(bottom_board_moves) * self.n_m[0]
		real_board_score = sum([sum(x) for x in self.board])
		if board_score != real_board_score:
			self.result = '-1'
		else:
			print('{0}'.format(moves))
			for x in range(self.n_m[0]):
				for y in range(left_board_moves[x]):
					print('row {0}'.format(x + 1))
			for x in range(self.n_m[1]):
				for y in range(bottom_board_moves[x]):
					print('col {0}'.format(x + 1))

	def get_result(self):
		return self.result
Solution = CodeforcesTask815ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
a = []
tot = 0
row = []
col = []
n1 = 'row'
n2 = 'col'
for _ in range(n):
	a += [[int(f) for f in input().split()]]
if n > m:
	a = list(map(list, zip(*a)))
	(n, m) = (m, n)
	(n1, n2) = (n2, n1)
for x in range(n):
	for y in range(min(a[x])):
		row += [x + 1]
	tot += sum(a[x])
for x in range(m):
	t = a[0][x] - min(a[0])
	if t <= 0:
		t = 0
	for y in range(t):
		col += [x + 1]
t = len(row) + len(col)
if tot - m * len(row) - n * len(col) == 0:
	print(t)
	for x in row:
		print(n1, x)
	for x in col:
		print(n2, x)
else:
	print(-1)


(n, m) = map(int, input().split())
grid = []
for _ in range(n):
	grid.append(list(map(int, input().split())))
count = 0
moves = []
grid2 = []
for row in grid:
	grid2.append(row[:])

def do_row(grid, row):
	global count
	r = row
	row = grid[row]
	m = min(row)
	count += m
	for _ in range(m):
		moves.append('row ' + str(r + 1))
	for idx in range(len(row)):
		row[idx] -= m

def do_rows(grid):
	for r in range(len(grid)):
		do_row(grid, r)

def do_col(grid, col):
	global count
	mcol = min((row[col] for row in grid))
	for _ in range(mcol):
		moves.append('col ' + str(col + 1))
	count += mcol
	for row in grid:
		row[col] -= mcol

def do_cols(grid):
	for c in range(len(grid[0])):
		do_col(grid, c)
big = 9999999999999999999999999999999999

def get_count(grid):
	if sum((sum(row) for row in grid)) != 0:
		return big
	return count
do_rows(grid)
do_cols(grid)
crc = get_count(grid)
gmoves = moves
moves = []
count = 0
do_cols(grid2)
do_rows(grid2)
ccr = get_count(grid2)
g2moves = moves
ans = min(ccr, crc)
ansmoves = gmoves if ans == crc else g2moves
if ans == big:
	ans = -1
	ansmoves = []
print(ans)
for m in ansmoves:
	print(m)


(n, m) = map(int, input().split())
a = []
row = []
col = []
for i in range(n):
	a.append(list(map(int, input().split())))
if m > n:
	for i in range(n):
		row.append(min(a[i]))
	for i in range(m):
		col.append(a[0][i] - row[0])
else:
	for i in range(m):
		r = 1000
		for j in range(n):
			r = min(r, a[j][i])
		col.append(r)
	for i in range(n):
		row.append(a[i][0] - col[0])
for i in range(n):
	for j in range(m):
		if a[i][j] != row[i] + col[j]:
			exit(print(-1))
print(sum(row) + sum(col))
for i in range(n):
	for j in range(row[i]):
		print('row', i + 1)
for i in range(m):
	for j in range(col[i]):
		print('col', i + 1)


(n, m) = map(int, input().split())
table = [list(map(int, input().split())) for i in range(n)]
table2 = [list(l) for l in table]
anslst = []
for i in range(n):
	minv = min(table[i])
	for v in range(minv):
		anslst.append('row {}'.format(i + 1))
	for j in range(m):
		table[i][j] -= minv
for j in range(m):
	minv = 1000000000.0
	for i in range(n):
		minv = min(minv, table[i][j])
	for v in range(minv):
		anslst.append('col {}'.format(j + 1))
	for i in range(n):
		table[i][j] -= minv
flg = True
for i in range(n):
	for j in range(m):
		if table[i][j] != 0:
			flg = False
if not flg:
	print(-1)
	exit()
anslst2 = []
for j in range(m):
	minv = 1000000000.0
	for i in range(n):
		minv = min(minv, table2[i][j])
	for v in range(minv):
		anslst2.append('col {}'.format(j + 1))
	for i in range(n):
		table2[i][j] -= minv
for i in range(n):
	minv = min(table2[i])
	for v in range(minv):
		anslst2.append('row {}'.format(i + 1))
	for j in range(m):
		table2[i][j] -= minv
if len(anslst) < len(anslst2):
	print(len(anslst))
	for a in anslst:
		print(a)
else:
	print(len(anslst2))
	for a in anslst2:
		print(a)


def printMatrix(matrix):
	s = [[str(e) for e in row] for row in matrix]
	lens = [max(map(len, col)) for col in zip(*s)]
	fmt = '\t'.join(('{{:{}}}'.format(x) for x in lens))
	table = [fmt.format(*row) for row in s]
	print('_________________')
	print('\n'.join(table))
	print('`````````````````')
(n, m) = map(int, input().split())
mat = []
ans = []
for i in range(n):
	temp = [int(x) for x in input().split()]
	mat.append(temp)
ok = True
for i in range(n):
	for j in range(m):
		if j == 0:
			if m > n:
				if mat[i][j]:
					MIN = mat[i][j]
					for row in range(m):
						MIN = min(MIN, mat[i][row])
					for __ in range(MIN):
						ans.append(['row', i + 1])
					for row in range(m):
						mat[i][row] -= MIN
				if mat[i][j]:
					MIN = mat[i][j]
					for col in range(n):
						MIN = min(MIN, mat[col][j])
					for __ in range(MIN):
						ans.append(['col', j + 1])
					for col in range(n):
						mat[col][j] -= MIN
			else:
				if mat[i][j]:
					MIN = mat[i][j]
					for col in range(n):
						MIN = min(MIN, mat[col][j])
					for __ in range(MIN):
						ans.append(['col', j + 1])
					for col in range(n):
						mat[col][j] -= MIN
				if mat[i][j]:
					MIN = mat[i][j]
					for row in range(m):
						MIN = min(MIN, mat[i][row])
					for __ in range(MIN):
						ans.append(['row', i + 1])
					for row in range(m):
						mat[i][row] -= MIN
			if mat[i][j]:
				ok = False
				break
		else:
			if mat[i][j]:
				MIN = mat[i][j]
				for col in range(n):
					MIN = min(MIN, mat[col][j])
				for __ in range(MIN):
					ans.append(['col', j + 1])
				for col in range(n):
					mat[col][j] -= MIN
			if mat[i][j]:
				ok = False
if ok:
	print(len(ans))
	for i in ans:
		print(i[0], i[1])
else:
	print(-1)


import sys
(n, m) = map(int, sys.stdin.readline().split())
l = []
row = [0] * n
col = [0] * m
flag = True
if m > n:
	for i in range(n):
		l.append(list(map(int, sys.stdin.readline().split())))
		tmp = min(l[i])
		row[i] = tmp
		if tmp != 0:
			l[i] = list(map(lambda x: x - tmp, l[i]))
	l2 = list(map(list, zip(*l)))
	for i in range(m):
		tmp = min(l2[i])
		col[i] = tmp
		if tmp != 0:
			l2[i] = list(map(lambda x: x - tmp, l2[i]))
		if sum(l2[i]) != 0:
			print(-1)
			flag = False
			break
	if flag:
		print(sum(row) + sum(col))
		for i in range(n):
			for k in range(row[i]):
				print('row', i + 1)
		for i in range(m):
			for k in range(col[i]):
				print('col', i + 1)
else:
	for i in range(n):
		l.append(list(map(int, sys.stdin.readline().split())))
	l2 = list(map(list, zip(*l)))
	for i in range(m):
		tmp = min(l2[i])
		col[i] = tmp
		if tmp != 0:
			l2[i] = list(map(lambda x: x - tmp, l2[i]))
	l = list(map(list, zip(*l2)))
	for i in range(n):
		tmp = min(l[i])
		row[i] = tmp
		if tmp != 0:
			l[i] = list(map(lambda x: x - tmp, l[i]))
		if sum(l[i]) != 0:
			print(-1)
			flag = False
			break
	if flag:
		print(sum(row) + sum(col))
		for i in range(n):
			for k in range(row[i]):
				print('row', i + 1)
		for i in range(m):
			for k in range(col[i]):
				print('col', i + 1)


(n, m) = map(int, input().split())
mat = [list(map(int, input().strip().split())) for _ in range(n)]

def clear_row():
	rows = []
	for i in range(n):
		minx = 501
		for j in range(m):
			minx = min(minx, mat[i][j])
		for j in range(m):
			mat[i][j] -= minx
		for j in range(minx):
			rows.append('row {}'.format(i + 1))
	return rows

def clear_col():
	cols = []
	for i in range(m):
		minx = 501
		for j in range(n):
			minx = min(minx, mat[j][i])
		for j in range(n):
			mat[j][i] -= minx
		for j in range(minx):
			cols.append('col {}'.format(i + 1))
	return cols

def empty():
	s = 0
	for i in range(n):
		s += sum(mat[i])
	return s == 0
if n < m:
	rows = clear_row()
	cols = clear_col()
else:
	cols = clear_col()
	rows = clear_row()
if empty():
	ans = rows + cols
	print(len(ans))
	for msg in ans:
		print(msg)
else:
	print(-1)


nm = [int(s) for s in input().split()]
a = []
for i in range(nm[0]):
	a.append([int(j) for j in input().split()])
rez = []

def stroka():
	global rez
	rez_row = []
	rez_r = 0
	for i in range(nm[0]):
		min_row = 501
		for j in range(nm[1]):
			if a[i][j] < min_row:
				min_row = a[i][j]
		rez_r += min_row
		if min_row != 0:
			for c in range(min_row):
				rez.append('row ' + str(i + 1))
		for j in range(nm[1]):
			if a[i][j] > 0:
				a[i][j] -= min_row

def grafa():
	global rez
	rez_c = 0
	for j in range(nm[1]):
		min_col = 501
		for i in range(nm[0]):
			if a[i][j] < min_col:
				min_col = a[i][j]
		rez_c += min_col
		if min_col != 0:
			for c in range(min_col):
				rez.append('col ' + str(j + 1))
		for i in range(nm[0]):
			if a[i][j] > 0:
				a[i][j] -= min_col
if nm[0] < nm[1]:
	stroka()
	grafa()
else:
	grafa()
	stroka()
maxEl = max(max(a))
if maxEl == 0:
	print(len(rez))
	for el in rez:
		print(el)
else:
	print(-1)


from sys import stdin, stdout
arr = ['row', 'col']

def solve(g, n, m, flag):
	newG = []
	ans = []
	for i in range(n):
		newG.append([0] * m)
	for i in range(n):
		k = min(g[i])
		newG[i] = [k] * m
		ans.extend([arr[flag] + ' {}'.format(i + 1)] * k)
	for i in range(m):
		k = 0
		while min([newG[u][i] for u in range(n)]) < min([g[u][i] for u in range(n)]):
			for u in range(n):
				newG[u][i] += 1
			k += 1
		if [newG[u][i] for u in range(n)] != [g[u][i] for u in range(n)]:
			return (-1, [])
		else:
			ans.extend([arr[1 - flag] + ' {}'.format(i + 1)] * k)
	else:
		return (len(ans), ans)
(n, m) = [int(item) for item in stdin.readline().strip().split()]
g = []
for i in range(n):
	g.append([int(item) for item in stdin.readline().strip().split()])
g2 = []
for i in range(m):
	g2.append([g[k][i] for k in range(n)])
(a, ans1) = solve(g, n, m, 0)
(b, ans2) = solve(g2, m, n, 1)
if a == -1 or b == -1:
	print(-1)
elif a <= b:
	print(a)
	for item in ans1:
		stdout.write(str(item) + '\n')
else:
	print(b)
	for item in ans2:
		stdout.write(str(item) + '\n')


(n, m) = (0, 0)
(arr, res_r, res_c) = ([], [], [])

def solve_row():
	global arr, res_r, n, m
	res = 0
	for i in range(n):
		mini = int(2000000000.0)
		for j in range(m):
			mini = min(mini, arr[i][j])
		if mini == 0:
			continue
		res += mini
		res_r += [(i + 1, mini)]
		for j in range(m):
			arr[i][j] -= mini
	return res

def solve_col():
	global arr, res_c, n, m
	res = 0
	for i in range(m):
		mini = int(2000000000.0)
		for j in range(n):
			mini = min(mini, arr[j][i])
		if mini == 0:
			continue
		res += mini
		res_c += [(i + 1, mini)]
		for j in range(n):
			arr[j][i] -= mini
	return res

def main():
	global arr, res_r, res_c, n, m
	(n, m) = map(int, input().split())
	arr = [0] * n
	for i in range(n):
		arr[i] = list(map(int, input().split()))
	res = 0
	if n < m:
		res += solve_row()
		res += solve_col()
	else:
		res += solve_col()
		res += solve_row()
	for i in range(n):
		for j in range(m):
			if arr[i][j] > 0:
				print(-1)
				return
	print(res)
	for i in range(len(res_r)):
		for j in range(res_r[i][1]):
			print('row', res_r[i][0])
	for i in range(len(res_c)):
		for j in range(res_c[i][1]):
			print('col', res_c[i][0])
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
realg = [list(map(int, input().split())) for _ in range(n)]
g = [[0] * m for _ in range(n)]
ans = []
f1 = min([realg[0][i] for i in range(m)])
for i in range(m):
	for _ in range(realg[0][i] - f1):
		ans.append('col %d' % (i + 1))
	for j in range(n):
		g[j][i] += realg[0][i] - f1
f2 = min([realg[i][0] for i in range(n)])
for i in range(n):
	for _ in range(realg[i][0] - f2):
		ans.append('row %d' % (i + 1))
	for j in range(m):
		g[i][j] += realg[i][0] - f2
bad = 0
floor = realg[0][0] - g[0][0]
for i in range(n):
	for j in range(m):
		if realg[i][j] - g[i][j] != floor:
			bad = 1
if bad:
	print('-1')
else:
	if n < m:
		for i in range(n):
			for j in range(floor):
				ans.append('row %d' % (i + 1))
	else:
		for i in range(m):
			for j in range(floor):
				ans.append('col %d' % (i + 1))
	print(len(ans))
	print('\n'.join(ans))


def min_row():
	ans = 0
	for i in range(n):
		ans += min(a[i])
	return ans

def min_col():
	ans = 0
	for i in range(m):
		mm = 10000
		for j in range(n):
			mm = min(mm, a[j][i])
		ans += mm
	return ans

def remove_cols():
	ans = 0
	min_col = [0] * m
	for i in range(m):
		min_col[i] = 1000
		for j in range(n):
			min_col[i] = min(min_col[i], a[j][i])
		ans += min_col[i]
		for j in range(n):
			a[j][i] -= min_col[i]
	return (ans, min_col)

def remove_rows():
	ans = 0
	min_row = []
	for i in range(n):
		min_row.append(min(a[i]))
		ans += min_row[-1]
		for j in range(m):
			a[i][j] -= min_row[i]
	return (ans, min_row)
(n, m) = list(map(int, input().split()))
a = []
s = 0
for i in range(n):
	row = list(map(int, input().split()))
	a.append(row)
	s += sum(row)
rows = min_row()
cols = min_col()
if rows == 0 and cols == 0:
	if s == 0:
		print(0)
		exit()
	else:
		print(-1)
		exit()
if cols == 0 or (rows != 0 and (s - rows * m) % n == 0 and ((s - cols * n) % m != 0 or (s - rows * m) // n + rows < (s - cols * n) // m + cols)):
	(ans, min_row) = remove_rows()
	(ans1, min_col) = remove_cols()
else:
	(ans1, min_col) = remove_cols()
	(ans, min_row) = remove_rows()
ans += ans1
for row in a:
	for ai in row:
		if ai != 0:
			print(-1)
			exit()
print(ans)
for i in range(n):
	for j in range(min_row[i]):
		print('row', i + 1)
for i in range(m):
	for j in range(min_col[i]):
		print('col', i + 1)


import copy
(n, m) = map(int, input().split())
a = []
ans = []
ans1 = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = copy.deepcopy(a)
for i in range(n):
	mn = min(a[i])
	for j in range(m):
		a[i][j] -= mn
	if mn > 0:
		ans.append(['row', i, mn])
for i in range(m):
	mn = 1000
	for j in range(n):
		if a[j][i] < mn:
			mn = a[j][i]
	for j in range(n):
		a[j][i] -= mn
	if mn > 0:
		ans.append(['col', i, mn])
for i in range(m):
	mn = 1000
	for j in range(n):
		if b[j][i] < mn:
			mn = b[j][i]
	for j in range(n):
		b[j][i] -= mn
	if mn > 0:
		ans1.append(['col', i, mn])
for i in range(n):
	mn = min(b[i])
	for j in range(m):
		b[i][j] -= mn
	if mn > 0:
		ans1.append(['row', i, mn])
if sum((sum(k) for k in a)) != 0:
	print(-1)
else:
	count = 0
	count1 = 0
	for i in ans:
		count += i[2]
	for i in ans1:
		count1 += i[2]
	if count1 > count:
		print(count)
		for i in ans:
			for j in range(i[2]):
				print(i[0], i[1] + 1, sep=' ')
	else:
		print(count1)
		for i in ans1:
			for j in range(i[2]):
				print(i[0], i[1] + 1, sep=' ')


(n, m) = map(int, input().split())
L = [list(map(int, input().split())) for i in range(n)]
s = 'row'
s1 = 'col'
if n > m:
	L1 = [[0 for i in range(n)] for j in range(m)]
	for i in range(n):
		for j in range(m):
			L1[j][i] = L[i][j]
	L = L1
	(n, m) = (m, n)
	(s, s1) = (s1, s)
w = [0 for i in range(n)]
w1 = [0 for i in range(m)]
for i in range(n):
	w[i] = min(L[i])
for i in range(m):
	for j in range(n):
		ma = 0
		ma = max(L[j][i] - w[j], ma)
	w1[i] = ma
for i in range(n):
	for j in range(m):
		if L[i][j] - w[i] - w1[j] != 0:
			print(-1)
			exit()
otv = []
for i in range(n):
	otv += [s + ' ' + str(i + 1)] * w[i]
for i in range(m):
	otv += [s1 + ' ' + str(i + 1)] * w1[i]
print(len(otv))
print('\n'.join(otv))


read = lambda : map(int, input().split())

def fail():
	print(-1)
	exit()
(n, m) = read()
g = [list(read()) for i in range(n)]
a = [g[i][0] - g[0][0] for i in range(n)]
b = [g[0][i] - g[0][0] for i in range(m)]
for i in range(n):
	for j in range(1, m):
		if g[i][j] - g[i][0] != b[j]:
			fail()
for j in range(m):
	for i in range(1, n):
		if g[i][j] - g[0][j] != a[i]:
			fail()
mn = min((min(i) for i in g))
mb = min(b)
for i in range(m):
	b[i] -= mb
ma = min(a)
for i in range(n):
	a[i] -= ma
if n < m:
	for i in range(n):
		a[i] += mn
else:
	for i in range(m):
		b[i] += mn
print(sum(a) + sum(b))
[print('row', i + 1) for i in range(n) for j in range(a[i])]
[print('col', i + 1) for i in range(m) for j in range(b[i])]


(n, m) = [int(i) for i in input().split(' ')]
g = []
(c, f) = (0, 0)
ans = ''

def row():
	global n, m, g, c, ans
	for i in range(n):
		t = min(g[i])
		c += t
		ans += 'row %d\n' % (i + 1) * t
		for j in range(m):
			g[i][j] -= t

def col():
	global n, m, g, c, ans
	for i in range(m):
		r = [_[i] for _ in g]
		t = min(r)
		c += t
		ans += 'col %d\n' % (i + 1) * t
		for j in range(n):
			g[j][i] -= t
for i in range(n):
	g.append([int(_) for _ in input().split(' ')])
if m >= n:
	row()
	col()
else:
	col()
	row()
for i in range(n):
	for j in range(m):
		if g[i][j] > 0:
			f = 1
			break
if f == 1:
	print(-1)
else:
	print(c)
	print(ans, end='')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
ans = [[0 for i in range(m)] for j in range(n)]
an = []
tot = 0
if n < m:
	for i in range(n):
		mi = min(l[i])
		for j in range(m):
			ans[i][j] += mi
		tot += mi
		an.append((1, i + 1, mi))
	for i in range(m):
		c = -ans[0][i] + l[0][i]
		for j in range(n):
			if c != l[j][i] - ans[j][i]:
				print(-1)
				sys.exit(0)
		tot += c
		an.append((0, i + 1, c))
else:
	for i in range(m):
		mi = 1000
		for j in range(n):
			mi = min(mi, l[j][i])
		for j in range(n):
			ans[j][i] += mi
		tot += mi
		an.append((0, i + 1, mi))
	for i in range(n):
		c = -ans[i][0] + l[i][0]
		for j in range(m):
			if c != l[i][j] - ans[i][j]:
				print(-1)
				sys.exit(0)
		tot += c
		an.append((1, i + 1, c))
print(tot)
for i in range(len(an)):
	if an[i][0] == 1:
		for j in range(an[i][2]):
			print('row', an[i][1])
	else:
		for j in range(an[i][2]):
			print('col', an[i][1])


inpt = input().split(' ')
n = int(inpt[0])
m = int(inpt[1])
arr = []
for i in range(n):
	inpt = input().split(' ')
	inpt = list(map(int, inpt))
	arr.append(inpt)
sol = []

def solver1(a, sol):
	allmin = min([min(suba) for suba in a])
	if allmin < 0:
		return False
	allmax = max([max(suba) for suba in a])
	if allmax == 0:
		return True
	else:
		for i in range(len(a)):
			p = min(a[i])
			if p > 0:
				for j in range(len(a[i])):
					a[i][j] -= p
				for q in range(p):
					sol.append(i + 1)
				return solver1(a, sol)
		for j in range(len(a[0])):
			b = []
			for i in range(len(a)):
				b.append(a[i][j])
			p = min(b)
			if p > 0:
				for k in range(len(b)):
					a[k][j] -= p
				for q in range(p):
					sol.append(len(a) + j + 1)
				return solver1(a, sol)

def solver2(a, sol):
	allmin = min([min(suba) for suba in a])
	if allmin < 0:
		return False
	allmax = max([max(suba) for suba in a])
	if allmax == 0:
		return True
	else:
		for j in range(len(a[0])):
			b = []
			for i in range(len(a)):
				b.append(a[i][j])
			p = min(b)
			if p > 0:
				for k in range(len(b)):
					a[k][j] -= p
				for q in range(p):
					sol.append(len(a) + j + 1)
				return solver2(a, sol)
		for i in range(len(a)):
			p = min(a[i])
			if p > 0:
				for j in range(len(a[i])):
					a[i][j] -= p
				for q in range(p):
					sol.append(i + 1)
				return solver2(a, sol)
if n < m:
	if solver1(arr, sol):
		print(len(sol))
		for i in sol:
			if i <= n:
				print('row', i)
			else:
				print('col', i - n)
	else:
		print('-1')
elif solver2(arr, sol):
	print(len(sol))
	for i in sol:
		if i <= n:
			print('row', i)
		else:
			print('col', i - n)
else:
	print('-1')


(n, m) = map(int, input().split())
table = list()
table_T = list()
for i in range(n):
	table.append(list(map(int, input().split())))
for i in range(m):
	a = [table[j][i] for j in range(n)]
	table_T.append(a)
OUT = list()
if n <= m:
	a = 0
	while a < n:
		is_0 = False
		for i in table[a]:
			if i == 0:
				is_0 = True
				break
		if is_0 == False:
			b = min(table[a])
			OUT.extend(['row {0}'.format(a + 1)] * b)
			for i in range(m):
				table[a][i] -= b
				table_T[i][a] -= b
		else:
			a += 1
	a = 0
	while a < m:
		is_0 = False
		for i in table_T[a]:
			if i == 0:
				is_0 = True
				break
		if is_0 == False:
			b = min(table_T[a])
			OUT.extend(['col {0}'.format(a + 1)] * b)
			for i in range(n):
				table[i][a] -= b
				table_T[a][i] -= b
		else:
			a += 1
else:
	a = 0
	while a < m:
		is_0 = False
		for i in table_T[a]:
			if i == 0:
				is_0 = True
				break
		if is_0 == False:
			b = min(table_T[a])
			OUT.extend(['col {0}'.format(a + 1)] * b)
			for i in range(n):
				table[i][a] -= b
				table_T[a][i] -= b
		else:
			a += 1
	a = 0
	while a < n:
		is_0 = False
		for i in table[a]:
			if i == 0:
				is_0 = True
				break
		if is_0 == False:
			b = min(table[a])
			OUT.extend(['row {0}'.format(a + 1)] * b)
			for i in range(m):
				table[a][i] -= b
				table_T[i][a] -= b
		else:
			a += 1
fail = False
for i in range(n):
	if sum(table[i]) != 0:
		fail = True
		break
if fail != True:
	print(len(OUT))
	for i in OUT:
		print(i)
else:
	print(-1)


(n, m) = map(int, input().split())
g = list()
moves = list()
(m1, m2) = ('row', 'col')
for _ in range(n):
	g.append(list(map(int, input().split())))
if n > m:
	g = list(map(list, zip(*g)))
	(n, m) = (m, n)
	(m1, m2) = (m2, m1)
for i in range(n):
	while min(g[i]) > 0:
		for j in range(m):
			g[i][j] -= 1
		moves.append('{} {}'.format(m1, i + 1))
g = list(map(list, zip(*g)))
for i in range(m):
	while min(g[i]) > 0:
		for j in range(n):
			g[i][j] -= 1
		moves.append('{} {}'.format(m2, i + 1))
for c in g:
	if any(c):
		moves = None
if moves is None:
	print(-1)
else:
	print(len(moves))
	print('\n'.join(moves))


def main():
	(n, m) = list(map(int, input().split()))
	(l, r) = ([list(map(int, input().split())) for _ in range(n)], [])
	if n > m:
		l = [list(col) for col in zip(*l)]
		(cols, rows) = ('row %d', 'col %d')
	else:
		(cols, rows) = ('col %d', 'row %d')
	for (y, row) in enumerate(l, 1):
		a = min(row)
		for (i, t) in enumerate(row):
			row[i] = t - a
		r += [rows % y] * a
	l = [list(col) for col in zip(*l)]
	for (x, col) in enumerate(l, 1):
		a = min(col)
		for (i, t) in enumerate(col):
			col[i] = t - a
		r += [cols % x] * a
	r.append(str(len(r)))
	print(-1 if any(map(any, l)) else '\n'.join(r[::-1]))

def __starting_point():
	main()
__starting_point()


(n, m) = input().strip().split()
(n, m) = (int(n), int(m))
g = [[int(j) for j in input().strip().split()] for i in range(n)]
answer = []

def b():
	for i in range(n):
		minRow = min(g[i])
		if minRow != 0:
			for k in range(minRow):
				answer.append('row ' + str(i + 1))
			for j in range(m):
				g[i][j] -= minRow

def a():
	for j in range(m):
		minCol = g[0][j]
		for i in range(n):
			if g[i][j] < minCol:
				minCol = g[i][j]
		if minCol != 0:
			for k in range(minCol):
				answer.append('col ' + str(j + 1))
			for i in range(n):
				g[i][j] -= minCol
if n < m:
	b()
	a()
else:
	a()
	b()
maxNumber = max(max(g))
if maxNumber == 0:
	print(len(answer))
	for el in answer:
		print(el)
else:
	print('-1')


(n, m) = (int(i) for i in input().split())
tbl = []
for i in range(n):
	crstr = [int(j) for j in input().split()]
	tbl.append(crstr)
true = 0

def prt():
	for xx in range(n):
		for yy in range(m):
			print(tbl[xx][yy], end='\t')
		print()
	print()
	print()

def lines():
	rows = []
	for i in range(n):
		while 1:
			may = 1
			for j in range(m):
				if tbl[i][j] == 0:
					for k in range(j):
						tbl[i][k] += 1
					may = 0
					break
				tbl[i][j] -= 1
			if not may:
				break
			rows.append(i + 1)
	return rows

def cols():
	stolbs = []
	for i in range(m):
		while 1:
			may = 1
			for j in range(n):
				if tbl[j][i] == 0:
					for k in range(j):
						tbl[k][i] += 1
					may = 0
					break
				tbl[j][i] -= 1
			if not may:
				break
			stolbs.append(i + 1)
	return stolbs
if m > n:
	l = lines()
	c = cols()
else:
	c = cols()
	l = lines()
br = 0
for i in range(n):
	for j in range(m):
		if tbl[i][j] != 0:
			br = 1
			break
	if br:
		break
if br:
	print(-1)
else:
	print(len(l) + len(c))
	for i in l:
		print('row', i)
	for i in c:
		print('col', i)


from itertools import product
(n, m) = map(int, input().split())
matr = []
for i in range(n):
	matr.append([int(num) for num in input().split()])

def walker(start_row, start_col, dif_row, dif_col):
	row = start_row
	col = start_col
	while 0 <= row < n and 0 <= col < m:
		yield (row, col)
		row += dif_row
		col += dif_col

def walker_row(row):
	return walker(row, 0, 0, 1)

def walker_col(col):
	return walker(0, col, 1, 0)

def get_min(line):
	res = float('inf')
	for (row, col) in line:
		res = min(res, matr[row][col])
	return res

def subtract(line, diff):
	for (row, col) in line:
		matr[row][col] -= diff

def resolve_rows():
	for row in range(n):
		min_num = get_min(walker_row(row))
		if min_num > 0:
			subtract(walker_row(row), min_num)
			step = 'row {}'.format(row + 1)
			for i in range(min_num):
				ans.append(step)

def resolve_cols():
	for col in range(m):
		min_num = get_min(walker_col(col))
		if min_num > 0:
			subtract(walker_col(col), min_num)
			step = 'col {}'.format(col + 1)
			for i in range(min_num):
				ans.append(step)
ans = []
if n > m:
	resolve_cols()
	resolve_rows()
else:
	resolve_rows()
	resolve_cols()
cant = False
for (row, col) in product(range(n), range(m)):
	cant |= matr[row][col] > 0
if cant:
	print(-1)
else:
	print(len(ans))
	print('\n'.join(ans))


(n, m) = map(int, input().split())
array = []
row_sums = [0 for x in range(n)]
for i in range(n):
	array.append(list(map(int, input().split())))
	row_sums[i] = sum(array[i])
col_sums = [sum(x) for x in zip(*array)]
min_row_index = row_sums.index(min(row_sums))
min_col_index = col_sums.index(min(col_sums))
row_boost = [0 for x in range(n)]
col_boost = [0 for x in range(m)]
if n <= m:
	col_boost[min_col_index] = 0
	for i in range(m):
		if i != min_col_index:
			col_boost[i] = (col_sums[i] - col_sums[min_col_index]) // n
		sum_col_boosts = sum(col_boost)
		for i in range(n):
			row_boost[i] = (row_sums[i] - sum_col_boosts) // m
if n >= m:
	row_boost[min_row_index] = 0
	for i in range(n):
		if i != min_row_index:
			row_boost[i] = (row_sums[i] - row_sums[min_row_index]) // m
	sum_row_boosts = sum(row_boost)
	for i in range(m):
		col_boost[i] = (col_sums[i] - sum_row_boosts) // n
for row in range(n):
	if [row_boost[row] + c for c in col_boost] != array[row]:
		print(-1)
		return
print(sum(row_boost + col_boost))
for i in range(n):
	for count in range(row_boost[i]):
		print('row ' + str(i + 1))
for j in range(m):
	for count in range(col_boost[j]):
		print('col ' + str(j + 1))


(n, m) = map(int, input().split())
g = [list(map(int, input().split())) for _ in range(n)]
a = [0] * n
b = [0] * m
a[0] = min(g[0])
for j in range(m):
	g[0][j] -= a[0]
	b[j] = g[0][j]
good = True
for i in range(n):
	for j in range(m):
		g[i][j] -= b[j]
	if min(g[i]) < 0 or min(g[i]) != max(g[i]):
		good = False
	a[i] += min(g[i])
if not good:
	print(-1)
else:
	if n > m:
		x = min(a)
		for i in range(n):
			a[i] -= x
		for j in range(m):
			b[j] += x
	num = sum(a) + sum(b)
	print(num)
	for i in range(n):
		for _ in range(a[i]):
			print('row {}'.format(i + 1))
	for j in range(m):
		for _ in range(b[j]):
			print('col {}'.format(j + 1))


(n, m) = map(int, input().split())
grid = [list(map(int, input().split())) for i in range(n)]
ans = []
if m > n:
	for i in range(n):
		mini = min(grid[i])
		for j in range(m):
			grid[i][j] -= mini
		for _ in range(mini):
			ans.append('row ' + str(i + 1))
	for i in range(m):
		mini = float('inf')
		for j in range(n):
			mini = min(grid[j][i], mini)
		for j in range(n):
			grid[j][i] -= mini
		for _ in range(mini):
			ans.append('col ' + str(i + 1))
else:
	for i in range(m):
		mini = float('inf')
		for j in range(n):
			mini = min(grid[j][i], mini)
		for j in range(n):
			grid[j][i] -= mini
		for _ in range(mini):
			ans.append('col ' + str(i + 1))
	for i in range(n):
		mini = min(grid[i])
		for j in range(m):
			grid[i][j] -= mini
		for _ in range(mini):
			ans.append('row ' + str(i + 1))
if all([sum(i) == 0 for i in grid]):
	print(len(ans))
	for i in ans:
		print(i)
else:
	print(-1)


(n, m) = map(int, input().split())
g = [list(map(int, input().split())) for i in range(n)]
(x, xi, xj) = (500, 0, 0)
for (i, gi) in enumerate(g):
	for (j, gij) in enumerate(gi):
		if gij < x:
			(x, xi, xj) = (gij, i, j)
(r, c) = ([g[i][xj] - x for i in range(n)], [g[xi][j] - x for j in range(m)])
for (i, gi) in enumerate(g):
	for (j, gij) in enumerate(gi):
		if gij != r[i] + c[j] + x:
			print(-1)
			return
print(min(n, m) * x + sum(r) + sum(c))
for i in range(n):
	for k in range(r[i] + (x if n <= m else 0)):
		print('row', i + 1)
for j in range(m):
	for k in range(c[j] + (x if m < n else 0)):
		print('col', j + 1)


def all_zero(A):
	for row in A:
		for e in row:
			if e != 0:
				return False
	return True
(n, m) = input().split(' ')
n = int(n)
m = int(m)
A = []
for _ in range(n):
	row = input().split(' ')
	row = list(map(int, row))
	A += [row]
moves = []
min_elem = min((min(row) for row in A))
if min_elem > 0:
	if m >= n:
		for x in range(n):
			moves += [f'row {x + 1}'] * min_elem
	else:
		for y in range(m):
			moves += [f'col {y + 1}'] * min_elem
	for x in range(n):
		for y in range(m):
			A[x][y] -= min_elem
pivot = None
for x in range(n):
	for y in range(m):
		if A[x][y] == 0:
			pivot = (x, y)
			break
assert pivot is not None
(pivot_x, pivot_y) = pivot
for x in range(n):
	if x == pivot_x:
		continue
	f = A[x][pivot_y]
	moves += [f'row {x + 1}'] * f
	for y in range(m):
		A[x][y] -= f
for y in range(m):
	if y == pivot_y:
		continue
	f = A[pivot_x][y]
	moves += [f'col {y + 1}'] * f
	for x in range(n):
		A[x][y] -= f
if not all_zero(A):
	print(-1)
else:
	print(len(moves))
	print('\n'.join(moves))


def Check(Mat, Row, Col, TotalSum):
	N = len(Mat)
	M = len(Mat[0])
	SummTillNow = Row[0] * M + Col[0] * N
	for i in range(0, N):
		for j in range(0, M):
			if not (i == 0 and j == 0):
				if Mat[i][j] == 0:
					if i in Row and Row[i] != 0 or (j in Col and Col[j] != 0):
						return False
					Row[i] = 0
					Col[j] = 0
				elif i in Row and j in Col:
					Val = Row[i] + Col[j]
					if Val != Mat[i][j]:
						return False
				elif i in Row:
					Val = Mat[i][j] - Row[i]
					if Val < 0:
						return False
					Col[j] = Val
					SummTillNow += N * Val
				elif j in Col:
					Val = Mat[i][j] - Col[j]
					if Val < 0:
						return False
					Row[i] = Val
					SummTillNow += M * Val
	if SummTillNow == TotalSum:
		return True
	return False
(N, M) = map(int, input().strip().split())
Mat = []
for i in range(N):
	Mat.append(list(map(int, input().strip().split())))
Num = Mat[0][0]
TotalSum = 0
Min_Count = float('inf')
for l in Mat:
	TotalSum += sum(l)
for i in range(0, Num + 1):
	Row = {}
	Col = {}
	Row[0] = i
	Col[0] = Num - i
	res = Check(Mat, Row, Col, TotalSum)
	if res:
		Count = 0
		for (k, v) in Row.items():
			Count += v
		for (k, v) in Col.items():
			Count += v
		if Min_Count > Count:
			Min_Count = min(Min_Count, Count)
			AnsRow = Row
			AnsCol = Col
if Min_Count == float('inf'):
	print(-1)
else:
	print(Min_Count)
	for (k, v) in AnsRow.items():
		for cnt in range(v):
			print('row', k + 1)
	for (k, v) in AnsCol.items():
		for cnt in range(v):
			print('col', k + 1)


(n, m) = list(map(int, input().split()))
g = [list(map(int, input().split())) for i in range(n)]

class Phrase:

	def __init__(self, x=0, y=0):
		self.x = x
		self.y = y

	def __add__(self, other):
		return Phrase(self.x + other.x, self.y + other.y)

	def __str__(self):
		return str(self.x) + 'a' + ' + ' + str(self.y)

class Equ:

	def __init__(self, a, b):
		self.left = a
		self.right = b

	def solve(self):
		if self.left.x == self.right.x and self.left.y == self.right.y:
			return 'infinity'
		self.left.x -= self.right.x
		self.right.x = 0
		self.right.y -= self.left.y
		self.left.y = 0
		if self.left.x == 0 and self.right.y != 0:
			return 'nothing'
		return self.right.y / self.left.x
(mina, maxa) = (0, 1000)
rows = []
for i in range(n):
	new = Phrase(-1, g[i][0])
	rows.append(new)
	if new.x < 0:
		maxa = min(maxa, new.y / -new.x)
	if new.y < 0:
		mina = max(-new.y / new.x, mina)

def f():
	global exact, mina, maxa, cols, rows, a, s, i, u, s2
	exact = ''
	cols = [Phrase(1, 0)]
	for i in range(1, m):
		last = Phrase(-rows[0].x, -rows[0].y + g[0][i])
		cols.append(last)
		if last.x < 0 and last.y < 0:
			print(-1)
			return
		if last.x < 0:
			maxa = min(maxa, last.y / -last.x)
		if last.y < 0:
			mina = max(-last.y / last.x, mina)
		for u in range(1, n):
			new = Phrase(-rows[u].x, -rows[u].y + g[u][i])
			rslt = Equ(last, new).solve()
			if rslt == 'nothing':
				print(-1)
				return
			if rslt == 'infinity':
				last = new
				continue
			if new.x < 0 and new.y < 0:
				print(-1)
				return
			if new.x < 0:
				maxa = min(maxa, new.y / -new.x)
			if new.y < 0:
				mina = max(-new.y / new.x, mina)
			if rslt % 1 != 0:
				print(-1)
				return
			if exact == '':
				exact = rslt
			elif rslt != exact:
				print(-1)
				return
	if mina % 1 != 0:
		mina = int(mina) + 1
	maxa = int(maxa)
	if maxa < mina:
		print(-1)
		return
	if exact != '':
		if exact > maxa or exact < mina:
			print(-1)
			return
		a = exact
		for i in range(m):
			for u in range(n):
				s = rows[i].x * a + rows[i].y + cols[u].x * a + cols[u].y
				if s != g[u][i]:
					print(-1)
					return
		for i in range(m):
			cols[i] = cols[i].x * a + cols[i].y
			if cols[i] % 1 != 0:
				print(-1)
				return
			cols[i] = int(cols[i])
		for i in range(n):
			rows[i] = rows[i].x * a + rows[i].y
			if rows[i] % 1 != 0:
				print(-1)
				return
			rows[i] = int(rows[i])
		s = sum(cols) + sum(rows)
		print(s)
		for i in range(m):
			for u in range(cols[i]):
				print('col', i + 1)
		for i in range(n):
			for u in range(rows[i]):
				print('row', i + 1)
		return
	else:
		s2 = Phrase()
		for i in range(m):
			s2 += cols[i]
		for i in range(n):
			s2 += rows[i]
		if s2.x < 0:
			a = maxa
		else:
			a = mina
		for i in range(m):
			cols[i] = cols[i].x * a + cols[i].y
			if cols[i] % 1 != 0:
				print(-1)
				return
			cols[i] = int(cols[i])
		for i in range(n):
			rows[i] = rows[i].x * a + rows[i].y
			if rows[i] % 1 != 0:
				print(-1)
				return
			rows[i] = int(rows[i])
		s = sum(cols) + sum(rows)
		print(s)
		for i in range(m):
			for u in range(cols[i]):
				print('col', i + 1)
		for i in range(n):
			for u in range(rows[i]):
				print('row', i + 1)
		return
f()


import sys

def min_i_v(row):
	min_v = None
	min_i = None
	for (i, v) in enumerate(row):
		if min_v is None or v < min_v:
			min_v = v
			min_i = i
	return (min_i, min_v)

def dec_row(matrix, row_i, val):
	for i in range(len(matrix[row_i])):
		matrix[row_i][i] -= val

def dec_col(matrix, col_i, val):
	for i in range(len(matrix)):
		matrix[i][col_i] -= val
(amount_of_rows, amount_of_cols) = [int(a) for a in sys.stdin.readline().split()]
matrix = []
for i in range(amount_of_rows):
	matrix.append([int(a) for a in sys.stdin.readline().split()])
log = []
interrupted = False
if amount_of_cols >= amount_of_rows:
	for (row_i, row) in enumerate(matrix):
		(min_i, min_v) = min_i_v(row)
		dec_row(matrix, row_i, min_v)
		for i in range(min_v):
			log.append('row ' + str(row_i + 1) + '\n')
		col = [0] * amount_of_rows
		for c_i in range(amount_of_cols):
			for r_i in range(amount_of_rows):
				col[r_i] = matrix[r_i][c_i]
			(min_i, min_v) = min_i_v(col)
			if min_v < col[row_i]:
				interrupted = True
				break
			else:
				min_v = col[row_i]
				dec_col(matrix, c_i, min_v)
				for i in range(min_v):
					log.append('col ' + str(c_i + 1) + '\n')
		if interrupted:
			break
else:
	col = [0] * amount_of_rows
	for col_i in range(amount_of_cols):
		for r_i in range(amount_of_rows):
			col[r_i] = matrix[r_i][col_i]
		(min_i, min_v) = min_i_v(col)
		dec_col(matrix, col_i, min_v)
		for i in range(min_v):
			log.append('col ' + str(col_i + 1) + '\n')
		for (r_i, row) in enumerate(matrix):
			(min_i, min_v) = min_i_v(row)
			if min_v < row[col_i]:
				interrupted = True
				break
			else:
				min_v = row[col_i]
				dec_row(matrix, r_i, min_v)
				for i in range(min_v):
					log.append('row ' + str(r_i + 1) + '\n')
		if interrupted:
			break
if interrupted:
	sys.stdout.write('-1\n')
else:
	sys.stdout.write(str(len(log)) + '\n')
	for i in log:
		sys.stdout.write(i)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
(s1, s2) = ('row', 'col')
if n > m:
	b = []
	for i in range(m):
		b.append([])
		for j in range(n):
			b[i].append(a[j][i])
	(n, m, s1, s2, a) = (m, n, s2, s1, b)
mi = min(a[0])
r = [mi]
cn = mi
for i in range(m):
	a[0][i] -= mi
	cn += a[0][i]
for i in range(1, n):
	mi = min(a[i])
	cn += mi
	r.append(mi)
	for j in range(m):
		if a[i][j] - mi != a[0][j]:
			print(-1)
			exit(0)
print(cn)
for i in range(n):
	for j in range(r[i]):
		print(s1 + ' ' + str(i + 1))
for i in range(m):
	for j in range(a[0][i]):
		print(s2 + ' ' + str(i + 1))


import sys
from functools import reduce
from queue import PriorityQueue
INFINITY = 1000

def do_row(mat, actions):
	n = len(mat)
	did_nothing = True
	for r in range(n):
		(mn, mx) = min_and_max(mat[r])
		if mn > 0:
			dec = mn
			perform(mat, 'row', r, dec)
			for __ in range(dec):
				actions.append(('row', r + 1))
			did_nothing = False
	return did_nothing

def do_col(mat, actions):
	did_nothing = True
	for (c, tup) in enumerate(zip(*mat)):
		(mn, mx) = min_and_max(tup)
		if mn > 0:
			dec = mn
			perform(mat, 'col', c, dec)
			for __ in range(dec):
				actions.append(('col', c + 1))
			did_nothing = False
	return did_nothing

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	mat = [None] * n
	actions = []
	for indx in range(n):
		mat[indx] = list(map(int, sys.stdin.readline().split()))
	while True:
		did_nothing = True
		if n <= m:
			did_nothing &= do_row(mat, actions)
			did_nothing &= do_col(mat, actions)
		else:
			did_nothing &= do_col(mat, actions)
			did_nothing &= do_row(mat, actions)
		if did_nothing:
			if max(map(max, mat)) == 0:
				print(len(actions))
				for act in actions:
					print(' '.join(map(str, act)))
				return
			else:
				print(-1)
				return

def min_and_max(ary):
	return reduce(lambda m_M, cur: (min(m_M[0], cur), max(m_M[1], cur)), ary, (INFINITY, -1))

def perform(mat, r_or_c, _indx, dec):
	if r_or_c == 'row':
		for indx in range(len(mat[_indx])):
			mat[_indx][indx] -= dec
	else:
		for indx in range(len(mat)):
			mat[indx][_indx] -= dec
main()


(n, m) = input().split()
n = int(n)
m = int(m)
a = []
for i in range(n):
	x = input().split()
	x = [int(p) for p in x]
	a.append(x)
if n <= m:
	ans = ''
	step = 0
	for i in range(n):
		t = 500
		for j in range(m):
			t = min(t, a[i][j])
		ans += ('row' + ' ' + str(i + 1) + '\n') * t
		step += t
		for j in range(m):
			a[i][j] -= t
	can = True
	for j in range(m):
		t = a[0][j]
		for i in range(n):
			if a[i][j] != t:
				can = False
		step += t
		ans += ('col' + ' ' + str(j + 1) + '\n') * t
	if can:
		print(step)
		print(ans)
	else:
		print(-1)
else:
	ans = ''
	step = 0
	for j in range(m):
		t = 500
		for i in range(n):
			t = min(t, a[i][j])
		ans += ('col' + ' ' + str(j + 1) + '\n') * t
		step += t
		for i in range(n):
			a[i][j] -= t
	can = True
	for i in range(n):
		t = a[i][0]
		for j in range(m):
			if a[i][j] != t:
				can = False
		step += t
		ans += ('row' + ' ' + str(i + 1) + '\n') * t
	if can:
		print(step)
		print(ans)
	else:
		print(-1)


def func(l, n, m, row, col):
	for i in range(n):
		mi = min(l[i])
		if mi:
			l[i] = [x - mi for x in l[i]]
			for j in range(mi):
				row.append(i)
	for j in range(m):
		c = [x[j] for x in l]
		mi = min(c)
		if max(c) - mi > 0:
			print('-1')
			exit()
		for i in range(mi):
			col.append(j)
R = lambda : map(int, input().split())
(n, m) = R()
(l, row, col, l2) = ([], [], [], [])
for _ in range(n):
	l.append(list(R()))
if n > m:
	for j in range(m):
		l2.append([x[j] for x in l])
	func(l2, m, n, col, row)
else:
	func(l, n, m, row, col)
print(len(row) + len(col))
for i in row:
	print('row ', i + 1)
for i in col:
	print('col', i + 1)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10 ** 8)
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
ans = [[0 for i in range(m)] for j in range(n)]
an = []
tot = 0
if n < m:
	for i in range(n):
		mi = min(l[i])
		for j in range(m):
			ans[i][j] += mi
		tot += mi
		an.append((1, i + 1, mi))
	for i in range(m):
		c = -ans[0][i] + l[0][i]
		for j in range(n):
			if c != l[j][i] - ans[j][i]:
				print(-1)
				sys.exit(0)
		tot += c
		an.append((0, i + 1, c))
else:
	for i in range(m):
		mi = 1000
		for j in range(n):
			mi = min(mi, l[j][i])
		for j in range(n):
			ans[j][i] += mi
		tot += mi
		an.append((0, i + 1, mi))
	for i in range(n):
		c = -ans[i][0] + l[i][0]
		for j in range(m):
			if c != l[i][j] - ans[i][j]:
				print(-1)
				sys.exit(0)
		tot += c
		an.append((1, i + 1, c))
print(tot)
for i in range(len(an)):
	if an[i][0] == 1:
		for j in range(an[i][2]):
			print('row', an[i][1])
	else:
		for j in range(an[i][2]):
			print('col', an[i][1])


(x, y) = map(int, input().split())
grid = []
for i in range(x):
	grid.append(list(map(int, input().split())))
mi = grid[0][0]
prints = []
for i in range(x):
	mi = min(mi, min(grid[i]))
if x > y:
	for k in range(mi):
		for i in range(1, y + 1):
			prints.append('col ' + str(i))
else:
	for k in range(mi):
		for i in range(1, x + 1):
			prints.append('row ' + str(i))
for i in range(x):
	for j in range(y):
		grid[i][j] -= mi
for i in range(x):
	while min(grid[i]) > 0:
		prints.append('row ' + str(i + 1))
		for j in range(y):
			grid[i][j] -= 1
for i in range(y):
	indy = []
	for ranind in range(x):
		indy.append(grid[ranind][i])
	mindy = min(indy)
	for ran2 in range(mindy):
		prints.append('col ' + str(i + 1))
		for j in range(x):
			grid[j][i] -= 1
ma = grid[0][0]
for i in range(x):
	ma = max(ma, max(grid[i]))
	if ma != 0:
		print('-1')
		quit()
print(len(prints))
print('\n'.join(prints))


import sys

def main():
	(n, m) = list(map(int, sys.stdin.readline().split()))
	field = []
	for i in range(n):
		row = list(map(int, sys.stdin.readline().split()))
		field.append(row)
	nmoves = 0
	moves = []
	while True:
		minrow = [min((field[i][j] for j in range(m))) for i in range(n)]
		mincol = [min((field[i][j] for i in range(n))) for j in range(m)]
		(maxrow, imaxrow) = max(((item, index) for (index, item) in enumerate(minrow)))
		(maxcol, imaxcol) = max(((item, index) for (index, item) in enumerate(mincol)))
		if maxrow == maxcol == 0:
			break
		if n >= m and maxcol > 0 or maxrow == 0:
			moves.append((maxcol, -(imaxcol + 1)))
			nmoves += maxcol
			for i in range(n):
				field[i][imaxcol] -= maxcol
		elif maxrow > 0:
			moves.append((maxrow, imaxrow + 1))
			nmoves += maxrow
			for j in range(m):
				field[imaxrow][j] -= maxrow
	maxelem = max((field[i][j] for i in range(n) for j in range(m)))
	if maxelem > 0:
		sys.stdout.write('-1' + '\n')
		return
	sys.stdout.write(str(nmoves) + '\n')
	for (repeat, move) in moves:
		for _ in range(repeat):
			mtype = 'row' if move > 0 else 'col'
			sys.stdout.write(mtype + ' ' + str(abs(move)) + '\n')
main()


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, m) = M()
l = []
x = []
req = []
req2 = []
ans = []
ans2 = []

def check(l, r):
	for i in range(len(l)):
		if l[i] != r[i]:
			return False
	return len(l) == len(r)
c = 0
f = 0
c2 = 0
for i in range(n):
	l.append(L())
	k = min(l[-1])
	if k > 0:
		ans.append(('r', i + 1, k))
		req.append([k] * m)
		c += k
	else:
		req.append([0] * m)
for i in range(n):
	for j in range(m):
		if l[i][j] != req[i][j]:
			e = l[i][j] - req[i][j]
			c += e
			for k in range(n):
				req[k][j] += e
			ans.append(('c', j + 1, e))
if check(req, l):
	f = 1
for i in range(n):
	req2.append([0] * m)
for i in range(m):
	k = 10 ** 10
	for j in range(n):
		k = min(k, l[j][i])
	if k > 0:
		for p in range(n):
			req2[p][i] = k
		c2 += k
		ans2.append(('c', i + 1, k))
for i in range(n):
	for j in range(m):
		if l[i][j] != req2[i][j]:
			e = l[i][j] - req2[i][j]
			c2 += e
			for k in range(m):
				req2[i][k] += e
			ans2.append(('r', i + 1, e))
if check(req2, l):
	f += 2
if f == 3:
	print(min(c, c2))
	if c < c2:
		for i in range(len(ans)):
			if ans[i][0] == 'c':
				for k in range(ans[i][2]):
					print('col', ans[i][1])
			else:
				for k in range(ans[i][2]):
					print('row', ans[i][1])
	else:
		for i in range(len(ans2)):
			if ans2[i][0] == 'c':
				for k in range(ans2[i][2]):
					print('col', ans2[i][1])
			else:
				for k in range(ans2[i][2]):
					print('row', ans2[i][1])
elif f == 1:
	print(c)
	for i in range(len(ans)):
		if ans[i][0] == 'c':
			for k in range(ans[i][2]):
				print('col', ans[i][1])
		else:
			for k in range(ans[i][2]):
				print('row', ans[i][1])
elif f == 2:
	print(c2)
	for i in range(len(ans2)):
		if ans2[i][0] == 'c':
			for k in range(ans2[i][2]):
				print('col', ans2[i][1])
		else:
			for k in range(ans2[i][2]):
				print('row', ans2[i][1])
else:
	print(-1)