import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int[][] SP = new int[r+1][c+1]; SP new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		} int x = 0 ; int x = 0 ; x 0 x < r x r x++ x++ x {
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		} {
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		} for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			} int y = 0; int y = 0; y 0 y < c y c y++ y++ y {
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			} {
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			} SP[x][y] = scanner.nextInt() SP[x][y] SP[x] SP x y scanner.nextInt() scanner.nextInt scanner SP[x][c] = SP[x][c] + SP[x][y] SP[x][c] SP[x] SP x c SP[x][c] + SP[x][y] SP[x][c] SP[x] SP x c SP[x][y] SP[x] SP x y SP[r][y] = SP[r][y] + SP[x][y] SP[r][y] SP[r] SP r y SP[r][y] + SP[x][y] SP[r][y] SP[r] SP r y SP[x][y] SP[x] SP x y SP[r][c] = SP[r][c] + SP[x][y] SP[r][c] SP[r] SP r c SP[r][c] + SP[x][y] SP[r][c] SP[r] SP r c SP[x][y] SP[x] SP x y for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		} int x = 0 ; int x = 0 ; x 0 x < r+1 x r+1 r 1 x++ x++ x {
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		} {
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		} for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			} int y = 0; int y = 0; y 0 y < c+1 y c+1 c 1 y++ y++ y {
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			} {
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			} if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				} y==c y c {
					System.out.print(SP[x][y] );
				} System.out.print(SP[x][y] ) System.out.print System.out System System.out SP[x][y] SP[x] SP x y {
					System.out.print(SP[x][y] + " ");
				} System.out.print(SP[x][y] + " ") System.out.print System.out System System.out SP[x][y] + " " SP[x][y] SP[x] SP x y " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	}

}