import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
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[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		}}	 import java.io.BufferedReader; BufferedReader java.io import java.io.FileNotFoundException; FileNotFoundException java.io import java.io.FileReader; FileReader java.io 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[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		}} Main public static void main(String[] args)  {
		//入力導入部
		Scanner sc=new Scanner(System.in);
		
			int r=sc.nextInt();
			int c=sc.nextInt();
			int[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		} main {
		//入力導入部
		Scanner sc=new Scanner(System.in);
		
			int r=sc.nextInt();
			int c=sc.nextInt();
			int[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		} 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[][] box=new int[r+1][c+1]; box new int[r+1][c+1] r+1 r 1 c+1 c 1 int total; total for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			} int i=0; int i=0; i 0 i<r i r i++ i++ i {total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			} {total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			} total=0 total 0 for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				} int l=0; int l=0; l 0 l<c+1 l c+1 c 1 l++ l++ l {
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				} {
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				} if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt(); l==c l c {box[i][c]=total;
					} box[i][c]=total box[i][c] box[i] box i c total total+=box[i][l]=sc.nextInt() total box[i][l]=sc.nextInt() box[i][l] box[i] box i l sc.nextInt() sc.nextInt sc for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			} int l=0; int l=0; l 0 l<=c l c l++ l++ l {total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			} {total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			} total=0 total 0 for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				} {
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				} if(i==r){box[r][l]=total;}
					else{total+=box[i][l];} i==r i r {box[r][l]=total;} box[r][l]=total box[r][l] box[r] box r l total {total+=box[i][l];} total+=box[i][l] total box[i][l] box[i] box i l for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			} {
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			} for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				} int l=0; int l=0; l 0 l<c+1 l c+1 c 1 l++ l++ l {
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				} {
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				} if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]); l==0 l 0 System.out.print(box[i][0]) System.out.print System.out System System.out box[i][0] box[i] box i 0 System.out.print(" "+box[i][l]) System.out.print System.out System System.out " "+box[i][l] " " box[i][l] box[i] box i l System.out.println() System.out.println System.out System System.out 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[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		}} public class Main {

	public static void main(String[] args)  {
		//入力導入部
		Scanner sc=new Scanner(System.in);
		
			int r=sc.nextInt();
			int c=sc.nextInt();
			int[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		}} Main
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
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[][] box=new int[r+1][c+1];
			///////////////////////////////////////////////////////////////////
			//計算部			x=n+n-i+n-l
			int total;
		
			for(int i=0;i<r;i++){total=0;
				for(int l=0;l<c+1;l++){
					if(l==c){box[i][c]=total;
					}else total+=box[i][l]=sc.nextInt();
					
					
				}
				
			}
			for(int l=0;l<=c;l++){total=0;
				for(int i=0;i<r+1;i++){
					if(i==r){box[r][l]=total;}
					else{total+=box[i][l];}
			
				}
			}
			for(int i=0;i<r+1;i++){
				for(int l=0;l<c+1;l++){
					if(l==0)System.out.print(box[i][0]);
					else System.out.print(" "+box[i][l]);
				}System.out.println();
			}
			
			
		}}	