import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	}
} import java.io.*; io.* java public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] dat = br.readLine().split(" "); dat br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(dat[0]); r Integer.parseInt(dat[0]) Integer.parseInt Integer dat[0] dat 0 int c = Integer.parseInt(dat[1]); c Integer.parseInt(dat[1]) Integer.parseInt Integer dat[1] dat 1 StringBuilder out=new StringBuilder(); out new StringBuilder() int g g p p gg=0; gg 0 String str; str int[] SumC=new int[c]; SumC new int[c] c for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		} {
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		} str =br.readLine() str br.readLine() br.readLine br dat = str.split(" ") dat str.split(" ") str.split str " " g=0 g 0 for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			} {
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			} p=Integer.parseInt(dat[j]) p Integer.parseInt(dat[j]) Integer.parseInt Integer dat[j] dat j g += p g p SumC[j] += p SumC[j] SumC j p gg+=g gg g out.append(str+" "+g+"\n") out.append out str+" "+g+"\n" g str+" "+g+"\n" str " " g "\n" for (int j=0;j<c;j++) out.append(SumC[j]+" "); int j=0; int j=0; j 0 j<c j c j++ j++ j out.append(SumC[j]+" "); out.append(SumC[j]+" ") out.append out SumC[j]+" " SumC[j] SumC j " " out.append(gg) out.append out gg System.out.println(out) System.out.println System.out System System.out out String[] args args public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	}
} public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	}
} Main
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat = br.readLine().split(" ");
		int r = Integer.parseInt(dat[0]);
		int c = Integer.parseInt(dat[1]);
		StringBuilder out=new StringBuilder();
		int g,p,gg=0;
		String str;
		int[] SumC=new int[c];
		for (int i=0;i<r;i++){
			str =br.readLine();
			dat = str.split(" ");
			g=0;
			for (int j=0;j<c;j++){
				p=Integer.parseInt(dat[j]);
				g += p;
				SumC[j] += p;
			}
			gg+=g;
			out.append(str+" "+g+"\n");
		}
		for (int j=0;j<c;j++) out.append(SumC[j]+" ");
		out.append(gg);
		System.out.println(out);
	}
}