import java.util.Scanner;


public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	}

} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	} main {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r r c c i=0 i 0 j=0 j 0 d=0; d 0 int sum=0; sum 0 r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc int table[][] = new int[r+1][c+1]; table new int[r+1][c+1] r+1 r 1 c+1 c 1 for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		} i=0; i=0 i 0 i<r i r i++ i++ i {
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		} {
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		} sum = 0 sum 0 for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			} j=0; j=0 j 0 j<c j c j++ j++ j {
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			} {
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			} table[i][j] = sc.nextInt() table[i][j] table[i] table i j sc.nextInt() sc.nextInt sc sum += table[i][j] sum table[i][j] table[i] table i j table[i][j] = sum table[i][j] table[i] table i j sum d += sum d sum for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		} i=0; i=0 i 0 i<c i c i++ i++ i {
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		} {
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		} sum = 0 sum 0 for(j=0;j<r;j++){
				sum += table[j][i];
			} j=0; j=0 j 0 j<r j r j++ j++ j {
				sum += table[j][i];
			} {
				sum += table[j][i];
			} sum += table[j][i] sum table[j][i] table[j] table j i table[j][i] = sum table[j][i] table[j] table j i sum table[j][i] = d table[j][i] table[j] table j i d for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		} i=0; i=0 i 0 i<=r i r i++ i++ i {
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		} {
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		} for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			} j=0; j=0 j 0 j<=c j c j++ j++ j {
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			} {
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			} System.out.print(table[i][j]) System.out.print System.out System System.out table[i][j] table[i] table i j if(c == j){
					break;
				} c == j c j {
					break;
				} break; System.out.print(" ") System.out.print System.out System System.out " " if(i<=r){
				System.out.println();
			} i<=r i r {
				System.out.println();
			} System.out.println() System.out.println System.out System System.out sc.close() sc.close sc String[] args args public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	}

} public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	}

} Main
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int r,c,i=0,j=0,d=0;
		int sum=0;

		r = sc.nextInt();
		c = sc.nextInt();
		int table[][] = new int[r+1][c+1];

		for(i=0;i<r;i++){
			sum = 0;
			for(j=0;j<c;j++){
				table[i][j] = sc.nextInt();
				sum += table[i][j];
			}
			table[i][j] = sum;
			d += sum;
		}
		for(i=0;i<c;i++){
			sum = 0;
			for(j=0;j<r;j++){
				sum += table[j][i];
			}
			table[j][i] = sum;
		}
		table[j][i] = d;
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(table[i][j]);
				if(c == j){
					break;
				}
				System.out.print(" ");
				
			}
			
			if(i<=r){
				System.out.println();
			}
			
			sc.close();
		}
	}

}
