import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] kari = line.split(" "); kari line.split(" ") line.split line " " int r = Integer.parseInt(kari[0]); r Integer.parseInt(kari[0]) Integer.parseInt Integer kari[0] kari 0 int c = Integer.parseInt(kari[1]); c Integer.parseInt(kari[1]) Integer.parseInt Integer kari[1] kari 1 int bigsum = 0; bigsum 0 int[] sum2 = new int[c]; sum2 new int[c] c for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		} {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		} String s = sc.nextLine(); s sc.nextLine() sc.nextLine sc String[] k = s.split(" "); k s.split(" ") s.split s " " int[] in = new int[c]; in new int[c] c int[] za = new int[2]; za new int[2] 2 int sum1 = 0; sum1 0 for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			} {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			} in[j] = Integer.parseInt(k[j]) in[j] in j Integer.parseInt(k[j]) Integer.parseInt Integer k[j] k j System.out.print(in[j]) System.out.print System.out System System.out in[j] in j System.out.print(" ") System.out.print System.out System System.out " " sum1 += in[j] sum1 in[j] in j sum2[j] += in[j] sum2[j] sum2 j in[j] in j System.out.println(sum1) System.out.println System.out System System.out sum1 bigsum += sum1 bigsum sum1 for (int i = 0; i < c; i++) {
			System.out.print(sum2[i]);
			System.out.print(" ");
		} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
			System.out.print(sum2[i]);
			System.out.print(" ");
		} {
			System.out.print(sum2[i]);
			System.out.print(" ");
		} System.out.print(sum2[i]) System.out.print System.out System System.out sum2[i] sum2 i System.out.print(" ") System.out.print System.out System System.out " " System.out.println(bigsum) System.out.println System.out System System.out bigsum String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] kari = line.split(" ");
		int r = Integer.parseInt(kari[0]);
		int c = Integer.parseInt(kari[1]);

		int bigsum = 0;

		int[] sum2 = new int[c];

		for (int i = 0; i < r; i++) {
			String s = sc.nextLine();
			String[] k = s.split(" ");
			int[] in = new int[c];
			int[] za = new int[2];
			int sum1 = 0;
			for (int j = 0; j < c; j++) {
				in[j] = Integer.parseInt(k[j]);
				System.out.print(in[j]);
				System.out.print(" ");

				sum1 += in[j];
				sum2[j] += in[j];
			}
			System.out.println(sum1);
			bigsum += sum1;
		}

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

		System.out.println(bigsum);

	}

}