

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

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		}
	} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		}
	} Main public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] size = new String[2]; size new String[2] 2 size = br.readLine().split(" ") size br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int gyoR = Integer.parseInt(size[0]); gyoR Integer.parseInt(size[0]) Integer.parseInt Integer size[0] size 0 int retsuC = Integer.parseInt(size[1]); retsuC Integer.parseInt(size[1]) Integer.parseInt Integer size[1] size 1 int[][] spreadSheet = new int[gyoR + 1][retsuC + 1]; spreadSheet new int[gyoR + 1][retsuC + 1] gyoR + 1 gyoR 1 retsuC + 1 retsuC 1 for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			} int i = 0; int i = 0; i 0 i < gyoR i gyoR i++ i++ i {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			} {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			} String tempInfo = br.readLine(); tempInfo br.readLine() br.readLine br String[] info = tempInfo.split(" "); info tempInfo.split(" ") tempInfo.split tempInfo " " for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				} int j = 0; int j = 0; j 0 j < retsuC j retsuC j++ j++ j {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				} {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				} spreadSheet[i][j] = Integer.parseInt(info[j]) spreadSheet[i][j] spreadSheet[i] spreadSheet i j Integer.parseInt(info[j]) Integer.parseInt Integer info[j] info j spreadSheet[i][retsuC] += Integer.parseInt(info[j]) spreadSheet[i][retsuC] spreadSheet[i] spreadSheet i retsuC Integer.parseInt(info[j]) Integer.parseInt Integer info[j] info j spreadSheet[gyoR][j] += Integer.parseInt(info[j]) spreadSheet[gyoR][j] spreadSheet[gyoR] spreadSheet gyoR j Integer.parseInt(info[j]) Integer.parseInt Integer info[j] info j spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]) spreadSheet[gyoR][retsuC] spreadSheet[gyoR] spreadSheet gyoR retsuC Integer.parseInt(info[j]) Integer.parseInt Integer info[j] info j for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			} int i = 0; int i = 0; i 0 i < gyoR + 1 i gyoR + 1 gyoR 1 i++ i++ i {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			} {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			} for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				} int j = 0; int j = 0; j 0 j < retsuC j retsuC j++ j++ j {
					System.out.print(spreadSheet[i][j] + " ");
				} {
					System.out.print(spreadSheet[i][j] + " ");
				} System.out.print(spreadSheet[i][j] + " ") System.out.print System.out System System.out spreadSheet[i][j] + " " spreadSheet[i][j] spreadSheet[i] spreadSheet i j " " System.out.println(spreadSheet[i][retsuC]) System.out.println System.out System System.out spreadSheet[i][retsuC] spreadSheet[i] spreadSheet i retsuC String[] args args public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		}
	} public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		}
	} Main


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

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// ????????????????????????
		String[] size = new String[2];
		size = br.readLine().split(" ");

		int gyoR = Integer.parseInt(size[0]);
		int retsuC = Integer.parseInt(size[1]);

		int[][] spreadSheet = new int[gyoR + 1][retsuC + 1];


			// ?¶????????????±??\???
			
			for (int i = 0; i < gyoR; i++) {
				String tempInfo = br.readLine();
				String[] info = tempInfo.split(" ");

				for (int j = 0; j < retsuC; j++) {
					spreadSheet[i][j] = Integer.parseInt(info[j]);
					spreadSheet[i][retsuC] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][j] += Integer.parseInt(info[j]);
					spreadSheet[gyoR][retsuC] += Integer.parseInt(info[j]);
				}
			}
			for (int i = 0; i < gyoR + 1; i++) {
				for (int j = 0; j < retsuC; j++) {
					System.out.print(spreadSheet[i][j] + " ");
				}
				System.out.println(spreadSheet[i][retsuC]);
			}
		}
	}