import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,tmp;
        int[][] A = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);   
        } 
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        }
        for(i=0;i<=n[0];i++){
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        }        
        System.out.flush();
    }
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util class Main{
    public static void main(String[] args) throws IOException {
        int i,j,tmp;
        int[][] A = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);   
        } 
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        }
        for(i=0;i<=n[0];i++){
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        }        
        System.out.flush();
    }
} Main public static void main(String[] args) throws IOException {
        int i,j,tmp;
        int[][] A = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);   
        } 
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        }
        for(i=0;i<=n[0];i++){
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        }        
        System.out.flush();
    } main {
        int i,j,tmp;
        int[][] A = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);   
        } 
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        }
        for(i=0;i<=n[0];i++){
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        }        
        System.out.flush();
    } int i i j j tmp; tmp int[][] A = new int[101][101]; A new int[101][101] 101 101 int[] n = new int[990]; n new int[990] 990 String[] str = new String[990]; str new String[990] 990 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) str = in.readLine().split(" ") str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);   
        } i=0; i=0 i 0 i<2 i 2 i++ i++ i {
            n[i]=Integer.parseInt(str[i]);   
        } {
            n[i]=Integer.parseInt(str[i]);   
        } n[i]=Integer.parseInt(str[i]) n[i] n i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        } i=0; i=0 i 0 i<n[0] i n[0] n 0 i++ i++ i {
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        } {
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        } str = in.readLine().split(" ") str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            } j=0; j=0 j 0 j<n[1] j n[1] n 1 j++ j++ j {
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            } {
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            } tmp = Integer.parseInt(str[j]) tmp Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j A[i][j]+=tmp A[i][j] A[i] A i j tmp A[n[0]][j]+=tmp A[n[0]][j] A[n[0]] A n[0] n 0 j tmp A[i][n[1]]+=tmp A[i][n[1]] A[i] A i n[1] n 1 tmp A[n[0]][n[1]]+=tmp A[n[0]][n[1]] A[n[0]] A n[0] n 0 n[1] n 1 tmp for(i=0;i<=n[0];i++){
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        } i=0; i=0 i 0 i<=n[0] i n[0] n 0 i++ i++ i {
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        } {
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        } for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            } j=0; j=0 j 0 j<=n[1] j n[1] n 1 j++ j++ j {
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            } {
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            } if(j!=0) System.out.print(" "); j!=0 j 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(A[i][j]) System.out.print System.out System System.out A[i][j] A[i] A i j System.out.println() System.out.println System.out System System.out System.out.flush() System.out.flush System.out System System.out String[] args args
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,tmp;
        int[][] A = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<2;i++){
            n[i]=Integer.parseInt(str[i]);   
        } 
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                tmp = Integer.parseInt(str[j]);
                A[i][j]+=tmp; A[n[0]][j]+=tmp; A[i][n[1]]+=tmp; A[n[0]][n[1]]+=tmp;
            }
        }
        for(i=0;i<=n[0];i++){
            for(j=0;j<=n[1];j++){
                if(j!=0) System.out.print(" ");
                System.out.print(A[i][j]);
            }
            System.out.println();
        }        
        System.out.flush();
    }
}