import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int r=as.nextInt();        //????????°
        int c=as.nextInt();        //????????°
        
        int i,j;
        int smr = 0;
        int src = 0;
        int glf[][];
        int smc[];
        glf = new int[r+1][c+1];   //??????
        smc = new int[c];
        String str;
        
        for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        }
        
        for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        }
        
        for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        }
            

	}

} import java.util.Scanner; Scanner java.util class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int r=as.nextInt();        //????????°
        int c=as.nextInt();        //????????°
        
        int i,j;
        int smr = 0;
        int src = 0;
        int glf[][];
        int smc[];
        glf = new int[r+1][c+1];   //??????
        smc = new int[c];
        String str;
        
        for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        }
        
        for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        }
        
        for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        }
            

	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int r=as.nextInt();        //????????°
        int c=as.nextInt();        //????????°
        
        int i,j;
        int smr = 0;
        int src = 0;
        int glf[][];
        int smc[];
        glf = new int[r+1][c+1];   //??????
        smc = new int[c];
        String str;
        
        for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        }
        
        for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        }
        
        for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        }
            

	} main {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int r=as.nextInt();        //????????°
        int c=as.nextInt();        //????????°
        
        int i,j;
        int smr = 0;
        int src = 0;
        int glf[][];
        int smc[];
        glf = new int[r+1][c+1];   //??????
        smc = new int[c];
        String str;
        
        for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        }
        
        for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        }
        
        for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        }
            

	} Scanner as = new Scanner(System.in); as new Scanner(System.in) int r=as.nextInt(); r as.nextInt() as.nextInt as int c=as.nextInt(); c as.nextInt() as.nextInt as int i i j; j int smr = 0; smr 0 int src = 0; src 0 int glf[][]; glf int smc[]; smc glf = new int[r+1][c+1] glf new int[r+1][c+1] r+1 r 1 c+1 c 1 smc = new int[c] smc new int[c] c String str; str for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        } i=0; i=0 i 0 i<r i r i++ i++ i {          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        } {          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        } for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            } j=0; j=0 j 0 j<c+1 j c+1 c 1 j++ j++ j {
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            } {
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            } if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	} j == c j c {
            		
            		glf[i][j]=smr;
            		
            	} glf[i][j]=smr glf[i][j] glf[i] glf i j smr {
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	} glf[i][j]=as.nextInt() glf[i][j] glf[i] glf i j as.nextInt() as.nextInt as smc[j]=smc[j]+glf[i][j] smc[j] smc j smc[j]+glf[i][j] smc[j] smc j glf[i][j] glf[i] glf i j smr=smr+glf[i][j] smr smr+glf[i][j] smr glf[i][j] glf[i] glf i j src=src+glf[i][j] src src+glf[i][j] src glf[i][j] glf[i] glf i j smr=0 smr 0 for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        } i=0; i=0 i 0 i<c+1 i c+1 c 1 i++ i++ i {
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        } {
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        } if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	} i == c i c {
        	
        		glf[r][i]=src;
        		
        	} glf[r][i]=src glf[r][i] glf[r] glf r i src {
        		
        		glf[r][i]=smc[i];
        		
        	} glf[r][i]=smc[i] glf[r][i] glf[r] glf r i smc[i] smc i for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        } i=0; i=0 i 0 i<r+1 i r+1 r 1 i++ i++ i {
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        } {
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        } for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	} j=0; j=0 j 0 j<c+1 j c+1 c 1 j++ j++ j {
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	} {
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	} if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		} j == c j c {
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		} str=String.valueOf(glf[i][j]) str String.valueOf(glf[i][j]) String.valueOf String glf[i][j] glf[i] glf i j System.out.println(str) System.out.println System.out System System.out str {
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		} str=String.valueOf(glf[i][j])+" " str String.valueOf(glf[i][j])+" " String.valueOf(glf[i][j]) String.valueOf String glf[i][j] glf[i] glf i j " " System.out.print(str) System.out.print System.out System System.out str String[] args args
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int r=as.nextInt();        //????????°
        int c=as.nextInt();        //????????°
        
        int i,j;
        int smr = 0;
        int src = 0;
        int glf[][];
        int smc[];
        glf = new int[r+1][c+1];   //??????
        smc = new int[c];
        String str;
        
        for(i=0;i<r;i++){          
            for(j=0;j<c+1;j++){
            	
            	if(j == c){
            		
            		glf[i][j]=smr;
            		
            	}
            	else{
            		
            		
   
            		glf[i][j]=as.nextInt();     //?????????????´?
                	smc[j]=smc[j]+glf[i][j];
            		smr=smr+glf[i][j];
            		src=src+glf[i][j];
            		
            	}
                 
            }
            
            smr=0;
            
        }
        
        for(i=0;i<c+1;i++){
        	if(i == c){
        	
        		glf[r][i]=src;
        		
        	}
        	else{
        		
        		glf[r][i]=smc[i];
        		
        	}
        	
        }
        
        for(i=0;i<r+1;i++){
        	for(j=0;j<c+1;j++){
        		
        		if(j == c){
        			
        			str=String.valueOf(glf[i][j]);
        			System.out.println(str);
        			
        		}
        		else{
        			
        			str=String.valueOf(glf[i][j])+" ";
        			System.out.print(str);
        			
        		}
        	}
        }
            

	}

}