import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int[][] table = new int[r+1][c+1]; table new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		} {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		} int sum_c = 0; sum_c 0 for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			} {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			} if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} i != r && j != c i != r i r j != c j c {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} table[i][j] = sc.nextInt() table[i][j] table[i] table i j sc.nextInt() sc.nextInt sc sum_c += table[i][j] sum_c table[i][j] table[i] table i j System.out.print(table[i][j] + " ") System.out.print System.out System System.out table[i][j] + " " table[i][j] table[i] table i j " " if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} j == c j c {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} table[i][j] = sum_c table[i][j] table[i] table i j sum_c System.out.println(table[i][j]) System.out.println System.out System System.out table[i][j] table[i] table i j {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} int sum_r = 0; sum_r 0 for(int k=0; k<r; k++){
						sum_r += table[k][j];
					} int k=0; int k=0; k 0 k<r k r k++ k++ k {
						sum_r += table[k][j];
					} {
						sum_r += table[k][j];
					} sum_r += table[k][j] sum_r table[k][j] table[k] table k j table[i][j] = sum_r table[i][j] table[i] table i j sum_r sum_c += table[i][j] sum_c table[i][j] table[i] table i j System.out.print(table[i][j] + " ") System.out.print System.out System System.out table[i][j] + " " table[i][j] table[i] table i j " " String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] table = new int[r+1][c+1];
		for(int i=0; i<r+1; i++) {
			int sum_c = 0;
			for(int j=0; j<c+1; j++) {
				if(i != r && j != c) {
					table[i][j] = sc.nextInt();
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				} else if(j == c) {
					table[i][j] = sum_c;
					System.out.println(table[i][j]);
				} else {
					int sum_r = 0;
					for(int k=0; k<r; k++){
						sum_r += table[k][j];
					}
					table[i][j] = sum_r;
					sum_c += table[i][j];
					System.out.print(table[i][j] + " ");
				}
			}
		}
	}

}