import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
  public static void main(String args[]) throws IOException{
   
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] token = br.readLine().split(" ");
   int r = Integer.parseInt(token[0]);      
   int c = Integer.parseInt(token[1]);   
   int[] Columnsum = new int[c];
   int totalsum = 0;  
   for(int k = 0;k < c; k++){      
        Columnsum[k] = 0;
   }
   
  
   for(int i = 0;i < r; i++){
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   }

   for(int l = 0;l < c; l++){      
        System.out.print(Columnsum[l] + " ");
   }
   System.out.println(totalsum);

    
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
  public static void main(String args[]) throws IOException{
   
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] token = br.readLine().split(" ");
   int r = Integer.parseInt(token[0]);      
   int c = Integer.parseInt(token[1]);   
   int[] Columnsum = new int[c];
   int totalsum = 0;  
   for(int k = 0;k < c; k++){      
        Columnsum[k] = 0;
   }
   
  
   for(int i = 0;i < r; i++){
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   }

   for(int l = 0;l < c; l++){      
        System.out.print(Columnsum[l] + " ");
   }
   System.out.println(totalsum);

    
  }
} Main public static void main(String args[]) throws IOException{
   
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] token = br.readLine().split(" ");
   int r = Integer.parseInt(token[0]);      
   int c = Integer.parseInt(token[1]);   
   int[] Columnsum = new int[c];
   int totalsum = 0;  
   for(int k = 0;k < c; k++){      
        Columnsum[k] = 0;
   }
   
  
   for(int i = 0;i < r; i++){
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   }

   for(int l = 0;l < c; l++){      
        System.out.print(Columnsum[l] + " ");
   }
   System.out.println(totalsum);

    
  } main {
   
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] token = br.readLine().split(" ");
   int r = Integer.parseInt(token[0]);      
   int c = Integer.parseInt(token[1]);   
   int[] Columnsum = new int[c];
   int totalsum = 0;  
   for(int k = 0;k < c; k++){      
        Columnsum[k] = 0;
   }
   
  
   for(int i = 0;i < r; i++){
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   }

   for(int l = 0;l < c; l++){      
        System.out.print(Columnsum[l] + " ");
   }
   System.out.println(totalsum);

    
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] token = br.readLine().split(" "); token br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(token[0]); r Integer.parseInt(token[0]) Integer.parseInt Integer token[0] token 0 int c = Integer.parseInt(token[1]); c Integer.parseInt(token[1]) Integer.parseInt Integer token[1] token 1 int[] Columnsum = new int[c]; Columnsum new int[c] c int totalsum = 0; totalsum 0 for(int k = 0;k < c; k++){      
        Columnsum[k] = 0;
   } int k = 0; int k = 0; k 0 k < c k c k++ k++ k {      
        Columnsum[k] = 0;
   } {      
        Columnsum[k] = 0;
   } Columnsum[k] = 0 Columnsum[k] Columnsum k 0 for(int i = 0;i < r; i++){
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   } {
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   } String[] token2 = br.readLine().split(" "); token2 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int sum = 0; sum 0 for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      } {      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      } System.out.print(token2[j] + " ") System.out.print System.out System System.out token2[j] + " " token2[j] token2 j " " Columnsum[j] += Integer.parseInt(token2[j]) Columnsum[j] Columnsum j Integer.parseInt(token2[j]) Integer.parseInt Integer token2[j] token2 j sum += Integer.parseInt(token2[j]) sum Integer.parseInt(token2[j]) Integer.parseInt Integer token2[j] token2 j totalsum += sum totalsum sum System.out.println(sum) System.out.println System.out System System.out sum for(int l = 0;l < c; l++){      
        System.out.print(Columnsum[l] + " ");
   } int l = 0; int l = 0; l 0 l < c l c l++ l++ l {      
        System.out.print(Columnsum[l] + " ");
   } {      
        System.out.print(Columnsum[l] + " ");
   } System.out.print(Columnsum[l] + " ") System.out.print System.out System System.out Columnsum[l] + " " Columnsum[l] Columnsum l " " System.out.println(totalsum) System.out.println System.out System System.out totalsum String args[] args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
  public static void main(String args[]) throws IOException{
   
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String[] token = br.readLine().split(" ");
   int r = Integer.parseInt(token[0]);      
   int c = Integer.parseInt(token[1]);   
   int[] Columnsum = new int[c];
   int totalsum = 0;  
   for(int k = 0;k < c; k++){      
        Columnsum[k] = 0;
   }
   
  
   for(int i = 0;i < r; i++){
      String[] token2 = br.readLine().split(" ");
      int sum = 0;
      for(int j = 0;j < c; j++){      
        System.out.print(token2[j] + " ");
        Columnsum[j] += Integer.parseInt(token2[j]);
        sum += Integer.parseInt(token2[j]);
      }
      totalsum += sum;
      System.out.println(sum);
   }

   for(int l = 0;l < c; l++){      
        System.out.print(Columnsum[l] + " ");
   }
   System.out.println(totalsum);

    
  }
}