import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] token = br.readLine().split(" ");
		int row = Integer.parseInt(token[0]);
		int col = Integer.parseInt(token[1]);
		int[][] table = new int[row + 1][col + 1];

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

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		}

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

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		}

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

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		}

		for(int i = 0; i <= row; i++){
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		}

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] token = br.readLine().split(" ");
		int row = Integer.parseInt(token[0]);
		int col = Integer.parseInt(token[1]);
		int[][] table = new int[row + 1][col + 1];

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

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		}

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

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		}

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

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		}

		for(int i = 0; i <= row; i++){
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		}

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] token = br.readLine().split(" ");
		int row = Integer.parseInt(token[0]);
		int col = Integer.parseInt(token[1]);
		int[][] table = new int[row + 1][col + 1];

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

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		}

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

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		}

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

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		}

		for(int i = 0; i <= row; i++){
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		}

	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] token = br.readLine().split(" ");
		int row = Integer.parseInt(token[0]);
		int col = Integer.parseInt(token[1]);
		int[][] table = new int[row + 1][col + 1];

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

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		}

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

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		}

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

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		}

		for(int i = 0; i <= row; i++){
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		}

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] token = br.readLine().split(" "); token br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int row = Integer.parseInt(token[0]); row Integer.parseInt(token[0]) Integer.parseInt Integer token[0] token 0 int col = Integer.parseInt(token[1]); col Integer.parseInt(token[1]) Integer.parseInt Integer token[1] token 1 int[][] table = new int[row + 1][col + 1]; table new int[row + 1][col + 1] row + 1 row 1 col + 1 col 1 for(int i = 0; i < row; i++){

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

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

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		} {

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		} token = br.readLine().split(" ") token br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			} int j = 0; int j = 0; j 0 j < col j col j++ j++ j {
				table[i][j] = Integer.parseInt(token[j]);
			} {
				table[i][j] = Integer.parseInt(token[j]);
			} table[i][j] = Integer.parseInt(token[j]) table[i][j] table[i] table i j Integer.parseInt(token[j]) Integer.parseInt Integer token[j] token j for(int i = 0; i < row; i++){

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

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

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		} {

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		} int sum = 0; sum 0 for(int j = 0; j < col; j++){
				sum += table[i][j];
			} int j = 0; int j = 0; j 0 j < col j col j++ j++ j {
				sum += table[i][j];
			} {
				sum += table[i][j];
			} sum += table[i][j] sum table[i][j] table[i] table i j table[i][col] = sum table[i][col] table[i] table i col sum for(int i = 0; i <= col; i++){

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

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

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		} {

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		} int sum = 0; sum 0 for(int j = 0; j < row; j++){
				sum += table[j][i];
			} int j = 0; int j = 0; j 0 j < row j row j++ j++ j {
				sum += table[j][i];
			} {
				sum += table[j][i];
			} sum += table[j][i] sum table[j][i] table[j] table j i table[row][i] = sum table[row][i] table[row] table row i sum for(int i = 0; i <= row; i++){
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		} int i = 0; int i = 0; i 0 i <= row i row i++ i++ i {
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		} {
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		} for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			} int j = 0; int j = 0; j 0 j <= col j col j++ j++ j {

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			} {

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			} System.out.print(table[i][j]) System.out.print System.out System System.out table[i][j] table[i] table i j if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				} j != col j col {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " {
					System.out.print("\n");
				} System.out.print("\n") System.out.print System.out System System.out "\n" String[] args args
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] token = br.readLine().split(" ");
		int row = Integer.parseInt(token[0]);
		int col = Integer.parseInt(token[1]);
		int[][] table = new int[row + 1][col + 1];

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

			token = br.readLine().split(" ");

			for(int j = 0; j < col; j++){
				table[i][j] = Integer.parseInt(token[j]);
			}

		}

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

			int sum = 0;

			for(int j = 0; j < col; j++){
				sum += table[i][j];
			}

			table[i][col] = sum;

		}

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

			int sum = 0;

			for(int j = 0; j < row; j++){
				sum += table[j][i];
			}

			table[row][i] = sum;

		}

		for(int i = 0; i <= row; i++){
			for(int j = 0; j <= col; j++){

				System.out.print(table[i][j]);

				if(j != col){
					System.out.print(" ");
				}else{
					System.out.print("\n");
				}

			}
		}

	}
}