import java.util.Scanner;

//20180510
//01

public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    }
} Main public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    } main {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int[][] output = new int[100+1][100+1]; output new int[100+1][100+1] 100+1 100 1 100+1 100 1 for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		} {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		} int ans_r = 0; ans_r 0 for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			} {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			} output[i][j] = scanner.nextInt() output[i][j] output[i] output i j scanner.nextInt() scanner.nextInt scanner ans_r += output[i][j] ans_r output[i][j] output[i] output i j output[r][j] += output[i][j] output[r][j] output[r] output r j output[i][j] output[i] output i j output[i][c] += ans_r output[i][c] output[i] output i c ans_r for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		} int y = 0; int y = 0; y 0 y < c y c y++ y++ y {
			output[r][c] += output[r][y];
		} {
			output[r][c] += output[r][y];
		} output[r][c] += output[r][y] output[r][c] output[r] output r c output[r][y] output[r] output r y scanner.close() scanner.close scanner for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		} {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		} for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
					System.out.printf("%d ",output[i][j]);
			} {
					System.out.printf("%d ",output[i][j]);
			} System.out.printf("%d ",output[i][j]) System.out.printf System.out System System.out "%d " output[i][j] output[i] output i j System.out.println(output[i][c]) System.out.println System.out System System.out output[i][c] output[i] output i c String[] args args public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    }
} public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    }
} Main
import java.util.Scanner;

//20180510
//01

public class Main {
    public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] output = new int[100+1][100+1];

		for(int i = 0;i < r;i++) {
			int ans_r = 0;
			for(int j = 0;j < c;j++) {
				output[i][j] = scanner.nextInt();
				ans_r += output[i][j];
				output[r][j] += output[i][j];
			}
			output[i][c] += ans_r;
		}

		for(int y = 0;y < c;y++) {
			output[r][c] += output[r][y];
		}

		scanner.close();

		for(int i = 0;i <= r;i++) {
			for(int j = 0;j < c;j++) {
					System.out.printf("%d ",output[i][j]);
			}
			System.out.println(output[i][c]);
		}
    }
}
