
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    } main {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) StringBuilder builder = new StringBuilder(); builder new StringBuilder() String line; line String[] columns; columns int x x y; y line = reader.readLine() line reader.readLine() reader.readLine reader columns = line.split(" ") columns line.split(" ") line.split line " " y = Integer.parseInt(columns[0]) y Integer.parseInt(columns[0]) Integer.parseInt Integer columns[0] columns 0 x = Integer.parseInt(columns[1]) x Integer.parseInt(columns[1]) Integer.parseInt Integer columns[1] columns 1 int[] total = new int[x+1]; total new int[x+1] x+1 x 1 for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        } int i = 0; int i = 0; i 0 i < y i y i++ i++ i {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        } {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        } int sum = 0; sum 0 line = reader.readLine() line reader.readLine() reader.readLine reader columns = line.split(" ") columns line.split(" ") line.split line " " for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            } int j = 0; int j = 0; j 0 j < x j x j++ j++ j {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            } {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            } sum += Integer.parseInt(columns[j]) sum Integer.parseInt(columns[j]) Integer.parseInt Integer columns[j] columns j builder.append(columns[j])
                        .append(" ") builder.append(columns[j])
                        .append builder.append(columns[j]) builder.append builder columns[j] columns j " " total[j] += Integer.parseInt(columns[j]) total[j] total j Integer.parseInt(columns[j]) Integer.parseInt Integer columns[j] columns j builder.append(sum)
                    .append("\n") builder.append(sum)
                    .append builder.append(sum) builder.append builder sum "\n" total[x] += sum total[x] total x sum for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        } int i = 0; int i = 0; i 0 i < x + 1 i x + 1 x 1 i++ i++ i {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        } {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        } if ( i != 0 ) {
                builder.append(" ");
            } i != 0 i 0 {
                builder.append(" ");
            } builder.append(" ") builder.append builder " " builder.append(total[i]) builder.append builder total[i] total i System.out.println(builder) System.out.println System.out System System.out builder String[] args args public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    }
} Main

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        String line;
        String[] columns;
        int x, y;
        line = reader.readLine();
        columns = line.split(" ");
        y = Integer.parseInt(columns[0]);
        x = Integer.parseInt(columns[1]);
        int[] total = new int[x+1];

        for (int i = 0; i < y; i++) {
            int sum = 0;
            line = reader.readLine();
            columns = line.split(" ");
            for (int j = 0; j < x; j++) {
                sum += Integer.parseInt(columns[j]);
                builder.append(columns[j])
                        .append(" ");
                total[j] += Integer.parseInt(columns[j]);
            }
            builder.append(sum)
                    .append("\n");
            total[x] += sum;
        }
        for (int i = 0; i < x + 1; i++) {
            if ( i != 0 ) {
                builder.append(" ");
            }
            builder.append(total[i]);
        }
//        builder.append("\n");
//        System.out.print("\n");
        System.out.println(builder);
    }
}