import java.util.Scanner;
import java.util.Arrays;

public class Main { 
	public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} 
}


 import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util public class Main { 
	public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} 
} Main public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} main { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int rows = sc.nextInt(); rows sc.nextInt() sc.nextInt sc int columns = sc.nextInt(); columns sc.nextInt() sc.nextInt sc int[][] data = new int[rows][columns]; data new int[rows][columns] rows columns for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<rows i rows i++ i++ i {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		} {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		} for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			} int j=0; int j=0; j 0 j<columns j columns j++ j++ j {
				data[i][j]=sc.nextInt();
			} {
				data[i][j]=sc.nextInt();
			} data[i][j]=sc.nextInt() data[i][j] data[i] data i j sc.nextInt() sc.nextInt sc int[] rowSums = new int[rows]; rowSums new int[rows] rows int[] colSums = new int[columns]; colSums new int[columns] columns int sum = 0; sum 0 Arrays.fill(rowSums, 0) Arrays.fill Arrays rowSums 0 Arrays.fill(colSums, 0) Arrays.fill Arrays colSums 0 for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		} int i = 0; int i = 0; i 0 i<rows i rows i++ i++ i {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		} {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		} for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			} int j = 0; int j = 0; j 0 j<columns j columns j++ j++ j {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			} {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			} rowSums[i]+= data[i][j] rowSums[i] rowSums i data[i][j] data[i] data i j colSums[j]+= data[i][j] colSums[j] colSums j data[i][j] data[i] data i j sum+= data[i][j] sum data[i][j] data[i] data i j for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		} int i=0; int i=0; i 0 i<rows i rows i++ i++ i {
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		} {
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		} for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			} int j=0; int j=0; j 0 j<columns j columns j++ j++ j {
				System.out.print(""+data[i][j]+" ");
			} {
				System.out.print(""+data[i][j]+" ");
			} System.out.print(""+data[i][j]+" ") System.out.print System.out System System.out ""+data[i][j]+" " ""+data[i][j]+" " "" data[i][j] data[i] data i j " " System.out.println(""+ rowSums[i]) System.out.println System.out System System.out ""+ rowSums[i] "" rowSums[i] rowSums i for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		} int j=0; int j=0; j 0 j<columns j columns j++ j++ j {
			System.out.print(""+colSums[j]+" ");
		} {
			System.out.print(""+colSums[j]+" ");
		} System.out.print(""+colSums[j]+" ") System.out.print System.out System System.out ""+colSums[j]+" " ""+colSums[j]+" " "" colSums[j] colSums j " " System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main { 
	public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} 
} public class Main { 
	public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} 
} Main
import java.util.Scanner;
import java.util.Arrays;

public class Main { 
	public static void main(String[] args) { 
		
		Scanner sc = new Scanner(System.in); 
			
		int rows = sc.nextInt(); 
		int columns = sc.nextInt(); 
		int[][] data = new int[rows][columns];
		
		for (int i=0; i<rows; i++) {
			for (int j=0; j<columns; j++) {
				data[i][j]=sc.nextInt();
			}
		}
		
		int[] rowSums = new int[rows];
		int[] colSums = new int[columns];
		int sum = 0;
		Arrays.fill(rowSums, 0);
		Arrays.fill(colSums, 0);
		for (int i = 0; i<rows; i++) {
			for (int j = 0; j<columns; j++ ) {
				rowSums[i]+= data[i][j];
				colSums[j]+= data[i][j];
				sum+= data[i][j];
			}
		}
		
		for(int i=0; i<rows; i++){
			for(int j=0; j<columns; j++){
				System.out.print(""+data[i][j]+" ");
			}
			System.out.println(""+ rowSums[i]);
		}
		for(int j=0; j<columns; j++){
			System.out.print(""+colSums[j]+" ");
		}
		System.out.println(sum);

		 
	} 
}



