The present invention aims to provide a compound having an MAGL inhibitory action, and useful as a prophylactic or therapeutic agent for neurodegenerative diseases (e.g., Alzheimer's disease, Huntington's disease, Parkinson's disease, amyotrophic lateral sclerosis, traumatic brain injury, glaucoma, multiple sclerosis and the like), anxiety disorder, pain (e.g., inflammatory pain, carcinomatous pain, nervous pain and the like), epilepsy and the like. The present invention relates to a compound represented by the formula (I):wherein each symbol is as described in the DESCRIPTION, or a salt thereof.