I have quiz todo. I solved the problem, but I want to improvement speed of calculation and reduce memory usage. Any idea how can I improvement it?
Input: 2 4: