import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	}
} Main public static void main(String[] args) {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	} main {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	} int r = 0; r 0 int c = 0; c 0 int[][] sp_sheet; sp_sheet Scanner sc= new Scanner( System.in ); sc new Scanner( System.in ) r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc sp_sheet = new int[r+1][c+1] sp_sheet 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++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		} int i = 0 ; int i = 0 ; i 0 i < r i r i++ i++ i {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		} {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		} for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			} int j = 0 ; int j = 0 ; j 0 j < c j c j++ j++ j {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			} {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			} sp_sheet[i][j] = sc.nextInt() sp_sheet[i][j] sp_sheet[i] sp_sheet i j sc.nextInt() sc.nextInt sc if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				} j == 0 j 0 {
					sp_sheet[i][c] = 0;
				} sp_sheet[i][c] = 0 sp_sheet[i][c] sp_sheet[i] sp_sheet i c 0 sp_sheet[i][c] += sp_sheet[i][j] sp_sheet[i][c] sp_sheet[i] sp_sheet i c sp_sheet[i][j] sp_sheet[i] sp_sheet i j if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				} i == 0 i 0 {
					sp_sheet[r][j] = 0;
				} sp_sheet[r][j] = 0 sp_sheet[r][j] sp_sheet[r] sp_sheet r j 0 sp_sheet[r][j] += sp_sheet[i][j] sp_sheet[r][j] sp_sheet[r] sp_sheet r j sp_sheet[i][j] sp_sheet[i] sp_sheet i j if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			} i == 0 i 0 {
				sp_sheet[r][c] = 0;
			} sp_sheet[r][c] = 0 sp_sheet[r][c] sp_sheet[r] sp_sheet r c 0 sp_sheet[r][c] += sp_sheet[i][c] sp_sheet[r][c] sp_sheet[r] sp_sheet r c sp_sheet[i][c] sp_sheet[i] sp_sheet i c for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		} int i = 0 ; int i = 0 ; i 0 i < ( r + 1 ) i ( r + 1 ) r 1 i++ i++ i {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		} {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		} for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			} int j = 0 ; int j = 0 ; j 0 j < ( c + 1 ) j ( c + 1 ) c 1 j++ j++ j {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			} {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			} System.out.print( sp_sheet[i][j] ) System.out.print System.out System System.out sp_sheet[i][j] sp_sheet[i] sp_sheet 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.print( "\n" ) System.out.print System.out System System.out "\n" sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	}
} public class Main {

	public static void main(String[] args) {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int r = 0;
		int c = 0;
		int[][] sp_sheet;

		Scanner sc= new Scanner( System.in );


		r = sc.nextInt();
		c = sc.nextInt();

		sp_sheet = new int[r+1][c+1];

		for( int i = 0 ; i < r ; i++ ) {
			for ( int j = 0 ; j < c ; j++ ) {

				sp_sheet[i][j] = sc.nextInt();

				if ( j == 0 ) {
					sp_sheet[i][c] = 0;
				}
				sp_sheet[i][c] += sp_sheet[i][j];

				if ( i == 0 ) {
					sp_sheet[r][j] = 0;
				}
				sp_sheet[r][j] += sp_sheet[i][j];
			}
			if ( i == 0 ) {
				sp_sheet[r][c] = 0;
			}
			sp_sheet[r][c] += sp_sheet[i][c];
		}

		for( int i = 0 ; i < ( r + 1 ) ; i++ ) {
			for ( int j = 0 ; j < ( c + 1 ) ; j++ ) {
				System.out.print( sp_sheet[i][j] );
				if ( j != c ) {
					System.out.print( " " );
				}
			}
			System.out.print( "\n" );
		}
		sc.close();
	}
}
