let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const [, ...rows] = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => parseInt(n, 10)));
  const result = rows.map(appendSum);
  const lastRow = [];
  for (let i = 0; i < result[0].length; i++) {
    let sum = 0;
    for (let j = 0; j < result.length; j++) {
      sum += result[j][i];
    }

    lastRow.push(sum);
  }

  result.push(lastRow);

  console.log(result.map(nums => nums.join(' ')).join('\n'));
});

const appendSum = nums => {
  const sum = nums.reduce((prev, cur) => prev + cur);
  return [...nums, sum];
};
