Optimal demand for medical and long-term care