import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str[] = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(str[0]); r Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int c = Integer.parseInt(str[1]); c Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int[][] a = new int[r+1][c+1]; a new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        } {
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        } str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            } {
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            } a[i][j] = Integer.parseInt(str[j]) a[i][j] a[i] a i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j a[i][c] += a[i][j] a[i][c] a[i] a i c a[i][j] a[i] a i j a[r][j] += a[i][j] a[r][j] a[r] a r j a[i][j] a[i] a i j a[r][c] += a[i][c] a[r][c] a[r] a r c a[i][c] a[i] a i c for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        } 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<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        } {
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        } for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            } int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            } {
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            } if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]); j<c j c System.out.print(a[i][j]+" ") System.out.print System.out System System.out a[i][j]+" " a[i][j] a[i] a i j " " System.out.println(a[i][j]) System.out.println System.out System System.out a[i][j] a[i] a i j String[] args args public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        int r = Integer.parseInt(str[0]);
        int c = Integer.parseInt(str[1]);
        int[][] a = new int[r+1][c+1];
        for(int i=0;i<r;i++){
            str = br.readLine().split(" ");
            for(int j=0;j<c;j++){
                a[i][j] = Integer.parseInt(str[j]);
                a[i][c] += a[i][j];
                a[r][j] += a[i][j];
            }
            a[r][c] += a[i][c];
        }
        for(int i=0;i<r+1;i++){
            for(int j=0;j<c+1;j++){
                if(j<c) System.out.print(a[i][j]+" ");
                else System.out.println(a[i][j]);
            }
        }
    }
}