import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	}

} Main public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	} main {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	} int numR; numR int numC; numC int add = 0; add 0 String outPut = ""; outPut "" int[][] tableList; tableList Scanner sc = null; sc null try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			} {
				sc.close();
			} sc.close() sc.close sc {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			} sc = new Scanner(System.in) sc new Scanner(System.in) numR = sc.nextInt() numR sc.nextInt() sc.nextInt sc numC = sc.nextInt() numC sc.nextInt() sc.nextInt sc tableList = new int[numR + 1][numC + 1] tableList new int[numR + 1][numC + 1] numR + 1 numR 1 numC + 1 numC 1 for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				} int i = 0; int i = 0; i 0 i < numR i numR i++ i++ i {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				} {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				} for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					} int j = 0; int j = 0; j 0 j < numC j numC j++ j++ j {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					} {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					} tableList[i][j] = sc.nextInt() tableList[i][j] tableList[i] tableList i j sc.nextInt() sc.nextInt sc add += tableList[i][j] add tableList[i][j] tableList[i] tableList i j tableList[i][numC] =add tableList[i][numC] tableList[i] tableList i numC add for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					} int k = 0; int k = 0; k 0 k < tableList[0].length k tableList[0].length tableList[0] tableList 0 tableList[0].length k++ k++ k {
						tableList[numR][k] += tableList[i][k];
					} {
						tableList[numR][k] += tableList[i][k];
					} tableList[numR][k] += tableList[i][k] tableList[numR][k] tableList[numR] tableList numR k tableList[i][k] tableList[i] tableList i k add = 0 add 0 for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				} int i = 0; int i = 0; i 0 i < tableList.length i tableList.length tableList tableList.length i++ i++ i {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				} {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				} for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					} int j = 0; int j = 0; j 0 j < tableList[0].length j tableList[0].length tableList[0] tableList 0 tableList[0].length j++ j++ j {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					} {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					} if (!outPut.equals("")) {
							outPut += " ";
						} !outPut.equals("") outPut.equals("") outPut.equals outPut "" {
							outPut += " ";
						} outPut += " " outPut " " outPut += tableList[i][j] outPut tableList[i][j] tableList[i] tableList i j System.out.println(outPut) System.out.println System.out System System.out outPut outPut = "" outPut "" String[] args args public class Main {

	public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	}

} public class Main {

	public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int numR;
		int numC;
		int add = 0;

		String outPut = "";

		int[][] tableList;

		Scanner sc = null;

		try {
			//??\????????????
			sc = new Scanner(System.in);

			numR = sc.nextInt();
			numC = sc.nextInt();

			//???????????°??¨
			//System.out.println(numR + " " + numC);

			//??¨??????????????£?¨?
			tableList = new int[numR + 1][numC + 1];

				//??¨?????\??????????????????
				for (int i = 0; i < numR; i++) {

					for (int j = 0; j < numC; j++) {
						tableList[i][j] = sc.nextInt();
						add += tableList[i][j];
					}
					//??????????¨???????????´?
					tableList[i][numC] =add;

					//??????????¨???????????´?
					for (int k = 0; k < tableList[0].length; k++) {
						tableList[numR][k] += tableList[i][k];
					}
					//????¨???????????????????
					add = 0;
				}

				//??¨?????????
				for (int i = 0; i < tableList.length; i++) {
					for (int j = 0; j < tableList[0].length; j++) {

						if (!outPut.equals("")) {
							outPut += " ";
						}
						outPut += tableList[i][j];

					}
					System.out.println(outPut);
					outPut = "";
				}

			}finally {
				sc.close();
			}
	}

}