import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        }
        sb2.append(h[r][c]);
        System.out.print(sb1);
        System.out.println(sb2);
	}
} import java.io.*; io.* java class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        }
        sb2.append(h[r][c]);
        System.out.print(sb1);
        System.out.println(sb2);
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        }
        sb2.append(h[r][c]);
        System.out.print(sb1);
        System.out.println(sb2);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        }
        sb2.append(h[r][c]);
        System.out.print(sb1);
        System.out.println(sb2);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb1=new StringBuilder(); sb1 new StringBuilder() StringBuilder sb2=new StringBuilder(); sb2 new StringBuilder() String b=" " b " " n="\n"; n "\n" String[] rc=br.readLine().split(b); rc br.readLine().split(b) br.readLine().split br.readLine() br.readLine br b 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+1][c+1]; h new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        } {
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        } String[] row=br.readLine().split(b); row br.readLine().split(b) br.readLine().split br.readLine() br.readLine br b for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	} int j=0; int j=0; j 0 j<c j c j++ j++ j {
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	} {
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	} 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 sb1.append(h[i][j]+b) sb1.append sb1 h[i][j]+b h[i][j] h[i] h i j b h[i][c]+=h[i][j] h[i][c] h[i] h i c h[i][j] h[i] h i j h[r][j]+=h[i][j] h[r][j] h[r] h r j h[i][j] h[i] h i j h[r][c]+=h[i][j] h[r][c] h[r] h r c h[i][j] h[i] h i j if(i==r-1) sb2.append(h[r][j]+b); i==r-1 i r-1 r 1 sb2.append(h[r][j]+b) sb2.append sb2 h[r][j]+b h[r][j] h[r] h r j b sb1.append(h[i][c]+n) sb1.append sb1 h[i][c]+n h[i][c] h[i] h i c n sb2.append(h[r][c]) sb2.append sb2 h[r][c] h[r] h r c System.out.print(sb1) System.out.print System.out System System.out sb1 System.out.println(sb2) System.out.println System.out System System.out sb2 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 sb1=new StringBuilder();
		StringBuilder sb2=new StringBuilder();
		String b=" ",n="\n";
        String[] rc=br.readLine().split(b);
        int r=Integer.parseInt(rc[0]);
        int c=Integer.parseInt(rc[1]);
        int[][] h=new int[r+1][c+1];
        
        for(int i=0;i<r;i++){
        	String[] row=br.readLine().split(b);
        	for(int j=0;j<c;j++){
        		h[i][j]=Integer.parseInt(row[j]);
        		sb1.append(h[i][j]+b);
        		h[i][c]+=h[i][j];
        		h[r][j]+=h[i][j];
        		h[r][c]+=h[i][j];
        		if(i==r-1) sb2.append(h[r][j]+b);
        	}
        	sb1.append(h[i][c]+n);
        }
        sb2.append(h[r][c]);
        System.out.print(sb1);
        System.out.println(sb2);
	}
}