problem 3 optimized