import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}
 import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    } main {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int inR inR inC; inC int[][] spd; spd inR = Integer.parseInt(scan.next()) inR Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan inC = Integer.parseInt(scan.next()) inC Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan spd = new int[inR + 1][inC + 1] spd new int[inR + 1][inC + 1] inR + 1 inR 1 inC + 1 inC 1 for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        } int i = 0; int i = 0; i 0 i < inR + 1 i inR + 1 inR 1 i++ i++ i {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        } {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        } for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            } int j = 0; int j = 0; j 0 j < inC + 1 j inC + 1 inC 1 j++ j++ j {
                spd[i][j] = 0;
            } {
                spd[i][j] = 0;
            } spd[i][j] = 0 spd[i][j] spd[i] spd i j 0 for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        } int i = 0; int i = 0; i 0 i < inR i inR i++ i++ i {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        } {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        } for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            } int j = 0; int j = 0; j 0 j < inC j inC j++ j++ j {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            } {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            } spd[i][j] = Integer.parseInt(scan.next()) spd[i][j] spd[i] spd i j Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan spd[inR][j] += spd[i][j] spd[inR][j] spd[inR] spd inR j spd[i][j] spd[i] spd i j spd[i][inC] += spd[i][j] spd[i][inC] spd[i] spd i inC spd[i][j] spd[i] spd i j spd[inR][inC] += spd[i][j] spd[inR][inC] spd[inR] spd inR inC spd[i][j] spd[i] spd i j for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        } int i = 0; int i = 0; i 0 i < inR + 1 i inR + 1 inR 1 i++ i++ i {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        } {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        } for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            } int j = 0; int j = 0; j 0 j < inC + 1 j inC + 1 inC 1 j++ j++ j {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            } {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            } System.out.print(spd[i][j]) System.out.print System.out System System.out spd[i][j] spd[i] spd i j if (j != inC) System.out.print(" "); j != inC j inC System.out.print(" ") System.out.print System.out System System.out " " System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}

