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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str = br.readLine(); str br.readLine() br.readLine br String[] size = str.split(" ", 2); size str.split(" ", 2) str.split str " " 2 int r = Integer.parseInt(size[0]); r Integer.parseInt(size[0]) Integer.parseInt Integer size[0] size 0 int c = Integer.parseInt(size[1]); c Integer.parseInt(size[1]) Integer.parseInt Integer size[1] size 1 int[][] data = new int[r + 1][c + 1]; data new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 String[] datastr = new String[c]; datastr new String[c] c for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		} {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		} str = br.readLine() str br.readLine() br.readLine br datastr = str.split(" ", c) datastr str.split(" ", c) str.split str " " c for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			} {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			} data[i][j] = Integer.parseInt(datastr[j]) data[i][j] data[i] data i j Integer.parseInt(datastr[j]) Integer.parseInt Integer datastr[j] datastr j data[i][c] = data[i][c] + data[i][j] data[i][c] data[i] data i c data[i][c] + data[i][j] data[i][c] data[i] data i c data[i][j] data[i] data i j data[r][j] = data[r][j] + data[i][j] data[r][j] data[r] data r j data[r][j] + data[i][j] data[r][j] data[r] data r j data[i][j] data[i] data i j data[r][c] = data[r][c] + data[i][j] data[r][c] data[r] data r c data[r][c] + data[i][j] data[r][c] data[r] data r c data[i][j] data[i] data i j System.out.print(data[i][j] + " ") System.out.print System.out System System.out data[i][j] + " " data[i][j] data[i] data i j " " if (j == c - 1) {
					System.out.println(data[i][c]);
				} j == c - 1 j c - 1 c 1 {
					System.out.println(data[i][c]);
				} System.out.println(data[i][c]) System.out.println System.out System System.out data[i][c] data[i] data i c if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			} i == r - 1 i r - 1 r 1 {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			} for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				} int k = 0; int k = 0; k 0 k <= c k c k++ k++ k {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				} {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				} System.out.print(data[r][k]) System.out.print System.out System System.out data[r][k] data[r] data r k if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					} k != c k c {
						System.out.print(" ");
					} System.out.print(" ") System.out.print System.out System System.out " " {
						System.out.println();
					} System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] size = str.split(" ", 2);
		int r = Integer.parseInt(size[0]);
		int c = Integer.parseInt(size[1]);
		int[][] data = new int[r + 1][c + 1];
		String[] datastr = new String[c];
		for (int i = 0; i < r; i++) {
			str = br.readLine();
			datastr = str.split(" ", c);
			for (int j = 0; j < c; j++) {
				data[i][j] = Integer.parseInt(datastr[j]);
				data[i][c] = data[i][c] + data[i][j];
				data[r][j] = data[r][j] + data[i][j];
				data[r][c] = data[r][c] + data[i][j];
				System.out.print(data[i][j] + " ");
				if (j == c - 1) {
					System.out.println(data[i][c]);
				}
			}
			if (i == r - 1) {
				for (int k = 0; k <= c; k++) {
					System.out.print(data[r][k]);
					if (k != c) {
						System.out.print(" ");
					} else {
						System.out.println();
					}
				}
			}
		}
	}
}