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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	}
} import java.io.InputStreamReader; InputStreamReader java.io import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strAry = br.readLine().split(" "); strAry br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(strAry[0]); r Integer.parseInt(strAry[0]) Integer.parseInt Integer strAry[0] strAry 0 int c = Integer.parseInt(strAry[1]); c Integer.parseInt(strAry[1]) Integer.parseInt Integer strAry[1] strAry 1 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 i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		} {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		} String[] tableAry = br.readLine().split(" "); tableAry br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			} {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			} table[i][j] = Integer.parseInt(tableAry[j]) table[i][j] table[i] table i j Integer.parseInt(tableAry[j]) Integer.parseInt Integer tableAry[j] tableAry j table[i][c] += Integer.parseInt(tableAry[j]) table[i][c] table[i] table i c Integer.parseInt(tableAry[j]) Integer.parseInt Integer tableAry[j] tableAry j table[r][j] += Integer.parseInt(tableAry[j]) table[r][j] table[r] table r j Integer.parseInt(tableAry[j]) Integer.parseInt Integer tableAry[j] tableAry j table[r][c] += table[i][c] table[r][c] table[r] table r c table[i][c] table[i] table i c for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[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.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		} {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		} for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			} {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			} if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " "); j == c j c System.out.println(table[i][j]) System.out.println System.out System System.out table[i][j] table[i] table i j System.out.print(table[i][j] + " ") System.out.print System.out System System.out table[i][j] + " " table[i][j] table[i] table i j " " String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	}
} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strAry = br.readLine().split(" ");
		int r = Integer.parseInt(strAry[0]);
		int c = Integer.parseInt(strAry[1]);
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			String[] tableAry = br.readLine().split(" ");
			for (int j = 0; j < c; j++) {
				table[i][j] = Integer.parseInt(tableAry[j]);
				table[i][c] += Integer.parseInt(tableAry[j]);
				table[r][j] += Integer.parseInt(tableAry[j]);
			}
			table[r][c] += table[i][c];
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == c) System.out.println(table[i][j]);
				else System.out.print(table[i][j] + " ");
			}
		}
	}
} Main
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

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