Discover the formula used to calculate retained earnings and its components.