import java.util.Scanner;

public class Main {

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

	}

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

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

	}

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int arr[][] = new int[r + 1][c + 1]; arr 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++) {
				arr[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		} {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				arr[i][j] = sc.nextInt();
			} {
				arr[i][j] = sc.nextInt();
			} arr[i][j] = sc.nextInt() arr[i][j] arr[i] arr i j sc.nextInt() sc.nextInt sc for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		} {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		} for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				arr[i][c] += arr[i][j];
			} {
				arr[i][c] += arr[i][j];
			} arr[i][c] += arr[i][j] arr[i][c] arr[i] arr i c arr[i][j] arr[i] arr i j for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		} int i = 0; int i = 0; i 0 i <= c i c i++ i++ i {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		} {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		} for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				arr[r][i] += arr[j][i];
			} {
				arr[r][i] += arr[j][i];
			} arr[r][i] += arr[j][i] arr[r][i] arr[r] arr r i arr[j][i] arr[j] arr j i for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		} {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		} for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			} {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			} if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				} j != c j c {
					System.out.print(arr[i][j] + " ");
				} System.out.print(arr[i][j] + " ") System.out.print System.out System System.out arr[i][j] + " " arr[i][j] arr[i] arr i j " " {
					System.out.println(arr[i][j]);
				} System.out.println(arr[i][j]) System.out.println System.out System System.out arr[i][j] arr[i] arr i j String[] args args public class Main {

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

	}

} public class Main {

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

	}

} Main
import java.util.Scanner;

public class Main {

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

		int r = sc.nextInt();
		int c = sc.nextInt();
		int arr[][] = new int[r + 1][c + 1];

		// ????????????
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][j] = sc.nextInt();
			}
		}

		// ????¨?
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				arr[i][c] += arr[i][j];
			}
		}
		for (int i = 0; i <= c; i++) {
			for (int j = 0; j < r; j++) {
				arr[r][i] += arr[j][i];
			}
		}

		// ????????????
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(arr[i][j] + " ");
				} else {
					System.out.println(arr[i][j]);
				}
			}
		}

	}

}