import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();
        int c = scan.nextInt();

        int[][] det = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        }

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

    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();
        int c = scan.nextInt();

        int[][] det = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        }

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

    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();
        int c = scan.nextInt();

        int[][] det = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        }

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

    } main {
        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();
        int c = scan.nextInt();

        int[][] det = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        }

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

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int[][] det = new int[r + 1][c + 1]; det new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        } {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        } for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            } {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            } det[i][j] = scan.nextInt() det[i][j] det[i] det i j scan.nextInt() scan.nextInt scan det[i][c] += det[i][j] det[i][c] det[i] det i c det[i][j] det[i] det i j det[r][j] += det[i][j] det[r][j] det[r] det r j det[i][j] det[i] det i j det[r][c] += det[i][c] det[r][c] det[r] det r c det[i][c] det[i] det i c for (int i = 0; i < r + 1; i++) {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(det[i][j]);
                if(j==c) continue;
                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(det[i][j]);
                if(j==c) continue;
                System.out.print(" ");
            }
            System.out.println();
        } {
            for (int j = 0; j < c + 1; j++) {
                System.out.print(det[i][j]);
                if(j==c) continue;
                System.out.print(" ");
            }
            System.out.println();
        } for (int j = 0; j < c + 1; j++) {
                System.out.print(det[i][j]);
                if(j==c) continue;
                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(det[i][j]);
                if(j==c) continue;
                System.out.print(" ");
            } {
                System.out.print(det[i][j]);
                if(j==c) continue;
                System.out.print(" ");
            } System.out.print(det[i][j]) System.out.print System.out System System.out det[i][j] det[i] det i j if(j==c) continue; j==c j c continue; 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) {
        Scanner scan = new Scanner(System.in);

        int r = scan.nextInt();
        int c = scan.nextInt();

        int[][] det = new int[r + 1][c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                det[i][j] = scan.nextInt();
                det[i][c] += det[i][j];
                det[r][j] += det[i][j];
            }
            det[r][c] += det[i][c];
        }

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

    }
}