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


