Competition for hydrogen-bond formation in the helix-coil transition and protein folding