To provide a novel compound having a HER2 inhibitory effect and having a cytostatic effect. It is also intended to provide a medicament useful in the prevention and/or treatment of a disease involving HER2, particularly, cancer, on the basis of the HER2 inhibitory effect. The present invention provides a compound of formula (I) wherein X, Y, Z 1 , Z 2 , Z 3 , Z 4 , W, n, R 1 , R 2 , and R 3 have meanings as defined in the present specification, or a salt thereof.