The present invention provides a heterocyclic compound having a HDAC inhibitory action, and useful for the treatment of inflammatory disease and the like, and a medicament comprising the compound.The present invention relates to a compound represented by the formula (I):wherein each symbol is as defined in the specification, or a salt thereof.