This problem is a really interesting problem I solved two times. The first time I solved it I failed to prove exactly how it works... then some years later I remembered the problem statement and was able to solve it properly. Let's see how you do!
Whenever I create something new, I share it with my mailing list of loyal readers. You can subscribe it too!