import java.util.Scanner;

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

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

    }

    private static void showSheet(int[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

    }

    private static void showSheet(int[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    }
} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

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

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int rows = input.nextInt(); rows input.nextInt() input.nextInt input int cols = input.nextInt(); cols input.nextInt() input.nextInt input int[][] result = new int[rows +1][cols+1]; result new int[rows +1][cols+1] rows +1 rows 1 cols+1 cols 1 int[] colTot = new int[cols]; colTot new int[cols] cols int total = 0; total 0 for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        } int row = 0; int row = 0; row 0 row < rows+1 row rows+1 rows 1 row++ row++ row {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        } {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        } int rowTemp = 0; rowTemp 0 for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            } int col = 0; int col = 0; col 0 col < cols+1 col cols+1 cols 1 col++ col++ col {
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            } {
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            } if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                } col == cols && row == rows col == cols col cols row == rows row rows {
                   result[row][col] = total;
                } result[row][col] = total result[row][col] result[row] result row col total if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                } col == cols col cols {
                   result[row][col] = rowTemp;
                } result[row][col] = rowTemp result[row][col] result[row] result row col rowTemp if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                } row == rows row rows {
                   result[row][col] = colTot[col];
                } result[row][col] = colTot[col] result[row][col] result[row] result row col colTot[col] colTot col {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                } int temp = input.nextInt(); temp input.nextInt() input.nextInt input total += temp total temp rowTemp += temp rowTemp temp colTot[col] += temp colTot[col] colTot col temp result[row][col] = temp result[row][col] result[row] result row col temp showSheet(result) showSheet result String[] args args private static void showSheet(int[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    } showSheet {
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    } for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        } int i = 0; int i = 0; i 0 i < result.length i result.length result result.length i++ i++ i {
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        } {
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        } for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            } int j = 0; int j = 0; j 0 j < result[0].length j result[0].length result[0] result 0 result[0].length j++ j++ j {
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            } {
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            } System.out.print(result[i][j]) System.out.print System.out System System.out result[i][j] result[i] result i j if( j < result[0].length - 1) System.out.print(" "); j < result[0].length - 1 j result[0].length - 1 result[0].length result[0] result 0 result[0].length 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.print("\n") System.out.print System.out System System.out "\n" int[][] result result public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

    }

    private static void showSheet(int[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

    }

    private static void showSheet(int[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    }
} Main
import java.util.Scanner;

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

        // Grab the row and col data
        int rows = input.nextInt();
        int cols = input.nextInt();

        // build the matrix and add 1 to the cols and rows for the result matrix
        int[][] result = new int[rows +1][cols+1];

        // Create the storage contains for the running total
        int[] colTot = new int[cols]; // only column totals are needed since row totals can be done while read in
        int total = 0;

        // Compute totals in line
        for(int row = 0; row < rows+1; row++) {
            int rowTemp = 0;
            for(int col = 0; col < cols+1; col++){
                // nested if-else structure that handles the three border cases:
                // 1 - on the end of the row
                // 2 - at the bottom of a column
                // 3 - at the bottom right hand corner of the matrix
                // These cases need special handling otherwise grab the next entry from the input and calculate the
                // appropriate values
                if(col == cols && row == rows){
                   result[row][col] = total;
                } else if(col == cols){
                   result[row][col] = rowTemp;
                } else if(row == rows) {
                   result[row][col] = colTot[col];
                } else {
                   // Compute the rest of the values
                   int temp = input.nextInt();
                   total += temp;
                   rowTemp += temp;
                   colTot[col] += temp;
                   result[row][col] = temp;
                }
            }
        }
        // display output
        showSheet(result);

    }

    private static void showSheet(int[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
 System.out.print("\n");
        }
    }
}

