
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner int b = scanner.nextInt(); b scanner.nextInt() scanner.nextInt scanner int[][] list = new int[a + 1][b + 1]; list new int[a + 1][b + 1] a + 1 a 1 b + 1 b 1 for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		} {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		} for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			} int j = 0; int j = 0; j 0 j < b j b j++ j++ j {
				list[i][j] = scanner.nextInt();
			} {
				list[i][j] = scanner.nextInt();
			} list[i][j] = scanner.nextInt() list[i][j] list[i] list i j scanner.nextInt() scanner.nextInt scanner for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		} {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		} int sum = 0; sum 0 for (int j = 0; j < b; j++) {
				sum += list[i][j];
			} int j = 0; int j = 0; j 0 j < b j b j++ j++ j {
				sum += list[i][j];
			} {
				sum += list[i][j];
			} sum += list[i][j] sum list[i][j] list[i] list i j list[i][b] = sum list[i][b] list[i] list i b sum for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		} int i = 0; int i = 0; i 0 i < b + 1 i b + 1 b 1 i++ i++ i {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		} {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		} int sum = 0; sum 0 for (int j = 0; j < a; j++) {
				sum += list[j][i];
			} int j = 0; int j = 0; j 0 j < a j a j++ j++ j {
				sum += list[j][i];
			} {
				sum += list[j][i];
			} sum += list[j][i] sum list[j][i] list[j] list j i list[a][i] = sum list[a][i] list[a] list a i sum for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i <= a i a i++ i++ i {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		} {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		} for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			} int j = 0; int j = 0; j 0 j <= b j b j++ j++ j {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			} {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			} if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]); j == 0 j 0 System.out.print(list[i][j]) System.out.print System.out System System.out list[i][j] list[i] list i j System.out.print(" " + list[i][j]) System.out.print System.out System System.out " " + list[i][j] " " list[i][j] list[i] list i j System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	}
} Main

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int[][] list = new int[a + 1][b + 1];
		for (int i = 0; i < a; i++) {
			for (int j = 0; j < b; j++) {
				list[i][j] = scanner.nextInt();
			}
		}
		for (int i = 0; i < a; i++) {
			int sum = 0;
			for (int j = 0; j < b; j++) {
				sum += list[i][j];
			}
			list[i][b] = sum;
		}
		for (int i = 0; i < b + 1; i++) {
			int sum = 0;
			for (int j = 0; j < a; j++) {
				sum += list[j][i];
			}
			list[a][i] = sum;

		}

		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				if (j == 0)
					System.out.print(list[i][j]);
				else
					System.out.print(" " + list[i][j]);

			}
			System.out.println();
		}
	}
}