The present invention provide a heterocyclic compound having a HDAC inhibitory action, and useful for the treatment of autoimmune diseases and/or inflammatory diseases, graft versus host disease, cancers, central nervous diseases including neurodegenerative diseases, Charcot-Marie-Tooth disease and the like, and a pharmaceutical composition 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.