import java.*;
import java.util.*;

public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	}
}
class spreadsheet{
	int nrow;
	int ncol;
	int[][] cells;
	public spreadsheet(int r, int c){
		nrow=r;
		ncol=c;
		cells = new int[nrow+1][ncol+1];
	}
	public void load(int i, int j, int n){
		cells[i][j]=n;
	}
	public void rowSum(){
		for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		}
	}
	public void colSum(){
		for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		}
	}
	public void show(){
		for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		}
	}
} import java.*; java.* import java.*; import java.util.*; util.* java public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	}
} Main public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	} main {
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int nrow nrow ncol; ncol spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt()); sp new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt()) for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt()); int i=0; int i=0; i 0 i<nrow i nrow i++ i++ i for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt()); for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt()); int j=0; int j=0; j 0 j<ncol j ncol j++ j++ j sp.load(i,j,scan.nextInt()); sp.load(i,j,scan.nextInt()) sp.load sp i j scan.nextInt() scan.nextInt scan sp.rowSum() sp.rowSum sp sp.colSum() sp.colSum sp sp.show() sp.show sp String args[] args class spreadsheet{
	int nrow;
	int ncol;
	int[][] cells;
	public spreadsheet(int r, int c){
		nrow=r;
		ncol=c;
		cells = new int[nrow+1][ncol+1];
	}
	public void load(int i, int j, int n){
		cells[i][j]=n;
	}
	public void rowSum(){
		for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		}
	}
	public void colSum(){
		for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		}
	}
	public void show(){
		for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		}
	}
} spreadsheet int nrow; nrow int ncol; ncol int[][] cells; cells public spreadsheet(int r, int c){
		nrow=r;
		ncol=c;
		cells = new int[nrow+1][ncol+1];
	} spreadsheet {
		nrow=r;
		ncol=c;
		cells = new int[nrow+1][ncol+1];
	} nrow=r nrow r ncol=c ncol c cells = new int[nrow+1][ncol+1] cells new int[nrow+1][ncol+1] nrow+1 nrow 1 ncol+1 ncol 1 int r r int c c public void load(int i, int j, int n){
		cells[i][j]=n;
	} load {
		cells[i][j]=n;
	} cells[i][j]=n cells[i][j] cells[i] cells i j n int i i int j j int n n public void rowSum(){
		for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		}
	} rowSum {
		for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		}
	} for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		} int i=0; int i=0; i 0 i< nrow i nrow i++ i++ i {
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		} {
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		} int sum=0; sum 0 for(int j=0;j<ncol;j++)
				sum+=cells[i][j]; int j=0; int j=0; j 0 j<ncol j ncol j++ j++ j sum+=cells[i][j]; sum+=cells[i][j] sum cells[i][j] cells[i] cells i j cells[i][ncol]=sum cells[i][ncol] cells[i] cells i ncol sum public void colSum(){
		for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		}
	} colSum {
		for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		}
	} for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		} int j=0; int j=0; j 0 j<= ncol j ncol j++ j++ j {
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		} {
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		} int sum=0; sum 0 for(int i=0;i<nrow;i++)
				sum+=cells[i][j]; int i=0; int i=0; i 0 i<nrow i nrow i++ i++ i sum+=cells[i][j]; sum+=cells[i][j] sum cells[i][j] cells[i] cells i j cells[nrow][j]=sum cells[nrow][j] cells[nrow] cells nrow j sum public void show(){
		for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		}
	} show {
		for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		}
	} for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		} int i=0; int i=0; i 0 i<= nrow i nrow i++ i++ i {
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		} {
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		} for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			} int j=0; int j=0; j 0 j<=ncol j ncol j++ j++ j {
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			} {
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			} if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]); j==0 j 0 System.out.printf("%d",cells[i][j]) System.out.printf System.out System System.out "%d" cells[i][j] cells[i] cells i j System.out.printf(" %d",cells[i][j]) System.out.printf System.out System System.out " %d" cells[i][j] cells[i] cells i j System.out.printf("\n") System.out.printf System.out System System.out "\n" public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	}
} public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	}
} Main
import java.*;
import java.util.*;

public class Main{
public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int nrow, ncol;
	spreadsheet sp=new spreadsheet(nrow=scan.nextInt(),ncol=scan.nextInt());
	for(int i=0;i<nrow;i++)
		for(int j=0;j<ncol;j++)
			sp.load(i,j,scan.nextInt());
	sp.rowSum();
	sp.colSum();
	sp.show();
	}
}
class spreadsheet{
	int nrow;
	int ncol;
	int[][] cells;
	public spreadsheet(int r, int c){
		nrow=r;
		ncol=c;
		cells = new int[nrow+1][ncol+1];
	}
	public void load(int i, int j, int n){
		cells[i][j]=n;
	}
	public void rowSum(){
		for(int i=0; i< nrow; i++){
			int sum=0;
			for(int j=0;j<ncol;j++)
				sum+=cells[i][j];
			cells[i][ncol]=sum;
		}
	}
	public void colSum(){
		for(int j=0; j<= ncol; j++){
			int sum=0;
			for(int i=0;i<nrow;i++)
				sum+=cells[i][j];
			cells[nrow][j]=sum;
		}
	}
	public void show(){
		for(int i=0; i<= nrow; i++){
			for(int j=0;j<=ncol;j++){
				if(j==0)
				System.out.printf("%d",cells[i][j]);
				else
				System.out.printf(" %d",cells[i][j]);
			}
			System.out.printf("\n");
		}
	}
}