The was an example when we know the number of pages for the PDF ahead and then I added an example when we count the number of pages right in the Power Automate flow and use variables to replace the pages. For example,
Try to take the same approach to count the number of pages and then add variables to split and merge the PDFs.