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!
You can use the TeX Paste tool to share LaTeX/MathJax equations across the internet.