import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

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

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

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

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	} main {

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	} int r = input(); r input() input int c = input(); c input() input int[][] table = new int[r + 1][c + 1]; table 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++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		} {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		} for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			} {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			} table[i][j] = input() table[i][j] table[i] table i j input() input table[i][c] += table[i][j] table[i][c] table[i] table i c table[i][j] table[i] table i j table[r][j] += table[i][j] table[r][j] table[r] table r j table[i][j] table[i] table i j table[r][c] += table[i][j] table[r][c] table[r] table r c table[i][j] table[i] table i j for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				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++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		} {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		} for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				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 {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			} {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			} if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				} i < r && j < c i < r i r j < c j c {

					System.out.print(table[i][j]);

				} System.out.print(table[i][j]) System.out.print System.out System System.out table[i][j] table[i] table i j if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				} i == r && j == c i == r i r j == c j c {

					System.out.print(table[r][c]);

				} System.out.print(table[r][c]) System.out.print System.out System System.out table[r][c] table[r] table r c if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				} i == r i r {

					System.out.print(table[r][j]);

				} System.out.print(table[r][j]) System.out.print System.out System System.out table[r][j] table[r] table r j if (j == c) {

					System.out.print(table[i][c]);

				} j == c j c {

					System.out.print(table[i][c]);

				} System.out.print(table[i][c]) System.out.print System.out System System.out table[i][c] table[i] table i c 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 "" close() close String[] args args public static int input() {

		return scanner.nextInt();

	} input {

		return scanner.nextInt();

	} return scanner.nextInt(); scanner.nextInt() scanner.nextInt scanner public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	} close {

		if (scanner != null) {

			scanner.close();

		}
	} if (scanner != null) {

			scanner.close();

		} scanner != null scanner null {

			scanner.close();

		} scanner.close() scanner.close scanner public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
} public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int r = input();
		int c = input();

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

		for (int i = 0; i < r; i++) {

			for (int j = 0; j < c; j++) {

				table[i][j] = input();
				table[i][c] += table[i][j];
				table[r][j] += table[i][j];
				table[r][c] += table[i][j];

			}
		}

		for (int i = 0; i < r + 1; i++) {

			for (int j = 0; j < c + 1; j++) {

				if (i < r && j < c) {

					System.out.print(table[i][j]);

				}else if (i == r && j == c) {

					System.out.print(table[r][c]);

				} else if (i == r) {

					System.out.print(table[r][j]);

				} else if (j == c) {

					System.out.print(table[i][c]);

				}

				if (j != c) {

					System.out.print(" ");

				}
			}

			System.out.println("");

		}

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}