import java.util.Scanner;

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

        scanner.close();
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int row row col; col int[] matrix; matrix row = scanner.nextInt() row scanner.nextInt() scanner.nextInt scanner col = scanner.nextInt() col scanner.nextInt() scanner.nextInt scanner matrix = new int[col] matrix new int[col] col int in in sum; sum for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        } int rowi = 0; int rowi = 0; rowi 0 rowi < row rowi row rowi++ rowi++ rowi {
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        } {
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        } sum = 0 sum 0 for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            } int coli = 0; int coli = 0; coli 0 coli < col coli col coli++ coli++ coli {
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            } {
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            } in = scanner.nextInt() in scanner.nextInt() scanner.nextInt scanner matrix[coli] += in matrix[coli] matrix coli in sum += in sum in System.out.print(in + " ") System.out.print System.out System System.out in + " " in " " System.out.println(sum) System.out.println System.out System System.out sum sum = 0 sum 0 for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        } int i matrix {
            sum += i;
            System.out.print(i + " ");
        } {
            sum += i;
            System.out.print(i + " ");
        } sum += i sum i System.out.print(i + " ") System.out.print System.out System System.out i + " " i " " System.out.println(sum) System.out.println System.out System System.out sum scanner.close() scanner.close scanner String[] args args public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

        scanner.close();
    }
} Main
import java.util.Scanner;

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

        int row, col;
        int[] matrix;

        row = scanner.nextInt();
        col = scanner.nextInt();

        matrix = new int[col];

        int in, sum;
        for(int rowi = 0; rowi < row; rowi++){
            sum = 0;
            for(int coli = 0; coli < col; coli++){
                in = scanner.nextInt();
                matrix[coli] += in;
                sum += in;
                System.out.print(in + " ");
            }
            System.out.println(sum);
        }

        sum = 0;
        for(int i:matrix){
            sum += i;
            System.out.print(i + " ");
        }
        System.out.println(sum);

        scanner.close();
    }
}

