import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	}
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	} main {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int r = s.nextInt(); r s.nextInt() s.nextInt s int c = s.nextInt(); c s.nextInt() s.nextInt s int rm = r + 1; rm r + 1 r 1 int cm = c + 1; cm c + 1 c 1 int[][] sheet = new int[rm][cm]; sheet new int[rm][cm] rm cm for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r ++i ++i i {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		} {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		} for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			} int j = 0; int j = 0; j 0 j < c j c ++j ++j j {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			} {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			} sheet[i][c] += sheet[i][j] = s.nextInt() sheet[i][c] sheet[i] sheet i c sheet[i][j] = s.nextInt() sheet[i][j] sheet[i] sheet i j s.nextInt() s.nextInt s sheet[r][j] += sheet[i][j] sheet[r][j] sheet[r] sheet r j sheet[i][j] sheet[i] sheet i j sheet[r][c] += sheet[i][j] sheet[r][c] sheet[r] sheet r c sheet[i][j] sheet[i] sheet i j for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i < rm i rm ++i ++i i {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		} {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		} for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			} int j = 0; int j = 0; j 0 j < cm j cm ++j ++j j {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			} {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			} System.out.print(((j != 0)?" ":"") + sheet[i][j]) System.out.print System.out System System.out ((j != 0)?" ":"") + sheet[i][j] ((j != 0)?" ":"") (j != 0) j 0 " " "" sheet[i][j] sheet[i] sheet 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) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rm = r + 1;
		int cm = c + 1;
		int[][] sheet = new int[rm][cm];
		for (int i = 0; i < r; ++i) {
			for(int j = 0; j < c; ++j) {
				sheet[i][c] += sheet[i][j] = s.nextInt();
				sheet[r][j] += sheet[i][j];
				sheet[r][c] += sheet[i][j];
			}
		}
		for(int i = 0; i < rm; ++i) {
			for (int j = 0; j < cm; ++j) {
				System.out.print(((j != 0)?" ":"") + sheet[i][j]);
			}
			System.out.println();
		}
	}
}