import java.util.Scanner;

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

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

