process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
	var lines = chunk.toString().split('\n');
	for(var i=0;i<lines.length;i++){
		var num = Number(lines[i]);
		if(num==0)	break;
		var v_sum = new Array();
		var all_sum = 0;
		var tmp_i = i;
		for(var j=i;j<num+tmp_i;j++){
			i++;
			var nums = lines[i].split(' ');
			var h_sum = 0;
			var h_txt = "";
			for(var k=0;k<nums.length;k++){
				if(v_sum[k]){
					v_sum[k] += Number(nums[k]);
				}else{
					v_sum[k] = Number(nums[k]);
				}
				h_sum+=Number(nums[k]);
				all_sum+=Number(nums[k]);
				h_txt += nums[k] + " ";
			}
			h_txt += h_sum;
			console.log(leftPad(h_txt));
		}
		console.log(leftPad(v_sum.join(' ') + " " + all_sum));
	}
}
	
function leftPad(num_t){
	var strs = num_t.split(' ');
	var retstr = "";
	for(var i=0;i<strs.length;i++){
		retstr += ("     " + strs[i]).substr(-5) + " ";
	}
	return retstr.substr(0,retstr.length-1);
}