import java.util.Scanner;

public class Main{
	private static Scanner sc=new Scanner(System.in);
	private static int r=sc.nextInt();
	private static int c=sc.nextInt();
	private static int[][] data=new int[r+1][c+1];
	public static void main(String args[]){
		input();
		setSum();
		output();
	}
	private static void input(){
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		}
	}
	private static void setSum(){
		for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		}
		for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		}
	}
	private static void output(){
		for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{
	private static Scanner sc=new Scanner(System.in);
	private static int r=sc.nextInt();
	private static int c=sc.nextInt();
	private static int[][] data=new int[r+1][c+1];
	public static void main(String args[]){
		input();
		setSum();
		output();
	}
	private static void input(){
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		}
	}
	private static void setSum(){
		for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		}
		for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		}
	}
	private static void output(){
		for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		}
	}
} Main private static Scanner sc=new Scanner(System.in); sc new Scanner(System.in) private static int r=sc.nextInt(); r sc.nextInt() sc.nextInt sc private static int c=sc.nextInt(); c sc.nextInt() sc.nextInt sc private static int[][] data=new int[r+1][c+1]; data new int[r+1][c+1] r+1 r 1 c+1 c 1 public static void main(String args[]){
		input();
		setSum();
		output();
	} main {
		input();
		setSum();
		output();
	} input() input setSum() setSum output() output String args[] args private static void input(){
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		}
	} input {
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		}
	} for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[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++){
				data[i][j]=sc.nextInt();
			}
		} {
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		} for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			} int j=0; int j=0; j 0 j<c j c 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 private static void setSum(){
		for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		}
		for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		}
	} setSum {
		for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		}
		for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		}
	} for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=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++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		} {
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		} int sum=0; sum 0 for(int j=0;j<c;j++){
				sum+=data[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				sum+=data[i][j];
			} {
				sum+=data[i][j];
			} sum+=data[i][j] sum data[i][j] data[i] data i j data[i][c]=sum data[i][c] data[i] data i c sum for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		} {
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		} int sum=0; sum 0 for(int i=0;i<r;i++){
				sum+=data[i][j];
			} int i=0; int i=0; i 0 i<r i r i++ i++ i {
				sum+=data[i][j];
			} {
				sum+=data[i][j];
			} sum+=data[i][j] sum data[i][j] data[i] data i j data[r][j]=sum data[r][j] data[r] data r j sum private static void output(){
		for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		}
	} output {
		for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		}
	} for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		} int i=0; int i=0; i 0 i<=r i r i++ i++ i {
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		} {
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		} for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			} int j=0; int j=0; j 0 j<c j c 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] data i j " " System.out.println(data[i][c]) System.out.println System.out System System.out data[i][c] data[i] data i c public class Main{
	private static Scanner sc=new Scanner(System.in);
	private static int r=sc.nextInt();
	private static int c=sc.nextInt();
	private static int[][] data=new int[r+1][c+1];
	public static void main(String args[]){
		input();
		setSum();
		output();
	}
	private static void input(){
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		}
	}
	private static void setSum(){
		for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		}
		for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		}
	}
	private static void output(){
		for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		}
	}
} public class Main{
	private static Scanner sc=new Scanner(System.in);
	private static int r=sc.nextInt();
	private static int c=sc.nextInt();
	private static int[][] data=new int[r+1][c+1];
	public static void main(String args[]){
		input();
		setSum();
		output();
	}
	private static void input(){
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				data[i][j]=sc.nextInt();
			}
		}
	}
	private static void setSum(){
		for(int i=0;i<r;i++){
			int sum=0;
			for(int j=0;j<c;j++){
				sum+=data[i][j];
			}
			data[i][c]=sum;
		}
		for(int j=0;j<c+1;j++){
			int sum=0;
			for(int i=0;i<r;i++){
				sum+=data[i][j];
			}
			data[r][j]=sum;
		}
	}
	private static void output(){
		for(int i=0;i<=r;i++){
			for(int j=0;j<c;j++){
				System.out.print(data[i][j]+" ");
			}
			System.out.println(data[i][c]);
		}
	}
} Main
import java.util.Scanner;

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