import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     int r = sc.nextInt();
     
     int c = sc.nextInt();
     
     int n[][] = new int[r + 1][c + 1];
     
     int rsum[] = new  int[c + 1];
     
     int csum[] = new int[r];
     
     for(int i = 0; i <= r; i ++)
     {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     }
     output(n);
   }
   static void output(int n[][])
   {
     for(int i = 0; i < n.length; i ++)
     {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     }
   }
 }
     import java.util.*; util.* java class Main
 {
   public static void main(String args[])
   { 
    input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     int r = sc.nextInt();
     
     int c = sc.nextInt();
     
     int n[][] = new int[r + 1][c + 1];
     
     int rsum[] = new  int[c + 1];
     
     int csum[] = new int[r];
     
     for(int i = 0; i <= r; i ++)
     {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     }
     output(n);
   }
   static void output(int n[][])
   {
     for(int i = 0; i < n.length; i ++)
     {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     }
   }
 } Main public static void main(String args[])
   { 
    input();
   } main { 
    input();
   } input() input String args[] args static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     int r = sc.nextInt();
     
     int c = sc.nextInt();
     
     int n[][] = new int[r + 1][c + 1];
     
     int rsum[] = new  int[c + 1];
     
     int csum[] = new int[r];
     
     for(int i = 0; i <= r; i ++)
     {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     }
     output(n);
   } input {
     Scanner sc = new Scanner(System.in);
     
     int r = sc.nextInt();
     
     int c = sc.nextInt();
     
     int n[][] = new int[r + 1][c + 1];
     
     int rsum[] = new  int[c + 1];
     
     int csum[] = new int[r];
     
     for(int i = 0; i <= r; i ++)
     {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     }
     output(n);
   } 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 n[][] = new int[r + 1][c + 1]; n new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 int rsum[] = new  int[c + 1]; rsum new  int[c + 1] c + 1 c 1 int csum[] = new int[r]; csum new int[r] r for(int i = 0; i <= r; i ++)
     {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[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(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     } {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     } for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       } int j = 0; int j = 0; j 0 j <= c j c j ++ j ++ j {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       } {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       } if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         } i == r i r {
           n[i][j] = rsum[j];
         } n[i][j] = rsum[j] n[i][j] n[i] n i j rsum[j] rsum j if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         } j == c j c {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         } n[i][j] = csum[i] n[i][j] n[i] n i j csum[i] csum i rsum[j] += n[i][j] rsum[j] rsum j n[i][j] n[i] n i j {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         } n[i][j] = sc.nextInt() n[i][j] n[i] n i j sc.nextInt() sc.nextInt sc rsum[j] += n[i][j] rsum[j] rsum j n[i][j] n[i] n i j csum[i] += n[i][j] csum[i] csum i n[i][j] n[i] n i j output(n) output n static void output(int n[][])
   {
     for(int i = 0; i < n.length; i ++)
     {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     }
   } output {
     for(int i = 0; i < n.length; i ++)
     {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     }
   } for(int i = 0; i < n.length; i ++)
     {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     } int i = 0; int i = 0; i 0 i < n.length i n.length n n.length i ++ i ++ i {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     } {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     } for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       } int j = 0; int j = 0; j 0 j < n[i].length j n[i].length n[i] n i n[i].length j ++ j ++ j {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       } {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       } if(j != 0)System.out.print(" "); j != 0 j 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(n[i][j]) System.out.print System.out System System.out n[i][j] n[i] n i j System.out.println() System.out.println System.out System System.out int n[][] n
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     int r = sc.nextInt();
     
     int c = sc.nextInt();
     
     int n[][] = new int[r + 1][c + 1];
     
     int rsum[] = new  int[c + 1];
     
     int csum[] = new int[r];
     
     for(int i = 0; i <= r; i ++)
     {
       for(int j = 0; j <= c; j ++)
       {
         if(i == r)
         {
           n[i][j] = rsum[j];
         }
         else if(j == c)
         {
           n[i][j] = csum[i];
           
           rsum[j] += n[i][j];
         }
         else
         {
           n[i][j] = sc.nextInt();
         
           rsum[j] += n[i][j];
         
           csum[i] += n[i][j];
         }
       }
     }
     output(n);
   }
   static void output(int n[][])
   {
     for(int i = 0; i < n.length; i ++)
     {
       for(int j = 0; j < n[i].length; j ++)
       {
         if(j != 0)System.out.print(" ");
         
         System.out.print(n[i][j]);
       }
       System.out.println();
     }
   }
 }
    
