import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int  r = scanner.nextInt();
	  	int  c = scanner.nextInt();
	  	int[][] array;//配列確保
        array = new int[r + 5][c + 5];
        
        //初期化
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        }
        // データ入力
        for (int i = 0; i < r; i++) {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        }
        
        // データ補完
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        }
        
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        }
        scanner.close();
  }
} import java.util.Scanner; Scanner java.util class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int  r = scanner.nextInt();
	  	int  c = scanner.nextInt();
	  	int[][] array;//配列確保
        array = new int[r + 5][c + 5];
        
        //初期化
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        }
        // データ入力
        for (int i = 0; i < r; i++) {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        }
        
        // データ補完
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        }
        
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        }
        scanner.close();
  }
} Main public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int  r = scanner.nextInt();
	  	int  c = scanner.nextInt();
	  	int[][] array;//配列確保
        array = new int[r + 5][c + 5];
        
        //初期化
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        }
        // データ入力
        for (int i = 0; i < r; i++) {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        }
        
        // データ補完
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        }
        
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        }
        scanner.close();
  } main {
	  	Scanner scanner = new Scanner(System.in);
	  	int  r = scanner.nextInt();
	  	int  c = scanner.nextInt();
	  	int[][] array;//配列確保
        array = new int[r + 5][c + 5];
        
        //初期化
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        }
        // データ入力
        for (int i = 0; i < r; i++) {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        }
        
        // データ補完
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        }
        
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        }
        scanner.close();
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int  r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner int  c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int[][] array; array array = new int[r + 5][c + 5] array new int[r + 5][c + 5] r + 5 r 5 c + 5 c 5 for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        } int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        } {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        } for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        } int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
        		array[i][j] = 0;
	        } {
        		array[i][j] = 0;
	        } array[i][j] = 0 array[i][j] array[i] array i j 0 for (int i = 0; i < r; i++) {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        } {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        } for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
        		array[i][j] = scanner.nextInt();
	        } {
        		array[i][j] = scanner.nextInt();
	        } array[i][j] = scanner.nextInt() array[i][j] array[i] array i j scanner.nextInt() scanner.nextInt scanner for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        } int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        } {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        } for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	} {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	} if( j < c ) {
	            	array[i][c] += array[i][j];
	            } j < c j c {
	            	array[i][c] += array[i][j];
	            } array[i][c] += array[i][j] array[i][c] array[i] array i c array[i][j] array[i] array i j if( i < r ) {
	            	array[r][j] += array[i][j];
	            } i < r i r {
	            	array[r][j] += array[i][j];
	            } array[r][j] += array[i][j] array[r][j] array[r] array r j array[i][j] array[i] array i j if( i == r && j == c )
	        	  	array[r][c] /= 2; i == r && j == c i == r i r j == c j c array[r][c] /= 2 array[r][c] array[r] array r c 2 for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        } int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        } {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        } for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        } int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        } {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        } if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " "); j == c && i < r j == c j c i < r i r System.out.println(array[i][j] ) System.out.println System.out System System.out array[i][j] array[i] array i j if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " "); j == c && i == r j == c j c i == r i r System.out.println(array[i][j]) System.out.println System.out System System.out array[i][j] array[i] array i j System.out.print(array[i][j] + " ") System.out.print System.out System System.out array[i][j] + " " array[i][j] array[i] array i j " " scanner.close() scanner.close scanner String args[] args
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	int  r = scanner.nextInt();
	  	int  c = scanner.nextInt();
	  	int[][] array;//配列確保
        array = new int[r + 5][c + 5];
        
        //初期化
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
        		array[i][j] = 0;
	        }
        }
        // データ入力
        for (int i = 0; i < r; i++) {
        	for (int j = 0; j < c; j++) {
        		array[i][j] = scanner.nextInt();
	        }
        }
        
        // データ補完
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j < c ) {
	            	array[i][c] += array[i][j];
	            }
		            
	            if( i < r ) {
	            	array[r][j] += array[i][j];
	            }

	            if( i == r && j == c )
	        	  	array[r][c] /= 2;
	            
        	}
        }
        
        for (int i = 0; i <= r; i++) {
        	for (int j = 0; j <= c; j++) {
	            if( j == c && i < r )
        			System.out.println(array[i][j] );
	            else if( j == c && i == r )
        			System.out.println(array[i][j]);
	            else
        			System.out.print(array[i][j] + " ");
	        }
        }
        scanner.close();
  }
}
