import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int i,j;
		String[] rc=br.readLine().split(" ");
		int r=Integer.parseInt(rc[0]);
		int c=Integer.parseInt(rc[1]);
		
		int[][] sheet=new int[r+1][c+1];
		
		for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	}
} import java.io.*; io.* java class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int i,j;
		String[] rc=br.readLine().split(" ");
		int r=Integer.parseInt(rc[0]);
		int c=Integer.parseInt(rc[1]);
		
		int[][] sheet=new int[r+1][c+1];
		
		for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	}
} Main public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int i,j;
		String[] rc=br.readLine().split(" ");
		int r=Integer.parseInt(rc[0]);
		int c=Integer.parseInt(rc[1]);
		
		int[][] sheet=new int[r+1][c+1];
		
		for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int i,j;
		String[] rc=br.readLine().split(" ");
		int r=Integer.parseInt(rc[0]);
		int c=Integer.parseInt(rc[1]);
		
		int[][] sheet=new int[r+1][c+1];
		
		for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int i i j; j String[] rc=br.readLine().split(" "); rc br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r=Integer.parseInt(rc[0]); r Integer.parseInt(rc[0]) Integer.parseInt Integer rc[0] rc 0 int c=Integer.parseInt(rc[1]); c Integer.parseInt(rc[1]) Integer.parseInt Integer rc[1] rc 1 int[][] sheet=new int[r+1][c+1]; sheet new int[r+1][c+1] r+1 r 1 c+1 c 1 for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		} i=0; i=0 i 0 i<r i r i++ i++ i {
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		} {
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		} String[] num=br.readLine().split(" "); num br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			} j=0; j=0 j 0 j<c j c j++ j++ j {
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			} {
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			} sheet[i][j]=Integer.parseInt(num[j]) sheet[i][j] sheet[i] sheet i j Integer.parseInt(num[j]) Integer.parseInt Integer num[j] num j sheet[i][c]+=sheet[i][j] sheet[i][c] sheet[i] sheet i c sheet[i][j] sheet[i] sheet i j sheet[r][j]+=sheet[i][j] sheet[r][j] sheet[r] sheet r j sheet[i][j] sheet[i] sheet i j sheet[r][c]+=sheet[i][c] sheet[r][c] sheet[r] sheet r c sheet[i][c] sheet[i] sheet i c for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		} i=0; i=0 i 0 i<=r i r i++ i++ i {
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		} {
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		} for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			} j=0; j=0 j 0 j<=c j c j++ j++ j {
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			} {
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			} System.out.print(sheet[i][j]) System.out.print System.out System System.out sheet[i][j] sheet[i] sheet i j if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				} j==c j c {
					System.out.println();
				} System.out.println() System.out.println System.out System System.out {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " String[]args args
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int i,j;
		String[] rc=br.readLine().split(" ");
		int r=Integer.parseInt(rc[0]);
		int c=Integer.parseInt(rc[1]);
		
		int[][] sheet=new int[r+1][c+1];
		
		for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	}
}