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

void main() {
    auto input = getStdin!(string[])[0..$];
    auto c = input[0].split(" ")[1].to!(int);
    auto set = input[1..$];
    int[][] matrix = [];
    foreach (line; set) {
    	auto num = line.split(" ").to!(int[]);
    	matrix ~= num;
    }
    
    for (int i = 0; i < matrix.length; i++) {
    	int sum = reduce!((a, b) => a + b)(0, matrix[i]);
    	matrix[i] ~= sum;
    }
    
    int[] extra = [];
    for (int i = 0; i < c + 1; i++) {
    	int sum = 0;
    	for (int j = 0; j < matrix.length; j++) {
    		sum += matrix[j][i];
    	}
    	extra ~= sum;
    }
    
    matrix ~= extra;
    
    for (int i = 0; i < matrix.length; i++) {
    	matrix[i].to!(string[]).join(" ").writeln;
    }
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}