import java.util.Scanner;
 
class Main{
	public static void main(String[]args){
        	Scanner sc = new Scanner(System.in);
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int table[][] = new int[x+1][y+1];
         
        	for(int i = 0; i < x; i++){
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	}
     
        	for(int i = 0; i < x+1; i++){
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	}
    	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[]args){
        	Scanner sc = new Scanner(System.in);
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int table[][] = new int[x+1][y+1];
         
        	for(int i = 0; i < x; i++){
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	}
     
        	for(int i = 0; i < x+1; i++){
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	}
    	}
} Main public static void main(String[]args){
        	Scanner sc = new Scanner(System.in);
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int table[][] = new int[x+1][y+1];
         
        	for(int i = 0; i < x; i++){
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	}
     
        	for(int i = 0; i < x+1; i++){
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	}
    	} main {
        	Scanner sc = new Scanner(System.in);
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int table[][] = new int[x+1][y+1];
         
        	for(int i = 0; i < x; i++){
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	}
     
        	for(int i = 0; i < x+1; i++){
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	}
    	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int y = sc.nextInt(); y sc.nextInt() sc.nextInt sc int table[][] = new int[x+1][y+1]; table new int[x+1][y+1] x+1 x 1 y+1 y 1 for(int i = 0; i < x; i++){
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	} int i = 0; int i = 0; i 0 i < x i x i++ i++ i {
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	} {
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	} for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		} int j = 0; int j = 0; j 0 j < y j y j++ j++ j {
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		} {
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		} table[i][j] = sc.nextInt() table[i][j] table[i] table i j sc.nextInt() sc.nextInt sc table[i][y]+=table[i][j] table[i][y] table[i] table i y table[i][j] table[i] table i j table[x][j]+=table[i][j] table[x][j] table[x] table x j table[i][j] table[i] table i j table[x][y]+=table[i][j] table[x][y] table[x] table x y table[i][j] table[i] table i j for(int i = 0; i < x+1; i++){
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	} int i = 0; int i = 0; i 0 i < x+1 i x+1 x 1 i++ i++ i {
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	} {
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	} for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		} int j = 0; int j = 0; j 0 j < y+1 j y+1 y 1 j++ j++ j {
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		} {
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		} System.out.print(table[i][j]) System.out.print System.out System System.out table[i][j] table[i] table i j if(j != y){
					System.out.print(" ");
				} j != y j y {
					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 String[]args args
import java.util.Scanner;
 
class Main{
	public static void main(String[]args){
        	Scanner sc = new Scanner(System.in);
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int table[][] = new int[x+1][y+1];
         
        	for(int i = 0; i < x; i++){
            		for(int j = 0; j < y; j++){
                		table[i][j] = sc.nextInt();
                		table[i][y]+=table[i][j];
                		table[x][j]+=table[i][j];
               			table[x][y]+=table[i][j];
            		}
        	}
     
        	for(int i = 0; i < x+1; i++){
            		for(int j = 0; j < y+1; j++){
                		System.out.print(table[i][j]);
                		if(j != y){
					System.out.print(" ");
				}
            		}
            	System.out.println();
        	}
    	}
}