import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split.map!(to!size_t);
  auto r = rd[0], c = rd[1];
  auto tij = iota(r).map!(_ => readln.split.map!(to!int).array).array;

  auto sij = new int[][](r + 1, c + 1);
  foreach (i; 0..r) sij[i][0..c][] = tij[i][];

  foreach (i; 0..r) sij[i][$-1] = tij[i].sum;
  foreach (j; 0..c) sij[$-1][j] = tij.map!(a => a[j]).sum;
  sij[$-1][$-1] = sij[$-1][0..c].sum;

  sij.each!(si => si.map!(a => a.to!string).join(" ").writeln);
}