import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br String[] arr = line.split(" "); arr line.split(" ") line.split line " " int r = Integer.parseInt(arr[0]); r Integer.parseInt(arr[0]) Integer.parseInt Integer arr[0] arr 0 int c = Integer.parseInt(arr[1]); c Integer.parseInt(arr[1]) Integer.parseInt Integer arr[1] arr 1 int[][] spreadsheet = new int[r + 1][c + 1]; spreadsheet new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 int row = 0; row 0 while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		} (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		} String[] cols = line.split(" "); cols line.split(" ") line.split line " " for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			} int col = 0; int col = 0; col 0 col < c col c col++ col++ col {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			} {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			} final int val = Integer.parseInt(cols[col]); val Integer.parseInt(cols[col]) Integer.parseInt Integer cols[col] cols col spreadsheet[row][col] = val spreadsheet[row][col] spreadsheet[row] spreadsheet row col val spreadsheet[row][c] += val spreadsheet[row][c] spreadsheet[row] spreadsheet row c val spreadsheet[r][col] += val spreadsheet[r][col] spreadsheet[r] spreadsheet r col val spreadsheet[r][c] += val spreadsheet[r][c] spreadsheet[r] spreadsheet r c val row++ row for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[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 != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		} {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		} for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			} {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			} if (j != 0)
					System.out.print(" "); j != 0 j 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(spreadsheet[i][j]) System.out.print System.out System System.out spreadsheet[i][j] spreadsheet[i] spreadsheet 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 Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j != 0)
					System.out.print(" ");
				System.out.print(spreadsheet[i][j]);
			}
			System.out.println();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		int r = Integer.parseInt(arr[0]);
		int c = Integer.parseInt(arr[1]);

		int[][] spreadsheet = new int[r + 1][c + 1];
		int row = 0;
		while ((line = br.readLine()) != null) {
			String[] cols = line.split(" ");
			for (int col = 0; col < c; col++) {
				final int val = Integer.parseInt(cols[col]);
				spreadsheet[row][col] = val;
				spreadsheet[row][c] += val;
				spreadsheet[r][col] += val;
				spreadsheet[r][c] += val;
			}
			row++;
		}

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