An object of the present invention is to provide a compound having a superior CH24H inhibitory action, which is useful as an agent for the prophylaxis or treatment of epilepsy, neurodegenerative disease and the like. The present invention relates to a compound represented by the formula:wherein each symbol is as defined in the specification, or a salt thereof.