
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
} Main /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    } main {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    } int r = 0; r 0 int c = 0; c 0 int l = 0; l 0 int matrix[][] = new int[100][100]; matrix new int[100][100] 100 100 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line; line while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        } (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        } java.util.StringTokenizer st = new StringTokenizer(line, " "); st new StringTokenizer(line, " ") while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            } st.hasMoreTokens() st.hasMoreTokens st {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            } if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                } r == 0 && c == 0 r == 0 r 0 c == 0 c 0 {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } r = Integer.parseInt(st.nextToken()) r Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st c = Integer.parseInt(st.nextToken()) c Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                } for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    } int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    } {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    } matrix[l][i] = Integer.parseInt(st.nextToken()) matrix[l][i] matrix[l] matrix l i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st l++ l if (l == r) {
                break;

            } l == r l r {
                break;

            } break; int sum = 0; sum 0 int ans_matrix[][] = new int[r + 1][c + 1]; ans_matrix 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++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        } {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        } for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            } {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            } ans_matrix[i][j] = matrix[i][j] ans_matrix[i][j] ans_matrix[i] ans_matrix i j matrix[i][j] matrix[i] matrix i j ans_matrix[i][c] += matrix[i][j] ans_matrix[i][c] ans_matrix[i] ans_matrix i c matrix[i][j] matrix[i] matrix i j sum += ans_matrix[i][c] sum ans_matrix[i][c] ans_matrix[i] ans_matrix i c for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        } {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        } for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                ans_matrix[r][j] += matrix[i][j];
            } {
                ans_matrix[r][j] += matrix[i][j];
            } ans_matrix[r][j] += matrix[i][j] ans_matrix[r][j] ans_matrix[r] ans_matrix r j matrix[i][j] matrix[i] matrix i j ans_matrix[r][c] = sum ans_matrix[r][c] ans_matrix[r] ans_matrix r c sum for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        } int i = 0; int i = 0; i 0 i < ans_matrix.length i ans_matrix.length ans_matrix ans_matrix.length i++ i++ i {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        } {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        } for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            } int j = 0; int j = 0; j 0 j < ans_matrix[i].length j ans_matrix[i].length ans_matrix[i] ans_matrix i ans_matrix[i].length j++ j++ j {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            } {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            } System.out.print(ans_matrix[i][j]) System.out.print System.out System System.out ans_matrix[i][j] ans_matrix[i] ans_matrix i j if (!(j == c)) {
                    System.out.print(" ");
                } !(j == c) (j == c) j 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 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
} public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
} Main

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {

        int r = 0;
        int c = 0;

        int l = 0;
        int matrix[][] = new int[100][100];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            java.util.StringTokenizer st = new StringTokenizer(line, " ");
            while (st.hasMoreTokens()) {
                if (r == 0 && c == 0) {
                    r = Integer.parseInt(st.nextToken());
                    c = Integer.parseInt(st.nextToken());
                } else {
                    for (int i = 0; i < c; i++) {
                        matrix[l][i] = Integer.parseInt(st.nextToken());
                    }
                    l++;
                }
            }
            if (l == r) {
                break;

            }

        }
        int sum = 0;
        int ans_matrix[][] = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[i][j] = matrix[i][j];
                ans_matrix[i][c] += matrix[i][j];
            }
            sum += ans_matrix[i][c];
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ans_matrix[r][j] += matrix[i][j];
            }
        }
        ans_matrix[r][c] = sum;

        for (int i = 0; i < ans_matrix.length; i++) {
            for (int j = 0; j < ans_matrix[i].length; j++) {
                System.out.print(ans_matrix[i][j]);
                if (!(j == c)) {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}

