import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    }
} Main public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    } main {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    } 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[][] nums = new int[r + 1][c + 1]; nums 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++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		} {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		} for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				int a = sc.nextInt();
				nums[i][j] = a;
			} {
				int a = sc.nextInt();
				nums[i][j] = a;
			} int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc nums[i][j] = a nums[i][j] nums[i] nums i j a for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					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++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

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

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

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

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			} {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			} System.out.print(nums[i][j]) System.out.print System.out System System.out nums[i][j] nums[i] nums i j if (j != c) {
					System.out.print(" ");
				} j != c j c {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				} r > i r i {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				} nums[r][j] += nums[i][j] nums[r][j] nums[r] nums r j nums[i][j] nums[i] nums i j nums[i][c] += nums[i][j] nums[i][c] nums[i] nums i c nums[i][j] nums[i] nums i j if (j == c) {
					System.out.println();
				} j == c j c {
					System.out.println();
				} System.out.println() System.out.println System.out System System.out String[] args args public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    }
} public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] nums = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int a = sc.nextInt();
				nums[i][j] = a;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c + 1; j++) {
				System.out.print(nums[i][j]);
				if (j != c) {
					System.out.print(" ");
				}

				if (r > i) {
					nums[r][j] += nums[i][j];
					nums[i][c] += nums[i][j];
				}

				if (j == c) {
					System.out.println();
				}
			}
		}
    }
}

