import java.util.Scanner;

public class Main {


    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		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();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		scan.close();
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		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 numlist[][] = new int[r + 1][c + 1]; numlist new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		} int cnt_r = 0; int cnt_r = 0; cnt_r 0 cnt_r < r cnt_r r cnt_r++ cnt_r++ cnt_r {
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		} {
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		} for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			} int cnt_c = 0; int cnt_c = 0; cnt_c 0 cnt_c < c cnt_c c cnt_c++ cnt_c++ cnt_c {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			} {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			} numlist[cnt_r][cnt_c] = scan.nextInt() numlist[cnt_r][cnt_c] numlist[cnt_r] numlist cnt_r cnt_c scan.nextInt() scan.nextInt scan numlist[cnt_r][c] += numlist[cnt_r][cnt_c] numlist[cnt_r][c] numlist[cnt_r] numlist cnt_r c numlist[cnt_r][cnt_c] numlist[cnt_r] numlist cnt_r cnt_c numlist[r][cnt_c] += numlist[cnt_r][cnt_c] numlist[r][cnt_c] numlist[r] numlist r cnt_c numlist[cnt_r][cnt_c] numlist[cnt_r] numlist cnt_r cnt_c numlist[r][c] += numlist[cnt_r][cnt_c] numlist[r][c] numlist[r] numlist r c numlist[cnt_r][cnt_c] numlist[cnt_r] numlist cnt_r cnt_c for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		} int cnt_r = 0; int cnt_r = 0; cnt_r 0 cnt_r < r + 1 cnt_r r + 1 r 1 cnt_r++ cnt_r++ cnt_r {
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		} {
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		} for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			} int cnt_c = 0; int cnt_c = 0; cnt_c 0 cnt_c < c + 1 cnt_c c + 1 c 1 cnt_c++ cnt_c++ cnt_c {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			} {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			} System.out.print( numlist[cnt_r][cnt_c]) System.out.print System.out System System.out numlist[cnt_r][cnt_c] numlist[cnt_r] numlist cnt_r cnt_c if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" "); cnt_c != c cnt_c c System.out.print(" ") System.out.print System.out System System.out " " System.out.print("\n") System.out.print System.out System System.out "\n" 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();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		scan.close();
	}
} public class Main {


    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		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();//r?????¨?????????
		int c = scan.nextInt();//c?????¨????¨????
		
		int numlist[][] = new int[r + 1][c + 1];//????¨???¨?????????????????????

		//???????????????????????????????????????????´???¨????¨???¨?????????????¨?????????????
		for (int cnt_r = 0; cnt_r < r; cnt_r++){
			for (int cnt_c = 0; cnt_c < c ; cnt_c++) {
				numlist[cnt_r][cnt_c] = scan.nextInt();//????????????????´?
				numlist[cnt_r][c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][cnt_c] += numlist[cnt_r][cnt_c];//????????¨???????¨?????¨????
				numlist[r][c] += numlist[cnt_r][cnt_c];//??¨??????????¨?????¨????
			}
		}
		for (int cnt_r = 0; cnt_r < r + 1; cnt_r++){
			for (int cnt_c = 0; cnt_c < c + 1 ; cnt_c++) {
				System.out.print( numlist[cnt_r][cnt_c]);
				if(cnt_c != c)//?????????????????°?????§???????????°?????????????????\??????
					System.out.print(" ");
			}
			System.out.print("\n");
		}
		scan.close();
	}
}