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[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		}
	}

} 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[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		}
	}

} Main public static void main(String[] args) {
		//??\????????????
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		}
	} main {
		//??\????????????
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					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[][] rc = new int[r+1][c+1]; rc new int[r+1][c+1] r+1 r 1 c+1 c 1 for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		} int ri = 0; int ri = 0; ri 0 ri < r ri r ri++ ri++ ri {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		} {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		} for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			} int ci = 0; int ci = 0; ci 0 ci < c ci c ci++ ci++ ci {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			} {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			} rc[ri][ci] = sc.nextInt() rc[ri][ci] rc[ri] rc ri ci sc.nextInt() sc.nextInt sc rc[r][ci] += rc[ri][ci] rc[r][ci] rc[r] rc r ci rc[ri][ci] rc[ri] rc ri ci rc[ri][c] += rc[ri][ci] rc[ri][c] rc[ri] rc ri c rc[ri][ci] rc[ri] rc ri ci rc[r][c] += rc[ri][c] rc[r][c] rc[r] rc r c rc[ri][c] rc[ri] rc ri c for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		} int ri = 0; int ri = 0; ri 0 ri <= r ri r ri++ ri++ ri {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		} {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		} for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			} int ci = 0; int ci = 0; ci 0 ci <= c ci c ci++ ci++ ci {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			} {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			} System.out.print(rc[ri][ci]) System.out.print System.out System System.out rc[ri][ci] rc[ri] rc ri ci if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				} ci < c ci c {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " {
					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) {
		//??\????????????
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		}
	}

} public class Main {

	public static void main(String[] args) {
		//??\????????????
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		}
	}

} 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[][] rc = new int[r+1][c+1];
		//?¨????
		for (int ri = 0; ri < r; ri++) {
			for (int ci = 0; ci < c; ci++) {
				rc[ri][ci] = sc.nextInt();
				rc[r][ci] += rc[ri][ci];
				rc[ri][c] += rc[ri][ci];
			}
			rc[r][c] += rc[ri][c];
		}
		//??????
		for (int ri = 0; ri <= r; ri++) {
			for (int ci = 0; ci <= c; ci++) {
				System.out.print(rc[ri][ci]);
				if (ci < c) {
					System.out.print(" ");
				} else {
					System.out.println("");
				}
			}
		}
	}

}