import itertools,time p=996979 I=[(22716,22810),(397695,397787),(731292,731385)] def inV(z,t): for l,r in I: a=(l+t)%p