import java.util.Scanner;

    class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

    int r, c, i, j, sum1 = 0, sum2 = 0;
    int data[][] = new int[150][150];
    //scanf("%d%d", &r, &c);
    r = scan.nextInt();
    c = scan.nextInt();
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    }
    for (j = 0; j <= c; j++) {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    }


	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

    int r, c, i, j, sum1 = 0, sum2 = 0;
    int data[][] = new int[150][150];
    //scanf("%d%d", &r, &c);
    r = scan.nextInt();
    c = scan.nextInt();
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    }
    for (j = 0; j <= c; j++) {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    }


	}
} Main public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

    int r, c, i, j, sum1 = 0, sum2 = 0;
    int data[][] = new int[150][150];
    //scanf("%d%d", &r, &c);
    r = scan.nextInt();
    c = scan.nextInt();
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    }
    for (j = 0; j <= c; j++) {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    }


	} main {
	Scanner scan = new Scanner(System.in);

    int r, c, i, j, sum1 = 0, sum2 = 0;
    int data[][] = new int[150][150];
    //scanf("%d%d", &r, &c);
    r = scan.nextInt();
    c = scan.nextInt();
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    }
    for (j = 0; j <= c; j++) {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    }


	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r r c c i i j j sum1 = 0 sum1 0 sum2 = 0; sum2 0 int data[][] = new int[150][150]; data new int[150][150] 150 150 r = scan.nextInt() r scan.nextInt() scan.nextInt scan c = scan.nextInt() c scan.nextInt() scan.nextInt scan for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    } i = 0; i = 0 i 0 i < r i r i++ i++ i {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    } {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    } for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        } j = 0; j = 0 j 0 j < c j c j++ j++ j {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        } {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        } data[i][j] = scan.nextInt() data[i][j] data[i] data i j scan.nextInt() scan.nextInt scan sum1 += data[i][j] sum1 data[i][j] data[i] data i j data[i][c] = sum1 data[i][c] data[i] data i c sum1 sum1 = 0 sum1 0 for (j = 0; j <= c; j++) {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    } j = 0; j = 0 j 0 j <= c j c j++ j++ j {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    } {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    } for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        } i = 0; i = 0 i 0 i < r i r i++ i++ i {
            sum2 += data[i][j];
        } {
            sum2 += data[i][j];
        } sum2 += data[i][j] sum2 data[i][j] data[i] data i j data[r][j] = sum2 data[r][j] data[r] data r j sum2 sum2 = 0 sum2 0 for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    } i = 0; i = 0 i 0 i <= r i r i++ i++ i {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    } {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    } for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        } j = 0; j = 0 j 0 j < c j c j++ j++ j {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        } {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        } System.out.print(data[i][j] + " ") System.out.print System.out System System.out data[i][j] + " " data[i][j] data[i] data i j " " System.out.println(data[i][c]) System.out.println System.out System System.out data[i][c] data[i] data i c String[] args args
import java.util.Scanner;

    class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

    int r, c, i, j, sum1 = 0, sum2 = 0;
    int data[][] = new int[150][150];
    //scanf("%d%d", &r, &c);
    r = scan.nextInt();
    c = scan.nextInt();
    for (i = 0; i < r; i++) {
        for (j = 0; j < c; j++) {
            //scanf("%d", &data[i][j]);
        	data[i][j] = scan.nextInt();
            sum1 += data[i][j];
        }
        data[i][c] = sum1;
        sum1 = 0;
    }
    for (j = 0; j <= c; j++) {
        for (i = 0; i < r; i++) {
            sum2 += data[i][j];
        }
        data[r][j] = sum2;
        sum2 = 0;
    }
    for (i = 0; i <= r; i++) {
        for (j = 0; j < c; j++) {
            //printf("%d ", data[i][j]);
        	System.out.print(data[i][j] + " ");
        }
        //printf("%d\n", data[i][c]);
        System.out.println(data[i][c]);
    }


	}
}