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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() String[] rc = br.readLine().split(" "); rc br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(rc[0]); r Integer.parseInt(rc[0]) Integer.parseInt Integer rc[0] rc 0 int c = Integer.parseInt(rc[1]); c Integer.parseInt(rc[1]) Integer.parseInt Integer rc[1] rc 1 int sumOfRow sumOfRow total = 0; total 0 int[] sumOfCol = new int[c]; sumOfCol new int[c] c for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		} {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		} String row = br.readLine(); row br.readLine() br.readLine br String[] elem = row.split(" "); elem row.split(" ") row.split row " " sumOfRow = 0 sumOfRow 0 for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			} {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			} sumOfRow += Integer.parseInt(elem[j]) sumOfRow Integer.parseInt(elem[j]) Integer.parseInt Integer elem[j] elem j sumOfCol[j] += Integer.parseInt(elem[j]) sumOfCol[j] sumOfCol j Integer.parseInt(elem[j]) Integer.parseInt Integer elem[j] elem j total += sumOfRow total sumOfRow sb.append(row + " " + sumOfRow + "\n") sb.append sb row + " " + sumOfRow + "\n" sumOfRow row + " " + sumOfRow + "\n" row " " sumOfRow "\n" for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
			sb.append(sumOfCol[j] + " ");
		} {
			sb.append(sumOfCol[j] + " ");
		} sb.append(sumOfCol[j] + " ") sb.append sb sumOfCol[j] + " " sumOfCol[j] sumOfCol j " " System.out.println(sb.append(total)) System.out.println System.out System System.out sb.append(total) sb.append sb total String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

	}
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] rc = br.readLine().split(" ");
		int r = Integer.parseInt(rc[0]);
		int c = Integer.parseInt(rc[1]);
		int sumOfRow, total = 0;
		int[] sumOfCol = new int[c];

		for(int i = 0; i < r; i++) {
			String row = br.readLine();
			String[] elem = row.split(" ");
			sumOfRow = 0;
			for(int j = 0; j < c; j++) {
				sumOfRow += Integer.parseInt(elem[j]);
				sumOfCol[j] += Integer.parseInt(elem[j]);
			}
			total += sumOfRow;
			sb.append(row + " " + sumOfRow + "\n");
		}

		for(int j = 0; j < c; j++) {
			sb.append(sumOfCol[j] + " ");
		}

		System.out.println(sb.append(total));

	}
}