import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

		String space = " ";
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j < c) {
					System.out.print(list[i][j] + space);
				} else {
					System.out.print(list[i][j]);
				}
			}
			System.out.println("");
		}
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

		String space = " ";
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j < c) {
					System.out.print(list[i][j] + space);
				} else {
					System.out.print(list[i][j]);
				}
			}
			System.out.println("");
		}
	}
} Main public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

		String space = " ";
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j < c) {
					System.out.print(list[i][j] + space);
				} else {
					System.out.print(list[i][j]);
				}
			}
			System.out.println("");
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

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

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

		String space = " ";
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j < c) {
					System.out.print(list[i][j] + space);
				} else {
					System.out.print(list[i][j]);
				}
			}
			System.out.println("");
		}
	}
} public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

		String space = " ";
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j < c) {
					System.out.print(list[i][j] + space);
				} else {
					System.out.print(list[i][j]);
				}
			}
			System.out.println("");
		}
	}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int[][] list = new int [101][101];
		int r = sc.nextInt();
		int c = sc.nextInt();

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

		for (int i = 0; i <= c; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += list[j][i];
			}
			list[r][i] = sum;
		}

		String space = " ";
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j < c) {
					System.out.print(list[i][j] + space);
				} else {
					System.out.print(list[i][j]);
				}
			}
			System.out.println("");
		}
	}
}