Fix a typo in the code that collected the costs recursively.