import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	} run {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int[] rsum = new int[c]; rsum new int[c] c int allsum = 0; allsum 0 for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		} {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		} int csum = 0; csum 0 for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			} 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.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			} {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			} if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				} i == r && j == c i == r i r j == c j c {
					System.out.println(allsum);
				} System.out.println(allsum) System.out.println System.out System System.out allsum if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				} j == c j c {
					allsum += csum;
					System.out.println(csum);
				} allsum += csum allsum csum System.out.println(csum) System.out.println System.out System System.out csum if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				} i == r i r {
					System.out.print(rsum[j] + " ");
				} System.out.print(rsum[j] + " ") System.out.print System.out System System.out rsum[j] + " " rsum[j] rsum j " " {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				} int val = scan.nextInt(); val scan.nextInt() scan.nextInt scan System.out.print(val + " ") System.out.print System.out System System.out val + " " val " " csum += val csum val rsum[j] += val rsum[j] rsum j val public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[] rsum = new int[c];
		int allsum = 0;
		for (int i = 0; i < r + 1; i++) {
			int csum = 0;
			for (int j = 0; j < c + 1; j++) {
				if (i == r && j == c) {
					System.out.println(allsum);
				} else if (j == c) {
					allsum += csum;
					System.out.println(csum);
				} else if (i == r) {
					System.out.print(rsum[j] + " ");
				} else {
					int val = scan.nextInt();
					System.out.print(val + " ");
					csum += val;
					rsum[j] += val;
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}