The present invention provides a heterocyclic compound possessing CDK8/19 inhibitory activity. The present invention provides a compound represented by the formula wherein each symbol is as defined herein, or a salt thereof.本發明提供一種具有CDK8/19抑制活性之雜環化合物。本發明提供一種如下式代表之化合物(其中各代號均如本文之定義)或其鹽。