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

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} Main public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	} main {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	} try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String input = reader.readLine(); input reader.readLine() reader.readLine reader String[] array = input.split(" "); array input.split(" ") input.split input " " int r = Integer.parseInt(array[0]); r Integer.parseInt(array[0]) Integer.parseInt Integer array[0] array 0 int c = Integer.parseInt(array[1]); c Integer.parseInt(array[1]) Integer.parseInt Integer array[1] array 1 int[][] cell = new int[r][c]; cell new int[r][c] r c for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			} {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			} input = reader.readLine() input reader.readLine() reader.readLine reader array = input.split(" ") array input.split(" ") input.split input " " for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
					cell[i][j] = Integer.parseInt(array[j]);
				} {
					cell[i][j] = Integer.parseInt(array[j]);
				} cell[i][j] = Integer.parseInt(array[j]) cell[i][j] cell[i] cell i j Integer.parseInt(array[j]) Integer.parseInt Integer array[j] array j int sumRow = 0; sumRow 0 int sumCol[] = new int[c + 1]; sumCol new int[c + 1] c + 1 c 1 int sum = 0; sum 0 for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			} int k = 0; int k = 0; k 0 k < r k r k++ k++ k {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			} {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			} for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				} int l = 0; int l = 0; l 0 l < c l c l++ l++ l {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				} {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				} System.out.print(cell[k][l] + " ") System.out.print System.out System System.out cell[k][l] + " " cell[k][l] cell[k] cell k l " " sumRow += cell[k][l] sumRow cell[k][l] cell[k] cell k l sumCol[l] += cell[k][l] sumCol[l] sumCol l cell[k][l] cell[k] cell k l System.out.println(sumRow) System.out.println System.out System System.out sumRow sum += sumRow sum sumRow sumRow = 0 sumRow 0 for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			} int m = 0; int m = 0; m 0 m < c m c m++ m++ m {
				System.out.print(sumCol[m] + " ");
			} {
				System.out.print(sumCol[m] + " ");
			} System.out.print(sumCol[m] + " ") System.out.print System.out System System.out sumCol[m] + " " sumCol[m] sumCol m " " System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

} public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

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

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}