Problem 1 optimized