import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int rc[][] = new int[r][c];
        int c_total = 0;
        int r_total[] = new int[c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        }
        for(int i = 0; i < c + 1; i++){
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        }
        System.out.println("");
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int rc[][] = new int[r][c];
        int c_total = 0;
        int r_total[] = new int[c + 1];

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

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

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        }
        for(int i = 0; i < c + 1; i++){
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        }
        System.out.println("");
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int rc[][] = new int[r][c]; rc new int[r][c] r c int c_total = 0; c_total 0 int r_total[] = new int[c + 1]; r_total new int[c + 1] c + 1 c 1 for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        } {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        } for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                int num = sc.nextInt();
                rc[i][j] = num;
            } {
                int num = sc.nextInt();
                rc[i][j] = num;
            } int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc rc[i][j] = num rc[i][j] rc[i] rc i j num for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        } {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        } for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            } {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            } c_total += rc[i][j] c_total rc[i][j] rc[i] rc i j r_total[j] += rc[i][j] r_total[j] r_total j rc[i][j] rc[i] rc i j System.out.print(rc[i][j]) System.out.print System.out System System.out rc[i][j] rc[i] rc i j System.out.print(" ") System.out.print System.out System System.out " " r_total[c] += c_total r_total[c] r_total c c_total System.out.println(c_total) System.out.println System.out System System.out c_total c_total = 0 c_total 0 for(int i = 0; i < c + 1; i++){
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        } int i = 0; int i = 0; i 0 i < c + 1 i c + 1 c 1 i++ i++ i {
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        } {
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        } System.out.print(r_total[i]) System.out.print System.out System System.out r_total[i] r_total i if(i != c){
            System.out.print(" ");
        } i != c i c {
            System.out.print(" ");
        } 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 public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int rc[][] = new int[r][c];
        int c_total = 0;
        int r_total[] = new int[c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        }
        for(int i = 0; i < c + 1; i++){
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        }
        System.out.println("");
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int rc[][] = new int[r][c];
        int c_total = 0;
        int r_total[] = new int[c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        }
        for(int i = 0; i < c + 1; i++){
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        }
        System.out.println("");
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int rc[][] = new int[r][c];
        int c_total = 0;
        int r_total[] = new int[c + 1];

        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                int num = sc.nextInt();
                rc[i][j] = num;
            }
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                c_total += rc[i][j];
                r_total[j] += rc[i][j];
                System.out.print(rc[i][j]);
                System.out.print(" ");
            }
            r_total[c] += c_total;  
            System.out.println(c_total);
            c_total = 0;
        }
        for(int i = 0; i < c + 1; i++){
        System.out.print(r_total[i]);
        if(i != c){
            System.out.print(" ");
        }
        }
        System.out.println("");
    }
}