import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
} Main public static final String EOL = System.getProperty("line.separator"); EOL System.getProperty("line.separator") System.getProperty System "line.separator" public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    } exec {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) String[] sar = br.readLine().split(" "); sar br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " String l; l int r = Integer.parseInt(sar[0]); r Integer.parseInt(sar[0]) Integer.parseInt Integer sar[0] sar 0 int c = Integer.parseInt(sar[1]); c Integer.parseInt(sar[1]) Integer.parseInt Integer sar[1] sar 1 int[] csum = new int[c]; csum new int[c] c int asum = 0; asum 0 for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	} int i=0; int i=0; i 0 i<r i r i++ i++ i {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	} {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	} l = br.readLine() l br.readLine() br.readLine br sar = l.split(" ") sar l.split(" ") l.split l " " int rsum = 0; rsum 0 for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		} int j=0; int j=0; j 0 j<c j c j++ j++ j {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		} {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		} int v = Integer.parseInt(sar[j]); v Integer.parseInt(sar[j]) Integer.parseInt Integer sar[j] sar j rsum += v rsum v csum[j] += v csum[j] csum j v out.print(l) out.print out l out.print(" ") out.print out " " out.println(rsum) out.println out rsum asum += rsum asum rsum for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        } int i=0; int i=0; i 0 i<c i c i++ i++ i {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        } {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        } if(i > 0){
        		out.print(" ");
        	} i > 0 i 0 {
        		out.print(" ");
        	} out.print(" ") out.print out " " out.print(csum[i]) out.print out csum[i] csum i out.print(" ") out.print out " " out.println(asum) out.println out asum out.flush() out.flush out public static void main(String[] args) throws IOException {
    	new Main().exec();
    } main {
    	new Main().exec();
    } new Main().exec() new Main().exec new Main() String[] args args public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
} public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	String[] sar = br.readLine().split(" ");
    	String l;
    	int r = Integer.parseInt(sar[0]);
    	int c = Integer.parseInt(sar[1]);
    	int[] csum = new int[c];
    	int asum = 0;
    	for(int i=0; i<r; i++) {
    		l = br.readLine();
    		sar = l.split(" ");
    		int rsum = 0;
    		for (int j=0; j<c; j++) {
    			int v = Integer.parseInt(sar[j]);
    			rsum += v;
    			csum[j] += v;
    		}
    		out.print(l);
    		out.print(" ");
    		out.println(rsum);
    		asum += rsum;
    	}
        for(int i=0; i<c; i++) {
        	if(i > 0){
        		out.print(" ");
        	}
        	out.print(csum[i]);
        }
        out.print(" ");
        out.println(asum);
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
}