
import std.stdio;
import std.range;
import std.conv;
import std.algorithm;
import std.array;
import std.string;


void main()
{
    int r, c;
    readf("%d %d\n", &r, &c);
    int[][] a = new int[][r];
    for (int y = 0; y < r; y++)
    {
        a[y] = readln.strip.split(' ').map!(to!int).array;
        writeln((a[y] ~ a[y].sum).map!(to!string).join(" "));
    }
    int D = 0;
    for (int x = 0; x < c; x++)
    {
        int C = 0;
        for (int y = 0; y < r; y++)
        {
            C += a[y][x];
        }
        D += C;
        write(C, " ");
    }
    writeln(D);
}

