import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner scn = new Scanner(System.in);
        
        int r = scn.nextInt();
        int c = scn.nextInt();
        int [][]rc = new int[r+1][c+1];
        int sum =0;
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        }
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        }
        

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

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

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

        for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        }        
        
        
        
    }
} Main public static void main(String[]args){
        Scanner scn = new Scanner(System.in);
        
        int r = scn.nextInt();
        int c = scn.nextInt();
        int [][]rc = new int[r+1][c+1];
        int sum =0;
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        }
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        }
        

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

        for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        }        
        
        
        
    } main {
        Scanner scn = new Scanner(System.in);
        
        int r = scn.nextInt();
        int c = scn.nextInt();
        int [][]rc = new int[r+1][c+1];
        int sum =0;
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        }
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        }
        

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

        for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        }        
        
        
        
    } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int r = scn.nextInt(); r scn.nextInt() scn.nextInt scn int c = scn.nextInt(); c scn.nextInt() scn.nextInt scn int [][]rc = new int[r+1][c+1]; rc new int[r+1][c+1] r+1 r 1 c+1 c 1 int sum =0; sum 0 for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        } {
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        } for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                rc[i][j]=scn.nextInt();
            } {
                rc[i][j]=scn.nextInt();
            } rc[i][j]=scn.nextInt() rc[i][j] rc[i] rc i j scn.nextInt() scn.nextInt scn for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        } {
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        } for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                rc[i][c]+=rc[i][j];
            } {
                rc[i][c]+=rc[i][j];
            } rc[i][c]+=rc[i][j] rc[i][c] rc[i] rc i c rc[i][j] rc[i] rc i j for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        } {
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        } for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            } {
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            } rc[r][j]+=rc[i][j] rc[r][j] rc[r] rc r j rc[i][j] rc[i] rc i j sum+=rc[i][j] sum rc[i][j] rc[i] rc i j rc[r][c]=sum rc[r][c] rc[r] rc r c sum for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        } int i=0; int i=0; i 0 i<=r i r i++ i++ i {
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        } {
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        } for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            } int j=0; int j=0; j 0 j<=c j c j++ j++ j {
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            } {
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            } if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                } j==c j c {
                    System.out.print(rc[i][j]+"\n");
                } System.out.print(rc[i][j]+"\n") System.out.print System.out System System.out rc[i][j]+"\n" rc[i][j] rc[i] rc i j "\n" {
                    System.out.print(rc[i][j]+" ");
                } System.out.print(rc[i][j]+" ") System.out.print System.out System System.out rc[i][j]+" " rc[i][j] rc[i] rc i j " " String[]args args public class Main{
    public static void main(String[]args){
        Scanner scn = new Scanner(System.in);
        
        int r = scn.nextInt();
        int c = scn.nextInt();
        int [][]rc = new int[r+1][c+1];
        int sum =0;
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        }
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        }
        

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

        for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        }        
        
        
        
    }
} public class Main{
    public static void main(String[]args){
        Scanner scn = new Scanner(System.in);
        
        int r = scn.nextInt();
        int c = scn.nextInt();
        int [][]rc = new int[r+1][c+1];
        int sum =0;
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        }
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        }
        

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

        for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        }        
        
        
        
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner scn = new Scanner(System.in);
        
        int r = scn.nextInt();
        int c = scn.nextInt();
        int [][]rc = new int[r+1][c+1];
        int sum =0;
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=scn.nextInt();
            }
        }
        
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][c]+=rc[i][j];
            }
        }
        

        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[r][j]+=rc[i][j];
                sum+=rc[i][j];
            }
        }
        
        rc[r][c]=sum;

        for(int i=0;i<=r;i++){
            for(int j=0;j<=c;j++){
                if(j==c){
                    System.out.print(rc[i][j]+"\n");
                }else{
                    System.out.print(rc[i][j]+" ");
                }                               
            }
        }        
        
        
        
    }
}