import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	}
} import java.util.*; util.* java public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	}
} Main private static final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	} main {
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	} int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int[][] sheet = new int[r + 1][c + 1]; sheet new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 int sum = 0; sum 0 for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][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][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		} {
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		} for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			} {
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			} sheet[i][j] = scan.nextInt() sheet[i][j] sheet[i] sheet i j scan.nextInt() scan.nextInt scan sum += sheet[i][j] sum sheet[i][j] sheet[i] sheet i j sheet[r][j] += sheet[i][j] sheet[r][j] sheet[r] sheet r j sheet[i][j] sheet[i] 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 sheet[r][c] = sum sheet[r][c] sheet[r] sheet r c sum for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		} {
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		} for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			} {
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			} if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				} j != c j c {
					System.out.printf("%d ", sheet[i][j]);
				} System.out.printf("%d ", sheet[i][j]) System.out.printf System.out System System.out "%d " sheet[i][j] sheet[i] sheet i j {
					System.out.printf("%d\n", sheet[i][j]);
				} System.out.printf("%d\n", sheet[i][j]) System.out.printf System.out System System.out "%d\n" sheet[i][j] sheet[i] sheet i j String[] args args public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	}
} public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	}
} Main
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] sheet = new int[r + 1][c + 1];
		int sum = 0;
		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				sheet[i][j] = scan.nextInt();
				sum += sheet[i][j];
				sheet[r][j] += sheet[i][j];
				sheet[i][c] += sheet[i][j];
			}
		}
		sheet[r][c] = sum;

		for(int i = 0; i < r + 1; i++){
			for(int j = 0; j < c + 1; j++){
				if(j != c){
					System.out.printf("%d ", sheet[i][j]);
				} else{
					System.out.printf("%d\n", sheet[i][j]);
				}
			}
		}
	}
}