import java.util.Scanner;

public class Main {
    private static Scanner scan;

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

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        }
        for (int i = 0; i < r +1; i++) {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    private static Scanner scan;

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

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

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

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        }
        for (int i = 0; i < r +1; i++) {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        }
    } main {
        scan = new Scanner(System.in);

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        }
        for (int i = 0; i < r +1; i++) {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        }
    } 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[][] hyou = new int[r+1][c+1]; hyou 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++) {
                hyou[i][j] = scan.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        } {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        } for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                hyou[i][j] = scan.nextInt();
            } {
                hyou[i][j] = scan.nextInt();
            } hyou[i][j] = scan.nextInt() hyou[i][j] hyou[i] hyou i j scan.nextInt() scan.nextInt scan for (int i = 0; i < r +1; i++) {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        } 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++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        } {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        } for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            } int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            } {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            } if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                } j == c j c {
                    System.out.println(hyou[i][c]);
                } System.out.println(hyou[i][c]) System.out.println System.out System System.out hyou[i][c] hyou[i] hyou i c {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                } System.out.print(hyou[i][j] + " ") System.out.print System.out System System.out hyou[i][j] + " " hyou[i][j] hyou[i] hyou i j " " hyou[i][c] += hyou[i][j] hyou[i][c] hyou[i] hyou i c hyou[i][j] hyou[i] hyou i j hyou[r][j] += hyou[i][j] hyou[r][j] hyou[r] hyou r j hyou[i][j] hyou[i] hyou i j String[] args args public class Main {
    private static Scanner scan;

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

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        }
        for (int i = 0; i < r +1; i++) {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        }
    }
} public class Main {
    private static Scanner scan;

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

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                hyou[i][j] = scan.nextInt();
            }
        }
        for (int i = 0; i < r +1; i++) {
            for (int j = 0; j < c + 1; j++) {
                if (j == c) {
                    System.out.println(hyou[i][c]);
                } else {
                    System.out.print(hyou[i][j] + " ");
                    hyou[i][c] += hyou[i][j];
                    hyou[r][j] += hyou[i][j];
                }
            }
        }
    }
} Main
import java.util.Scanner;

public class Main {
    private static Scanner scan;

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

        // 表の行数rと列数c、r × c の要素を持つ表
        int r = scan.nextInt();
        int c = scan.nextInt();
        int[][] hyou = new int[r+1][c+1];

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