public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	} main {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	} java.util.Scanner sc = new java.util.Scanner(System.in); sc new java.util.Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc int[][] mat = new int[r+1][c+1]; mat new int[r+1][c+1] r+1 r 1 c+1 c 1 for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		} int i=0; int i=0; i 0 i < r i r i++ i++ i {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		} {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		} String[] data = sc.nextLine().split(" "); data sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			} int j=0; int j=0; j 0 j < c j c j++ j++ j {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			} {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			} mat[i][j] = Integer.parseInt(data[j]) mat[i][j] mat[i] mat i j Integer.parseInt(data[j]) Integer.parseInt Integer data[j] data j mat[i][c] += mat[i][j] mat[i][c] mat[i] mat i c mat[i][j] mat[i] mat i j mat[r][j] += mat[i][j] mat[r][j] mat[r] mat r j mat[i][j] mat[i] mat i j mat[r][c] += mat[i][c] mat[r][c] mat[r] mat r c mat[i][c] mat[i] mat i c for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		} {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		} for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				System.out.print(mat[i][j] + " ");
			} {
				System.out.print(mat[i][j] + " ");
			} System.out.print(mat[i][j] + " ") System.out.print System.out System System.out mat[i][j] + " " mat[i][j] mat[i] mat i j " " System.out.print(mat[i][c] + "\n") System.out.print System.out System System.out mat[i][c] + "\n" mat[i][c] mat[i] mat i c "\n" String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	}

} Main
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int r = sc.nextInt();
		int c = sc.nextInt();
		sc.nextLine();

		int[][] mat = new int[r+1][c+1];

		for (int i=0; i < r; i++) {

			String[] data = sc.nextLine().split(" ");

			for (int j=0; j < c; j++) {
				mat[i][j] = Integer.parseInt(data[j]);

				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
			}
			mat[r][c] += mat[i][c];

		}

		for (int i=0; i<r+1; i++) {

			for (int j=0; j<c; j++) {
				System.out.print(mat[i][j] + " ");
			}
			System.out.print(mat[i][c] + "\n");

		}
	}

}