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

public class Main {

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

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} 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) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} Main public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		} try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			} catch (IOException ioe) {
			} IOException ioe {
			} {
				if (br != null) {
					br.close();
				}
			} if (br != null) {
					br.close();
				} br != null br null {
					br.close();
				} br.close() br.close br {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} String str = br.readLine(); str br.readLine() br.readLine br String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " int r = Integer.parseInt(strArr[0]); r Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 int c = Integer.parseInt(strArr[1]); c Integer.parseInt(strArr[1]) Integer.parseInt Integer strArr[1] strArr 1 int[][] set = new int[r + 1][c + 1]; set new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			} {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			} str = br.readLine() str br.readLine() br.readLine br strArr = str.split(" ") strArr str.split(" ") str.split str " " for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				} {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				} set[i][j] = Integer.parseInt(strArr[j]) set[i][j] set[i] set i j Integer.parseInt(strArr[j]) Integer.parseInt Integer strArr[j] strArr j set[i][c] += set[i][j] set[i][c] set[i] set i c set[i][j] set[i] set i j set[r][j] += set[i][j] set[r][j] set[r] set r j set[i][j] set[i] set i j set[r][c] += set[i][j] set[r][c] set[r] set r c set[i][j] set[i] set i j for (int i = 0; i < set.length; i++) {
				for (int j = 0; j < set[i].length; j++) {
					System.out.print(set[i][j]);
					if (j < c)
						System.out.print(" ");
				}
				System.out.println();
			} int i = 0; int i = 0; i 0 i < set.length i set.length set set.length i++ i++ i {
				for (int j = 0; j < set[i].length; j++) {
					System.out.print(set[i][j]);
					if (j < c)
						System.out.print(" ");
				}
				System.out.println();
			} {
				for (int j = 0; j < set[i].length; j++) {
					System.out.print(set[i][j]);
					if (j < c)
						System.out.print(" ");
				}
				System.out.println();
			} for (int j = 0; j < set[i].length; j++) {
					System.out.print(set[i][j]);
					if (j < c)
						System.out.print(" ");
				} int j = 0; int j = 0; j 0 j < set[i].length j set[i].length set[i] set i set[i].length j++ j++ j {
					System.out.print(set[i][j]);
					if (j < c)
						System.out.print(" ");
				} {
					System.out.print(set[i][j]);
					if (j < c)
						System.out.print(" ");
				} System.out.print(set[i][j]) System.out.print System.out System System.out set[i][j] set[i] set i j if (j < c)
						System.out.print(" "); j < c j c 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 {

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

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} public class Main {

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

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} Main

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

public class Main {

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

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");

			int r = Integer.parseInt(strArr[0]);
			int c = Integer.parseInt(strArr[1]);

			int[][] set = new int[r + 1][c + 1];
			for (int i = 0; i < r; i++) {

				str = br.readLine();
				strArr = str.split(" ");

				for (int j = 0; j < c; j++) {
					set[i][j] = Integer.parseInt(strArr[j]);

					// ????¨????????¨????
					set[i][c] += set[i][j]; // ???
					set[r][j] += set[i][j]; // ???
					set[r][c] += set[i][j]; // ?????????????¨?
				}
			}

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

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
}