Consider the set of pairs "(ia,ib)" where "ia" is an index in "a" and "ib" is an index in "b". Since the chains are circular, this set is a toroidal integer grid with periods "ma=NUMBER(a)" and "mb = NUMBER(b)", respectively. In this program, we only look for candidates that are defined by `perfect' matchings, i.e. matchings without half-steps. Such a matching is a segment of some diagonal line of the "(ia,ib)" grid. Therefore, we enumerate the diagonals of the toroidal grid, and search for candidates within each diagonal in turn. The number of diagonals is "numDiagonal = GCD(ma,mb)", and each diagonal is a circular sequence of "diagSize = (ma*mb)/nDiags". We number the diagonals from "[0..nDiags-1]" and their elements from [0..diagSize-1]", as follows: element index "r" of diagonal number "t" is the pair "(ia,ib)" where "ia = r MOD ma" and "ib = (t-r) MOD mb". Within each diagonal "t", we compute a vector "d2" such that "d2[r]" is the distance squared between "a[ia]" and "b[ib]", where "ia,ib" are the corresponding chain indices. We also compute a boolean vector "ok", such that "ok[r]" tells whether the the "minSteps+1" elements beginning with element "r" would be an acceptable candidate. Specifically, "ok[r] = TRUE" iff the root mean of the squared distances "d2[r+k]" is less than "cutDist". The average is taken for "k" ranging in [0..minSteps]". We then exclude from the "ok" vector any pairs "(ia,ib)" where either "ia" or "ib" lies within a segment listed in "exSeg". The candidates are then found by identifying the maximal substrings of consecutive "TRUE"s in the "ok" vector.