import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        	int r = scan.nextInt();
        	int c = scan.nextInt();
        	int [][]sheet;
        	sheet = new int[(r+1)][(c+1)];
        	int sheetr,sheetc;

        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	}
        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetc = 0; sheetc <= c; sheetc++){
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetr = 0; sheetr <= r; sheetr++){
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	}
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        	int r = scan.nextInt();
        	int c = scan.nextInt();
        	int [][]sheet;
        	sheet = new int[(r+1)][(c+1)];
        	int sheetr,sheetc;

        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	}
        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetc = 0; sheetc <= c; sheetc++){
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetr = 0; sheetr <= r; sheetr++){
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	}
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        	int r = scan.nextInt();
        	int c = scan.nextInt();
        	int [][]sheet;
        	sheet = new int[(r+1)][(c+1)];
        	int sheetr,sheetc;

        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	}
        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetc = 0; sheetc <= c; sheetc++){
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetr = 0; sheetr <= r; sheetr++){
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	}
    } main {
        Scanner scan = new Scanner(System.in);
        
        	int r = scan.nextInt();
        	int c = scan.nextInt();
        	int [][]sheet;
        	sheet = new int[(r+1)][(c+1)];
        	int sheetr,sheetc;

        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	}
        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetc = 0; sheetc <= c; sheetc++){
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetr = 0; sheetr <= r; sheetr++){
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	}
    } 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 [][]sheet; sheet sheet = new int[(r+1)][(c+1)] sheet new int[(r+1)][(c+1)] (r+1) r 1 (c+1) c 1 int sheetr sheetr sheetc; sheetc for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	} sheetr = 0; sheetr = 0 sheetr 0 sheetr < r sheetr r sheetr++ sheetr++ sheetr {
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	} {
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	} for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		} sheetc = 0; sheetc = 0 sheetc 0 sheetc < c sheetc c sheetc++ sheetc++ sheetc {
        		sheet[sheetr][sheetc] = scan.nextInt();
        		} {
        		sheet[sheetr][sheetc] = scan.nextInt();
        		} sheet[sheetr][sheetc] = scan.nextInt() sheet[sheetr][sheetc] sheet[sheetr] sheet sheetr sheetc scan.nextInt() scan.nextInt scan for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	} sheetr = 0; sheetr = 0 sheetr 0 sheetr < r sheetr r sheetr++ sheetr++ sheetr {
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	} {
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	} for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		} sheetc = 0; sheetc = 0 sheetc 0 sheetc < c sheetc c sheetc++ sheetc++ sheetc {        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		} {        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		} sheet[sheetr][c] += sheet[sheetr][sheetc] sheet[sheetr][c] sheet[sheetr] sheet sheetr c sheet[sheetr][sheetc] sheet[sheetr] sheet sheetr sheetc for(sheetc = 0; sheetc <= c; sheetc++){
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	} sheetc = 0; sheetc = 0 sheetc 0 sheetc <= c sheetc c sheetc++ sheetc++ sheetc {
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	} {
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	} for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		} sheetr = 0; sheetr = 0 sheetr 0 sheetr < r sheetr r sheetr++ sheetr++ sheetr {
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		} {
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		} sheet[r][sheetc] += sheet[sheetr][sheetc] sheet[r][sheetc] sheet[r] sheet r sheetc sheet[sheetr][sheetc] sheet[sheetr] sheet sheetr sheetc for(sheetr = 0; sheetr <= r; sheetr++){
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	} sheetr = 0; sheetr = 0 sheetr 0 sheetr <= r sheetr r sheetr++ sheetr++ sheetr {
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	} {
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	} for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		} sheetc = 0; sheetc = 0 sheetc 0 sheetc <= c sheetc c sheetc++ sheetc++ sheetc { 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		} { 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		} if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			} sheetc < c sheetc c {
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			} System.out.print(sheet[sheetr][sheetc]+" ") System.out.print System.out System System.out sheet[sheetr][sheetc]+" " sheet[sheetr][sheetc] sheet[sheetr] sheet sheetr sheetc " " if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			} sheetc == c sheetc c {
        			System.out.print(sheet[sheetr][sheetc]);
        			} System.out.print(sheet[sheetr][sheetc]) System.out.print System.out System System.out sheet[sheetr][sheetc] sheet[sheetr] sheet sheetr sheetc if(sheetc == c){
        				System.out.print("\r\n");
        			} sheetc == c sheetc c {
        				System.out.print("\r\n");
        			} System.out.print("\r\n") System.out.print System.out System System.out "\r\n" String[] args args
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        	int r = scan.nextInt();
        	int c = scan.nextInt();
        	int [][]sheet;
        	sheet = new int[(r+1)][(c+1)];
        	int sheetr,sheetc;

        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){
        		sheet[sheetr][sheetc] = scan.nextInt();
        		}
        	}
        	for(sheetr = 0; sheetr < r; sheetr++){
        		for(sheetc = 0; sheetc < c; sheetc++){        			
        		sheet[sheetr][c] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetc = 0; sheetc <= c; sheetc++){
        		for(sheetr = 0; sheetr < r; sheetr++){
        		sheet[r][sheetc] += sheet[sheetr][sheetc];
        		}
        	}
        	for(sheetr = 0; sheetr <= r; sheetr++){
        		for(sheetc = 0; sheetc <= c; sheetc++){ 
        			if(sheetc < c){
        				System.out.print(sheet[sheetr][sheetc]+" ");
        			}
        			else if(sheetc == c){
        			System.out.print(sheet[sheetr][sheetc]);
        			}
        			if(sheetc == c){
        				System.out.print("\r\n");
        			}
        		}
        	}
    }
}