The dynamics of public goods