import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	} main {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int r= stdIn.nextInt(); r stdIn.nextInt() stdIn.nextInt stdIn int c= stdIn.nextInt(); c stdIn.nextInt() stdIn.nextInt stdIn int x[][] = new int[r+1][c+1]; x new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		} {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		} for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			} {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			} x[i][j] = stdIn.nextInt() x[i][j] x[i] x i j stdIn.nextInt() stdIn.nextInt stdIn x[i][c] +=x[i][j] x[i][c] x[i] x i c x[i][j] x[i] x i j x[r][j] +=x[i][j] x[r][j] x[r] x r j x[i][j] x[i] x i j x[r][c] +=x[i][j] x[r][c] x[r] x r c x[i][j] x[i] x i j stdIn.close() stdIn.close stdIn for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		} 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++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		} {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		} for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			} {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			} System.out.print(x[i][j]) System.out.print System.out System System.out x[i][j] x[i] x i j if (j<c) {
					System.out.print(" ");
				} j<c j c {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r= stdIn.nextInt();
		int c= stdIn.nextInt();
		int x[][] = new int[r+1][c+1];
		for(int i=0;i<r; i++) {
			for(int j=0;j<c; j++) {
				x[i][j] = stdIn.nextInt();
				x[i][c] +=x[i][j];
				x[r][j] +=x[i][j];
				x[r][c] +=x[i][j];
			}
		}
		stdIn.close();
		for(int i=0;i<r+1; i++) {
			for(int j=0;j<c+1; j++) {
				System.out.print(x[i][j]);
				if (j<c) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

