import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	}
} import java.util.Scanner; Scanner java.util import java.util.StringJoiner; StringJoiner 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[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	} main {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	} 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[][] table = new int[r+1][c+1]; table new int[r+1][c+1] r+1 r 1 c+1 c 1 for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		} int row = 0; int row = 0; row 0 row < r row r row++ row++ row {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		} {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		} for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			} int col = 0; int col = 0; col 0 col < c col c col++ col++ col {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			} {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			} int now = sc.nextInt(); now sc.nextInt() sc.nextInt sc table[row][col] = now table[row][col] table[row] table row col now table[row][c] += now table[row][c] table[row] table row c now table[r][col] += now table[r][col] table[r] table r col now table[r][c] += now table[r][c] table[r] table r c now sc.close() sc.close sc for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		} int[] col table {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		} {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		} StringJoiner sj = new StringJoiner(" "); sj new StringJoiner(" ") for(int val : col) {
				sj.add(String.valueOf(val));
			} int val col {
				sj.add(String.valueOf(val));
			} {
				sj.add(String.valueOf(val));
			} sj.add(String.valueOf(val)) sj.add sj String.valueOf(val) String.valueOf String val System.out.println(sj) System.out.println System.out System System.out sj 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[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	}
} Main
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] table = new int[r+1][c+1];

		for (int row = 0; row < r; row++) {
			for (int col = 0; col < c; col++) {
				int now = sc.nextInt();

				table[row][col] = now;

				table[row][c] += now;
				table[r][col] += now;
				table[r][c] += now;
			}
		}
		sc.close();

		for(int[] col : table) {
			StringJoiner sj = new StringJoiner(" ");
			for(int val : col) {
				sj.add(String.valueOf(val));
			}
			System.out.println(sj);
		}
	}
}