// ITP1_7_C
import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
} import java.io.*; io.* java public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
} Main public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   } main {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   } try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      } catch (Exception e) {
         System.err.println(e);
      } Exception e {
         System.err.println(e);
      } System.err.println(e) System.err.println System.err System System.err e {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strAry0 = br.readLine().split(" "); strAry0 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(strAry0[0]); r Integer.parseInt(strAry0[0]) Integer.parseInt Integer strAry0[0] strAry0 0 int c = Integer.parseInt(strAry0[1]); c Integer.parseInt(strAry0[1]) Integer.parseInt Integer strAry0[1] strAry0 1 int[][] s = new int[r + 1][c + 1]; s new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         } int i = 0; int i = 0; i 0 i < s.length -1 i s.length -1 s.length s s.length 1 i++ i++ i {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         } {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         } String[] strAry1 = br.readLine().split(" "); strAry1 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            } int j = 0; int j = 0; j 0 j < s[i].length -1 j s[i].length -1 s[i].length s[i] s i s[i].length 1 j++ j++ j {
               s[i][j] = Integer.parseInt(strAry1[j]);
            } {
               s[i][j] = Integer.parseInt(strAry1[j]);
            } s[i][j] = Integer.parseInt(strAry1[j]) s[i][j] s[i] s i j Integer.parseInt(strAry1[j]) Integer.parseInt Integer strAry1[j] strAry1 j for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         } int i = 0; int i = 0; i 0 i < s.length -1 i s.length -1 s.length s s.length 1 i++ i++ i {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         } {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         } for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            } int j = 0; int j = 0; j 0 j < s[i].length - 1 j s[i].length - 1 s[i].length s[i] s i s[i].length 1 j++ j++ j {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            } {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            } s[i][s[i].length -1] += s[i][j] s[i][s[i].length -1] s[i] s i s[i].length -1 s[i].length s[i] s i s[i].length 1 s[i][j] s[i] s i j s[s.length - 1][j] += s[i][j] s[s.length - 1][j] s[s.length - 1] s s.length - 1 s.length s s.length 1 j s[i][j] s[i] s i j for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         } int i = 0; int i = 0; i 0 i < s.length - 1 i s.length - 1 s.length s s.length 1 i++ i++ i {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         } {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         } for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            } int j = 0; int j = 0; j 0 j < s[i].length - 1 j s[i].length - 1 s[i].length s[i] s i s[i].length 1 j++ j++ j {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            } {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            } s[s.length - 1][s[i].length - 1] += s[i][j] s[s.length - 1][s[i].length - 1] s[s.length - 1] s s.length - 1 s.length s s.length 1 s[i].length - 1 s[i].length s[i] s i s[i].length 1 s[i][j] s[i] s i j for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         } int i = 0; int i = 0; i 0 i < s.length i s.length s s.length i++ i++ i {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         } {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         } for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            } int j = 0; int j = 0; j 0 j < s[i].length j s[i].length s[i] s i s[i].length j++ j++ j {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            } {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            } System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ") System.out.print System.out System System.out j == s[i].length - 1 ? s[i][j] : s[i][j] + " " j == s[i].length - 1 j s[i].length - 1 s[i].length s[i] s i s[i].length 1 s[i][j] s[i] s i j s[i][j] + " " s[i][j] s[i] s i j " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
} public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
} Main
// ITP1_7_C
import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         String[] strAry0 = br.readLine().split(" ");
         int r = Integer.parseInt(strAry0[0]);
         int c = Integer.parseInt(strAry0[1]);
         int[][] s = new int[r + 1][c + 1];

         for (int i = 0; i < s.length -1; i++) {
            String[] strAry1 = br.readLine().split(" ");
            for (int j = 0; j < s[i].length -1; j++) {
               s[i][j] = Integer.parseInt(strAry1[j]);
            }
         }

         for (int i = 0; i < s.length -1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[i][s[i].length -1] += s[i][j];
               s[s.length - 1][j] += s[i][j];
            }
         }

         for (int i = 0; i < s.length - 1; i++) {
            for (int j = 0; j < s[i].length - 1; j++) {
               s[s.length - 1][s[i].length - 1] += s[i][j];
            }
         }

         for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[i].length; j++) {
               System.out.print(j == s[i].length - 1 ? s[i][j] : s[i][j] + " ");
            }
            System.out.println();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
}