added solution for hercules problem