import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	}

}
 import java.util.*; util.* java import java.io.*; io.* java public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	}

} Main public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	} main {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) PrintWriter out=new PrintWriter(System.out); out new PrintWriter(System.out) int r=in.nextInt() r in.nextInt() in.nextInt in c=in.nextInt() c in.nextInt() in.nextInt in M[][]=new int[r+1][c+1]; M 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++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		} {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		} for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			} {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			} int n=Integer.parseInt(in.next()); n Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in M[i][j]=n M[i][j] M[i] M i j n M[i][c]+=n M[i][c] M[i] M i c n M[r][j]+=n M[r][j] M[r] M r j n M[r][c]+=n M[r][c] M[r] M r c n for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		} int i=0; int i=0; i 0 i<=r i r i++ i++ i {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		} {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		} for(int j=0;j<c;j++)out.print(M[i][j]+" "); int j=0; int j=0; j 0 j<c j c j++ j++ j out.print(M[i][j]+" "); out.print(M[i][j]+" ") out.print out M[i][j]+" " M[i][j] M[i] M i j " " out.println(M[i][c]) out.println out M[i][c] M[i] M i c out.flush() out.flush out String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	}

} Main
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int r=in.nextInt(),c=in.nextInt(),M[][]=new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				int n=Integer.parseInt(in.next());
				M[i][j]=n; M[i][c]+=n; M[r][j]+=n; M[r][c]+=n;
			}
		}
		
		for(int i=0;i<=r;i++) {
			for(int j=0;j<c;j++)out.print(M[i][j]+" ");
			out.println(M[i][c]);
		}
		out.flush();
	}

}

