import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int total_sum=0; total_sum 0 int r=sc.nextInt(); r sc.nextInt() sc.nextInt sc int c=sc.nextInt(); c sc.nextInt() sc.nextInt sc int[][] cell=new int[r+1][c+1]; cell new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		} {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		} int sum=0; sum 0 for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			} {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			} cell[i][j]=sc.nextInt() cell[i][j] cell[i] cell i j sc.nextInt() sc.nextInt sc sum+=cell[i][j] sum cell[i][j] cell[i] cell i j cell[r][j]+=cell[i][j] cell[r][j] cell[r] cell r j cell[i][j] cell[i] cell i j cell[i][c]=sum cell[i][c] cell[i] cell i c sum total_sum+=sum total_sum sum cell[r][c]=total_sum cell[r][c] cell[r] cell r c total_sum for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		} 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; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		} {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		} for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				System.out.printf("%d ", cell[i][j]);
			} {
				System.out.printf("%d ", cell[i][j]);
			} System.out.printf("%d ", cell[i][j]) System.out.printf System.out System System.out "%d " cell[i][j] cell[i] cell i j System.out.printf("%d", cell[i][c]) System.out.printf System.out System System.out "%d" cell[i][c] cell[i] cell i c 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 total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	}
}

