import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    } main {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] l = line.split(" "); l line.split(" ") line.split line " " int r = Integer.parseInt(l[0]); r Integer.parseInt(l[0]) Integer.parseInt Integer l[0] l 0 int c = Integer.parseInt(l[1]); c Integer.parseInt(l[1]) Integer.parseInt Integer l[1] l 1 int[] SUM = new int[c]; SUM new int[c] c for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        } int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        } {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        } int sum = 0; sum 0 if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          } i != r i r {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          } line = sc.nextLine() line sc.nextLine() sc.nextLine sc String[] L = line.split(" "); L line.split(" ") line.split line " " for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            } {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            } int C = Integer.parseInt(L[j]); C Integer.parseInt(L[j]) Integer.parseInt Integer L[j] L j System.out.print(C + " ") System.out.print System.out System System.out C + " " C " " sum += C sum C SUM[j] += C SUM[j] SUM j C if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          } i == r i r {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          } for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            } {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            } int C = SUM[j]; C SUM[j] SUM j System.out.print(C + " ") System.out.print System.out System System.out C + " " C " " sum += C sum C System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int r = Integer.parseInt(l[0]);
        int c = Integer.parseInt(l[1]);

        int[] SUM = new int[c];
        for(int i = 0; i <= r; i++) {

          int sum = 0;

          if(i != r) {
            line = sc.nextLine();
            String[] L = line.split(" ");

            for(int j = 0; j < c; j++) {
              int C = Integer.parseInt(L[j]);
              System.out.print(C + " ");
              sum += C;
              SUM[j] += C;
            }
          }

          if(i == r) {
            for(int j = 0; j < c; j++) {
              int C = SUM[j];
              System.out.print(C + " ");
              sum += C;
            }
          }

          System.out.println(sum);
        }
    }
}