import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int row = Integer.parseInt(input[0]);
        int col = Integer.parseInt(input[1]);
        int sumOfRow;
        int[] sumOfCol = new int[col + 1];
        String line;
        int i, j, num;
        for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        }
        for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        }
        line = "";
        for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        }
        System.out.println(line);
    }
} import java.io.*; io.* java class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int row = Integer.parseInt(input[0]);
        int col = Integer.parseInt(input[1]);
        int sumOfRow;
        int[] sumOfCol = new int[col + 1];
        String line;
        int i, j, num;
        for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        }
        for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        }
        line = "";
        for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        }
        System.out.println(line);
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int row = Integer.parseInt(input[0]);
        int col = Integer.parseInt(input[1]);
        int sumOfRow;
        int[] sumOfCol = new int[col + 1];
        String line;
        int i, j, num;
        for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        }
        for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        }
        line = "";
        for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        }
        System.out.println(line);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int row = Integer.parseInt(input[0]);
        int col = Integer.parseInt(input[1]);
        int sumOfRow;
        int[] sumOfCol = new int[col + 1];
        String line;
        int i, j, num;
        for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        }
        for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        }
        line = "";
        for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        }
        System.out.println(line);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int row = Integer.parseInt(input[0]); row Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 int col = Integer.parseInt(input[1]); col Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 int sumOfRow; sumOfRow int[] sumOfCol = new int[col + 1]; sumOfCol new int[col + 1] col + 1 col 1 String line; line int i i j j num; num for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        } i = 0; i = 0 i 0 i < col + 1 i col + 1 col 1 i++ i++ i {
            sumOfCol[i] = 0;
        } {
            sumOfCol[i] = 0;
        } sumOfCol[i] = 0 sumOfCol[i] sumOfCol i 0 for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        } i = 0; i = 0 i 0 i < row i row i++ i++ i {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        } {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        } line = br.readLine() line br.readLine() br.readLine br input = line.split(" ") input line.split(" ") line.split line " " sumOfRow = 0 sumOfRow 0 for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            } j = 0; j = 0 j 0 j < col j col j++ j++ j {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            } {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            } num = Integer.parseInt(input[j]) num Integer.parseInt(input[j]) Integer.parseInt Integer input[j] input j sumOfRow += num sumOfRow num sumOfCol[j] += num sumOfCol[j] sumOfCol j num sumOfCol[col] += sumOfRow sumOfCol[col] sumOfCol col sumOfRow System.out.println(line + " " + sumOfRow) System.out.println System.out System System.out line + " " + sumOfRow line + " " + sumOfRow line " " sumOfRow line = "" line "" for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        } i = 0; i = 0 i 0 i < col + 1 i col + 1 col 1 i++ i++ i {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        } {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        } line += sumOfCol[i] line sumOfCol[i] sumOfCol i if (i == col) break; i == col i col break; line += " " line " " System.out.println(line) System.out.println System.out System System.out line String[] args args
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int row = Integer.parseInt(input[0]);
        int col = Integer.parseInt(input[1]);
        int sumOfRow;
        int[] sumOfCol = new int[col + 1];
        String line;
        int i, j, num;
        for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        }
        for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        }
        line = "";
        for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        }
        System.out.println(line);
    }
}