import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        final int r = Integer.parseInt(sc.next());
        final int c = Integer.parseInt(sc.next());
        final int[][] cells = new int[r+1][c+1];
        for(int i = 0; i<r; i++){
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        }
        for(final int[] cell:cells){
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        }
        out.flush();
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        final int r = Integer.parseInt(sc.next());
        final int c = Integer.parseInt(sc.next());
        final int[][] cells = new int[r+1][c+1];
        for(int i = 0; i<r; i++){
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        }
        for(final int[] cell:cells){
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        }
        out.flush();
    }
} Main private static final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) private static final PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] Args){
        final int r = Integer.parseInt(sc.next());
        final int c = Integer.parseInt(sc.next());
        final int[][] cells = new int[r+1][c+1];
        for(int i = 0; i<r; i++){
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        }
        for(final int[] cell:cells){
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        }
        out.flush();
    } main {
        final int r = Integer.parseInt(sc.next());
        final int c = Integer.parseInt(sc.next());
        final int[][] cells = new int[r+1][c+1];
        for(int i = 0; i<r; i++){
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        }
        for(final int[] cell:cells){
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        }
        out.flush();
    } final int r = Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc final int c = Integer.parseInt(sc.next()); c Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc final int[][] cells = new int[r+1][c+1]; cells new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i = 0; i<r; i++){
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        } int i = 0; int i = 0; i 0 i<r i r i++ i++ i {
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        } {
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        } for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            } int j = 0; int j = 0; j 0 j<c j c j++ j++ j {
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            } {
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            } final int num = Integer.parseInt(sc.next()); num Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc cells[i][j] = num cells[i][j] cells[i] cells i j num cells[r][j] += num cells[r][j] cells[r] cells r j num cells[i][c] += num cells[i][c] cells[i] cells i c num cells[r][c] += num cells[r][c] cells[r] cells r c num for(final int[] cell:cells){
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        } final int[] cell cells {
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        } {
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        } boolean first = true; first true for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            } final int element cell {
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            } {
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            } if(first) first = false;
                else out.print(' '); first first = false first false out.print(' ') out.print out ' ' out.print(element) out.print out element out.println() out.println out out.flush() out.flush out String[] Args Args
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        final int r = Integer.parseInt(sc.next());
        final int c = Integer.parseInt(sc.next());
        final int[][] cells = new int[r+1][c+1];
        for(int i = 0; i<r; i++){
            for(int j = 0; j<c; j++){
                final int num = Integer.parseInt(sc.next());
                cells[i][j] = num;
                cells[r][j] += num;
                cells[i][c] += num;
                cells[r][c] += num;
            }
        }
        for(final int[] cell:cells){
            boolean first = true;
            for(final int element:cell){
                if(first) first = false;
                else out.print(' ');
                out.print(element);
            }
            out.println();
        }
        out.flush();
    }
}