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 gi, 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 gi, j (0 ≤ gi, 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.

Difficulty: MEDIUM_HARD
Tags: Complete search

Implementation

Greedy algorithms
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
(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 sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def opr_col(x):
	for i in range(n):
		l[i][x] -= 1

def opr_row(x):
	for i in range(m):
		l[x][i] -= 1

def min_col(x):
	mn = sys.maxsize
	for i in range(n):
		mn = min(l[i][x], mn)
	return mn
(n, m) = invr()
l = []
oprs = []
for i in range(n):
	l.append(inlt())
if n <= m:
	for i in range(n):
		while min(l[i]) != 0:
			oprs.append('row {}'.format(i + 1))
			opr_row(i)
	for i in range(m):
		while min_col(i) != 0:
			oprs.append('col {}'.format(i + 1))
			opr_col(i)
	sm = 0
	for i in range(n):
		sm += sum(l[i])
	if sm != 0:
		print(-1)
	else:
		print(len(oprs))
		for each in oprs:
			print(each)
else:
	for i in range(m):
		while min_col(i) != 0:
			oprs.append('col {}'.format(i + 1))
			opr_col(i)
	for i in range(n):
		while min(l[i]) != 0:
			oprs.append('row {}'.format(i + 1))
			opr_row(i)
	sm = 0
	for i in range(n):
		sm += sum(l[i])
	if sm != 0:
		print(-1)
	else:
		print(len(oprs))
		for each in oprs:
			print(each)


(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()


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) = 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())
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)


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())
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)


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)


(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) = 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)


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) = 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())
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))


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)


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()


(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))


(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])


(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)