import java.util.Scanner;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	}
}

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

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	}
} Main public static final int BIG_NUM  = 2000000000; BIG_NUM 2000000000 public static final int MOD  = 1000000007; MOD 1000000007 public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int H H W; W H = sc.nextInt() H sc.nextInt() sc.nextInt sc W = sc.nextInt() W sc.nextInt() sc.nextInt sc int table[][] = new int[H+1][W+1]; table new int[H+1][W+1] H+1 H 1 W+1 W 1 for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		} int row = 0; int row = 0; row 0 row < H row H row++ row++ row {
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		} {
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		} for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			} int col = 0; int col = 0; col 0 col < W col W col++ col++ col {
				table[row][col] = sc.nextInt();
			} {
				table[row][col] = sc.nextInt();
			} table[row][col] = sc.nextInt() table[row][col] table[row] table row col sc.nextInt() sc.nextInt sc for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		} int row = 0; int row = 0; row 0 row < H row H row++ row++ row {
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		} {
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		} table[row][W] = 0 table[row][W] table[row] table row W 0 for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			} int col = 0; int col = 0; col 0 col < W col W col++ col++ col {
				table[row][W] += table[row][col];
			} {
				table[row][W] += table[row][col];
			} table[row][W] += table[row][col] table[row][W] table[row] table row W table[row][col] table[row] table row col for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		} int col = 0; int col = 0; col 0 col <= W col W col++ col++ col {
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		} {
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		} table[H][col] = 0 table[H][col] table[H] table H col 0 for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			} int row = 0; int row = 0; row 0 row < H row H row++ row++ row {
				table[H][col] += table[row][col];
			} {
				table[H][col] += table[row][col];
			} table[H][col] += table[row][col] table[H][col] table[H] table H col table[row][col] table[row] table row col for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		} int row = 0; int row = 0; row 0 row <= H row H row++ row++ row {
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		} {
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		} System.out.printf("%d", table[row][0]) System.out.printf System.out System System.out "%d" table[row][0] table[row] table row 0 for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			} int col = 1; int col = 1; col 1 col <= W col W col++ col++ col {
				System.out.printf(" %d", table[row][col]);
			} {
				System.out.printf(" %d", table[row][col]);
			} System.out.printf(" %d", table[row][col]) System.out.printf System.out System System.out " %d" table[row][col] table[row] table row col System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	}
} public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	}
} Main
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int H,W;

		H = sc.nextInt();
		W = sc.nextInt();

		int table[][] = new int[H+1][W+1];

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				table[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < H; row++){
			table[row][W] = 0;
			for(int col = 0; col < W; col++){
				table[row][W] += table[row][col];
			}
		}

		for(int col = 0; col <= W; col++){
			table[H][col] = 0;
			for(int row = 0; row < H; row++){
				table[H][col] += table[row][col];
			}
		}

		for(int row = 0; row <= H; row++){
			System.out.printf("%d", table[row][0]);
			for(int col = 1; col <= W; col++){
				System.out.printf(" %d", table[row][col]);
			}
			System.out.printf("\n");
		}
	}
}


