import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int[][] sheet = new int[r+1][c+1];

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

        for(int i = 0; i <= r; i++){
            for(int j = 0; j <= c; j++){
                 System.out.print(sheet[i][j]);
                 if(j != c)
                   System.out.print(" ");
            }
                System.out.print("\n");
        }
    }
} import java.io.*; io.* java public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int[][] sheet = new int[r+1][c+1];

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

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

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

        for(int i = 0; i <= r; i++){
            for(int j = 0; j <= c; j++){
                 System.out.print(sheet[i][j]);
                 if(j != c)
                   System.out.print(" ");
            }
                System.out.print("\n");
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int[][] sheet = new int[r+1][c+1];

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

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

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

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

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

        for(int i = 0; i <= r; i++){
            for(int j = 0; j <= c; j++){
                 System.out.print(sheet[i][j]);
                 if(j != c)
                   System.out.print(" ");
            }
                System.out.print("\n");
        }
    }
} Main
import java.io.*;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int[][] sheet = new int[r+1][c+1];

        for(int i = 0; i < r; i++){
            line = br.readLine().split(" ");
            int[] a = new int[c];
            for(int k = 0; k < c; k++){
                a[k] = Integer.parseInt(line[k]);
            }
            for(int j = 0; j < c; j++){
                sheet[i][j] = a[j];
                sheet[r][c] += a[j];
                sheet[i][c] += a[j];
                sheet[r][j] += a[j];
            }
        }

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