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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	}

	static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	}
	
	static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
} 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) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	}

	static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	}
	
	static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int[] arr = parceIntArray(br.readLine().split(" ")); arr parceIntArray(br.readLine().split(" ")) parceIntArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = arr[0]; r arr[0] arr 0 int c = arr[1]; c arr[1] arr 1 int[][] sheet = new int[r + 1][c + 1]; sheet new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		} {
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		} arr = parceIntArray(br.readLine().split(" ")) arr parceIntArray(br.readLine().split(" ")) parceIntArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			} int j = 0; int j = 0; j 0 j < arr.length j arr.length arr arr.length j++ j++ j {
				sheet[i][j] = arr[j];
			} {
				sheet[i][j] = arr[j];
			} sheet[i][j] = arr[j] sheet[i][j] sheet[i] sheet i j arr[j] arr j arr = null arr null for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		} {
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		} for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				sheet[i][c] += sheet[i][j];
			} {
				sheet[i][c] += sheet[i][j];
			} sheet[i][c] += sheet[i][j] sheet[i][c] sheet[i] sheet i c sheet[i][j] sheet[i] sheet i j for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		} int i = 0; int i = 0; i 0 i < c + 1 i c + 1 c 1 i++ i++ i {
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		} {
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		} for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				sheet[r][i] +=  sheet[j][i];
			} {
				sheet[r][i] +=  sheet[j][i];
			} sheet[r][i] +=  sheet[j][i] sheet[r][i] sheet[r] sheet r i sheet[j][i] sheet[j] sheet j i for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			write(sheet[i]);
		} {
			write(sheet[i]);
		} write(sheet[i]) write sheet[i] sheet i String[] args args static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	} parceIntArray {
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	} int[] arr = new int[strArr.length]; arr new int[strArr.length] strArr.length strArr strArr.length for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		} int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {
			arr[i] = Integer.parseInt(strArr[i]);
		} {
			arr[i] = Integer.parseInt(strArr[i]);
		} arr[i] = Integer.parseInt(strArr[i]) arr[i] arr i Integer.parseInt(strArr[i]) Integer.parseInt Integer strArr[i] strArr i return arr; arr String[] strArr strArr static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	} write {
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		} int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		} {
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		} sb.append(arr[i]) sb.append sb arr[i] arr i if(i >= arr.length - 1){
				break;
			} i >= arr.length - 1 i arr.length - 1 arr.length arr arr.length 1 {
				break;
			} break; sb.append(" ") sb.append sb " " System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb int[] arr arr public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	}

	static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	}
	
	static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	}

	static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	}
	
	static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arr = parceIntArray(br.readLine().split(" "));
		int r = arr[0];
		int c = arr[1];
		int[][] sheet = new int[r + 1][c + 1];
		for(int i = 0;i < r;i++){
			arr = parceIntArray(br.readLine().split(" "));
			for(int j = 0;j < arr.length;j++){
				sheet[i][j] = arr[j];
			}
		}
		arr = null;
		for(int i = 0;i < r;i++){
			for(int j = 0;j < c;j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		for(int i = 0;i < c + 1;i++){
			for(int j = 0;j < r;j++){
				sheet[r][i] +=  sheet[j][i];
			}
		}
		for(int i = 0;i < r + 1;i++){
			write(sheet[i]);
		}
	}

	static int[] parceIntArray(String[] strArr){
		int[] arr = new int[strArr.length];
		for(int i = 0;i < arr.length;i++){
			arr[i] = Integer.parseInt(strArr[i]);
		}
		return arr;
	}
	
	static void write(int[] arr){
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < arr.length;i++){
			sb.append(arr[i]);
			if(i >= arr.length - 1){
				break;
			}
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
}