Cyclic imides of polybasic carboxylic acids or thio analogues thereof