import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    }

    private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    }

    private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    } main {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] a = new int[]{sc.nextInt(), sc.nextInt()}; a new int[]{sc.nextInt(), sc.nextInt()} int[][] m = new int[a[0]][a[1]]; m new int[a[0]][a[1]] a[0] a 0 a[1] a 1 for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        } int i = 0; int i = 0; i 0 i < a[0] i a[0] a 0 i++ i++ i {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        } {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        } for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            } int j = 0; int j = 0; j 0 j < a[1] j a[1] a 1 j++ j++ j {
                m[i][j] = sc.nextInt();
            } {
                m[i][j] = sc.nextInt();
            } m[i][j] = sc.nextInt() m[i][j] m[i] m i j sc.nextInt() sc.nextInt sc print2DArray(m) print2DArray m String[] args args private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    } print2DArray {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    } StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        } int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        } {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        } int sum = 0; sum 0 for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            } int j = 0; int j = 0; j 0 j < array[i].length j array[i].length array[i] array i array[i].length j++ j++ j {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            } {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            } sb.append(array[i][j]) sb.append sb array[i][j] array[i] array i j if (j != array[i].length - 1) {
                    sb.append(" ");
                } j != array[i].length - 1 j array[i].length - 1 array[i].length array[i] array i array[i].length 1 {
                    sb.append(" ");
                } sb.append(" ") sb.append sb " " sum += array[i][j] sum array[i][j] array[i] array i j sb.append(" ").append(sum) sb.append(" ").append sb.append(" ") sb.append sb " " sum sb.append("\n") sb.append sb "\n" int allsum = 0; allsum 0 for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        } int i = 0; int i = 0; i 0 i < array[0].length i array[0].length array[0] array 0 array[0].length i++ i++ i {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        } {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        } int sum = 0; sum 0 for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            } int j = 0; int j = 0; j 0 j < array.length j array.length array array.length j++ j++ j {
                sum += array[j][i];
            } {
                sum += array[j][i];
            } sum += array[j][i] sum array[j][i] array[j] array j i sb.append(sum) sb.append sb sum if (i != array[0].length - 1) {
                sb.append(" ");
            } i != array[0].length - 1 i array[0].length - 1 array[0].length array[0] array 0 array[0].length 1 {
                sb.append(" ");
            } sb.append(" ") sb.append sb " " allsum += sum allsum sum sb.append(" ").append(allsum) sb.append(" ").append sb.append(" ") sb.append sb " " allsum System.out.println(sb) System.out.println System.out System System.out sb int[][] array array public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    }

    private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    }

    private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[]{sc.nextInt(), sc.nextInt()};
        int[][] m = new int[a[0]][a[1]];
        for (int i = 0; i < a[0]; i++) {
            for (int j = 0; j < a[1]; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        print2DArray(m);
    }

    private static void print2DArray(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            int sum = 0;
            for (int j = 0; j < array[i].length; j++) {
                sb.append(array[i][j]);
                if (j != array[i].length - 1) {
                    sb.append(" ");
                }
                sum += array[i][j];
            }
            sb.append(" ").append(sum);
            sb.append("\n");
        }
        int allsum = 0;
        for (int i = 0; i < array[0].length; i++) {
            int sum = 0;
            for (int j = 0; j < array.length; j++) {
                sum += array[j][i];
            }
            sb.append(sum);
            if (i != array[0].length - 1) {
                sb.append(" ");
            }
            allsum += sum;
        }
        sb.append(" ").append(allsum);
        System.out.println(sb);
    }
}