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

        int h = scan.nextInt();
        int w = scan.nextInt();

        int number[][] = new int[h + 1][w + 1];

        for (int i = 0; i < h;i++) {
            for (int j = 0; j < w;j++) {
                number[i][j] = scan.nextInt();
                number[i][w] += number[i][j];
                number[h][j] += number[i][j];
            }
            number[h][w] += number[i][w];
        }

        for (int i = 0;i < h + 1;i++) {
            for (int j = 0;j < w + 1;j++) {
                System.out.print(number[i][j]);
                if(j == w) {
                    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 h = scan.nextInt();
        int w = scan.nextInt();

        int number[][] = new int[h + 1][w + 1];

        for (int i = 0; i < h;i++) {
            for (int j = 0; j < w;j++) {
                number[i][j] = scan.nextInt();
                number[i][w] += number[i][j];
                number[h][j] += number[i][j];
            }
            number[h][w] += number[i][w];
        }

        for (int i = 0;i < h + 1;i++) {
            for (int j = 0;j < w + 1;j++) {
                System.out.print(number[i][j]);
                if(j == w) {
                    continue;
                }
                System.out.print(" ");
            }
            System.out.println();
        }
    }
} Main public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int h = scan.nextInt();
        int w = scan.nextInt();

        int number[][] = new int[h + 1][w + 1];

        for (int i = 0; i < h;i++) {
            for (int j = 0; j < w;j++) {
                number[i][j] = scan.nextInt();
                number[i][w] += number[i][j];
                number[h][j] += number[i][j];
            }
            number[h][w] += number[i][w];
        }

        for (int i = 0;i < h + 1;i++) {
            for (int j = 0;j < w + 1;j++) {
                System.out.print(number[i][j]);
                if(j == w) {
                    continue;
                }
                System.out.print(" ");
            }
            System.out.println();
        }
    } main {
        Scanner scan = new Scanner(System.in);

        int h = scan.nextInt();
        int w = scan.nextInt();

        int number[][] = new int[h + 1][w + 1];

        for (int i = 0; i < h;i++) {
            for (int j = 0; j < w;j++) {
                number[i][j] = scan.nextInt();
                number[i][w] += number[i][j];
                number[h][j] += number[i][j];
            }
            number[h][w] += number[i][w];
        }

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

        int number[][] = new int[h + 1][w + 1];

        for (int i = 0; i < h;i++) {
            for (int j = 0; j < w;j++) {
                number[i][j] = scan.nextInt();
                number[i][w] += number[i][j];
                number[h][j] += number[i][j];
            }
            number[h][w] += number[i][w];
        }

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