import java.util.Scanner;

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

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

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

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

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

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c; j++) {
				System.out.print(sum[i][j] + " ");
			}
			System.out.println(sum[i][c]);
		}
	} main {
		Scanner scn = new Scanner(System.in);
		int r = scn.nextInt();
		int c = scn.nextInt();
		int[][] sum = new int[r + 1][c + 1];

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

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

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

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

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c; j++) {
				System.out.print(sum[i][j] + " ");
			}
			System.out.println(sum[i][c]);
		}
	}
} Main
import java.util.Scanner;

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

		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][j] = scn.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				sum[i][c] += sum[i][j];
				sum[r][j] += sum[i][j];
			}
			sum[r][c] += sum[i][c];
		}

		for (int i = 0; i < r + 1; i++) {
			for (int j = 0; j < c; j++) {
				System.out.print(sum[i][j] + " ");
			}
			System.out.println(sum[i][c]);
		}
	}
}

