Gem Stones problem