The document uses calculus to determine the profit-maximizing level of output for a firm in perfect competition facing a price of $4 and total costs of Q3 – 7Q2 + 12Q+5. It finds the marginal revenue is $4 and sets marginal cost equal to marginal revenue. This yields two possible output levels: 2/3 and 4. However, only at 4 is the slope of the marginal cost curve positive, indicating profit maximization. The total profit at this optimal output of 4 is calculated to be $11.