import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		}} 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 str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		}} Main public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str = br.readLine(); str br.readLine() br.readLine br String[] i=str.split(" "); i str.split(" ") str.split str " " int r=Integer.parseInt(i[0]) r Integer.parseInt(i[0]) Integer.parseInt Integer i[0] i 0 c=Integer.parseInt(i[1]); c Integer.parseInt(i[1]) Integer.parseInt Integer i[1] i 1 int [][]hyo=new int[r+2][c+2]; hyo new int[r+2][c+2] r+2 r 2 c+2 c 2 for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		} int x=1; int x=1; x 1 x<=r x r x++ x++ x {
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		} {
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		} str = br.readLine() str br.readLine() br.readLine br i=str.split(" ") i str.split(" ") str.split str " " for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);} int y=0; int y=0; y 0 y<c y c y++ y++ y {
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);} {
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);} hyo[x][y+1]=Integer.parseInt(i[y]) hyo[x][y+1] hyo[x] hyo x y+1 y 1 Integer.parseInt(i[y]) Integer.parseInt Integer i[y] i y hyo[x][c+1]+=Integer.parseInt(i[y]) hyo[x][c+1] hyo[x] hyo x c+1 c 1 Integer.parseInt(i[y]) Integer.parseInt Integer i[y] i y hyo[r+1][y+1]+=Integer.parseInt(i[y]) hyo[r+1][y+1] hyo[r+1] hyo r+1 r 1 y+1 y 1 Integer.parseInt(i[y]) Integer.parseInt Integer i[y] i y hyo[r+1][c+1]+=hyo[x][c+1] hyo[r+1][c+1] hyo[r+1] hyo r+1 r 1 c+1 c 1 hyo[x][c+1] hyo[x] hyo x c+1 c 1 for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		} int x=1; int x=1; x 1 x<=r+1 x r+1 r 1 x++ x++ x {
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		} {
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		} for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}} int y=1; int y=1; y 1 y<=c+1 y c+1 c 1 y++ y++ y {System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}} {System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}} System.out.print(hyo[x][y]) System.out.print System.out System System.out hyo[x][y] hyo[x] hyo x y if(y!=c+1){System.out.print(" ");} y!=c+1 y c+1 c 1 {System.out.print(" ");} System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		}} public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		}} Main
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		}}