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

void main() {
    int[] tmp = readln.chomp.split.to!(int[]);
    int r = tmp[0], c = tmp[1];
    int[][] mat = new int[][](r, c);
    foreach (i; 0 .. r) {
        int[] row = readln.chomp.split.to!(int[]);
        foreach(j; 0 .. c) {
            mat[i][j] = row[j];
        }
    }
    int[] vec = new int[c+1];
    foreach (j; 0 .. c) {
        foreach (i; 0 .. r) {
            vec[j] += mat[i][j];
        }
    }
    foreach (i; 0 .. r) {
        vec[c] += mat[i].sum;
    }
    foreach (i; 0 .. r) {
        foreach (j; 0 .. c) {
            write(mat[i][j], " ");
        }
        mat[i].sum.writeln;
    }
    foreach (j; 0 .. c) {
        write(vec[j], " ");
    }
    vec[c].writeln;
}
