Constrained Sampling and Counting