import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	}
} Main public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	} main {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int a=sc.nextInt(); a sc.nextInt() sc.nextInt sc int b=sc.nextInt(); b sc.nextInt() sc.nextInt sc int[][] ab=new int[a+1][b+1]; ab new int[a+1][b+1] a+1 a 1 b+1 b 1 for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		} int i=0; int i=0; i 0 i<a i a i++ i++ i {
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		} {
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		} for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt(); int j=0; int j=0; j 0 j<b j b j++ j++ j ab[i][j]=sc.nextInt(); ab[i][j]=sc.nextInt() ab[i][j] ab[i] ab i j sc.nextInt() sc.nextInt sc for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		} int i=0; int i=0; i 0 i<a i a i++ i++ i {
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		} {
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		} for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			} int j=0; int j=0; j 0 j<b j b j++ j++ j {
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			} {
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			} ab[i][b]=ab[i][b]+ab[i][j] ab[i][b] ab[i] ab i b ab[i][b]+ab[i][j] ab[i][b] ab[i] ab i b ab[i][j] ab[i] ab i j ab[a][j]=ab[a][j]+ab[i][j] ab[a][j] ab[a] ab a j ab[a][j]+ab[i][j] ab[a][j] ab[a] ab a j ab[i][j] ab[i] ab i j ab[a][b]=ab[a][b]+ab[i][b] ab[a][b] ab[a] ab a b ab[a][b]+ab[i][b] ab[a][b] ab[a] ab a b ab[i][b] ab[i] ab i b for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		} int i=0; int i=0; i 0 i<=a i a i++ i++ i {
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		} {
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		} for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			} int j=0; int j=0; j 0 j<=b j b j++ j++ j {
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			} {
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			} if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" "); j==b j b {
					System.out.print(ab[i][j]);
					System.out.print("\n");
				} System.out.print(ab[i][j]) System.out.print System.out System System.out ab[i][j] ab[i] ab i j System.out.print("\n") System.out.print System.out System System.out "\n" System.out.print(ab[i][j]+" ") System.out.print System.out System System.out ab[i][j]+" " ab[i][j] ab[i] ab i j " " String[]args args public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	}
} public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int[][] ab=new int[a+1][b+1];
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++)
				ab[i][j]=sc.nextInt();
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				ab[i][b]=ab[i][b]+ab[i][j];
				ab[a][j]=ab[a][j]+ab[i][j];
			}
			ab[a][b]=ab[a][b]+ab[i][b];
		}
		for(int i=0;i<=a;i++){
			for(int j=0;j<=b;j++){
				if(j==b){
					System.out.print(ab[i][j]);
					System.out.print("\n");
				}else
					System.out.print(ab[i][j]+" ");
			}
		}
	}
}

