import java.util.Scanner;
class Main{
	public static void main(String args[]){
		int i,j,g,r,x;
		Scanner sc = new Scanner(System.in);
		g=sc.nextInt();
		r=sc.nextInt();
		int[][] map= new int[g+1][r+1];
		for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		}
		for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String args[]){
		int i,j,g,r,x;
		Scanner sc = new Scanner(System.in);
		g=sc.nextInt();
		r=sc.nextInt();
		int[][] map= new int[g+1][r+1];
		for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		}
		for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		}
	}
} Main public static void main(String args[]){
		int i,j,g,r,x;
		Scanner sc = new Scanner(System.in);
		g=sc.nextInt();
		r=sc.nextInt();
		int[][] map= new int[g+1][r+1];
		for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		}
		for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		}
	} main {
		int i,j,g,r,x;
		Scanner sc = new Scanner(System.in);
		g=sc.nextInt();
		r=sc.nextInt();
		int[][] map= new int[g+1][r+1];
		for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		}
		for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		}
	} int i i j j g g r r x; x Scanner sc = new Scanner(System.in); sc new Scanner(System.in) g=sc.nextInt() g sc.nextInt() sc.nextInt sc r=sc.nextInt() r sc.nextInt() sc.nextInt sc int[][] map= new int[g+1][r+1]; map new int[g+1][r+1] g+1 g 1 r+1 r 1 for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		} i=0; i=0 i 0 i<g+1 i g+1 g 1 i++ i++ i {
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		} {
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		} for(j=0;j<r+1;j++)
			map[i][j]=0; j=0; j=0 j 0 j<r+1 j r+1 r 1 j++ j++ j map[i][j]=0; map[i][j]=0 map[i][j] map[i] map i j 0 for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		} i=0; i=0 i 0 i<g i g i++ i++ i {
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		} {
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		} for(j=0;j<r;j++)
				map[i][j]=sc.nextInt(); j=0; j=0 j 0 j<r j r j++ j++ j map[i][j]=sc.nextInt(); map[i][j]=sc.nextInt() map[i][j] map[i] map i j sc.nextInt() sc.nextInt sc for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		} i=0; i=0 i 0 i<g i g i++ i++ i {
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		} {
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		} for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];} j=0; j=0 j 0 j<r j r j++ j++ j {
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];} {
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];} map[i][r]+=map[i][j] map[i][r] map[i] map i r map[i][j] map[i] map i j map[g][j]+=map[i][j] map[g][j] map[g] map g j map[i][j] map[i] map i j map[g][r]+=map[i][r] map[g][r] map[g] map g r map[i][r] map[i] map i r for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		} i=0; i=0 i 0 i<g+1 i g+1 g 1 i++ i++ i {
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		} {
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		} for(j=0;j<r;j++)
				System.out.print(map[i][j]+" "); j=0; j=0 j 0 j<r j r j++ j++ j System.out.print(map[i][j]+" "); System.out.print(map[i][j]+" ") System.out.print System.out System System.out map[i][j]+" " map[i][j] map[i] map i j " " System.out.println(map[i][r]) System.out.println System.out System System.out map[i][r] map[i] map i r String args[] args
import java.util.Scanner;
class Main{
	public static void main(String args[]){
		int i,j,g,r,x;
		Scanner sc = new Scanner(System.in);
		g=sc.nextInt();
		r=sc.nextInt();
		int[][] map= new int[g+1][r+1];
		for(i=0;i<g+1;i++){
			for(j=0;j<r+1;j++)
			map[i][j]=0;
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++)
				map[i][j]=sc.nextInt();
		}
		for(i=0;i<g;i++){
			for(j=0;j<r;j++){
				map[i][r]+=map[i][j];
				map[g][j]+=map[i][j];}
			map[g][r]+=map[i][r];
		}
		for(i=0;i<g+1;i++){
			for(j=0;j<r;j++)
				System.out.print(map[i][j]+" ");
			System.out.println(map[i][r]);
		}
	}
}
