//7-C

import java.util.Scanner;

class Main {
    public static void main(String [] args){
    	Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();//行
        int c = sc.nextInt();//列
        
        int[][] num = new int[r+1][c+1];//配列宣言 //ok
        
        //配列の中に整数代入
        for( int i = 0 ; i < r ; i++ ){
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        }
        
        //総合計入力
    	for ( int j = 0 ; j < c ; j++ ){
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	}
        	
        
        //配列の中身と合計を出力
       for( int i = 0 ; i < r+1 ; i++ ){
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	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 r = sc.nextInt();//行
        int c = sc.nextInt();//列
        
        int[][] num = new int[r+1][c+1];//配列宣言 //ok
        
        //配列の中に整数代入
        for( int i = 0 ; i < r ; i++ ){
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        }
        
        //総合計入力
    	for ( int j = 0 ; j < c ; j++ ){
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	}
        	
        
        //配列の中身と合計を出力
       for( int i = 0 ; i < r+1 ; i++ ){
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        }
    }
} Main public static void main(String [] args){
    	Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();//行
        int c = sc.nextInt();//列
        
        int[][] num = new int[r+1][c+1];//配列宣言 //ok
        
        //配列の中に整数代入
        for( int i = 0 ; i < r ; i++ ){
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        }
        
        //総合計入力
    	for ( int j = 0 ; j < c ; j++ ){
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	}
        	
        
        //配列の中身と合計を出力
       for( int i = 0 ; i < r+1 ; i++ ){
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        }
    } main {
    	Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();//行
        int c = sc.nextInt();//列
        
        int[][] num = new int[r+1][c+1];//配列宣言 //ok
        
        //配列の中に整数代入
        for( int i = 0 ; i < r ; i++ ){
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        }
        
        //総合計入力
    	for ( int j = 0 ; j < c ; j++ ){
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	}
        	
        
        //配列の中身と合計を出力
       for( int i = 0 ; i < r+1 ; i++ ){
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int[][] num = new int[r+1][c+1]; num new int[r+1][c+1] r+1 r 1 c+1 c 1 for( int i = 0 ; i < r ; i++ ){
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        } int i = 0 ; int i = 0 ; i 0 i < r i r i++ i++ i {
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        } {
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        } for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	} int j = 0 ; int j = 0 ; j 0 j < c j c j++ j++ j {
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	} {
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	} num[i][j] = sc.nextInt() num[i][j] num[i] num i j sc.nextInt() sc.nextInt sc num[r][j] = num[r][j] + num[i][j] num[r][j] num[r] num r j num[r][j] + num[i][j] num[r][j] num[r] num r j num[i][j] num[i] num i j num[i][c] = num[i][c] + num[i][j] num[i][c] num[i] num i c num[i][c] + num[i][j] num[i][c] num[i] num i c num[i][j] num[i] num i j for ( int j = 0 ; j < c ; j++ ){
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	} int j = 0 ; int j = 0 ; j 0 j < c j c j++ j++ j {
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	} {
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	} num[r][c] = num[r][c] + num[r][j] num[r][c] num[r] num r c num[r][c] + num[r][j] num[r][c] num[r] num r c num[r][j] num[r] num r j for( int i = 0 ; i < r+1 ; i++ ){
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        } int i = 0 ; int i = 0 ; i 0 i < r+1 i r+1 r 1 i++ i++ i {
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        } {
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        } for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	} int j = 0 ; int j = 0 ; j 0 j < c+1 j c+1 c 1 j++ j++ j {
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	} {
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	} if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		} j == 0 j 0 {
        			System.out.print(num[i][j]);
        		} System.out.print(num[i][j]) System.out.print System.out System System.out num[i][j] num[i] num i j {
        			System.out.print(" " + num[i][j]);
        		} System.out.print(" " + num[i][j]) System.out.print System.out System System.out " " + num[i][j] " " num[i][j] num[i] num i j System.out.println() System.out.println System.out System System.out String [] args args
//7-C

import java.util.Scanner;

class Main {
    public static void main(String [] args){
    	Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();//行
        int c = sc.nextInt();//列
        
        int[][] num = new int[r+1][c+1];//配列宣言 //ok
        
        //配列の中に整数代入
        for( int i = 0 ; i < r ; i++ ){
        	for ( int j = 0 ; j < c ; j++ ){
        		
        		num[i][j] = sc.nextInt();
        		
        		num[r][j] = num[r][j] + num[i][j];
        		num[i][c] = num[i][c] + num[i][j];
        		
        	}
        }
        
        //総合計入力
    	for ( int j = 0 ; j < c ; j++ ){
    		
    		num[r][c] = num[r][c] + num[r][j];
    		
    	}
        	
        
        //配列の中身と合計を出力
       for( int i = 0 ; i < r+1 ; i++ ){
        	for ( int j = 0 ; j < c+1 ; j++ ){
        		
        		if(j == 0){
        			System.out.print(num[i][j]);
        		}else{
        			System.out.print(" " + num[i][j]);
        		}
        		
        	}
        	System.out.println();
        }
    }
}