import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	}
} Main public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	} main {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int line = sc.nextInt(); line sc.nextInt() sc.nextInt sc int column = sc.nextInt(); column sc.nextInt() sc.nextInt sc int[][] table = new int[line + 1][column + 1]; table new int[line + 1][column + 1] line + 1 line 1 column + 1 column 1 for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		} int cnt1 = 0; int cnt1 = 0; cnt1 0 cnt1 < line cnt1 line cnt1++ cnt1++ cnt1 {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		} {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		} for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			} int cnt2 = 0; int cnt2 = 0; cnt2 0 cnt2 < column cnt2 column cnt2++ cnt2++ cnt2 {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			} {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			} table[cnt1][cnt2] = sc.nextInt() table[cnt1][cnt2] table[cnt1] table cnt1 cnt2 sc.nextInt() sc.nextInt sc table[cnt1][column] += table[cnt1][cnt2] table[cnt1][column] table[cnt1] table cnt1 column table[cnt1][cnt2] table[cnt1] table cnt1 cnt2 table[line][cnt2] += table[cnt1][cnt2] table[line][cnt2] table[line] table line cnt2 table[cnt1][cnt2] table[cnt1] table cnt1 cnt2 table[line][column] += table[cnt1][column] table[line][column] table[line] table line column table[cnt1][column] table[cnt1] table cnt1 column for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		} int cnt1 = 0; int cnt1 = 0; cnt1 0 cnt1 <= line cnt1 line cnt1++ cnt1++ cnt1 {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		} {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		} for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			} int cnt2 = 0; int cnt2 = 0; cnt2 0 cnt2 <= column cnt2 column cnt2++ cnt2++ cnt2 {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			} {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			} if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				} cnt2 != column cnt2 column {
					System.out.print(table[cnt1][cnt2] + " ");

				} System.out.print(table[cnt1][cnt2] + " ") System.out.print System.out System System.out table[cnt1][cnt2] + " " table[cnt1][cnt2] table[cnt1] table cnt1 cnt2 " " {
					System.out.println(table[cnt1][cnt2]);
				} System.out.println(table[cnt1][cnt2]) System.out.println System.out System System.out table[cnt1][cnt2] table[cnt1] table cnt1 cnt2 sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	}
} public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);

		// ??\??????????????°???????????¨?????¨???????¬??????????????????????
		int line = sc.nextInt();
		int column = sc.nextInt();

		int[][] table = new int[line + 1][column + 1];

		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
				sc.close();
			}
		}
	}
}