import java.util.Scanner;

public class Main {
	static int[][] array;
	public static void main(String[] args) {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	}
	static final int getRsum(int num, int cSize) {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	}
	static final int getCsum(int num, int rSize) {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static int[][] array;
	public static void main(String[] args) {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	}
	static final int getRsum(int num, int cSize) {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	}
	static final int getCsum(int num, int rSize) {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	}
} Main static int[][] array; array public static void main(String[] args) {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	} main {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	} int r r c; c Scanner sc = new Scanner(System.in); sc new Scanner(System.in) r = Integer.parseInt(sc.next()) r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc c = Integer.parseInt(sc.next()) c Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc r += 1 r 1 c += 1 c 1 array = new int[r][c] array new int[r][c] r c for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		} int i=0; int i=0; i 0 i < r i r i++ i++ i {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		} {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		} for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			} int j=0; int j=0; j 0 j < c j c j++ j++ j {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			} {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			} if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				} i == r-1 i r-1 r 1 {
					array[i][j] = getCsum(j, i);
				} array[i][j] = getCsum(j, i) array[i][j] array[i] array i j getCsum(j, i) getCsum j i if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				} j == c-1 j c-1 c 1 {
					array[i][j] = getRsum(i, j);
				} array[i][j] = getRsum(i, j) array[i][j] array[i] array i j getRsum(i, j) getRsum i j {
					array[i][j] = Integer.parseInt(sc.next());
				} array[i][j] = Integer.parseInt(sc.next()) array[i][j] array[i] array i j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		} int i=0; int i=0; i 0 i < r i r i++ i++ i {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		} {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			} int j=0; int j=0; j 0 j < c j c j++ j++ j {
				sb.append(array[i][j]).append(' ');
			} {
				sb.append(array[i][j]).append(' ');
			} sb.append(array[i][j]).append(' ') sb.append(array[i][j]).append sb.append(array[i][j]) sb.append sb array[i][j] array[i] array i j ' ' sb.deleteCharAt(sb.length()-1) sb.deleteCharAt sb sb.length()-1 sb.length() sb.length sb 1 System.out.println(sb) System.out.println System.out System System.out sb String[] args args static final int getRsum(int num, int cSize) {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	} getRsum {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	} int sum = 0; sum 0 for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		} int i=0; int i=0; i 0 i < cSize i cSize i++ i++ i {
			sum = sum + array[num][i];
		} {
			sum = sum + array[num][i];
		} sum = sum + array[num][i] sum sum + array[num][i] sum array[num][i] array[num] array num i return sum; sum int num num int cSize cSize static final int getCsum(int num, int rSize) {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	} getCsum {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	} int sum = 0; sum 0 for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		} int i=0; int i=0; i 0 i < rSize i rSize i++ i++ i {
			sum = sum + array[i][num];
		} {
			sum = sum + array[i][num];
		} sum = sum + array[i][num] sum sum + array[i][num] sum array[i][num] array[i] array i num return sum; sum int num num int rSize rSize public class Main {
	static int[][] array;
	public static void main(String[] args) {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	}
	static final int getRsum(int num, int cSize) {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	}
	static final int getCsum(int num, int rSize) {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	}
} public class Main {
	static int[][] array;
	public static void main(String[] args) {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	}
	static final int getRsum(int num, int cSize) {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	}
	static final int getCsum(int num, int rSize) {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	}
} Main
import java.util.Scanner;

public class Main {
	static int[][] array;
	public static void main(String[] args) {
		// r = ???, c = ?即?
		int r, c;
		Scanner sc = new Scanner(System.in);
		r = Integer.parseInt(sc.next());
		c = Integer.parseInt(sc.next());
		r += 1;
		c += 1;
		array = new int[r][c];
		for (int i=0; i < r; i++) {
			for (int j=0; j < c; j++) {
				if (i == r-1) {
					array[i][j] = getCsum(j, i);
				} else if (j == c-1) {
					array[i][j] = getRsum(i, j);
				} else {
					array[i][j] = Integer.parseInt(sc.next());
				}
			}
		}
		sc.close();
		for (int i=0; i < r; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j < c; j++) {
				sb.append(array[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length()-1);
			System.out.println(sb);
		}
	}
	static final int getRsum(int num, int cSize) {
		int sum = 0;
		for (int i=0; i < cSize; i++) {
			sum = sum + array[num][i];
		}
		return sum;
	}
	static final int getCsum(int num, int rSize) {
		int sum = 0;
		for (int i=0; i < rSize; i++){
			sum = sum + array[i][num];
		}
		return sum;
	}
}