The present invention provides a heterocyclic compound having an RIP1 kinase inhibitory action, which is useful for the prophylaxis or treatment of Gauchers disease, Niemann-Pick disease, inflammatory bowel disease, multiple sclerosis, chronic kidney disease, acute kidney injury, acute hepatic failure, autoimmune hepatitis, hepatitis B, hepatitis C, alcohol steatohepatitis, non-alcohol steatohepatitis and the like.The present invention relates to a compound represented by the following formula (I):wherein each symbol is as defined in the specification, or a salt thereof.