import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int r, c, sum;
        int[][] table;
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        table = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        }

        for (int i = 0; i < c + 1; i++) 
                table[r][i] = 0;

        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        }
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        int r, c, sum;
        int[][] table;
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        table = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        }

        for (int i = 0; i < c + 1; i++) 
                table[r][i] = 0;

        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        }
    }
} Main public static void main(String[] args) {
        int r, c, sum;
        int[][] table;
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        table = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        }

        for (int i = 0; i < c + 1; i++) 
                table[r][i] = 0;

        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        }
    } main {
        int r, c, sum;
        int[][] table;
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        table = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        }

        for (int i = 0; i < c + 1; i++) 
                table[r][i] = 0;

        for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        }
    } int r r c c sum; sum int[][] table; table Scanner sc = new Scanner(System.in); sc new Scanner(System.in) r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc table = new int[r + 1][c + 1] table new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < r; i++) {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        } {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        } sum = 0 sum 0 for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            } {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            } table[i][j] = sc.nextInt() table[i][j] table[i] table i j sc.nextInt() sc.nextInt sc sum += table[i][j] sum table[i][j] table[i] table i j table[i][c] = sum table[i][c] table[i] table i c sum for (int i = 0; i < c + 1; i++) 
                table[r][i] = 0; int i = 0; int i = 0; i 0 i < c + 1 i c + 1 c 1 i++ i++ i table[r][i] = 0; table[r][i] = 0 table[r][i] table[r] table r i 0 for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        } 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++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        } {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            }
            System.out.println();
        } for (int j = 0; j < c + 1; j++) {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            } int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            } {
                System.out.print(table[i][j]);
                table[r][j] += table[i][j];
                if (j != c)
                    System.out.print(" ");
            } System.out.print(table[i][j]) System.out.print System.out System System.out table[i][j] table[i] table i j table[r][j] += table[i][j] table[r][j] table[r] table r j table[i][j] table[i] table 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.println() System.out.println System.out System System.out String[] args args
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int r, c, sum;
        int[][] table;
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        table = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
            }
            table[i][c] = sum;
        }

        for (int i = 0; i < c + 1; i++) 
                table[r][i] = 0;

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