
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


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

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


	} main {

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int[][] arrayInput = new  int[r][c]; arrayInput new  int[r][c] r c int x = r+1; x r+1 r 1 int y = c+1; y c+1 c 1 int[][] arrayOutput = new  int[x][y]; arrayOutput new  int[x][y] x y for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		} {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		} for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				arrayInput[i][j] = sc.nextInt();
			} {
				arrayInput[i][j] = sc.nextInt();
			} arrayInput[i][j] = sc.nextInt() arrayInput[i][j] arrayInput[i] arrayInput i j sc.nextInt() sc.nextInt sc int Sum = 0; Sum 0 int Num = 0; Num 0 for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		} int i = 0; int i = 0; i 0 i < x i x i++ i++ i {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		} {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		} for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			} int j = 0; int j = 0; j 0 j < y j y j++ j++ j {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			} {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			} if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				} !(i+1 == x) && !( j+1 == y ) !(i+1 == x) (i+1 == x) i+1 i 1 x !( j+1 == y ) ( j+1 == y ) j+1 j 1 y {
					arrayOutput[i][j] = arrayInput[i][j];
				} arrayOutput[i][j] = arrayInput[i][j] arrayOutput[i][j] arrayOutput[i] arrayOutput i j arrayInput[i][j] arrayInput[i] arrayInput i j if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				} j+1 == y j+1 j 1 y {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				} for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					} int k=0; int k=0; k 0 k < y-1 k y-1 y 1 k++ k++ k {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					} {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					} Num = arrayOutput[i][k] Num arrayOutput[i][k] arrayOutput[i] arrayOutput i k Sum = Sum + Num Sum Sum + Num Sum Num arrayOutput[i][j] = Sum arrayOutput[i][j] arrayOutput[i] arrayOutput i j Sum Num = 0 Num 0 Sum = 0 Sum 0 int Sum1 = 0; Sum1 0 int Num1 = 0; Num1 0 for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				} int j = 0; int j = 0; j 0 j < y j y j++ j++ j {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				} {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				} for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					} int i = 0; int i = 0; i 0 i < x i x i++ i++ i {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					} {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					} if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						} i+1 == x i+1 i 1 x {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						} for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							} int k=0; int k=0; k 0 k < x-1 k x-1 x 1 k++ k++ k {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							} {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							} Num1 = arrayOutput[k][j] Num1 arrayOutput[k][j] arrayOutput[k] arrayOutput k j Sum1 = Sum1 + Num1 Sum1 Sum1 + Num1 Sum1 Num1 arrayOutput[i][j] = Sum1 arrayOutput[i][j] arrayOutput[i] arrayOutput i j Sum1 Num1 = 0 Num1 0 Sum1 = 0 Sum1 0 for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

			}
			System.out.println("");
		} int i = 0; int i = 0; i 0 i < x i x i++ i++ i {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

			}
			System.out.println("");
		} {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

			}
			System.out.println("");
		} for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

			} int j = 0; int j = 0; j 0 j < y j y j++ j++ j {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

			} {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

			} if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				} j+1 == y j+1 j 1 y {
					System.out.print(arrayOutput[i][j]);
				} System.out.print(arrayOutput[i][j]) System.out.print System.out System System.out arrayOutput[i][j] arrayOutput[i] arrayOutput i j {
					System.out.print(arrayOutput[i][j]+" ");
				} System.out.print(arrayOutput[i][j]+" ") System.out.print System.out System System.out arrayOutput[i][j]+" " arrayOutput[i][j] arrayOutput[i] arrayOutput 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 sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


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

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


	}
} Main

import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] arrayInput = new  int[r][c];

		int x = r+1;
		int y = c+1;

		int[][] arrayOutput = new  int[x][y];


		//?????????????????\???????????????
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				arrayInput[i][j] = sc.nextInt();
			}
		}


		//??????????¨?????±???????
		int Sum = 0;
		int Num = 0;
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(!(i+1 == x) && !( j+1 == y )) {
					arrayOutput[i][j] = arrayInput[i][j];
				}

				else if(j+1 == y) {
					for(int k=0; k < y-1; k++) {
						Num = arrayOutput[i][k];
						Sum = Sum + Num;
					}
					arrayOutput[i][j] = Sum;
					Num = 0;
					Sum = 0;
				}
			}
		}

		//??????????¨?????±???????
				int Sum1 = 0;
				int Num1 = 0;
				for(int j = 0; j < y; j++) {
					for(int i = 0; i < x; i++) {

						if(i+1 == x) {
							for(int k=0; k < x-1; k++) {
								Num1 = arrayOutput[k][j];
								Sum1 = Sum1 + Num1;
							}
							arrayOutput[i][j] = Sum1;
							Num1 = 0;
							Sum1 = 0;
						}
					}
				}

		//?????????????????????
		for(int i = 0; i < x; i++) {
			for(int j = 0; j < y; j++) {

				if(j+1 == y) {
					System.out.print(arrayOutput[i][j]);
				}
				else {
					System.out.print(arrayOutput[i][j]+" ");
				}

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


	}
}