import java.io.*;

class Main{
    public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] data = makeIntArray(br);
        int r = data[0], c = data[1];
        int[][] exl = new int[r + 1][c + 1];
        int i, j;
        for(i = 0; i < r; i++){
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        }
        for(j = 0; j <= c; j++){
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        }
        for(i = 0; i <= r; i++){ show(exl[i]); }
    }
    public static void show(int[] a){
        int n = a.length;
        for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); }
        System.out.println(a[n - 1]);
    }
    public static int[] makeIntArray(BufferedReader br) throws IOException
    {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    }
} import java.io.*; io.* java class Main{
    public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] data = makeIntArray(br);
        int r = data[0], c = data[1];
        int[][] exl = new int[r + 1][c + 1];
        int i, j;
        for(i = 0; i < r; i++){
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        }
        for(j = 0; j <= c; j++){
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        }
        for(i = 0; i <= r; i++){ show(exl[i]); }
    }
    public static void show(int[] a){
        int n = a.length;
        for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); }
        System.out.println(a[n - 1]);
    }
    public static int[] makeIntArray(BufferedReader br) throws IOException
    {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    }
} Main public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] data = makeIntArray(br);
        int r = data[0], c = data[1];
        int[][] exl = new int[r + 1][c + 1];
        int i, j;
        for(i = 0; i < r; i++){
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        }
        for(j = 0; j <= c; j++){
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        }
        for(i = 0; i <= r; i++){ show(exl[i]); }
    } main {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] data = makeIntArray(br);
        int r = data[0], c = data[1];
        int[][] exl = new int[r + 1][c + 1];
        int i, j;
        for(i = 0; i < r; i++){
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        }
        for(j = 0; j <= c; j++){
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        }
        for(i = 0; i <= r; i++){ show(exl[i]); }
    } InputStreamReader is = new InputStreamReader(System.in); is new InputStreamReader(System.in) BufferedReader br = new BufferedReader(is); br new BufferedReader(is) int[] data = makeIntArray(br); data makeIntArray(br) makeIntArray br int r = data[0] r data[0] data 0 c = data[1]; c data[1] data 1 int[][] exl = new int[r + 1][c + 1]; exl new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 int i i j; j for(i = 0; i < r; i++){
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        } i = 0; i = 0 i 0 i < r i r i++ i++ i {
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        } {
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        } data = makeIntArray(br) data makeIntArray(br) makeIntArray br exl[i][c] = 0 exl[i][c] exl[i] exl i c 0 for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            } j = 0; j = 0 j 0 j < c j c j++ j++ j {
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            } {
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            } exl[i][j] = data[j] exl[i][j] exl[i] exl i j data[j] data j exl[i][c] += data[j] exl[i][c] exl[i] exl i c data[j] data j for(j = 0; j <= c; j++){
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        } j = 0; j = 0 j 0 j <= c j c j++ j++ j {
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        } {
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        } exl[r][j] = 0 exl[r][j] exl[r] exl r j 0 for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; } i = 0; i = 0 i 0 i < r i r i++ i++ i { exl[r][j] += exl[i][j]; } { exl[r][j] += exl[i][j]; } exl[r][j] += exl[i][j] exl[r][j] exl[r] exl r j exl[i][j] exl[i] exl i j for(i = 0; i <= r; i++){ show(exl[i]); } i = 0; i = 0 i 0 i <= r i r i++ i++ i { show(exl[i]); } { show(exl[i]); } show(exl[i]) show exl[i] exl i String[] args args public static void show(int[] a){
        int n = a.length;
        for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); }
        System.out.println(a[n - 1]);
    } show {
        int n = a.length;
        for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); }
        System.out.println(a[n - 1]);
    } int n = a.length; n a.length a a.length for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i { System.out.print(a[i] + " "); } { System.out.print(a[i] + " "); } System.out.print(a[i] + " ") System.out.print System.out System System.out a[i] + " " a[i] a i " " System.out.println(a[n - 1]) System.out.println System.out System System.out a[n - 1] a n - 1 n 1 int[] a a public static int[] makeIntArray(BufferedReader br) throws IOException
    {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    } makeIntArray {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    } String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = str.length; n str.length str str.length int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); } int i = 0; int i = 0; i 0 i < n i n i++ i++ i { a[i] = Integer.parseInt(str[i]); } { a[i] = Integer.parseInt(str[i]); } a[i] = Integer.parseInt(str[i]) a[i] a i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i return a; a BufferedReader br br
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException
    {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        int[] data = makeIntArray(br);
        int r = data[0], c = data[1];
        int[][] exl = new int[r + 1][c + 1];
        int i, j;
        for(i = 0; i < r; i++){
            data = makeIntArray(br);
            exl[i][c] = 0;
            for(j = 0; j < c; j++){
                exl[i][j] = data[j];
                exl[i][c] += data[j];
            }
        }
        for(j = 0; j <= c; j++){
            exl[r][j] = 0;
            for(i = 0; i < r; i++){ exl[r][j] += exl[i][j]; }
        }
        for(i = 0; i <= r; i++){ show(exl[i]); }
    }
    public static void show(int[] a){
        int n = a.length;
        for(int i = 0; i < n - 1; i++){ System.out.print(a[i] + " "); }
        System.out.println(a[n - 1]);
    }
    public static int[] makeIntArray(BufferedReader br) throws IOException
    {
        String[] str = br.readLine().split(" ");
        int n = str.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++){ a[i] = Integer.parseInt(str[i]); }
        return a;
    }
}
