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 mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	}
} 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 mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	} 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 mat[][] = new int[r + 1][c + 1]; mat 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++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		} {
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		} for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			} {
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			} mat[i][j] = scan.nextInt() mat[i][j] mat[i] mat i j scan.nextInt() scan.nextInt scan mat[i][c] += mat[i][j] mat[i][c] mat[i] mat i c mat[i][j] mat[i] mat i j mat[r][j] += mat[i][j] mat[r][j] mat[r] mat r j mat[i][j] mat[i] mat i j mat[r][c] += mat[i][j] mat[r][c] mat[r] mat r c mat[i][j] mat[i] mat i j for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		} {
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		} for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			} {
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			} System.out.print(mat[i][j]) System.out.print System.out System System.out mat[i][j] mat[i] mat i j if(j != c){
					System.out.print(" ");
				} j != c j c {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out scan.close() scan.close scan 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 mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	}
} 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 mat[][] = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				mat[i][j] = scan.nextInt();
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				mat[r][c] += mat[i][j];
			}
		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				System.out.print(mat[i][j]);
				if(j != c){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		scan.close();
	}
}