import java.util.*;

class Main{
	Scanner scan=new Scanner(System.in);
	int [][] a;
	int r;
	int c;
	int i;
	int j;
	public Main(){
		r=scan.nextInt();
		c=scan.nextInt();
		a=new int[r+1][c+1];
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			}
		}
		for(j=0;j<=c;j++){
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		}
	}
	public static void main(String[] args){
		new Main();
	}
} import java.util.*; util.* java class Main{
	Scanner scan=new Scanner(System.in);
	int [][] a;
	int r;
	int c;
	int i;
	int j;
	public Main(){
		r=scan.nextInt();
		c=scan.nextInt();
		a=new int[r+1][c+1];
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			}
		}
		for(j=0;j<=c;j++){
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		}
	}
	public static void main(String[] args){
		new Main();
	}
} Main Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int [][] a; a int r; r int c; c int i; i int j; j public Main(){
		r=scan.nextInt();
		c=scan.nextInt();
		a=new int[r+1][c+1];
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			}
		}
		for(j=0;j<=c;j++){
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		}
	} Main {
		r=scan.nextInt();
		c=scan.nextInt();
		a=new int[r+1][c+1];
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			}
		}
		for(j=0;j<=c;j++){
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		}
	} r=scan.nextInt() r scan.nextInt() scan.nextInt scan c=scan.nextInt() c scan.nextInt() scan.nextInt scan a=new int[r+1][c+1] a new int[r+1][c+1] r+1 r 1 c+1 c 1 for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+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]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			}
		} {
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			}
		} for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			} j=0; j=0 j 0 j<c j c j++ j++ j {
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			} {
				a[i][j]=scan.nextInt();
				a[i][c]=a[i][c]+a[i][j];
			} a[i][j]=scan.nextInt() a[i][j] a[i] a i j scan.nextInt() scan.nextInt scan a[i][c]=a[i][c]+a[i][j] a[i][c] a[i] a i c a[i][c]+a[i][j] a[i][c] a[i] a i c a[i][j] a[i] a i j for(j=0;j<=c;j++){
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		} j=0; j=0 j 0 j<=c j c j++ j++ j {
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		} {
			for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			}
	//		System.out.print(a[r][j]+" ");
		} for(i=0;i<r;i++){
				a[r][j]=a[r][j]+a[i][j];
			} i=0; i=0 i 0 i<r i r i++ i++ i {
				a[r][j]=a[r][j]+a[i][j];
			} {
				a[r][j]=a[r][j]+a[i][j];
			} a[r][j]=a[r][j]+a[i][j] a[r][j] a[r] a r j a[r][j]+a[i][j] a[r][j] a[r] a r j a[i][j] a[i] a i j for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		} i=0; i=0 i 0 i<=r i r i++ i++ i {
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		} {
			for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			}
		} for(j=0;j<=c;j++){
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			} j=0; j=0 j 0 j<=c j c j++ j++ j {
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			} {
				if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				}
					
			} if(j==c){
					System.out.println(a[i][c]);
				}else{
					System.out.print(a[i][j]+" ");
				} j==c j c {
					System.out.println(a[i][c]);
				} System.out.println(a[i][c]) System.out.println System.out System System.out a[i][c] a[i] a i c {
					System.out.print(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 " " public static void main(String[] args){
		new Main();
	} main {
		new Main();
	} new Main() String[] args args
import java.util.*;

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