The present invention aims to provide a heterocyclic compound having an IP6K inhibitory action and expected to be useful as a prophylactic or therapeutic agent for- diseases such as cardiac failure, diabetes and the like. A compound represented by the formula (I) : wherein each symbol is as defined in the SPECIFICATION, or a salt thereof has an IP6K inhibitory action and is expected to be useful as a prophylactic or therapeutic agent for diseases such as cardiac failure, diabetes and the like.