Marginal cost and total cost formulas