import java.util.Scanner;

public class Main {

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

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

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

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int r,c,i,j,csum;
        r=scan.nextInt();
        c=scan.nextInt();
        int array[][]=new int[r][c],rsum[]=new int[c+1];
        for(i=0;i<c;i++) {
        	rsum[i]=0;
        }
        for(i=0;i<r;i++) {
        	for(j=0;j<c;j++) {
        		array[i][j]=scan.nextInt();
        	}
        }
        for(i=0;i<=r;i++) {
        	csum=0;
        	if(i<r) {
        		for(j=0;j<=c;j++) {
        			if(j<c) {
        				System.out.print(array[i][j] + " ");
        				csum+=array[i][j];
        				rsum[j]+=array[i][j];
        			}
        			else {
        				System.out.println(csum);
        				rsum[j]+=csum;
        			}
        		}
        	}
        	else {
        		for(j=0;j<=c;j++) {
        			if(j<c) {
        				System.out.print(rsum[j] + " ");
        			}
        			else {
        				System.out.println(rsum[j]);
        			}
        		}
        	}
        }
    }
} Main
import java.util.Scanner;

public class Main {

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

