import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r, c, i, j, sum1;
		r = stdIn.nextInt();
		c = stdIn.nextInt();
		int[][] a = new int[r][c];
		int[] sum = new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		}
		for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		}
		sum1=0;
		for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		}
		stdIn.close();
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r, c, i, j, sum1;
		r = stdIn.nextInt();
		c = stdIn.nextInt();
		int[][] a = new int[r][c];
		int[] sum = new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		}
		for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		}
		sum1=0;
		for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		}
		stdIn.close();
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r, c, i, j, sum1;
		r = stdIn.nextInt();
		c = stdIn.nextInt();
		int[][] a = new int[r][c];
		int[] sum = new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		}
		for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		}
		sum1=0;
		for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		}
		stdIn.close();
	} main {
		Scanner stdIn = new Scanner(System.in);
		int r, c, i, j, sum1;
		r = stdIn.nextInt();
		c = stdIn.nextInt();
		int[][] a = new int[r][c];
		int[] sum = new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		}
		for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		}
		sum1=0;
		for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		}
		stdIn.close();
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int r r c c i i j j sum1; sum1 r = stdIn.nextInt() r stdIn.nextInt() stdIn.nextInt stdIn c = stdIn.nextInt() c stdIn.nextInt() stdIn.nextInt stdIn int[][] a = new int[r][c]; a new int[r][c] r c int[] sum = new int[c]; sum new int[c] c for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		} i = 0; i = 0 i 0 i < r i r i++ i++ i {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		} {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		} for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			} j = 0; j = 0 j 0 j < c j c j++ j++ j {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			} {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			} a[i][j] = stdIn.nextInt() a[i][j] a[i] a i j stdIn.nextInt() stdIn.nextInt stdIn sum[j] += a[i][j] sum[j] sum j a[i][j] a[i] a i j for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		} i = 0; i = 0 i 0 i < r i r i++ i++ i {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		} {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		} sum1 = 0 sum1 0 for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			} j = 0; j = 0 j 0 j < c j c j++ j++ j {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			} {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			} System.out.print(a[i][j] + " ") System.out.print System.out System System.out a[i][j] + " " a[i][j] a[i] a i j " " sum1 += a[i][j] sum1 a[i][j] a[i] a i j System.out.println(sum1) System.out.println System.out System System.out sum1 sum1=0 sum1 0 for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		} j = 0; j = 0 j 0 j < c j c j++ j++ j {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		} {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		} System.out.print(sum[j] + " ") System.out.print System.out System System.out sum[j] + " " sum[j] sum j " " sum1 += sum[j] sum1 sum[j] sum j if(j==c-1){
				System.out.println(sum1);
			} j==c-1 j c-1 c 1 {
				System.out.println(sum1);
			} System.out.println(sum1) System.out.println System.out System System.out sum1 stdIn.close() stdIn.close stdIn String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r, c, i, j, sum1;
		r = stdIn.nextInt();
		c = stdIn.nextInt();
		int[][] a = new int[r][c];
		int[] sum = new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		}
		for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		}
		sum1=0;
		for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		}
		stdIn.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r, c, i, j, sum1;
		r = stdIn.nextInt();
		c = stdIn.nextInt();
		int[][] a = new int[r][c];
		int[] sum = new int[c];
		for (i = 0; i < r; i++) {
			for (j = 0; j < c; j++) {
				a[i][j] = stdIn.nextInt();
				sum[j] += a[i][j];
			}
		}
		for (i = 0; i < r; i++) {
			sum1 = 0;
			for (j = 0; j < c; j++) {
				System.out.print(a[i][j] + " ");
				sum1 += a[i][j];
			}
			System.out.println(sum1);
		}
		sum1=0;
		for (j = 0; j < c; j++) {
			System.out.print(sum[j] + " ");
			sum1 += sum[j];
			if(j==c-1){
				System.out.println(sum1);
			}
		}
		stdIn.close();
	}
} Main
import java.util.Scanner;

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

