import java.util.Scanner;

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

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