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];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	}
	public static int sum (int[] array){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	}
	public static int sum (int[][] array, int col){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	}
} 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];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	}
	public static int sum (int[] array){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	}
	public static int sum (int[][] array, int col){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	}
} 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];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	} main {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();	//行数
		int c = scan.nextInt();	//列数
		int[][] array = new int[r + 1][c + 1];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	} 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 for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for {
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		} for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for int l = 0; int l = 0; l 0 l < c l c l++ l++ l {
					array[i][l] = scan.nextInt();
			}//for {
					array[i][l] = scan.nextInt();
			} array[i][l] = scan.nextInt() array[i][l] array[i] array i l scan.nextInt() scan.nextInt scan array[i][c] = sum(array[i]) array[i][c] array[i] array i c sum(array[i]) sum array[i] array i for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		} int i = 0; int i = 0; i 0 i < c + 1 i c + 1 c 1 i++ i++ i {
			array[r][i] = sum(array, i);
		} {
			array[r][i] = sum(array, i);
		} array[r][i] = sum(array, i) array[r][i] array[r] array r i sum(array, i) sum array i for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for {
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		} for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for int l = 0; int l = 0; l 0 l < c + 1 l c + 1 c 1 l++ l++ l {
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for {
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			} if(l != 0) System.out.print(" "); l != 0 l 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(array[i][l]) System.out.print System.out System System.out array[i][l] array[i] array i l System.out.println() System.out.println System.out System System.out String[] args args public static int sum (int[] array){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	} sum {
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	} int n = 0; n 0 for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		} int i = 0; int i = 0; i 0 i < array.length - 1 i array.length - 1 array.length array array.length 1 i++ i++ i {
			n += array[i];
		} {
			n += array[i];
		} n += array[i] n array[i] array i return n; n int[] array array public static int sum (int[][] array, int col){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	} sum {
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	} int n = 0; n 0 for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		} int i = 0; int i = 0; i 0 i < array.length - 1 i array.length - 1 array.length array array.length 1 i++ i++ i {
			n += array[i][col];
		} {
			n += array[i][col];
		} n += array[i][col] n array[i][col] array[i] array i col return n; n int[][] array array int col col 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];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	}
	public static int sum (int[] array){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	}
	public static int sum (int[][] array, int col){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	}
} 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];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	}
	public static int sum (int[] array){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	}
	public static int sum (int[][] array, int col){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	}
} 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];
		for(int i = 0; i < r; i++){
			for(int l = 0; l < c; l++){
					array[i][l] = scan.nextInt();
			}//for
			array[i][c] = sum(array[i]);
		}//for
		for(int i = 0; i < c + 1; i++){
			array[r][i] = sum(array, i);
		}
		for(int i = 0; i < r + 1; i++){
			for(int l = 0; l < c + 1; l++){
				if(l != 0) System.out.print(" ");
				System.out.print(array[i][l]);
			}//for
			System.out.println();
		}//for
	}
	public static int sum (int[] array){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i];
		}
		return n;
	}
	public static int sum (int[][] array, int col){
		int n = 0;
		for(int i = 0; i < array.length - 1; i++){
			n += array[i][col];
		}
		return n;
	}
}