import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	} main {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() sb.append("") sb.append sb "" int r r c; c r = scan.nextInt() r scan.nextInt() scan.nextInt scan c = scan.nextInt() c scan.nextInt() scan.nextInt scan int[][] ar = new int[r+1][c+1]; ar 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++) {
				ar[i][j] = scan.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		} {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		} for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				ar[i][j] = scan.nextInt();
			} {
				ar[i][j] = scan.nextInt();
			} ar[i][j] = scan.nextInt() ar[i][j] ar[i] ar i j scan.nextInt() scan.nextInt scan for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		} {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		} for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			} {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			} ar[i][c] += ar[i][j] ar[i][c] ar[i] ar i c ar[i][j] ar[i] ar i j ar[r][j] += ar[i][j] ar[r][j] ar[r] ar r j ar[i][j] ar[i] ar i j for (int i : ar[r]) {
			ar[r][c] += i;
		} int i ar[r] ar r {
			ar[r][c] += i;
		} {
			ar[r][c] += i;
		} ar[r][c] += i ar[r][c] ar[r] ar r c i ar[r][c] /= 2 ar[r][c] ar[r] ar r c 2 for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[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(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		} {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		} for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			} {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			} if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				} j != c j c {
					System.out.print(ar[i][j] + " ");
				} System.out.print(ar[i][j] + " ") System.out.print System.out System System.out ar[i][j] + " " ar[i][j] ar[i] ar i j " " {
					System.out.println(ar[i][j]);
				} System.out.println(ar[i][j]) System.out.println System.out System System.out ar[i][j] ar[i] ar i j String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		sb.append("");
		int r, c;
		r = scan.nextInt();
		c = scan.nextInt();
		int[][] ar = new int[r+1][c+1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				ar[i][c] += ar[i][j];
				ar[r][j] += ar[i][j];
			}
		}
		for (int i : ar[r]) {
			ar[r][c] += i;
		}
		ar[r][c] /= 2;
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != c) {
					System.out.print(ar[i][j] + " ");
				}else {
					System.out.println(ar[i][j]);
				}
			}
		}
	}
}