Optimal quantum codes for preventing collective amplitude damping