import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int[][] sheet = new int[r + 1][c + 1]; sheet new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		} {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		} for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			} {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			} int data = sc.nextInt(); data sc.nextInt() sc.nextInt sc sheet[i][j] = data sheet[i][j] sheet[i] sheet i j data sheet[i][c] += data sheet[i][c] sheet[i] sheet i c data sheet[r][j] += data sheet[r][j] sheet[r] sheet r j data sheet[r][c] += data sheet[r][c] sheet[r] sheet r c data for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		} {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		} StringBuffer line = new StringBuffer(); line new StringBuffer() for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			} {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			} line.append(sheet[i][j]) line.append line sheet[i][j] sheet[i] sheet i j if (j != c) {
					line.append(' ');
				} j != c j c {
					line.append(' ');
				} line.append(' ') line.append line ' ' System.out.println(line) System.out.println System.out System System.out line sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[][] sheet = new int[r + 1][c + 1];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				int data = sc.nextInt();
				sheet[i][j] = data;
				sheet[i][c] += data;
				sheet[r][j] += data;
				sheet[r][c] += data;
			}
		}

		for (int i = 0; i < r + 1; i++) {
			StringBuffer line = new StringBuffer();
			for (int j = 0; j < c + 1; j++) {
				line.append(sheet[i][j]);
				if (j != c) {
					line.append(' ');
				}
			}
			System.out.println(line);
		}

		sc.close();
	}
}