var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var rc=Arr[0].split(" ").map(Number);
var c=[];
for(var i=0;i<rc[1]+1;i++)c.push(0);

for(var i=1;i<Arr.length;i++){
   var arr=Arr[i].split(" ").map(Number);
   var sum=arr.reduce(function(a,b){return a+b;});
   console.log(Arr[i]+" "+sum);
   arr.push(sum);
   arr.forEach(function(v,i){c[i]+=v;});
}
console.log(c.join(" "));