public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  } run {
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  } java.util.Scanner sc = new java.util.Scanner(in); sc new java.util.Scanner(in) int r r c; c int[][] a; a int i i j; j r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc a = new int[r + 1][c + 1] a new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    } i = 0; i = 0 i 0 i < r i r i++ i++ i {
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    } {
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    } for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      } j = 0; j = 0 j 0 j < c j c j++ j++ j {
        a[i][j] = sc.nextInt();
      } {
        a[i][j] = sc.nextInt();
      } a[i][j] = sc.nextInt() a[i][j] a[i] a i j sc.nextInt() sc.nextInt sc for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    } i = 0; i = 0 i 0 i < r i r i++ i++ i {
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    } {
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    } for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      } j = 0; j = 0 j 0 j < c j c j++ j++ j {
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      } {
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      } a[i][c] += a[i][j] a[i][c] a[i] a i c a[i][j] a[i] a i j a[r][j] += a[i][j] a[r][j] a[r] a r j a[i][j] a[i] a i j a[r][c] += a[i][c] a[r][c] a[r] a r c a[i][c] a[i] a i c for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    } i = 0; i = 0 i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    } {
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    } for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      } j = 0; j = 0 j 0 j < c j c 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.println(a[i][j]) System.out.println System.out System System.out a[i][j] a[i] a i j sc.close() sc.close sc java.io.InputStream in in java.io.PrintStream out out public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  } main {
    (new Main()).run(System.in, System.out);
  } (new Main()).run(System.in, System.out) (new Main()).run (new Main()) System.in System System.in System.out System System.out String[] args args public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
} Main
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int r, c;
    int[][] a;
    int i, j;

    r = sc.nextInt();
    c = sc.nextInt();
    a = new int[r + 1][c + 1];

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][j] = sc.nextInt();
      }
    }

    for(i = 0;i < r;i++){
      for(j = 0;j < c;j++){
        a[i][c] += a[i][j];
        a[r][j] += a[i][j];
      }
      a[r][c] += a[i][c];
    }

    for(i = 0;i < r + 1;i++){
      for(j = 0;j < c;j++){
        System.out.print(a[i][j] + " ");
      }
      System.out.println(a[i][j]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}