import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int r, c, num, ssum = 0,total=0;
		int i, j;
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		int[] vsum=new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		}
		for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		}
		System.out.println(total);

	}

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

	}

} Main public static void main(String[] args) {
		int r, c, num, ssum = 0,total=0;
		int i, j;
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		int[] vsum=new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		}
		for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		}
		System.out.println(total);

	} main {
		int r, c, num, ssum = 0,total=0;
		int i, j;
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		int[] vsum=new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		}
		for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		}
		System.out.println(total);

	} int r r c c num num ssum = 0 ssum 0 total=0; total 0 int i i j; j Scanner scan = new Scanner(System.in); scan new Scanner(System.in) r = scan.nextInt() r scan.nextInt() scan.nextInt scan c = scan.nextInt() c scan.nextInt() scan.nextInt scan int[] vsum=new int[c]; vsum new int[c] c for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		} i = 0; i = 0 i 0 i < r i r i++ i++ i {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		} {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		} for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			} j = 0; j = 0 j 0 j < c j c j++ j++ j {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			} {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			} num = scan.nextInt() num scan.nextInt() scan.nextInt scan ssum += num ssum num vsum[j]+=num vsum[j] vsum j num System.out.print(num+" ") System.out.print System.out System System.out num+" " num " " System.out.println(ssum) System.out.println System.out System System.out ssum total+=ssum total ssum ssum=0 ssum 0 for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		} i=0; i=0 i 0 i<c i c i++ i++ i {
			System.out.print(vsum[i]+" ");
		} {
			System.out.print(vsum[i]+" ");
		} System.out.print(vsum[i]+" ") System.out.print System.out System System.out vsum[i]+" " vsum[i] vsum i " " System.out.println(total) System.out.println System.out System System.out total String[] args args public class Main {
	public static void main(String[] args) {
		int r, c, num, ssum = 0,total=0;
		int i, j;
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		int[] vsum=new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		}
		for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		}
		System.out.println(total);

	}

} public class Main {
	public static void main(String[] args) {
		int r, c, num, ssum = 0,total=0;
		int i, j;
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		int[] vsum=new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		}
		for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		}
		System.out.println(total);

	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int r, c, num, ssum = 0,total=0;
		int i, j;
		Scanner scan = new Scanner(System.in);
		r = scan.nextInt();
		c = scan.nextInt();
		int[] vsum=new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				num = scan.nextInt();
				ssum += num;
				vsum[j]+=num;
				System.out.print(num+" ");
			}
			System.out.println(ssum);
			total+=ssum;
			ssum=0;
		}
		for(i=0;i<c;i++) {
			System.out.print(vsum[i]+" ");
		}
		System.out.println(total);

	}

}