Statistics of Diophantine problems and the Cohen-Lenstra heuristics