'use strict';
(function(stdin) {
	var lines  = stdin.toString().split('\n');
	var result = (function(params,data) {

		var table = data.slice(0,params[0]).map(function(v) {
			var tmp = v.split(' ').slice(0,params[1]).map(Number);
			tmp.push(tmp.reduce(function(a,b){ return a + b; }));
			return tmp;
		});

		var line = table[0].map(function(col, i) { 
			return table.map(function(row) { 
				return row[i] 
			})
			.reduce(function(a,b){return a + b});
		});


		return (table.join('\n').replace(/,/g,' '));

	}(
		lines.shift().split(' ').map(Number)
		,lines
		));

	console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));