import java.io.*;
 
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] rc = line.split(" ");
        int r = Integer.parseInt(rc[0]);
        int c = Integer.parseInt(rc[1]);
        int[][] matrix = new int[r+1][c+1];	//????¨???§?????\??????
        int[] s = new int[c+1];
        for(int i=0; i<r; i++) {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        }
        for(int i=0; i <= c; i++) {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        }
        for(int i = 0 ; i <= r ; i++ ) {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		}
    }
} import java.io.*; io.* java class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] rc = line.split(" ");
        int r = Integer.parseInt(rc[0]);
        int c = Integer.parseInt(rc[1]);
        int[][] matrix = new int[r+1][c+1];	//????¨???§?????\??????
        int[] s = new int[c+1];
        for(int i=0; i<r; i++) {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        }
        for(int i=0; i <= c; i++) {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        }
        for(int i = 0 ; i <= r ; i++ ) {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		}
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] rc = line.split(" ");
        int r = Integer.parseInt(rc[0]);
        int c = Integer.parseInt(rc[1]);
        int[][] matrix = new int[r+1][c+1];	//????¨???§?????\??????
        int[] s = new int[c+1];
        for(int i=0; i<r; i++) {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        }
        for(int i=0; i <= c; i++) {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        }
        for(int i = 0 ; i <= r ; i++ ) {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		}
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] rc = line.split(" ");
        int r = Integer.parseInt(rc[0]);
        int c = Integer.parseInt(rc[1]);
        int[][] matrix = new int[r+1][c+1];	//????¨???§?????\??????
        int[] s = new int[c+1];
        for(int i=0; i<r; i++) {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        }
        for(int i=0; i <= c; i++) {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        }
        for(int i = 0 ; i <= r ; i++ ) {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		}
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br String[] rc = line.split(" "); rc line.split(" ") line.split line " " 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[][] matrix = new int[r+1][c+1]; matrix new int[r+1][c+1] r+1 r 1 c+1 c 1 int[] s = new int[c+1]; s new int[c+1] c+1 c 1 for(int i=0; i<r; i++) {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        } {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        } line = br.readLine() line br.readLine() br.readLine br String[] inputs = line.split(" "); inputs line.split(" ") line.split line " " matrix[i][c] = 0 matrix[i][c] matrix[i] matrix i c 0 for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            } int j=0; int j=0; j 0 j<c j c j++ j++ j {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            } {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            } matrix[i][j] = Integer.parseInt(inputs[j]) matrix[i][j] matrix[i] matrix i j Integer.parseInt(inputs[j]) Integer.parseInt Integer inputs[j] inputs j matrix[i][c] += matrix[i][j] matrix[i][c] matrix[i] matrix i c matrix[i][j] matrix[i] matrix i j for(int i=0; i <= c; i++) {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        } int i=0; int i=0; i 0 i <= c i c i++ i++ i {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        } {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        } matrix[r][i] = 0 matrix[r][i] matrix[r] matrix r i 0 for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			} int j = 0 ; int j = 0 ; j 0 j < r j r j++ j++ j {
				matrix[r][i] += matrix[j][i];
			} {
				matrix[r][i] += matrix[j][i];
			} matrix[r][i] += matrix[j][i] matrix[r][i] matrix[r] matrix r i matrix[j][i] matrix[j] matrix j i for(int i = 0 ; i <= r ; i++ ) {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		} int i = 0 ; int i = 0 ; i 0 i <= r i r i++ i++ i {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		} {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		} for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			} int j = 0 ; int j = 0 ; j 0 j <= c j c j++ j++ j {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			} {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			} System.out.print( matrix[i][j]) System.out.print System.out System System.out matrix[i][j] matrix[i] matrix i j if ( j < c ) {
					System.out.print( " " ) ;
				} j < c j c {
					System.out.print( " " ) ;
				} System.out.print( " " ) System.out.print System.out System System.out " " System.out.println("") System.out.println 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));
        String line = br.readLine();
        String[] rc = line.split(" ");
        int r = Integer.parseInt(rc[0]);
        int c = Integer.parseInt(rc[1]);
        int[][] matrix = new int[r+1][c+1];	//????¨???§?????\??????
        int[] s = new int[c+1];
        for(int i=0; i<r; i++) {
            line = br.readLine();
            String[] inputs = line.split(" ");
            matrix[i][c] = 0;				//????¨?
            for(int j=0; j<c; j++) {
                matrix[i][j] = Integer.parseInt(inputs[j]);
                matrix[i][c] += matrix[i][j];
            }
        }
        for(int i=0; i <= c; i++) {	//????¨????????¨?????¨??????????
			matrix[r][i] = 0;
			for( int j = 0 ; j < r ; j++ ) {
				matrix[r][i] += matrix[j][i];
			}
        }
        for(int i = 0 ; i <= r ; i++ ) {
			for( int j = 0 ; j <= c ; j++ ) {
				System.out.print( matrix[i][j]) ;
				if ( j < c ) {
					System.out.print( " " ) ;
				}
			}
			System.out.println("");
		}
    }
}