import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) 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[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] strargs = null; strargs null int[][] iTable; iTable strargs = br.readLine().split("\\s+") strargs br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" int x = Integer.parseInt(strargs[0]); x Integer.parseInt(strargs[0]) Integer.parseInt Integer strargs[0] strargs 0 int y = Integer.parseInt(strargs[1]); y Integer.parseInt(strargs[1]) Integer.parseInt Integer strargs[1] strargs 1 iTable = new int[x + 1][y + 1] iTable new int[x + 1][y + 1] x + 1 x 1 y + 1 y 1 for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		} int i = 0; int i = 0; i 0 i < x i x i++ i++ i {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		} {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		} strargs = br.readLine().split("\\s+") strargs br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			} int j = 0; int j = 0; j 0 j < y j y j++ j++ j {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			} {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			} iTable[i][j] = Integer.parseInt(strargs[j]) iTable[i][j] iTable[i] iTable i j Integer.parseInt(strargs[j]) Integer.parseInt Integer strargs[j] strargs j iTable[i][y] += iTable[i][j] iTable[i][y] iTable[i] iTable i y iTable[i][j] iTable[i] iTable i j iTable[x][j] += iTable[i][j] iTable[x][j] iTable[x] iTable x j iTable[i][j] iTable[i] iTable i j iTable[x][y] += iTable[i][y] iTable[x][y] iTable[x] iTable x y iTable[i][y] iTable[i] iTable i y for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i < x + 1 i x + 1 x 1 i++ i++ i {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		} {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		} for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			} int j = 0; int j = 0; j 0 j < y + 1 j y + 1 y 1 j++ j++ j {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			} {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			} System.out.print(iTable[i][j]) System.out.print System.out System System.out iTable[i][j] iTable[i] iTable i j if (j != y) System.out.print(" "); j != y j y 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[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) 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[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) 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[] strargs = null;
		int[][] iTable;
		
		strargs = br.readLine().split("\\s+");
		int x = Integer.parseInt(strargs[0]);
		int y = Integer.parseInt(strargs[1]);
		
		iTable = new int[x + 1][y + 1];
		
		for (int i = 0; i < x; i++) {
			strargs = br.readLine().split("\\s+");
			for (int j = 0; j < y; j++) {
				iTable[i][j] = Integer.parseInt(strargs[j]);
				iTable[i][y] += iTable[i][j];
				iTable[x][j] += iTable[i][j];
			}
			iTable[x][y] += iTable[i][y];
		}
		
		for(int i = 0; i < x + 1; i++) {
			for(int j = 0; j < y + 1; j++) {
				System.out.print(iTable[i][j]);
				if (j != y) System.out.print(" ");
			}
			System.out.println();
		}
	}
}