import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int matrix[][] = new int[c + 1][r + 1]; matrix new int[c + 1][r + 1] c + 1 c 1 r + 1 r 1 for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		} {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		} for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				matrix[i][j] = sc.nextInt();
			} {
				matrix[i][j] = sc.nextInt();
			} matrix[i][j] = sc.nextInt() matrix[i][j] matrix[i] matrix i j sc.nextInt() sc.nextInt sc for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		} {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		} for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				matrix[i][r] += matrix[i][j];
			} {
				matrix[i][r] += matrix[i][j];
			} matrix[i][r] += matrix[i][j] matrix[i][r] matrix[i] matrix i r matrix[i][j] matrix[i] matrix i j for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		} {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		} for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			} int j = 0; int j = 0; j 0 j <= r j r j++ j++ j {
				matrix[c][j] += matrix[i][j];
			} {
				matrix[c][j] += matrix[i][j];
			} matrix[c][j] += matrix[i][j] matrix[c][j] matrix[c] matrix c j matrix[i][j] matrix[i] matrix i j for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i <= c i c i++ i++ i {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		} {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		} for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			} int j = 0; int j = 0; j 0 j <= r j r j++ j++ j {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			} {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			} System.out.print(matrix[i][j]) System.out.print System.out System System.out matrix[i][j] matrix[i] matrix i j if (!(j == r))
					System.out.print(" "); !(j == r) (j == r) j r 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) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int r = sc.nextInt();
		int matrix[][] = new int[c + 1][r + 1];
		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][j] = sc.nextInt();
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j < r; j++) {
				matrix[i][r] += matrix[i][j];
			}
		}

		for (int i = 0; i < c; i++) {
			for (int j = 0; j <= r; j++) {
				matrix[c][j] += matrix[i][j];
			}
		}

		for (int i = 0; i <= c; i++) {
			for (int j = 0; j <= r; j++) {
				System.out.print(matrix[i][j]);
				if (!(j == r))
					System.out.print(" ");
			}
			System.out.println();
		}
	}

}