import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  }
}
 import java.util.*; util.* java public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  } main {
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r r c c count; count r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc int[][] cells = new int[r+1][c+1]; cells new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i <= r;i++)cells[i][c] = 0; int i=0; int i=0; i 0 i <= r i r i++ i++ i cells[i][c] = 0; cells[i][c] = 0 cells[i][c] cells[i] cells i c 0 for(int j=0;j <= c;j++)cells[r][j] = 0; int j=0; int j=0; j 0 j <= c j c j++ j++ j cells[r][j] = 0; cells[r][j] = 0 cells[r][j] cells[r] cells r j 0 for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    } int i=0; int i=0; i 0 i < r i r i++ i++ i {
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    } {
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    } for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      } int j=0; int j=0; j 0 j < c j c j++ j++ j {
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      } {
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      } cells[i][j] = sc.nextInt() cells[i][j] cells[i] cells i j sc.nextInt() sc.nextInt sc cells[i][c] += cells[i][j] cells[i][c] cells[i] cells i c cells[i][j] cells[i] cells i j cells[r][j] += cells[i][j] cells[r][j] cells[r] cells r j cells[i][j] cells[i] cells i j cells[r][c] += cells[i][j] cells[r][c] cells[r] cells r c cells[i][j] cells[i] cells i j for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    } int i=0; int i=0; i 0 i <= r i r i++ i++ i {
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    } {
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    } for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      } int j=0; int j=0; j 0 j <= c j c j++ j++ j {
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      } {
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      } System.out.print(cells[i][j]) System.out.print System.out System System.out cells[i][j] cells[i] cells i j if(j != c)System.out.print(" "); j != c j c System.out.print(" ") System.out.print System.out System System.out " " System.out.println("") System.out.println System.out System System.out "" sc.close() sc.close sc String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r,c,count;
    r = sc.nextInt();
    c = sc.nextInt();
    int[][] cells = new int[r+1][c+1];
    for(int i=0;i <= r;i++)cells[i][c] = 0;
    for(int j=0;j <= c;j++)cells[r][j] = 0;
    for(int i=0;i < r;i++){
      for(int j=0;j < c;j++){
        cells[i][j] = sc.nextInt();
        cells[i][c] += cells[i][j];
        cells[r][j] += cells[i][j];
        cells[r][c] += cells[i][j];
      }
    }
    for(int i=0;i <= r;i++){
      for(int j=0;j <= c;j++){
        System.out.print(cells[i][j]);
        if(j != c)System.out.print(" ");
      }
      System.out.println("");
    }
    sc.close();
  }
}

