import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    }
} Main public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    } main {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int r = scn.nextInt() r scn.nextInt() scn.nextInt scn c = scn.nextInt(); c scn.nextInt() scn.nextInt scn int[][] fld = new int[-~r][-~c]; fld new int[-~r][-~c] -~r ~r r -~c ~c c for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        } {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        } for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            } {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            } fld[i][j] = scn.nextInt() fld[i][j] fld[i] fld i j scn.nextInt() scn.nextInt scn fld[r][j] += fld[i][j] fld[r][j] fld[r] fld r j fld[i][j] fld[i] fld i j fld[i][c] += fld[i][j] fld[i][c] fld[i] fld i c fld[i][j] fld[i] fld i j fld[r][c] += fld[i][j] fld[r][c] fld[r] fld r c fld[i][j] fld[i] fld i j for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        } int i = 0; int i = 0; i 0 i < fld.length i fld.length fld fld.length i++ i++ i {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        } {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        } for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                System.out.print(fld[i][j] + " ");
            } {
                System.out.print(fld[i][j] + " ");
            } System.out.print(fld[i][j] + " ") System.out.print System.out System System.out fld[i][j] + " " fld[i][j] fld[i] fld i j " " System.out.println(fld[i][c]) System.out.println System.out System System.out fld[i][c] fld[i] fld i c String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int r = scn.nextInt(), c = scn.nextInt();
        int[][] fld = new int[-~r][-~c];
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                fld[i][j] = scn.nextInt();
                fld[r][j] += fld[i][j];
                fld[i][c] += fld[i][j];
                fld[r][c] += fld[i][j];
            }
        }
        for(int i = 0; i < fld.length; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print(fld[i][j] + " ");
            }
            System.out.println(fld[i][c]);
        }
    }
}