This question is building off a preliminary solution given by Lukasz Tracewski (Thank you!).
How to modify the python code below to determine the optimum pad length s