def compress(rows):
	columns = list(zip(*rows))
	size = len(rows)
	symbols = range(size)
	output = size - 1
	weight = 25
	for i in symbols:
		for j in symbols:
			choices = set(rows[i][j:]) & set(columns[j][i:])
			output += weight * sorted(choices).index(rows[i][j])
			weight *= len(choices)
	return bin(output + 1)[3:]

def decompress(bitstring):
	number = int('1' + bitstring, 2) - 1
	number, size = divmod(number, 25)
	size += 1
	symbols = range(size)
	rows = [[None] * size for _ in symbols]
	columns = [list(column) for column in zip(*rows)]
	for i in symbols:
		for j in symbols:
			choices = set(symbols) - set(rows[i]) - set(columns[j])
			number, index = divmod(number, len(choices))
			rows[i][j] = columns[j][i] = sorted(choices)[index]
	return rows

score = 0

for line in open(0).read().split():
	rows = eval(line)
	bitstring = compress(rows)
	score += len(bitstring)
	assert decompress(bitstring) == rows

print('%g bits (%.7g bytes)' % (score, score / 8))