import java.util.Scanner;


public class Main{

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

	}

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

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

	}

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

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

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

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

	}

} public class Main{

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

	}

} Main
import java.util.Scanner;


public class Main{

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

	}

}