import java.util.*;

class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		final String[] len = sc.nextLine().split(" ");
		final int r = Integer.parseInt(len[0]);
		final int c = Integer.parseInt(len[1]);
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[][] mat = new int[r + 1][c + 1];
		
		for(int i = 0; i < r; i++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		}
		for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		}
		sb.append(mat[r][c]).append(lb);
		System.out.print(sb.toString());
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		final String[] len = sc.nextLine().split(" ");
		final int r = Integer.parseInt(len[0]);
		final int c = Integer.parseInt(len[1]);
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[][] mat = new int[r + 1][c + 1];
		
		for(int i = 0; i < r; i++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		}
		for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		}
		sb.append(mat[r][c]).append(lb);
		System.out.print(sb.toString());
	}
} Main public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		final String[] len = sc.nextLine().split(" ");
		final int r = Integer.parseInt(len[0]);
		final int c = Integer.parseInt(len[1]);
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[][] mat = new int[r + 1][c + 1];
		
		for(int i = 0; i < r; i++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		}
		for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		}
		sb.append(mat[r][c]).append(lb);
		System.out.print(sb.toString());
	} main {
		
		Scanner sc = new Scanner(System.in);
		
		final String[] len = sc.nextLine().split(" ");
		final int r = Integer.parseInt(len[0]);
		final int c = Integer.parseInt(len[1]);
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[][] mat = new int[r + 1][c + 1];
		
		for(int i = 0; i < r; i++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		}
		for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		}
		sb.append(mat[r][c]).append(lb);
		System.out.print(sb.toString());
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final String[] len = sc.nextLine().split(" "); len sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " final int r = Integer.parseInt(len[0]); r Integer.parseInt(len[0]) Integer.parseInt Integer len[0] len 0 final int c = Integer.parseInt(len[1]); c Integer.parseInt(len[1]) Integer.parseInt Integer len[1] len 1 StringBuilder sb = new StringBuilder(); sb new StringBuilder() final String lb = System.getProperty("line.separator"); lb System.getProperty("line.separator") System.getProperty System "line.separator" 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++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		} {
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		} final String[] col = sc.nextLine().split(" "); col sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			} {
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			} mat[i][j] = Integer.parseInt(col[j]) mat[i][j] mat[i] mat i j Integer.parseInt(col[j]) Integer.parseInt Integer col[j] col 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 sb.append(col[j]).append(" ") sb.append(col[j]).append sb.append(col[j]) sb.append sb col[j] col j " " sb.append(mat[i][c]).append(lb) sb.append(mat[i][c]).append sb.append(mat[i][c]) sb.append sb mat[i][c] mat[i] mat i c lb for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		} {
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		} sb.append(mat[r][i]).append(" ") sb.append(mat[r][i]).append sb.append(mat[r][i]) sb.append sb mat[r][i] mat[r] mat r i " " mat[r][c] += mat[r][i] mat[r][c] mat[r] mat r c mat[r][i] mat[r] mat r i sb.append(mat[r][c]).append(lb) sb.append(mat[r][c]).append sb.append(mat[r][c]) sb.append sb mat[r][c] mat[r] mat r c lb System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args
import java.util.*;

class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		final String[] len = sc.nextLine().split(" ");
		final int r = Integer.parseInt(len[0]);
		final int c = Integer.parseInt(len[1]);
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[][] mat = new int[r + 1][c + 1];
		
		for(int i = 0; i < r; i++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		}
		for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		}
		sb.append(mat[r][c]).append(lb);
		System.out.print(sb.toString());
	}
}