import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int r=0, c=0, x=0;
        int i, j, k, l, m, n;
        r=scan.nextInt();
        c=scan.nextInt();
        int[][] a=new int[r+1][c+1];
        
        for (i=0; i<r; i++) {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        }
        for (k=0; k<r; k++) {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        }
        for(m=0; m<=c; m++){ 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        }
        for(i = 0; i <= r; i++){
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		}
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int r=0, c=0, x=0;
        int i, j, k, l, m, n;
        r=scan.nextInt();
        c=scan.nextInt();
        int[][] a=new int[r+1][c+1];
        
        for (i=0; i<r; i++) {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        }
        for (k=0; k<r; k++) {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        }
        for(m=0; m<=c; m++){ 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        }
        for(i = 0; i <= r; i++){
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		}
    }
} Main public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int r=0, c=0, x=0;
        int i, j, k, l, m, n;
        r=scan.nextInt();
        c=scan.nextInt();
        int[][] a=new int[r+1][c+1];
        
        for (i=0; i<r; i++) {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        }
        for (k=0; k<r; k++) {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        }
        for(m=0; m<=c; m++){ 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        }
        for(i = 0; i <= r; i++){
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		}
    } main {
        Scanner scan=new Scanner(System.in);
        int r=0, c=0, x=0;
        int i, j, k, l, m, n;
        r=scan.nextInt();
        c=scan.nextInt();
        int[][] a=new int[r+1][c+1];
        
        for (i=0; i<r; i++) {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        }
        for (k=0; k<r; k++) {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        }
        for(m=0; m<=c; m++){ 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        }
        for(i = 0; i <= r; i++){
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		}
    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int r=0 r 0 c=0 c 0 x=0; x 0 int i i j j k k l l m m n; n r=scan.nextInt() r scan.nextInt() scan.nextInt scan c=scan.nextInt() c scan.nextInt() scan.nextInt scan int[][] a=new int[r+1][c+1]; a new int[r+1][c+1] r+1 r 1 c+1 c 1 for (i=0; i<r; i++) {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        } i=0; i=0 i 0 i<r i r i++ i++ i {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        } {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        } for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            } j=0; j=0 j 0 j<c j c j++ j++ j {
            x=scan.nextInt();
            a[i][j] = x;
            } {
            x=scan.nextInt();
            a[i][j] = x;
            } x=scan.nextInt() x scan.nextInt() scan.nextInt scan a[i][j] = x a[i][j] a[i] a i j x for (k=0; k<r; k++) {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        } k=0; k=0 k 0 k<r k r k++ k++ k {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        } {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        } for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            } l=0; l=0 l 0 l<c l c l++ l++ l {
            a[k][c] += a[k][l];
            } {
            a[k][c] += a[k][l];
            } a[k][c] += a[k][l] a[k][c] a[k] a k c a[k][l] a[k] a k l for(m=0; m<=c; m++){ 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        } m=0; m=0 m 0 m<=c m c m++ m++ m { 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        } { 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        } for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            } n=0; n=0 n 0 n<r n r n++ n++ n {
            a[r][m] += a[n][m];
            } {
            a[r][m] += a[n][m];
            } a[r][m] += a[n][m] a[r][m] a[r] a r m a[n][m] a[n] a n m for(i = 0; i <= r; i++){
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		} i = 0; i = 0 i 0 i <= r i r i++ i++ i {
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		} {
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		} System.out.printf("%d", a[i][0]) System.out.printf System.out System System.out "%d" a[i][0] a[i] a i 0 for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			} j = 1; j = 1 j 1 j <= c j c j++ j++ j {
				System.out.printf(" %d", a[i][j]);
			} {
				System.out.printf(" %d", a[i][j]);
			} System.out.printf(" %d", a[i][j]) System.out.printf System.out System System.out " %d" a[i][j] a[i] a i j System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int r=0, c=0, x=0;
        int i, j, k, l, m, n;
        r=scan.nextInt();
        c=scan.nextInt();
        int[][] a=new int[r+1][c+1];
        
        for (i=0; i<r; i++) {
        for (j=0; j<c; j++) {
            x=scan.nextInt();
            a[i][j] = x;
            }
        }
        for (k=0; k<r; k++) {
        for (l=0; l<c; l++) {
            a[k][c] += a[k][l];
            }
        }
        for(m=0; m<=c; m++){ 
        for(n=0; n<r; n++){
            a[r][m] += a[n][m];
            }
        }
        for(i = 0; i <= r; i++){
			System.out.printf("%d", a[i][0]);
			for(j = 1; j <= c; j++){
				System.out.printf(" %d", a[i][j]);
			}
			System.out.printf("\n");
		}
    }
}
