Optimized time and memory