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[][] rc=new int[r+1][c+1];     
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            }
        }
        int sum;
        for(int k=0;k<r;k++){
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        }for(int a=0;a<=c;a++){
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        }
        for(int d=0;d<=r;d++){
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    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 r=sc.nextInt();
        int c=sc.nextInt();
        int[][] rc=new int[r+1][c+1];     
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            }
        }
        int sum;
        for(int k=0;k<r;k++){
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        }for(int a=0;a<=c;a++){
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        }
        for(int d=0;d<=r;d++){
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            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[][] rc=new int[r+1][c+1];     
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            }
        }
        int sum;
        for(int k=0;k<r;k++){
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        }for(int a=0;a<=c;a++){
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        }
        for(int d=0;d<=r;d++){
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    } main {
        Scanner sc=new Scanner(System.in);
        int r=sc.nextInt();
        int c=sc.nextInt();
        int[][] rc=new int[r+1][c+1];     
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            }
        }
        int sum;
        for(int k=0;k<r;k++){
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        }for(int a=0;a<=c;a++){
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        }
        for(int d=0;d<=r;d++){
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            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[][] rc=new int[r+1][c+1]; rc 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++){
                rc[i][j]=sc.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]=sc.nextInt();
            }
        } {
            for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            }
        } for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                rc[i][j]=sc.nextInt();
            } {
                rc[i][j]=sc.nextInt();
            } rc[i][j]=sc.nextInt() rc[i][j] rc[i] rc i j sc.nextInt() sc.nextInt sc int sum; sum for(int k=0;k<r;k++){
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        } int k=0; int k=0; k 0 k<r k r k++ k++ k {
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        } {
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        } sum=0 sum 0 for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            } int l=0; int l=0; l 0 l<c l c l++ l++ l {
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            } {
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            } sum=sum+rc[k][l] sum sum+rc[k][l] sum rc[k][l] rc[k] rc k l if(l==c-1){
                    rc[k][c]=sum;
                } l==c-1 l c-1 c 1 {
                    rc[k][c]=sum;
                } rc[k][c]=sum rc[k][c] rc[k] rc k c sum for(int a=0;a<=c;a++){
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        } int a=0; int a=0; a 0 a<=c a c a++ a++ a {
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        } {
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        } sum=0 sum 0 for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            } int b=0; int b=0; b 0 b<r b r b++ b++ b {
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            } {
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            } sum=sum+rc[b][a] sum sum+rc[b][a] sum rc[b][a] rc[b] rc b a if(b==r-1){
                    rc[r][a]=sum;
                } b==r-1 b r-1 r 1 {
                    rc[r][a]=sum;
                } rc[r][a]=sum rc[r][a] rc[r] rc r a sum for(int d=0;d<=r;d++){
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            System.out.println();
        } int d=0; int d=0; d 0 d<=r d r d++ d++ d {
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            System.out.println();
        } {
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            System.out.println();
        } for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            } int e=0; int e=0; e 0 e<=c e c e++ e++ e {
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            } {
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            } System.out.print(rc[d][e]) System.out.print System.out System System.out rc[d][e] rc[d] rc d e if(e!=c){
                    System.out.print(" ");
                } e!=c e c {
                    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 r=sc.nextInt();
        int c=sc.nextInt();
        int[][] rc=new int[r+1][c+1];     
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                rc[i][j]=sc.nextInt();
            }
        }
        int sum;
        for(int k=0;k<r;k++){
            sum=0;
            for(int l=0;l<c;l++){
                sum=sum+rc[k][l];
                if(l==c-1){
                    rc[k][c]=sum;
                }
            }
        }for(int a=0;a<=c;a++){
            sum=0;
            for(int b=0;b<r;b++){
                sum=sum+rc[b][a];
                if(b==r-1){
                    rc[r][a]=sum;
                }
            }
        }
        for(int d=0;d<=r;d++){
            for(int e=0;e<=c;e++){
                System.out.print(rc[d][e]);
                if(e!=c){
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}
