import java.util.Scanner;
class Main{
    int r,c,x,y;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        int [][] a = new int [r+1][c+1];
        for(x = r; x < r+1; x++){
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        }
        for(x = 0; x < r; x++){
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        }
        for(x = 0; x < r+1; x++){
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
} import java.util.Scanner; Scanner java.util class Main{
    int r,c,x,y;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        int [][] a = new int [r+1][c+1];
        for(x = r; x < r+1; x++){
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        }
        for(x = 0; x < r; x++){
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        }
        for(x = 0; x < r+1; x++){
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
} Main int r r c c x x y; y public void solve(){
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        int [][] a = new int [r+1][c+1];
        for(x = r; x < r+1; x++){
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        }
        for(x = 0; x < r; x++){
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        }
        for(x = 0; x < r+1; x++){
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        }
    } solve {
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        int [][] a = new int [r+1][c+1];
        for(x = r; x < r+1; x++){
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        }
        for(x = 0; x < r; x++){
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        }
        for(x = 0; x < r+1; x++){
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc int [][] a = new int [r+1][c+1]; a new int [r+1][c+1] r+1 r 1 c+1 c 1 for(x = r; x < r+1; x++){
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        } x = r; x = r x r x < r+1 x r+1 r 1 x++ x++ x {
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        } {
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        } for(y = c; y < c+1; y++){
                a[x][y] = 0;
            } y = c; y = c y c y < c+1 y c+1 c 1 y++ y++ y {
                a[x][y] = 0;
            } {
                a[x][y] = 0;
            } a[x][y] = 0 a[x][y] a[x] a x y 0 for(x = 0; x < r; x++){
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        } x = 0; x = 0 x 0 x < r x r x++ x++ x {
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        } {
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        } for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            } y = 0; y = 0 y 0 y < c y c y++ y++ y {
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            } {
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            } a[x][y] = sc.nextInt() a[x][y] a[x] a x y sc.nextInt() sc.nextInt sc a[x][c] += a[x][y] a[x][c] a[x] a x c a[x][y] a[x] a x y a[r][y] += a[x][y] a[r][y] a[r] a r y a[x][y] a[x] a x y a[r][c] += a[x][y] a[r][c] a[r] a r c a[x][y] a[x] a x y for(x = 0; x < r+1; x++){
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        } x = 0; x = 0 x 0 x < r+1 x r+1 r 1 x++ x++ x {
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        } {
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        } for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            } y = 0; y = 0 y 0 y < c y c y++ y++ y {
                System.out.printf("%d ",a[x][y]);
            } {
                System.out.printf("%d ",a[x][y]);
            } System.out.printf("%d ",a[x][y]) System.out.printf System.out System System.out "%d " a[x][y] a[x] a x y System.out.printf("%d",a[x][y]) System.out.printf System.out System System.out "%d" a[x][y] a[x] a x y System.out.println() System.out.println System.out System System.out public static void main(String[] args){
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args
import java.util.Scanner;
class Main{
    int r,c,x,y;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        c = sc.nextInt();
        int [][] a = new int [r+1][c+1];
        for(x = r; x < r+1; x++){
            for(y = c; y < c+1; y++){
                a[x][y] = 0;
            }
        }
        for(x = 0; x < r; x++){
            for(y = 0; y < c; y++){
                a[x][y] = sc.nextInt();
                a[x][c] += a[x][y];
                a[r][y] += a[x][y];
                a[r][c] += a[x][y];
            }
        }
        for(x = 0; x < r+1; x++){
            for(y = 0; y < c; y++){
                System.out.printf("%d ",a[x][y]);
            }
            System.out.printf("%d",a[x][y]);
            System.out.println();
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
}