Optimal Response to a Demographic Shock