

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	}

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

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	}

} Main public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	} main {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int line = in.nextInt(); line in.nextInt() in.nextInt in int column = in.nextInt(); column in.nextInt() in.nextInt in int[][] matrix = new int[line + 1][column + 1]; matrix new int[line + 1][column + 1] line + 1 line 1 column + 1 column 1 for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		} int l = 0; int l = 0; l 0 l < line l line l++ l++ l {

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		} {

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		} for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			} int c = 0; int c = 0; c 0 c < column c column c++ c++ c {

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			} {

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			} matrix[l][c] = in.nextInt() matrix[l][c] matrix[l] matrix l c in.nextInt() in.nextInt in matrix[l][column] += matrix[l][c] matrix[l][column] matrix[l] matrix l column matrix[l][c] matrix[l] matrix l c for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		} int c = 0; int c = 0; c 0 c < column c column c++ c++ c {

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		} {

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		} for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			} int l = 0; int l = 0; l 0 l < line l line l++ l++ l {

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			} {

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			} matrix[line][c] += matrix[l][c] matrix[line][c] matrix[line] matrix line c matrix[l][c] matrix[l] matrix l c matrix[line][column] += matrix[l][c] matrix[line][column] matrix[line] matrix line column matrix[l][c] matrix[l] matrix l c for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		} int l = 0; int l = 0; l 0 l <= line l line l++ l++ l {

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		} {

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		} for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			} int c = 0; int c = 0; c 0 c < column c column c++ c++ c {

				System.out.print(matrix[l][c] + " ");

			} {

				System.out.print(matrix[l][c] + " ");

			} System.out.print(matrix[l][c] + " ") System.out.print System.out System System.out matrix[l][c] + " " matrix[l][c] matrix[l] matrix l c " " System.out.println(matrix[l][column]) System.out.println System.out System System.out matrix[l][column] matrix[l] matrix l column String[] args args public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	}

} public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	}

} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		// ?????°??¨?????°?????????
		int line = in.nextInt();
		int column = in.nextInt();

		// ????????????????´??????????????????¨???
		int[][] matrix = new int[line + 1][column + 1];

		// ?????????????????????????´?
		for(int l = 0; l < line; l++){

			for(int c = 0; c < column; c++){

				matrix[l][c] = in.nextInt();

				matrix[l][column] += matrix[l][c];

			}
		}

		for(int c = 0; c < column; c++){

			for(int l = 0; l < line; l++){

				matrix[line][c] += matrix[l][c];

				matrix[line][column] += matrix[l][c];

			}

		}

		// ???????????????????????????
		for(int l = 0; l <= line; l++){

			for(int c = 0; c < column; c++){

				System.out.print(matrix[l][c] + " ");

			}

			System.out.println(matrix[l][column]);

		}

	}

}