How to optimize combined pipe lengths for purchase quantities?

Thanks for the script Daan, this is great… I’m looking to add additional inputs so I can process all of the sublists at once. I’ve been struggling with Python for awhile now, and tried to add additional ins, but can’t seem to get it right. I grabbed the first 4 sizes just by index from my grouped sublist, but I’d love to be able to be able to understand adding the inputs to this!