import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
        String[] rc=br.readLine().split(" ");
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r][c];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        }
        int ts=0;
        for(int j=0;j<c;j++){
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        }
        sb.append(ts);
        System.out.println(sb);
	}
} import java.io.*; io.* java class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
        String[] rc=br.readLine().split(" ");
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r][c];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        }
        int ts=0;
        for(int j=0;j<c;j++){
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        }
        sb.append(ts);
        System.out.println(sb);
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
        String[] rc=br.readLine().split(" ");
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r][c];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        }
        int ts=0;
        for(int j=0;j<c;j++){
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        }
        sb.append(ts);
        System.out.println(sb);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
        String[] rc=br.readLine().split(" ");
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r][c];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        }
        int ts=0;
        for(int j=0;j<c;j++){
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        }
        sb.append(ts);
        System.out.println(sb);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb=new StringBuilder(); sb new StringBuilder() String[] rc=br.readLine().split(" "); rc br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r=Integer.parseInt(rc[0]); r Integer.parseInt(rc[0]) Integer.parseInt Integer rc[0] rc 0 int c=Integer.parseInt(rc[1]); c Integer.parseInt(rc[1]) Integer.parseInt Integer rc[1] rc 1 int[][] h=new int[r][c]; h new int[r][c] r c for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        } {
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        } String[] row=br.readLine().split(" "); row br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int s=0; s 0 for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	} int j=0; int j=0; j 0 j<c j c j++ j++ j {
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	} {
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	} h[i][j]=Integer.parseInt(row[j]) h[i][j] h[i] h i j Integer.parseInt(row[j]) Integer.parseInt Integer row[j] row j sb.append(h[i][j]+" ") sb.append sb h[i][j]+" " h[i][j] h[i] h i j " " s+=h[i][j] s h[i][j] h[i] h i j sb.append(s+"\n") sb.append sb s+"\n" s "\n" int ts=0; ts 0 for(int j=0;j<c;j++){
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        } int j=0; int j=0; j 0 j<c j c j++ j++ j {
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        } {
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        } int s=0; s 0 for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	} int i=0; int i=0; i 0 i<r i r i++ i++ i {
        		s+=h[i][j];
        		ts+=h[i][j];
        	} {
        		s+=h[i][j];
        		ts+=h[i][j];
        	} s+=h[i][j] s h[i][j] h[i] h i j ts+=h[i][j] ts h[i][j] h[i] h i j sb.append(s+" ") sb.append sb s+" " s " " sb.append(ts) sb.append sb ts System.out.println(sb) System.out.println System.out System System.out sb String[] args args
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
        String[] rc=br.readLine().split(" ");
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r][c];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(" ");
        	int s=0;
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb.append(h[i][j]+" ");
        		s+=h[i][j];
        	}
        	sb.append(s+"\n");
        }
        int ts=0;
        for(int j=0;j<c;j++){
        	int s=0;
        	for(int i=0;i<r;i++){
        		s+=h[i][j];
        		ts+=h[i][j];
        	}
        	sb.append(s+" ");
        }
        sb.append(ts);
        System.out.println(sb);
	}
}