We consider the design of contests for n agents when the principal can choose both the prize profile and the contest success function. Our framework includes Tullock contests, Lazear-Rosen tournaments and all-pay contests as special cases, among others. We show that the optimal contest has an intermediate degree of competitiveness in the contest success function, and a minimally competitive prize profile with n−1 identical prizes. The optimum can be achieved with a nested Tullock contest. We extend the model to allow for imperfect performance measurement and for heterogeneous agents. We relate our results to a recent literature which has asked similar questions but has typically focused on the design of either the prize profile or the contest success function.