#!/usr/bin/env python
from sys import argv
if len(argv)==1:exit('Usage mat2bin mat')
file=open(argv[1])
meta=file.readline().split()
print ' '.join(meta)
if len(meta)==2:
	for line in file:
		for i in line.split():
			if i=='0':print 0,
			else:print 1,
		print
else:
	for line in file:
		line=line.split()
		for i in range(0,len(line),2):
			print line[i],1,
		print
