"use strict";
main(require("fs").readFileSync("/dev/stdin", "utf8").replace(/\r?\n$/, "").split(/\r?\n/));

function main(lines){
	var rows = lines.slice(1).map(function(str){return str.split(" ").map(Number)});
	rows.forEach(function(row){
		row.push(row.reduce(function(a,b){return a+b;}));
	});
	rows.push(rows[0].map(function(_,i){
		return rows.reduce(function(a,b){return a+b[i];}, 0);
	}));
	console.log(rows.map(function(a){return a.join(" ")}).join("\n"));
}