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

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} Main public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String buffer; buffer int count = 0; count 0 int r = 0; r 0 int c = 0; c 0 int[][] sheet = null; sheet null try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		} Exception ex {
			ex.printStackTrace();
		} ex.printStackTrace() ex.printStackTrace ex {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			} (buffer = reader.readLine())  != null (buffer = reader.readLine()) buffer reader.readLine() reader.readLine reader null {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			} String[] strings = buffer.split(" "); strings buffer.split(" ") buffer.split buffer " " if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				} count == 0 count 0 {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				} r = Integer.valueOf(strings[0]) r Integer.valueOf(strings[0]) Integer.valueOf Integer strings[0] strings 0 c = Integer.valueOf(strings[1]) c Integer.valueOf(strings[1]) Integer.valueOf Integer strings[1] strings 1 sheet = new int[r + 1][c + 1] sheet new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				} count <= r count r {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				} for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					} {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					} sheet[count - 1][i] = Integer.valueOf(strings[i]) sheet[count - 1][i] sheet[count - 1] sheet count - 1 count 1 i Integer.valueOf(strings[i]) Integer.valueOf Integer strings[i] strings i if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				} count == r count r {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				} for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					} int w = 0; int w = 0; w 0 w < c w c w++ w++ w {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					} {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					} int sum = 0; sum 0 for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						} int h = 0; int h = 0; h 0 h < r h r h++ h++ h {
							sum += sheet[h][w];
						} {
							sum += sheet[h][w];
						} sum += sheet[h][w] sum sheet[h][w] sheet[h] sheet h w sheet[r][w] = sum sheet[r][w] sheet[r] sheet r w sum for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					} int h = 0; int h = 0; h 0 h < r + 1 h r + 1 r 1 h++ h++ h {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					} {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					} int sum = 0; sum 0 for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						} int w = 0; int w = 0; w 0 w < c w c w++ w++ w {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						} {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						} sum += sheet[h][w] sum sheet[h][w] sheet[h] sheet h w System.out.print(sheet[h][w] + " ") System.out.print System.out System System.out sheet[h][w] + " " sheet[h][w] sheet[h] sheet h w " " if (w + 1 == c) {
								System.out.println(sum);
							} w + 1 == c w + 1 w 1 c {
								System.out.println(sum);
							} System.out.println(sum) System.out.println System.out System System.out sum count++ count String[] args args public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		int count = 0;
		int r = 0;
		int c = 0;
		int[][] sheet = null;
		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				if (count == 0) {
					r = Integer.valueOf(strings[0]);
					c = Integer.valueOf(strings[1]);
					sheet = new int[r + 1][c + 1];
				}
				else if (count <= r) {
					for (int i = 0; i < c; i++) {
						sheet[count - 1][i] = Integer.valueOf(strings[i]);
					}
				}
				if (count == r) {
					for (int w = 0; w < c; w++) {
						int sum = 0;
						for (int h = 0; h < r; h++) {
							sum += sheet[h][w];
						}
						sheet[r][w] = sum;
					}

					for (int h = 0; h < r + 1; h++) {
						int sum = 0;
						for (int w = 0; w < c; w++) {
								sum += sheet[h][w];
								System.out.print(sheet[h][w] + " ");
							if (w + 1 == c) {
								System.out.println(sum);
							}
						}
					}

				}

				count++;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

