A compound represented by the formula: or a pharmaceutically acceptable salt thereof, wherein: Ring A is a 6-membered heteroaryl containing 1-3 N, or phenyl; ring B is a 6-membered heteroaryl containing 1-3 N; R 1 is selected from the group consisting of 5- or 6-membered heteroaryl containing 1-4 O, S, or N, optionally substituted by C 1-3 alkyl, 3-8 membered heterocyclyl containing 1-3 O, S, or N, and C NR 4 R 5; each R 2 is selected from the group consisting of C 1-3 alkyl, C 1-3 alkoxy, haloC 1-3 alkyl, haloC 1-3 alkoxy, halo, and cyano; R 3 is selected from the group consisting of CN, halo, -C 1-6 alkyl, -haloC 1-6 alkyl, -C 1-6 alkoxy, -haloC 1-6 alkoxy, -C 1-6 alkyl-OH, -C 1-3 alkyl-O-C 1-3 alkyl, and -C 1-3 alkyl-S-C 1-3 alkyl; R 4 and R 5 are independently selected from the group consisting of hydrogen, hydroxy, C 1-6 alkyl, C 1-6 alkyl-OH, C 1-6 alkyl-O-C 1-3 alkyl, haloC 1-6 alkyl, C 1-6 alkoxy, C 3-6 cycloalkyl, C 1-3 alkyl-C 3-6 cycloalkyl, wherein the alkyl group is optionally substituted by hydroxy, or 1-3 fluoro, C 1-3 alkyl(C 3-6 cycloalkyl) 2, C 1-3 alkyl-C 3-5 heterocyclyl containing 1-3 N, O, or S, wherein the heterocyclyl is optionally substituted by 1-2 oxo, C 3-5 heterocyclyl containing 1-3 N, O or S, wherein the heterocyclyl is optionally substituted by 1-2 oxo, C 1-3 alkyl-C NH 2, C 1-3 alkyl-S 2 C 1-3 alkyl, C 1-3 alkyl-C 2 C 1-3 alkyl, C C 1-6 alkyl, C C 3-6 cycloalkyl, S 2 C 1-6 alkyl, and S 2 C 3-6 cycloalkyl, or R 4 and R 5 are linked together with the nitrogen to which they are both attached to form a 3-9 membered monocyclic or bicyclic heterocyclic ring, comprising C, O, N, or S ring atoms, wherein the heterocyclic ring is optionally substituted with 1-3 R 6; each R 6 is selected from the group consisting of: C 1-3 alkyl, haloC 1-3 alkyl, C 1-3 alkoxy, C 1-3 alkyl-OH, C 1-3 alkyl-O-C 1-3 alkyl, halo, hydroxy, oxo, C 2 C 1-3 alkyl, C NH 2, C N C 1-6 alkyl, C C 3-6 cycloalkyl, C 3-6 cycloalkyl, C 1-3 alkyl-phenyl, phenyl, 5- or 6-membered heteroaryl, containing 1-3 N, O, or S; and n is 0, 1, 2 or 3. Ring A is a 6-membered heteroaryl containing 1-3 N, or phenyl; ring B is a 6-membered heteroaryl containing 1-3 N; R 1 is selected from the group consisting of 5- or 6-membered heteroaryl containing 1-4 O, S, or N, optionally substituted by C 1-3 alkyl, 3-8 membered heterocyclyl containing 1-3 O, S, or N, and C NR 4 R 5; 5- or 6-membered heteroaryl containing 1-4 O, S, or N, optionally substituted by C 1-3 alkyl, 3-8 membered heterocyclyl containing 1-3 O, S, or N, and C NR 4 R 5; each R 2 is selected from the group consisting of C 1-3 alkyl, C 1-3 alkoxy, haloC 1-3 alkyl, haloC 1-3 alkoxy, halo, and cyano; C 1-3 alkyl, C 1-3 alkoxy, haloC 1-3 alkyl, haloC 1-3 alkoxy, halo, and cyano; R 3 is selected from the group consisting of CN, halo, -C 1-6 alkyl, -haloC 1-6 alkyl, -C 1-6 alkoxy, -haloC 1-6 alkoxy, -C 1-6 alkyl-OH, -C 1-3 alkyl-O-C 1-3 alkyl, and -C 1-3 alkyl-S-C 1-3 alkyl; CN, halo, -C 1-6 alkyl, -haloC 1-6 alkyl, -C 1-6 alkoxy, -haloC 1-6 alkoxy, -C 1-6 alkyl-OH, -C 1-3 alkyl-O-C 1-3 alkyl, and -C 1-3 alkyl-S-C 1-3 alkyl; R 4 and R 5 are independently selected from the group consisting of hydrogen, hydroxy, C 1-6 alkyl, C 1-6 alkyl-OH, C 1-6 alkyl-O-C 1-3 alkyl, haloC 1-6 alkyl, C 1-6 alkoxy, C 3-6 cycloalkyl, C 1-3 alkyl-C 3-6 cycloalkyl, wherein the alkyl group is optionally substituted by hydroxy, or 1-3 fluoro, C 1-3 alkyl(C 3-6 cycloalkyl) 2, C 1-3 alkyl-C 3-5 heterocyclyl containing 1-3 N, O, or S, wherein the heterocyclyl is optionally substituted by 1-2 oxo, C 3-5 heterocyclyl containing 1-3 N, O or S, wherein the heterocyclyl is optionally substituted by 1-2 oxo, C 1-3 alkyl-C NH 2, C 1-3 alkyl-S 2 C 1-3 alkyl, C 1-3 alkyl-C 2 C 1-3 alkyl, C C 1-6 alkyl, C C 3-6 cycloalkyl, S 2 C 1-6 alkyl, and S 2 C 3-6 cycloalkyl, hydrogen, hydroxy, C 1-6 alkyl, C 1-6 alkyl-OH, C 1-6 alkyl-O-C 1-3 alkyl, haloC 1-6 alkyl, C 1-6 alkoxy, C 3-6 cycloalkyl, C 1-3 alkyl-C 3-6 cycloalkyl, wherein the alkyl group is optionally substituted by hydroxy, or 1-3 fluoro, C 1-3 alkyl(C 3-6 cycloalkyl) 2, C 1-3 alkyl-C 3-5 heterocyclyl containing 1-3 N, O, or S, wherein the heterocyclyl is optionally substituted by 1-2 oxo, C 3-5 heterocyclyl containing 1-3 N, O or S, wherein the heterocyclyl is optionally substituted by 1-2 oxo, C 1-3 alkyl-C NH 2, C 1-3 alkyl-S 2 C 1-3 alkyl, C 1-3 alkyl-C 2 C 1-3 alkyl, C C 1-6 alkyl, C C 3-6 cycloalkyl, S 2 C 1-6 alkyl, and S 2 C 3-6 cycloalkyl, each R 6 is selected from the group consisting of: C 1-3 alkyl, haloC 1-3 alkyl, C 1-3 alkoxy, C 1-3 alkyl-OH, C 1-3 alkyl-O-C 1-3 alkyl, halo, hydroxy, oxo, C 2 C 1-3 alkyl, C NH 2, C N C 1-6 alkyl, C C 3-6 cycloalkyl, C 3-6 cycloalkyl, C 1-3 alkyl-phenyl, phenyl, 5- or 6-membered heteroaryl, containing 1-3 N, O, or S; and C 1-3 alkyl, haloC 1-3 alkyl, C 1-3 alkoxy, C 1-3 alkyl-OH, C 1-3 alkyl-O-C 1-3 alkyl, halo, hydroxy, oxo, C 2 C 1-3 alkyl, C NH 2, C N C 1-6 alkyl, C C 3-6 cycloalkyl, C 3-6 cycloalkyl, C 1-3 alkyl-phenyl, phenyl, 5- or 6-membered heteroaryl, containing 1-3 N, O, or S; and n is 0, 1, 2 or 3.