import java.util.Scanner;

public class Main {

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

	}

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

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

	}

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line1 = sc.nextLine(); line1 sc.nextLine() sc.nextLine sc String[] array1 = line1.split(" "); array1 line1.split(" ") line1.split line1 " " int r = Integer.parseInt(array1[0]); r Integer.parseInt(array1[0]) Integer.parseInt Integer array1[0] array1 0 int c = Integer.parseInt(array1[1]); c Integer.parseInt(array1[1]) Integer.parseInt Integer array1[1] array1 1 String[][] h = new String[r][c]; h new String[r][c] r c int[][] hyou = new int[r + 1][c + 1]; hyou new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		} {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		} String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			} {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			} String[] string = line2.split(" "); string line2.split(" ") line2.split line2 " " h[i][j] = string[j] h[i][j] h[i] h i j string[j] string j hyou[i][j] = Integer.parseInt(h[i][j]) hyou[i][j] hyou[i] hyou i j Integer.parseInt(h[i][j]) Integer.parseInt Integer h[i][j] h[i] h i j for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		} {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		} if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			} i == r i r {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				} int k = 0; int k = 0; k 0 k <= c k c k++ k++ k {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				} {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				} for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					} int p = 0; int p = 0; p 0 p <= r p r p++ p++ p {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					} {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					} if (p < r) {
							hyou[r][k] += hyou[p][k];
						} p < r p r {
							hyou[r][k] += hyou[p][k];
						} hyou[r][k] += hyou[p][k] hyou[r][k] hyou[r] hyou r k hyou[p][k] hyou[p] hyou p k if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					} k == c k c {
						System.out.print(hyou[r][k]);

					} System.out.print(hyou[r][k]) System.out.print System.out System System.out hyou[r][k] hyou[r] hyou r k {
						System.out.print(hyou[r][k] + " ");

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

					} else {
						System.out.print(hyou[i][j] + " ");

					}

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

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				} {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				} if (j < c) {
						hyou[i][c] += hyou[i][j];
					} j < c j c {
						hyou[i][c] += hyou[i][j];
					} hyou[i][c] += hyou[i][j] hyou[i][c] hyou[i] hyou i c hyou[i][j] hyou[i] hyou i j if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					} j == c j c {
						System.out.print(hyou[i][j]);

					} System.out.print(hyou[i][j]) System.out.print System.out System System.out hyou[i][j] hyou[i] hyou i j {
						System.out.print(hyou[i][j] + " ");

					} System.out.print(hyou[i][j] + " ") System.out.print System.out System System.out hyou[i][j] + " " hyou[i][j] hyou[i] hyou i j " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

	}

} public class Main {

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

	}

} Main
import java.util.Scanner;

public class Main {

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

		String line1 = sc.nextLine();
		String[] array1 = line1.split(" ");
		int r = Integer.parseInt(array1[0]);
		int c = Integer.parseInt(array1[1]);

		String[][] h = new String[r][c];
		int[][] hyou = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String line2 = sc.nextLine();
			for (int j = 0; j < c; j++) {
				String[] string = line2.split(" ");
				h[i][j] = string[j];
				hyou[i][j] = Integer.parseInt(h[i][j]);
			}

		}

		for (int i = 0; i <= r; i++) {
			if (i == r) {
				for (int k = 0; k <= c; k++) {
					for (int p = 0; p <= r; p++) {
						if (p < r) {
							hyou[r][k] += hyou[p][k];
						}

					}
					if (k == c) {
						System.out.print(hyou[r][k]);

					} else {
						System.out.print(hyou[r][k] + " ");

					}

				}
				System.out.println();

			} else {
				for (int j = 0; j <= c; j++) {
					if (j < c) {
						hyou[i][c] += hyou[i][j];
					}
					if (j == c) {
						System.out.print(hyou[i][j]);

					} else {
						System.out.print(hyou[i][j] + " ");

					}

				}
				System.out.println();
			}
		}

	}

}