The present invention provides a compound having an MAGL inhibitory action, and useful as an agent for the prophylaxis or treatment of neurodegenerative diseases (e.g., Alzheimer's disease, Parkinson's disease, Huntington's disease, amyotrophic lateral sclerosis, traumatic brain injury, glaucoma, multiple sclerosis etc.), anxiety disorder, pains (e.g., inflammatory pain, cancerous pain, neurogenic pain etc.), epilepsy, depression and the like. 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.