import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    } main {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int r r c; c 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 int sum; sum int i i j j k; k 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;
        } 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;
        } {
            sum=0;
            for(j=0;j<c;j++){
                table[i][j]=sc.nextInt();
                sum+=table[i][j];
            }
            table[i][j]=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 for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        } j=0; j=0 j 0 j<c+1 j c+1 c 1 j++ j++ j {
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        } {
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        } for(k=0;k<r;k++)table[i][j]+=table[k][j]; k=0; k=0 k 0 k<r k r k++ k++ k table[i][j]+=table[k][j]; table[i][j]+=table[k][j] table[i][j] table[i] table i j table[k][j] table[k] table k j for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        } i=0; i=0 i 0 i<r+1 i r+1 r 1 i++ i++ i {
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        } {
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        } for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            } j=0; j=0 j 0 j<c+1 j c+1 c 1 j++ j++ j {
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            } {
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            } if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]); j==0 j 0 System.out.printf("%d",table[i][j]) System.out.printf System.out System System.out "%d" table[i][j] table[i] table i j System.out.printf(" %d",table[i][j]) System.out.printf System.out System System.out " %d" table[i][j] table[i] table i j System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int r,c;
        r=sc.nextInt();
        c=sc.nextInt();
        
        int table[][]=new int[r+1][c+1];
        
        int sum;
        int i,j,k;
        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;
        }
        for(j=0;j<c+1;j++){
            for(k=0;k<r;k++)table[i][j]+=table[k][j];
        }
        
        for(i=0;i<r+1;i++){
            for(j=0;j<c+1;j++){
                if(j==0)System.out.printf("%d",table[i][j]);
                else System.out.printf(" %d",table[i][j]);
            }
            System.out.printf("\n");
        }

    }
}
