import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int gyou = sc.nextInt(); gyou sc.nextInt() sc.nextInt sc int retu = sc.nextInt(); retu sc.nextInt() sc.nextInt sc int[][] hyou = new int[gyou][retu]; hyou new int[gyou][retu] gyou retu for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < hyou.length i hyou.length hyou hyou.length i++ i++ i {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		} {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		} for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < hyou[i].length j hyou[i].length hyou[i] hyou i hyou[i].length j++ j++ j {
				hyou[i][j] = sc.nextInt();
			} {
				hyou[i][j] = sc.nextInt();
			} hyou[i][j] = sc.nextInt() hyou[i][j] hyou[i] hyou i j sc.nextInt() sc.nextInt sc int[] gyousum = new int[gyou]; gyousum new int[gyou] gyou int[] retusum = new int[retu]; retusum new int[retu] retu for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		} int i = 0; int i = 0; i 0 i < hyou.length i hyou.length hyou hyou.length i++ i++ i {
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		} {
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		} for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			} int j  = 0; int j  = 0; j 0 j < hyou[i].length j hyou[i].length hyou[i] hyou i hyou[i].length j++ j++ j {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			} {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			} gyousum[i] += hyou[i][j] gyousum[i] gyousum i hyou[i][j] hyou[i] hyou i j retusum[j] += hyou[i][j] retusum[j] retusum j hyou[i][j] hyou[i] hyou i j for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		} int i = 0; int i = 0; i 0 i < hyou.length i hyou.length hyou hyou.length i++ i++ i {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		} {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		} for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			} int j = 0; int j = 0; j 0 j < hyou[i].length j hyou[i].length hyou[i] hyou i hyou[i].length j++ j++ j {
				System.out.print(hyou[i][j] + " ");
			} {
				System.out.print(hyou[i][j] + " ");
			} System.out.print(hyou[i][j] + " ") System.out.print System.out System System.out hyou[i][j] + " " hyou[i][j] hyou[i] hyou i j " " System.out.println(gyousum[i]) System.out.println System.out System System.out gyousum[i] gyousum i int sum = 0; sum 0 for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		} int i = 0; int i = 0; i 0 i < retusum.length i retusum.length retusum retusum.length i++ i++ i {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		} {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		} System.out.print(retusum[i] + " ") System.out.print System.out System System.out retusum[i] + " " retusum[i] retusum i " " sum += retusum[i] sum retusum[i] retusum i System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();

		int[][] hyou = new int[gyou][retu];

		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length;j++) {
				hyou[i][j] = sc.nextInt();
			}
		}

		int[] gyousum = new int[gyou];
		int[] retusum = new int[retu];
		for(int i = 0;i < hyou.length;i++ ){
			for(int j  = 0;j < hyou[i].length;j++) {
				gyousum[i] += hyou[i][j];
				retusum[j] += hyou[i][j];
			}
		}
		for(int i = 0;i < hyou.length;i++) {
			for(int j = 0;j < hyou[i].length; j++) {
				System.out.print(hyou[i][j] + " ");
			}
			System.out.println(gyousum[i]);
		}
		int sum = 0;
		for(int i = 0;i < retusum.length;i++) {
			System.out.print(retusum[i] + " ");
			sum += retusum[i];
		}
		System.out.println(sum);
	}
}