import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int r, c;
		Scanner stdIn = new Scanner(System.in);

		r = stdIn.nextInt();
		c = stdIn.nextInt();

		int[][] ss = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		}

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

	}
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) {

		int r, c;
		Scanner stdIn = new Scanner(System.in);

		r = stdIn.nextInt();
		c = stdIn.nextInt();

		int[][] ss = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		}

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

	}
} Main public static void main(String[] args) {

		int r, c;
		Scanner stdIn = new Scanner(System.in);

		r = stdIn.nextInt();
		c = stdIn.nextInt();

		int[][] ss = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		}

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

	} main {

		int r, c;
		Scanner stdIn = new Scanner(System.in);

		r = stdIn.nextInt();
		c = stdIn.nextInt();

		int[][] ss = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		}

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

	} int r r c; c Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) r = stdIn.nextInt() r stdIn.nextInt() stdIn.nextInt stdIn c = stdIn.nextInt() c stdIn.nextInt() stdIn.nextInt stdIn int[][] ss = new int[r + 1][c + 1]; ss 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++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		} {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		} for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			} {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			} ss[i][j] = stdIn.nextInt() ss[i][j] ss[i] ss i j stdIn.nextInt() stdIn.nextInt stdIn ss[i][c] += ss[i][j] ss[i][c] ss[i] ss i c ss[i][j] ss[i] ss i j ss[r][j] += ss[i][j] ss[r][j] ss[r] ss r j ss[i][j] ss[i] ss i j ss[r][c] += ss[i][j] ss[r][c] ss[r] ss r c ss[i][j] ss[i] ss i j for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(ss[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			}
			
				System.out.println();
			
		} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(ss[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			}
			
				System.out.println();
			
		} {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(ss[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			}
			
				System.out.println();
			
		} for (int j = 0; j < c + 1; j++) {
				System.out.print(ss[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
				System.out.print(ss[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			} {
				System.out.print(ss[i][j]);
				if (j != c) {
					System.out.print(" ");
				}
			} System.out.print(ss[i][j]) System.out.print System.out System System.out ss[i][j] ss[i] ss i j if (j != c) {
					System.out.print(" ");
				} 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
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int r, c;
		Scanner stdIn = new Scanner(System.in);

		r = stdIn.nextInt();
		c = stdIn.nextInt();

		int[][] ss = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ss[i][j] = stdIn.nextInt();
				ss[i][c] += ss[i][j];
				ss[r][j] += ss[i][j];
				ss[r][c] += ss[i][j];
			}
		}

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

	}
}