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[][] array = new int[r+1][c+1];
		int intTemp = 0;
		int intSumC = 0;
		int intSumR = 0;
		for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		}
		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[][] array = new int[r+1][c+1];
		int intTemp = 0;
		int intSumC = 0;
		int intSumR = 0;
		for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

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

			}

		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r+1][c+1];
		int intTemp = 0;
		int intSumC = 0;
		int intSumR = 0;
		for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		}
		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[][] array = new int[r+1][c+1]; array new int[r+1][c+1] r+1 r 1 c+1 c 1 int intTemp = 0; intTemp 0 int intSumC = 0; intSumC 0 int intSumR = 0; intSumR 0 for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		} {
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		} intSumC = 0 intSumC 0 for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			} {
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			} if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				} i == r && j == c i == r i r j == c j c {
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				} for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					} int k = 0; int k = 0; k 0 k < c k c k++ k++ k {
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					} {
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					} array[r][c] += array[r][k] array[r][c] array[r] array r c array[r][k] array[r] array r k intSumC = array[r][c] intSumC array[r][c] array[r] array r c if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				} i == r i r {
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				} for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					} int k = 0; int k = 0; k 0 k < r k r k++ k++ k {
						array[r][j] += array[k][j];
					} {
						array[r][j] += array[k][j];
					} array[r][j] += array[k][j] array[r][j] array[r] array r j array[k][j] array[k] array k j if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				} j == c j c {
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				} for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					} int k = 0; int k = 0; k 0 k < c k c k++ k++ k {
						array[i][c] += array[i][k];
					} {
						array[i][c] += array[i][k];
					} array[i][c] += array[i][k] array[i][c] array[i] array i c array[i][k] array[i] array i k {
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				} intTemp = scan.nextInt() intTemp scan.nextInt() scan.nextInt scan array[i][j] = intTemp array[i][j] array[i] array i j intTemp intSumC += intTemp intSumC intTemp array[i][c] = intSumC array[i][c] array[i] array i c intSumC for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		} 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++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		} {
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		} for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			} {
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			} if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				} j == c j c {
					System.out.println(array[i][j]);
				} System.out.println(array[i][j]) System.out.println System.out System System.out array[i][j] array[i] array i j {
					System.out.print(array[i][j] + " ");
				} System.out.print(array[i][j] + " ") System.out.print System.out System System.out array[i][j] + " " array[i][j] array[i] array i j " " 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[][] array = new int[r+1][c+1];
		int intTemp = 0;
		int intSumC = 0;
		int intSumR = 0;
		for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		}
		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[][] array = new int[r+1][c+1];
		int intTemp = 0;
		int intSumC = 0;
		int intSumR = 0;
		for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		}
		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[][] array = new int[r+1][c+1];
		int intTemp = 0;
		int intSumC = 0;
		int intSumR = 0;
		for(int i = 0; i <= r; i++){
			intSumC = 0;
			for(int j = 0; j <= c; j++){
				if(i == r && j == c){
					for(int k = 0; k < c; k++){
						array[r][c] += array[r][k];
						intSumC = array[r][c];
					}
				}else if(i == r){
					for(int k = 0; k < r; k++){
						array[r][j] += array[k][j];
					}
				}else if(j == c){
					for(int k = 0; k < c; k++){
						array[i][c] += array[i][k];
					}
				}else{
					intTemp = scan.nextInt();
					array[i][j] = intTemp;
					intSumC += intTemp;
				}
				array[i][c] = intSumC;

			}

		}
		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j == c){
					System.out.println(array[i][j]);
				}else{
					System.out.print(array[i][j] + " ");
				}
			}
		}
		scan.close();
	}
}