import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main
}//class import java.util.*; util.* java import java.text.*; text.* java public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main
}//class Main public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main main {
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String str; str String[] arr; arr int row; row int column; column int[][] a; a int[] sum_r; sum_r int[] sum_c; sum_c int grandTotal = 0; grandTotal 0 str = sc.nextLine() str sc.nextLine() sc.nextLine sc arr = str.split(" ") arr str.split(" ") str.split str " " row = Integer.parseInt(arr[0]) row Integer.parseInt(arr[0]) Integer.parseInt Integer arr[0] arr 0 column = Integer.parseInt(arr[1]) column Integer.parseInt(arr[1]) Integer.parseInt Integer arr[1] arr 1 a = new int[row][column] a new int[row][column] row column sum_r = new int[row] sum_r new int[row] row sum_c = new int[column] sum_c new int[column] column for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      } int i = 0; int i = 0; i 0 i < row i row i ++ i ++ i {
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      } {
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      } str = sc.nextLine() str sc.nextLine() sc.nextLine sc arr = str.split(" ") arr str.split(" ") str.split str " " for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         } int j = 0; int j = 0; j 0 j < column j column j ++ j ++ j {
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         } {
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         } a[i][j] = Integer.parseInt(arr[j]) a[i][j] a[i] a i j Integer.parseInt(arr[j]) Integer.parseInt Integer arr[j] arr j sum_r[i] += a[i][j] sum_r[i] sum_r i a[i][j] a[i] a i j sum_c[j] += a[i][j] sum_c[j] sum_c j a[i][j] a[i] a i j grandTotal += a[i][j] grandTotal a[i][j] a[i] a i j for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      } int i = 0; int i = 0; i 0 i < row i row i ++ i ++ i {
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      } {
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      } for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         } int j = 0; int j = 0; j 0 j < column j column j ++ j ++ j {
            System.out.print(a[i][j] + " ");
         } {
            System.out.print(a[i][j] + " ");
         } System.out.print(a[i][j] + " ") System.out.print System.out System System.out a[i][j] + " " a[i][j] a[i] a i j " " System.out.print(sum_r[i]) System.out.print System.out System System.out sum_r[i] sum_r i System.out.println() System.out.println System.out System System.out for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      } int i = 0; int i = 0; i 0 i < column i column i++ i++ i {
         System.out.print(sum_c[i] + " ");
      } {
         System.out.print(sum_c[i] + " ");
      } System.out.print(sum_c[i] + " ") System.out.print System.out System System.out sum_c[i] + " " sum_c[i] sum_c i " " System.out.println(grandTotal) System.out.println System.out System System.out grandTotal String[] args args public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main
}//class public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main
}//class Main
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int row;
      int column;
      
      int[][] a;
      int[] sum_r;
      int[] sum_c;
      int grandTotal = 0;
      
      //read column and row
      str = sc.nextLine();
      arr = str.split(" ");
      
      row = Integer.parseInt(arr[0]);
      column = Integer.parseInt(arr[1]);
      
      a = new int[row][column];
      sum_r = new int[row];
      sum_c = new int[column];
      
      //read the table
      for(int i = 0; i < row; i ++){
         str = sc.nextLine();
         arr = str.split(" ");
         for(int j = 0; j < column; j ++){
            a[i][j] = Integer.parseInt(arr[j]);
            sum_r[i] += a[i][j];
            sum_c[j] += a[i][j];
            grandTotal += a[i][j];
            
         }
      }
      
      //check
      for(int i = 0; i < row; i ++){
         for(int j = 0; j < column; j ++){
            System.out.print(a[i][j] + " ");
         }
         System.out.print(sum_r[i]);
         System.out.println();
      }
      
      for(int i = 0; i < column; i++){
         System.out.print(sum_c[i] + " ");
      }
      System.out.println(grandTotal);
      
      
      
   }//main
}//class