Skip to content
C

PDF Merger

Mediumpython

Create several small PDF files (each with a given number of blank pages) and merge them into a single combined PDF, then report its total page count.

Why create the PDFs first? a judge sandbox has no pre-existing PDF files to merge, so the script builds its own simple ones first (using PdfWriter.addblankpage()), then merges them — testing the actual merge operation the notes cover, just without needing real report files handed to it.

Note on the library: the notes teach PyPDF2's PdfMerger; this uses pypdf (PyPDF2's actively-maintained successor — recent PyPDF2 releases are themselves just a thin wrapper around it) and PdfWriter.append(), which is the current recommended way to merge PDFs, since PdfMerger has been removed in modern pypdf versions.

Approach: build one small PDF per given page count, then append each into one combined PdfWriter, save it, and report the merged file's total page count.

Input: One line: space-separated page counts, one per PDF to create and merge.

Output: One line: Total pages: <sum of all page counts>.

Input (stdin)

Output

Run your code to see output here...