import java.util.Scanner;

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

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