prob 39 solved
prob 39 optimizing side check