import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	} main {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int[][] Aay_rc; Aay_rc Aay_rc = new int[r][c] Aay_rc new int[r][c] r c for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				Aay_rc[i][j] = scan.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				Aay_rc[i][j] = scan.nextInt();
			}
		} {
			for (int j = 0; j < c; j++) {
				Aay_rc[i][j] = scan.nextInt();
			}
		} for (int j = 0; j < c; j++) {
				Aay_rc[i][j] = scan.nextInt();
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				Aay_rc[i][j] = scan.nextInt();
			} {
				Aay_rc[i][j] = scan.nextInt();
			} Aay_rc[i][j] = scan.nextInt() Aay_rc[i][j] Aay_rc[i] Aay_rc i j scan.nextInt() scan.nextInt scan for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				System.out.print(Aay_rc[i][j] + " ");
			}

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		} {
			for (int j = 0; j < c; j++) {
				System.out.print(Aay_rc[i][j] + " ");
			}

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		} for (int j = 0; j < c; j++) {
				System.out.print(Aay_rc[i][j] + " ");
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				System.out.print(Aay_rc[i][j] + " ");
			} {
				System.out.print(Aay_rc[i][j] + " ");
			} System.out.print(Aay_rc[i][j] + " ") System.out.print System.out System System.out Aay_rc[i][j] + " " Aay_rc[i][j] Aay_rc[i] Aay_rc i j " " int sum_r = 0; sum_r 0 for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			} int k = 0; int k = 0; k 0 k < c k c k++ k++ k {
				sum_r = sum_r + Aay_rc[i][k];
			} {
				sum_r = sum_r + Aay_rc[i][k];
			} sum_r = sum_r + Aay_rc[i][k] sum_r sum_r + Aay_rc[i][k] sum_r Aay_rc[i][k] Aay_rc[i] Aay_rc i k System.out.println(sum_r) System.out.println System.out System System.out sum_r int sum_all = 0; sum_all 0 for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		} int L = 0; int L = 0; L 0 L < c L c L++ L++ L {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		} {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		} int sum_c = 0; sum_c 0 for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			} int m = 0; int m = 0; m 0 m < r m r m++ m++ m {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			} {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			} sum_c = sum_c + Aay_rc[m][L] sum_c sum_c + Aay_rc[m][L] sum_c Aay_rc[m][L] Aay_rc[m] Aay_rc m L sum_all = sum_all + Aay_rc[m][L] sum_all sum_all + Aay_rc[m][L] sum_all Aay_rc[m][L] Aay_rc[m] Aay_rc m L System.out.print(sum_c + " ") System.out.print System.out System System.out sum_c + " " sum_c " " System.out.println(sum_all) System.out.println System.out System System.out sum_all String[] args args public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	}
} public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] Aay_rc;
		Aay_rc = new int[r][c];

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

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

			int sum_r = 0;
			for (int k = 0; k < c; k++) {
				sum_r = sum_r + Aay_rc[i][k];
			}
			System.out.println(sum_r);
		}

		int sum_all = 0;
		for (int L = 0; L < c; L++) {
			int sum_c = 0;
			for (int m = 0; m < r; m++) {
				sum_c = sum_c + Aay_rc[m][L];
				sum_all = sum_all + Aay_rc[m][L];
			}
			System.out.print(sum_c + " ");
		}
		System.out.println(sum_all);
	}
}