import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

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

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

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

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

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

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
} main {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

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

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

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

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
}
} public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

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

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r  = scan.nextInt();
		int c  = scan.nextInt();
		int[][] table = new int[r+1][c+1];
		for(int i = 0;i<r;i++){
			for(int j=0;j<c;j++){
				table[i][j] = scan.nextInt();
			}
		}

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

		for(int i = 0; i<=r; i++){
			System.out.print(table[i][0]);
			for(int j=1;j<=c;j++){
				System.out.print(" "+table[i][j]);	
		}
		System.out.println();
	}
}
}