import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	}
} import java.io.*; io.* java public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String line = reader.readLine(); line reader.readLine() reader.readLine reader String[] sarray = line.split(" ", -1); sarray line.split(" ", -1) line.split line " " -1 1 int n = Integer.parseInt(sarray[0]); n Integer.parseInt(sarray[0]) Integer.parseInt Integer sarray[0] sarray 0 int m = Integer.parseInt(sarray[1]); m Integer.parseInt(sarray[1]) Integer.parseInt Integer sarray[1] sarray 1 int matrix[][] = new int[n + 1][m + 1]; matrix new int[n + 1][m + 1] n + 1 n 1 m + 1 m 1 for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		} {//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		} String str = reader.readLine(); str reader.readLine() reader.readLine reader String[] mat = str.split(" ", -1); mat str.split(" ", -1) str.split str " " -1 1 for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			} int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			} {
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			} matrix[i][j] = Integer.parseInt(mat[j]) matrix[i][j] matrix[i] matrix i j Integer.parseInt(mat[j]) Integer.parseInt Integer mat[j] mat j while(i == 0){
					matrix[n][j] = 0;
					break;
				} i == 0 i 0 {
					matrix[n][j] = 0;
					break;
				} matrix[n][j] = 0 matrix[n][j] matrix[n] matrix n j 0 break; matrix[i][m] = 0 matrix[i][m] matrix[i] matrix i m 0 matrix[n][m] = 0 matrix[n][m] matrix[n] matrix n m 0 for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		} int k = 0; int k = 0; k 0 k < n k n k++ k++ k {
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		} {
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		} for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			} int l = 0; int l = 0; l 0 l < m l m l++ l++ l {
				matrix[k][m] += matrix[k][l];//??????????¨?
			} {
				matrix[k][m] += matrix[k][l];//??????????¨?
			} matrix[k][m] += matrix[k][l] matrix[k][m] matrix[k] matrix k m matrix[k][l] matrix[k] matrix k l for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		} int p = 0; int p = 0; p 0 p < m p m p++ p++ p {
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		} {
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		} for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			} int q = 0; int q = 0; q 0 q < n q n q++ q++ q {
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			} {
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			} matrix[n][p] += matrix[q][p] matrix[n][p] matrix[n] matrix n p matrix[q][p] matrix[q] matrix q p while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				} p == 0 p 0 {
					matrix[n][m] += matrix[q][m];
					break;
				} matrix[n][m] += matrix[q][m] matrix[n][m] matrix[n] matrix n m matrix[q][m] matrix[q] matrix q m break; for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		} int r = 0; int r = 0; r 0 r < n + 1 r n + 1 n 1 r++ r++ r {
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		} {
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		} for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			} int s = 0; int s = 0; s 0 s < m s m s++ s++ s {
				System.out.print(matrix[r][s] + " ");
			} {
				System.out.print(matrix[r][s] + " ");
			} System.out.print(matrix[r][s] + " ") System.out.print System.out System System.out matrix[r][s] + " " matrix[r][s] matrix[r] matrix r s " " System.out.println(matrix[r][m]) System.out.println System.out System System.out matrix[r][m] matrix[r] matrix r m String[] args args public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	}
} Main
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		String[] sarray = line.split(" ", -1);
		int n = Integer.parseInt(sarray[0]);//?????°
		int m = Integer.parseInt(sarray[1]);//?????°
		int matrix[][] = new int[n + 1][m + 1];
		for(int i = 0; i < n; i++){//?????????????????????
			String str = reader.readLine();
			String[] mat = str.split(" ", -1);
			for(int j = 0; j < m; j++){
				matrix[i][j] = Integer.parseInt(mat[j]);
				while(i == 0){
					matrix[n][j] = 0;
					break;
				}
			}
			matrix[i][m] = 0;
		}
		matrix[n][m] = 0;
		for(int k = 0; k < n; k++){
			for(int l = 0; l < m; l++){
				matrix[k][m] += matrix[k][l];//??????????¨?
			}
		}
		for(int p = 0; p < m; p++){
			for(int q = 0; q < n; q++){
				matrix[n][p] += matrix[q][p];//??????????¨?
				while(p == 0){
					matrix[n][m] += matrix[q][m];
					break;
				}
			}
		}
		for(int r = 0; r < n + 1; r++){
			for(int s = 0; s < m; s++){
				System.out.print(matrix[r][s] + " ");
			}
			System.out.println(matrix[r][m]);
		}
	}
}