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[] ct=new int[c];
        int t=0;
        for(int i=0;i<r;i++){
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        }
        sb1.append(sb2).append(t);
        System.out.println(sb1);
	}
} 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[] ct=new int[c];
        int t=0;
        for(int i=0;i<r;i++){
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        }
        sb1.append(sb2).append(t);
        System.out.println(sb1);
	}
} 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[] ct=new int[c];
        int t=0;
        for(int i=0;i<r;i++){
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        }
        sb1.append(sb2).append(t);
        System.out.println(sb1);
	} 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[] ct=new int[c];
        int t=0;
        for(int i=0;i<r;i++){
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        }
        sb1.append(sb2).append(t);
        System.out.println(sb1);
	} 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[] ct=new int[c]; ct new int[c] c int t=0; t 0 for(int i=0;i<r;i++){
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        } int i=0; int i=0; i 0 i<r i r i++ i++ i {
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        } {
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        } String str=br.readLine(); str br.readLine() br.readLine br String[] row=str.split(b); row str.split(b) str.split str b int rt=0; rt 0 for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	} int j=0; int j=0; j 0 j<c j c j++ j++ j {
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	} {
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	} int v=Integer.parseInt(row[j]); v Integer.parseInt(row[j]) Integer.parseInt Integer row[j] row j ct[j]+=v ct[j] ct j v rt+=v rt v if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		} i==r-1 i r-1 r 1 {
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		} t+=ct[j] t ct[j] ct j sb2.append(ct[j]+b) sb2.append sb2 ct[j]+b ct[j] ct j b sb1.append(str+b+rt+n) sb1.append sb1 str+b+rt+n rt str+b+rt+n str b rt n sb1.append(sb2).append(t) sb1.append(sb2).append sb1.append(sb2) sb1.append sb1 sb2 t System.out.println(sb1) System.out.println System.out System System.out sb1 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[] ct=new int[c];
        int t=0;
        for(int i=0;i<r;i++){
        	String str=br.readLine();
        	String[] row=str.split(b);
        	int rt=0;
        	for(int j=0;j<c;j++){
        		int v=Integer.parseInt(row[j]);
        		ct[j]+=v;
        		rt+=v;
        		if(i==r-1){
        			t+=ct[j];
        			sb2.append(ct[j]+b);
        		}
        	}
        	sb1.append(str+b+rt+n);
        }
        sb1.append(sb2).append(t);
        System.out.println(sb1);
	}
}