import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		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 r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	} main {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		} {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		} for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				cell[i][j] = sc.nextInt();
				
			} {
				cell[i][j] = sc.nextInt();
				
			} cell[i][j] = sc.nextInt() cell[i][j] cell[i] cell i j sc.nextInt() sc.nextInt sc for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		} 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++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		} {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		} int sum = 0; sum 0 for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			} {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			} sum += cell[i][j] sum cell[i][j] cell[i] 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",sum) System.out.printf System.out System System.out "%d" sum System.out.println() System.out.println System.out System System.out int total = 0; total 0 for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		} {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		} int sum = 0; sum 0 for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
				sum += cell[i][j];
				} {
				sum += cell[i][j];
				} sum += cell[i][j] sum cell[i][j] cell[i] cell i j System.out.printf("%d ",sum) System.out.printf System.out System System.out "%d " sum total += sum total sum System.out.printf("%d",total) System.out.printf System.out System System.out "%d" total 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 r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] cell = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			for(int j = 0; j < c; j++) {
				cell[i][j] = sc.nextInt();
				
			}
			
		}

		for(int i = 0; i < r; i++) {
			int sum = 0;
			for(int j = 0; j < c; j++) {
				sum += cell[i][j];
				System.out.printf("%d ",cell[i][j]);
				
			}
			System.out.printf("%d",sum);
			System.out.println();
		}
		
		int total = 0;
		for(int j = 0; j < c; j++) {
			int sum = 0;
			for(int i = 0; i < r; i++) {
				sum += cell[i][j];
				}
			System.out.printf("%d ",sum);
			total += sum;
		}
		System.out.printf("%d",total);
		System.out.println();
		

	}
}
