Second quarter profit was $41.5 million, or 18 cents a share, compared with $3.6 million, or 1 cent a share, a year earlier.

Hershey has been losing market share to rival Mars Inc in recent months while also facing the same soaring costs that most food companies have had to cope with.

In June, the company said it would increase advertising spending by 20 percent in each of the next two years and focus on its most popular candies to try to increase sales. At the time, the company also cut its long-term earnings-per-share growth goal.

(Reporting by Brad Dorfman; Editing by Derek Caney)