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[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	}

} 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[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner( System.in );
		
		// 入力
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	} main {
		Scanner sc = new Scanner( System.in );
		
		// 入力
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	} 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[][] vector = new int[r + 1][c + 1]; vector new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		} int iR = 0; int iR = 0; iR 0 iR < r iR r iR++ iR++ iR {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		} {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		} for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			} int iC = 0; int iC = 0; iC 0 iC < c iC c iC++ iC++ iC {
				vector[iR][iC] = sc.nextInt();
				
			} {
				vector[iR][iC] = sc.nextInt();
				
			} vector[iR][iC] = sc.nextInt() vector[iR][iC] vector[iR] vector iR iC sc.nextInt() sc.nextInt sc for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		} int iR = 0; int iR = 0; iR 0 iR < r iR r iR++ iR++ iR {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		} {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		} for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			} int iC = 0; int iC = 0; iC 0 iC < c iC c iC++ iC++ iC {
				vector[iR][c] += vector[iR][iC];
				
			} {
				vector[iR][c] += vector[iR][iC];
				
			} vector[iR][c] += vector[iR][iC] vector[iR][c] vector[iR] vector iR c vector[iR][iC] vector[iR] vector iR iC for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		} int iC = 0; int iC = 0; iC 0 iC < c iC c iC++ iC++ iC {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		} {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		} for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			} int iR = 0; int iR = 0; iR 0 iR < r iR r iR++ iR++ iR {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			} {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			} vector[r][iC] += vector[iR][iC] vector[r][iC] vector[r] vector r iC vector[iR][iC] vector[iR] vector iR iC vector[r][c] += vector[iR][iC] vector[r][c] vector[r] vector r c vector[iR][iC] vector[iR] vector iR iC for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		} int iR = 0; int iR = 0; iR 0 iR < r+1 iR r+1 r 1 iR++ iR++ iR {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		} {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		} for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			} int iC = 0; int iC = 0; iC 0 iC < c+1 iC c+1 c 1 iC++ iC++ iC {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			} {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			} System.out.print(vector[iR][iC]) System.out.print System.out System System.out vector[iR][iC] vector[iR] vector iR iC if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				} iC != c iC c {
					System.out.print(" ");
					
				} System.out.print(" ") System.out.print System.out System System.out " " {
					System.out.println();
					
				} System.out.println() System.out.println System.out System System.out sc.close() sc.close sc 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[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner( System.in );
		
		// 入力
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	}

} 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[][] vector = new int[r + 1][c + 1];
		
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][iC] = sc.nextInt();
				
			}
		}
		
		// 計算
		for ( int iR = 0; iR < r; iR++ ) {
			for ( int iC = 0; iC < c; iC++ ) {
				vector[iR][c] += vector[iR][iC];
				
			}
		}
		
		for ( int iC = 0; iC < c; iC++ ) {
			for ( int iR = 0; iR < r; iR++ ) {
				vector[r][iC] += vector[iR][iC];
				vector[r][c] += vector[iR][iC];
			}
		}
				
		// 出力
		for ( int iR = 0; iR < r+1; iR++ ) {
			for ( int iC = 0; iC < c+1; iC++ ) {
				System.out.print(vector[iR][iC]);
				if( iC != c ) {
					System.out.print(" ");
					
				} else {
					System.out.println();
					
				}
			}
		}
		
		sc.close();
	}

}