Polymer having a heterocyclic ring with at least three different elements within the ring