import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int r = Integer.parseInt(s[0]);
    int c = Integer.parseInt(s[1]);
    int rPlus1 = r + 1;
    int cPlus1 = c + 1;
    int t[][] = new int[rPlus1][cPlus1];
    for (int i = 0; i < r; i++) {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    }
    for (int i = 0; i < rPlus1; i++) {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    }
  }
} import java.util.*; util.* java class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int r = Integer.parseInt(s[0]);
    int c = Integer.parseInt(s[1]);
    int rPlus1 = r + 1;
    int cPlus1 = c + 1;
    int t[][] = new int[rPlus1][cPlus1];
    for (int i = 0; i < r; i++) {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    }
    for (int i = 0; i < rPlus1; i++) {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    }
  }
} Main public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int r = Integer.parseInt(s[0]);
    int c = Integer.parseInt(s[1]);
    int rPlus1 = r + 1;
    int cPlus1 = c + 1;
    int t[][] = new int[rPlus1][cPlus1];
    for (int i = 0; i < r; i++) {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    }
    for (int i = 0; i < rPlus1; i++) {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    }
  } main {
    Scanner sc = new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int r = Integer.parseInt(s[0]);
    int c = Integer.parseInt(s[1]);
    int rPlus1 = r + 1;
    int cPlus1 = c + 1;
    int t[][] = new int[rPlus1][cPlus1];
    for (int i = 0; i < r; i++) {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    }
    for (int i = 0; i < rPlus1; i++) {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] s = sc.nextLine().split(" "); s sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int r = Integer.parseInt(s[0]); r Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 int c = Integer.parseInt(s[1]); c Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 int rPlus1 = r + 1; rPlus1 r + 1 r 1 int cPlus1 = c + 1; cPlus1 c + 1 c 1 int t[][] = new int[rPlus1][cPlus1]; t new int[rPlus1][cPlus1] rPlus1 cPlus1 for (int i = 0; i < r; i++) {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    } {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    } t[i][c] = 0 t[i][c] t[i] t i c 0 for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      } {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      } t[i][j] = sc.nextInt() t[i][j] t[i] t i j sc.nextInt() sc.nextInt sc t[i][c] += t[i][j] t[i][c] t[i] t i c t[i][j] t[i] t i j t[r][j] += t[i][j] t[r][j] t[r] t r j t[i][j] t[i] t i j t[r][c] += t[i][j] t[r][c] t[r] t r c t[i][j] t[i] t i j for (int i = 0; i < rPlus1; i++) {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    } int i = 0; int i = 0; i 0 i < rPlus1 i rPlus1 i++ i++ i {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    } {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    } for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      } int j = 0; int j = 0; j 0 j < cPlus1 j cPlus1 j++ j++ j {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      } {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      } if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        } j != c j c {
          System.out.print(t[i][j] + " ");
        } System.out.print(t[i][j] + " ") System.out.print System.out System System.out t[i][j] + " " t[i][j] t[i] t i j " " {
          System.out.println(t[i][j]);
        } System.out.println(t[i][j]) System.out.println System.out System System.out t[i][j] t[i] t i j String args[] args
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int r = Integer.parseInt(s[0]);
    int c = Integer.parseInt(s[1]);
    int rPlus1 = r + 1;
    int cPlus1 = c + 1;
    int t[][] = new int[rPlus1][cPlus1];
    for (int i = 0; i < r; i++) {
      t[i][c] = 0;
      for (int j = 0; j < c; j++) {
        t[i][j] = sc.nextInt();
        t[i][c] += t[i][j];
        t[r][j] += t[i][j];
        t[r][c] += t[i][j];
      }
    }
    for (int i = 0; i < rPlus1; i++) {
      for (int j = 0; j < cPlus1; j++) {
        if (j != c) {
          System.out.print(t[i][j] + " ");
        } else {
          System.out.println(t[i][j]);
        }
      }
    }
  }
}