A compound represented by the formula or a pharmaceutically acceptable salt thereof: wherein ring A is C 3-6 cycloalkyl, C 6-10 aryl or heterocycle; X is independently CR 4a or a nitrogen atom; R 1 and R 2 are independently a hydrogen atom, a halogen atom, hydroxy, amino, formyl, hydroxy C 1-6 alkyl, C 1-6 alkoxy, C 1-6 alkyl, halo C 1-6 alkyl, cyano, C 1-6 alkylsulfonylamino, imidazolyl, 1,3-dioxolyl or mono(di)C 1-6 alkoxy C 1-6 alkyl; R 3 is a hydrogen atom, a halogen atom, C 1-6 alkyl or formyl; R 4 and R 4a are independently a hydrogen atom, a halogen atom, hydroxy, C 1-6 alkyl, C 1-6 alkoxy, C 1-6 alkoxy C 1-6 alkoxy, halo C 1-6 alkyl, halo C 1-6 alkoxy, hydroxy C 1-6 alkyl, hydroxy C 1-6 alkoxy, cyano, carbamoyl, C 1-6 alkoxycarbonyl C 1-6 alkoxy, C 7-10 aralkyloxy, C 7-10 aralkyloxy C 1-6 alkoxy or 1,3-dioxolyl; ring B is C 6-10 aryl or heterocycle; R 5 is a hydrogen atom, C 1-6 alkyl, mono(di)hydroxy C 1-6 alkyl, C 1-6 alkoxy(hydroxy)C 1-6 alkyl, carboxy C 1-6 alkyl or C 1-6 alkoxycarbonyl C 1-6 alkyl; R 6a is a hydrogen atom, C(=O)R 9, C(=O)NR 10 R 11, -CR 12 R 13 R 14 or a group selected from the following formula: wherein, ( ∗∗) is a bonding site; R 7a is independently a hydrogen atom, a fluorine atom, hydroxy, hydroxy C 1-6 alkyl, C 1-6 alkyl, C 1-6 alkoxy, C 1-6 alkoxy C 1-6 alkyl or amino C 1-6 alkyl; R 7b is independently a hydrogen atom, a fluorine atom or C 1-6 alkyl, or one of R 5 and R 6a may bind together with ring B to form 6-membered ring or may bind together with R 7a to form 5-membered ring; R 6b is a hydrogen atom or C 1-6 alkyl; R 8 is a hydrogen atom, a halogen atom, C 1-6 alkyl, C 1-6 alkoxy, hydroxy, amino, cyano, C 1-6 alkoxycarbonyl, C 1-6 alkoxy C 1-6 alkoxy, carbamoyl, C 1-6 alkoxy C 1-6 alkyl, carboxy, azido, halo C 1-6 alkyl or tetrazolyl; R 9 is hydroxy, C 1-6 alkyl or hydroxy pyrrolidinyl; R 10 and R 11 are independently a hydrogen atom, C 1-6 alkyl, hydroxy C 1-6 alkyl, mono(di)C 1-6 alkylamino C 1-6 alkyl, pyrrolidinyl or piperidinyl; R 12, R 13 and R 14 are independently a hydrogen atom, hydroxy, C 1-6 alkyl, NR 15 R 16, R 15 R 16 N-C 1-6 alkyl, C 1-6 alkoxy, mono(di)hydroxy C 1-6 alkyl, carbamoyl, C 7-10 aralkyloxy C 1-6 alkyl, C 1-6 alkoxy C 1-6 alkyl, a fluorine atom or fluoro C 1-6 alkyl; R 15 is a hydrogen atom, C 1-6 alkyl, (C 1-6 alkyl)carbonyl or C 7-10 aralkyl; R 16 is a hydrogen atom, C 1-6 alkyl or C 7-10 aralkyl; R 17 is a hydrogen atom or C 1-6 alkyl; n is 0, 1 or 2. ring A is C 3-6 cycloalkyl, C 6-10 aryl or heterocycle; X is independently CR 4a or a nitrogen atom; R 1 and R 2 are independently a hydrogen atom, a halogen atom, hydroxy, amino, formyl, hydroxy C 1-6 alkyl, C 1-6 alkoxy, C 1-6 alkyl, halo C 1-6 alkyl, cyano, C 1-6 alkylsulfonylamino, imidazolyl, 1,3-dioxolyl or mono(di)C 1-6 alkoxy C 1-6 alkyl; R 3 is a hydrogen atom, a halogen atom, C 1-6 alkyl or formyl; R 4 and R 4a are independently a hydrogen atom, a halogen atom, hydroxy, C 1-6 alkyl, C 1-6 alkoxy, C 1-6 alkoxy C 1-6 alkoxy, halo C 1-6 alkyl, halo C 1-6 alkoxy, hydroxy C 1-6 alkyl, hydroxy C 1-6 alkoxy, cyano, carbamoyl, C 1-6 alkoxycarbonyl C 1-6 alkoxy, C 7-10 aralkyloxy, C 7-10 aralkyloxy C 1-6 alkoxy or 1,3-dioxolyl; ring B is C 6-10 aryl or heterocycle; R 5 is a hydrogen atom, C 1-6 alkyl, mono(di)hydroxy C 1-6 alkyl, C 1-6 alkoxy(hydroxy)C 1-6 alkyl, carboxy C 1-6 alkyl or C 1-6 alkoxycarbonyl C 1-6 alkyl; R 6a is a hydrogen atom, C(=O)R 9, C(=O)NR 10 R 11, -CR 12 R 13 R 14 or a group selected from the following formula: wherein, ( ∗∗) is a bonding site; R 7a is independently a hydrogen atom, a fluorine atom, hydroxy, hydroxy C 1-6 alkyl, C 1-6 alkyl, C 1-6 alkoxy, C 1-6 alkoxy C 1-6 alkyl or amino C 1-6 alkyl; R 7b is independently a hydrogen atom, a fluorine atom or C 1-6 alkyl, or one of R 5 and R 6a may bind together with ring B to form 6-membered ring or may bind together with R 7a to form 5-membered ring; R 6b is a hydrogen atom or C 1-6 alkyl; R 8 is a hydrogen atom, a halogen atom, C 1-6 alkyl, C 1-6 alkoxy, hydroxy, amino, cyano, C 1-6 alkoxycarbonyl, C 1-6 alkoxy C 1-6 alkoxy, carbamoyl, C 1-6 alkoxy C 1-6 alkyl, carboxy, azido, halo C 1-6 alkyl or tetrazolyl; R 9 is hydroxy, C 1-6 alkyl or hydroxy pyrrolidinyl; R 10 and R 11 are independently a hydrogen atom, C 1-6 alkyl, hydroxy C 1-6 alkyl, mono(di)C 1-6 alkylamino C 1-6 alkyl, pyrrolidinyl or piperidinyl; R 12, R 13 and R 14 are independently a hydrogen atom, hydroxy, C 1-6 alkyl, NR 15 R 16, R 15 R 16 N-C 1-6 alkyl, C 1-6 alkoxy, mono(di)hydroxy C 1-6 alkyl, carbamoyl, C 7-10 aralkyloxy C 1-6 alkyl, C 1-6 alkoxy C 1-6 alkyl, a fluorine atom or fluoro C 1-6 alkyl; R 15 is a hydrogen atom, C 1-6 alkyl, (C 1-6 alkyl)carbonyl or C 7-10 aralkyl; R 16 is a hydrogen atom, C 1-6 alkyl or C 7-10 aralkyl; R 17 is a hydrogen atom or C 1-6 alkyl; n is 0, 1 or 2.