diff --git a/README.md b/README.md index 14e6bae..ae7c243 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A **Combinatorics** and **Algebraic Number Theory** Symbolic Computation library for Javascript, Python -**version 1.0.7** (~ 317kB minified) +**version 1.0.7** (~ 331kB minified) ![abacus combinatorial numbers](/abacus.jpg) @@ -305,7 +305,7 @@ console.log(m.inv().mul(m).toString()); * add efficient `rank`/`unrank` methods for `Composition` & `Partition` **[DONE]** * add efficient `rank`/`unrank` methods for `DerangementPermutation` **[DONE]** * add efficient `rank`/`unrank` methods for `ConnectedPermutation` **[DONE]** -* add efficient `rank`/`unrank` methods for `InvolutionPermutation` **[DONE PARTIALLY]** +* add efficient `rank`/`unrank` methods for `InvolutionPermutation` **[DONE] (not very efficient)** * support `minimal`/`gray` ordering (and successor) for all supported combinatorial objects (TODO) * support generation (and counting) of combinatorial objects (including the basic supported ones) based on **generic user-defined symbolic constraints / symmetries / rules** to satisfy, for example `permutations` defined symbolicaly and directly by their *symmetries / constraints* instead of being hardcoded as elementary objects (TODO?, see using `filtering` as a similar alternative to this approach) * support *graph-based* combinatorial objects like `Graph`, `Grammar`,.. (TODO?) (for regular grammars and expressions see [RegexAnalyzer](https://github.com/foo123/RegexAnalyzer) for an example) diff --git a/src/js/Abacus.js b/src/js/Abacus.js index f70e33d..68e00af 100644 --- a/src/js/Abacus.js +++ b/src/js/Abacus.js @@ -6620,6 +6620,111 @@ function permutation2count(count, permutation, dir) } return count; } +function countswaps(n, x, y, unvisited) +{ + var Arithmetic = Abacus.Arithmetic, c = Arithmetic.O, j, k; + if (y+1 === n) return Arithmetic.I; + unvisited.rem(x); + unvisited.rem(y); + for (j=unvisited.last(); j && (j.index>y); j=j.prev) + { + unvisited.rem(j); + for (k=j.prev; k && (k.index>=0); k=k.prev) + { + unvisited.rem(k); + c = Arithmetic.add(c, Arithmetic.add(countswaps(n, k.index, j.index, unvisited), j.index+1= swaps.length) return c; + if (y+1 === n) return Arithmetic.I; + s0 = swaps[i][0]; + s1 = swaps[i][1]; + unvisited.rem(x); + unvisited.rem(y); + for (j=unvisited.last(); j && (j.index>y); j=j.prev) + { + b = false; + unvisited.rem(j); + for (k=j.prev; k && (k.index>=0); k=k.prev) + { + unvisited.rem(k); + if (k.index===s0 && j.index===s1) + { + c = Arithmetic.add(Arithmetic.add(c, matchswaps(n, k.index, j.index, swaps, i+1, unvisited)), Arithmetic.I); + b = true; + } + else + { + c = Arithmetic.add(c, Arithmetic.add(countswaps(n, k.index, j.index, unvisited), j.index+1y); j=j.prev) + { + b = false; + unvisited.rem(j); + for (k=j.prev; k && (k.index>=0); k=k.prev) + { + unvisited.rem(k); + r2 = r; + r = Arithmetic.add(r, Arithmetic.add(countswaps(n, k.index, j.index, unvisited), j.index+1y; j--) + { + for (k=j-1; k>=0; k--) + { + c = Arithmetic.add(c, Arithmetic.add(countswaps(n, k, j, unvisited), j+1x; k--) + { + c = Arithmetic.add(c, Arithmetic.add(countswaps(n, k, y, unvisited), y+1=kcycles) return false; fixed = false !== fixed; - var n = perm.length, i, pi, ncycles, cycle, done; - i = 0; ncycles = 0; done = 0; cycle = new Array(n); - while (done="===compare||"=>"===compare ? ncycles>=kcycles : ncycles===kcycles); } @@ -7495,6 +7603,25 @@ ListSet = Abacus.ListSet = function ListSet(a) { } return item.incl; }; + self.item = function(x) { + // return x + var item = null; + if (x === +x) + { + if (0>x || x>=n) return false; + item = a[x]; + } + else if (x && (null != x.index)) + { + if (0>x.index || x.index>=n) return false; + item = x; + } + else + { + return null; + } + return item; + }; self.dispose = function() { a = null; _first = null; @@ -20189,7 +20316,7 @@ Tensor = Abacus.Tensor = Class(CombinatorialIterator, { $.dimension = n.length; if ("gray" === $.output) { - $.output = function(item, n){ return Tensor.gray(item,n); }; + $.output = function(item, n){ return Tensor.toGray(item,n); }; } else if ("inversion" === $.output) { @@ -20416,16 +20543,10 @@ Tensor = Abacus.Tensor = Class(CombinatorialIterator, { return item; } - ,gray: function(item, n, dir) { - dir = -1 === dir ? -1 : 1; - return 0 > dir ? igray(new Array(item.length), item, n) : gray(new Array(item.length), item, n); - } ,toGray: function(item, n) { - dir = -1 === dir ? -1 : 1; return gray(new Array(item.length), item, n); } ,fromGray: function(item, n) { - dir = -1 === dir ? -1 : 1; return igray(new Array(item.length), item, n); } ,inversion: function(inv) { @@ -20555,7 +20676,6 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { // random ordering for derangements / involutions / connecteds // is based on random generation, instead of random unranking $.rand = $.rand || {}; - $.rand["involution"] = 1; if ("multiset" === $.type) { $.multiplicity = is_array($.multiplicity) && $.multiplicity.length ? $.multiplicity.slice() : array($.dimension, 1, 0); @@ -20599,7 +20719,8 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { var item, klass = this, type = $ && $.type ? $.type : "permutation", order = $ && null!=-$.order ? $.order : LEX, kcycles = $ && null!=$['cycles='] ? $['cycles=']|0 : null, - kfixed = $ && null!=$['fixed='] ? $['fixed=']|0 : null + kfixed = $ && null!=$['fixed='] ? $['fixed=']|0 : null, + n_2, nn ; if (0 > n) return null; @@ -20615,10 +20736,27 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { } else if ("derangement" === type) { - if ((null!=kfixed) || (2>n)) return null; - if (n&1) // odd + if (null != kfixed) + { + nn = n-kfixed; + if (0 > nn) return null; + if (nn & 1) // odd + { + n_2 = stdMath.floor(nn/2); + item = 0 > dir ? array(nn-n_2-1, nn-1, -1).concat(1 <= n_2 ? [n_2-1,n_2] : []).concat(array(n_2-1, n_2-2, -1)).concat(array(kfixed, nn, 1)) : array(kfixed, 0, 1).concat(array(nn-3, function(i){return kfixed+(i&1?i-1:i+1);}).concat(3 <= nn ? [n-2,n-1,n-3] : [])); + } + else + { + item = 0 > dir ? array(nn, nn-1, -1).concat(array(kfixed, nn, 1)) : array(kfixed, 0, 1).concat(array(nn, function(i){return kfixed+(i&1?i-1:i+1);})); + } + } + else if (2>n) { - var n_2 = stdMath.floor(n/2); + return null; + } + else if (n & 1) // odd + { + n_2 = stdMath.floor(n/2); item = 0 > dir ? array(n-n_2-1, n-1, -1).concat([n_2-1,n_2]).concat(array(n_2-1, n_2-2, -1)) : array(n-3, function(i){return i&1?i-1:i+1;}).concat([n-2,n-1,n-3]); } else // even @@ -20632,16 +20770,23 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { } else if ("connected" === type) { - // TODO item = cycles2permutation([0 > dir ? array(n, n-1, -1) : [n-1].concat(array(n-1, 0, 1))], n); } else if ("involution" === type) { - item = 0 > dir ? array(n, n-1, -1) : array(n, 0, 1); + item = 0 > dir ? array(n, function(i){return /*n-1-i;*/i&1 ? i-1 : (i+1 dir ? array(n, n-1, -1) : array(n, 0, 1)); + if (null!=kcycles) + { + if (kcycles > n) return null; + item = cycles2permutation(0 > dir ? array(kcycles, function(i){return 0 === i ? array(n-kcycles+1, n-kcycles, -1) : [n-kcycles+i];}) : array(kcycles, function(i){return i+1===kcycles ? [n-1].concat(array(n-kcycles, n-kcycles, 1)) : [i];}), n); + } + else + { + item = 0 > dir ? array(n, n-1, -1) : array(n, 0, 1); + } } item = klass.DUAL(item, n, $); @@ -20708,7 +20853,7 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { if (0 > x || x >= n || 1 === dict[x]) return false; dict[x] = 1; } - if (null!=kcycles && kcycles !== permutation2cycles(item).length) return false; + if (null!=kcycles && !is_kcycle(item, kcycles, '==', true)) return false; } return true; } @@ -20883,82 +21028,13 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { } else if ("involution" === type) { - // O(n^2) - var countswaps = function countswaps(n, x, y, unvisited) { - var c = O, j, k; - if (y+1 === n) return I; - unvisited.rem(x); - unvisited.rem(y); - for (j=unvisited.last(); j && (j.index>y); j=j.prev) - { - unvisited.rem(j); - for (k=j.prev; k && (k.index>=0); k=k.prev) - { - unvisited.rem(k); - c = add(c, add(countswaps(n, k.index, j.index, unvisited), j.index+1= inv.length) return c; - if (y+1 === n) return I; - s0 = inv[i][0]; - s1 = inv[i][1]; - unvisited.rem(x); - unvisited.rem(y); - for (j=unvisited.last(); j && (j.index>y); j=j.prev) - { - b = false; - unvisited.rem(j); - for (k=j.prev; k && (k.index>=0); k=k.prev) - { - unvisited.rem(k); - if (k.index===s0 && j.index===s1) - { - c = add(add(c, matchswaps(n, k.index, j.index, inv, i+1, unvisited)), 1); - b = true; - } - else - { - c = add(c, add(countswaps(n, k.index, j.index, unvisited), j.index+1y; j--) - { - for (k=j-1; k>=0; k--) - { - c = add(c, add(countswaps(n, k, j, unvisited), j+1x; k--) - { - c = add(c, add(countswaps(n, k, y, unvisited), y+1 i +1) + if (y.index > i+1) C.offset(y.index-1, 1).offset(i, -1); i++; } @@ -21154,45 +21254,35 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { ,directsum: function(/* permutations */) { return arguments.length ? permutationdirectsum(is_array(arguments[0])&&is_array(arguments[0][0]) ? arguments[0] : slice.call(arguments)) : null; } - ,cycles: function(item, dir) { - return -1 === dir ? cycles2permutation(item) : permutation2cycles(item); - } ,toCycles: function(item) { return permutation2cycles(item); } ,fromCycles: function(item, n) { return cycles2permutation(item, n); } - ,swaps: function(item, dir) { - return -1 === dir ? swaps2permutation(item) : permutation2swaps(item); - } ,toSwaps: function(item) { return permutation2swaps(item); } ,fromSwaps: function(item, n) { return swaps2permutation(item, n); } - ,inversion: function(item, dir) { - return -1 === dir ? inversion2permutation(null, item) : permutation2inversion(null, item); - } ,toInversion: function(item) { return permutation2inversion(null, item); } ,fromInversion: function(item) { return inversion2permutation(null, item); } - ,inverse: function(item) { - return permutation2inverse(null, item); - } ,toInverse: function(item) { return permutation2inverse(null, item); } - ,multiset: function(item, multi, dir) { - if (item === +item) return multiset(multi, item, -1===dir?-1:1) /*generate multiset*/; - return -1 === dir ? multiset2permutation(item) : permutation2multiset(item, multi); + ,Multiset: function(n, multi, dir) { + return multiset(multi, n, -1===dir?-1:1); } - ,matrix: function(item, transposed, dir) { - return -1 === dir ? matrix2permutation(null, item, transposed) : permutation2matrix(null, item, transposed); + ,toMultiset: function(item, multi) { + return permutation2multiset(item, multi); + } + ,fromMultiset: function(item) { + return multiset2permutation(item); } ,toMatrix: function(item, transposed) { return permutation2matrix(null, item, transposed); @@ -21270,7 +21360,7 @@ function next_permutation(item, N, dir, type, order, multiplicity, PI) { //maybe "use asm" var n = N, m = null == multiplicity ? n : multiplicity, - k, kl, l, r, s, s0, fixed, k0, DK, a, b, da, db, MIN, MAX; + k, kl, l, r, s, s0, fixed, done, k0, DK, a, b, da, db, MIN, MAX; if (0 >= n) return null; if ("connected" === type) @@ -21574,8 +21664,8 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { sub = $.sub; } $.base = n; $.dimension = stdMath.max(0, k); - if ("binary"===$.output) $.output = function(item,n){ return Combination.binary(item,n[0],1); }; - else if ("conjugate"===$.output) $.output = function(item,n){ return Combination.complement(item,n[0]); }; + if ("binary"===$.output) $.output = function(item,n){ return Combination.toBinary(item,n[0]); }; + else if ("conjugate"===$.output) $.output = function(item,n){ return Combination.toComplement(item,n[0]); }; CombinatorialIterator.call(self, "Combination", [n, k], $, sub?{method:$.submethod,iter:sub,pos:$.subpos,cascade:$.subcascade}:null); } @@ -21888,12 +21978,9 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { return item; } - ,complement: function(alpha, n, ordered) { + ,toComplement: function(alpha, n, ordered) { return true === ordered ? shuffle(complement(n, alpha, true)) : complement(n, alpha); } - ,binary: function(item, n, dir) { - return -1 === dir ? binary2subset(item, n) : subset2binary(item, n); - } ,toBinary: function(item, n) { return subset2binary(item, n); } @@ -21916,7 +22003,7 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { } }); // aliases -Combination.conjugate = Combination.complement; +Combination.toConjugate = Combination.toComplement; Combination.project = Combination.choose; function comb_item_(item, n, k, order, type) { @@ -22181,7 +22268,7 @@ Subset = Abacus.Powerset = Abacus.Subset = Class(CombinatorialIterator, { $.mindimension = 0; $.maxdimension = stdMath.max(0, n); $.dimension = $.maxdimension; - if ("binary"===$.output) $.output = function(item,n){ return Subset.binary(item,n,1); }; + if ("binary"===$.output) $.output = function(item,n){ return Subset.toBinary(item,n); }; CombinatorialIterator.call(self, "Subset", n, $, sub?{method:$.submethod,iter:sub,pos:$.subpos,cascade:$.subcascade}:null); } @@ -22463,8 +22550,11 @@ Subset = Abacus.Powerset = Abacus.Subset = Class(CombinatorialIterator, { return item; } - ,binary: function(item, n, dir) { - return -1 === dir ? binary2subset(item, n) : subset2binary(item, n); + ,toBinary: function(item, n) { + return subset2binary(item, n); + } + ,fromBinary: function(item, n) { + return binary2subset(item, n); } } @@ -22632,8 +22722,8 @@ Partition = Abacus.Partition = Class(CombinatorialIterator, { if ("conjugate"===$.output) $.output = function(item,n){ return conjugatepartition(0, item, (REFLECTED&$.order)&&!(COLEX&$.order) || (COLEX&$.order)&&!(REFLECTED&$.order) ? -1 : 1); }; - else if ("subset"===$.output) $.output = function(item,n){ return Partition.subset(item,1); }; - else if ("packed"===$.output) $.output = function(item,n){ return Partition.pack(item,1); }; + else if ("subset"===$.output) $.output = function(item,n){ return Partition.toSubset(item); }; + else if ("packed"===$.output) $.output = function(item,n){ return Partition.toPacked(item); }; CombinatorialIterator.call(self, "Partition", n, $, sub?{method:$.submethod,iter:sub,pos:$.subpos,cascade:$.subcascade}:null); } @@ -23406,14 +23496,20 @@ Partition = Abacus.Partition = Class(CombinatorialIterator, { item = klass.DUAL(item, n, $, 1); return item; } - ,conjugate: function(item, type) { + ,toConjugate: function(item, type) { return conjugatepartition("composition"===type, item); } - ,subset: function(item, dir) { - return -1 === dir ? subset2composition(item) : composition2subset(item); + ,toSubset: function(item) { + return composition2subset(item); + } + ,fromSubset: function(item) { + return subset2composition(item); + } + ,toPacked: function(item) { + return packpartition(item); } - ,pack: function(item, dir) { - return -1 === dir ? unpackpartition(item) : packpartition(item) + ,fromPacked: function(item) { + return unpackpartition(item); } } ,_update: function() { @@ -24693,7 +24789,7 @@ SetPartition = Abacus.SetPartition = Class(CombinatorialIterator, { ,randu: CombinatorialIterator.rand ,rank: NotImplemented ,unrank: NotImplemented - ,conjugate: conjugatesetpartition + ,toConjugate: conjugatesetpartition } ,output: function(item) { if (null == item) return null; diff --git a/src/js/Abacus.min.js b/src/js/Abacus.min.js index 1d79fc6..ae33246 100644 --- a/src/js/Abacus.min.js +++ b/src/js/Abacus.min.js @@ -5,4 +5,4 @@ * @version: 1.0.7 * https://github.com/foo123/Abacus **/ -!function(t,n,e){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(t.$deps=t.$deps||{})&&(t.EXPORTED_SYMBOLS=[n])&&(t[n]=t.$deps[n]=e.call(t)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=e.call(t)):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return e.moduleUri=n.uri,e.call(t)}):n in t||(t[n]=e.call(t)||1)&&"function"==typeof define&&define.amd&&define(function(){return t[n]})}("undefined"!=typeof self?self:this,"Abacus",function(){"use strict";function c(){return Object.create(null)}function r(){for(var n,t,e=arguments,r=e.length,i=(r?e[0]:{})||{},u=1;ue[h]||-1===r&&ae[h]||-1===r&&t[a]e[g][0]?(n[_++]=v=t[d],d+=f):(1===r&&t[d][0]>e[g][0]||-1===r&&t[d][0]e[g][1]?(n[_++]=v=t[d],b&&(n[_++]=e[g])):(n[_++]=v=e[g],b&&(n[_++]=t[d])),d+=f),g+=a):1===r&&t[d]e[g]?(n[_++]=v=t[d],d+=f):(1===r&&t[d]>e[g]||-1===r&&t[d]>=1;return i?Tn(e,e,1):e}function Vn(n,t,e,r){var i,u,l,s=n.length;if(null==e&&(e=0),null==r&&(r=s-1),null==t||0===t){for(t=0,u=n[e],i=e+1;i<=r;i++){if(u<(l=n[i])){if(-1===t)return 0;0===t&&(t=1)}else if(l>>1],t)?r=l+1:i=l;else for(;r>>1])?i=l:r=l+1;return r}function Yn(n,t,e){var r=n.length;return e=e||" ",r>=1,n=ut(n,n,e);else for(r=u.II;!u.equ(t,l);)u.equ(s,u.mod(t,r))&&(i=ut(i,n,e)),t=u.div(t,r),n=ut(n,n,e);return i}function ot(n,t){var e,r,i=J.Arithmetic,u=i.O,l=i.I;i.num;if(i.gt(u,t))return null;if(i.equ(u,t))return l;if(i.equ(l,t))return n;if(r=l,i.isDefault()||i.lte(t,un))for(t=i.val(t);0!==t;)1&t&&(r=i.mul(r,n)),t>>=1,n=i.mul(n,n);else for(e=i.II;!i.equ(u,t);)i.equ(l,i.mod(t,e))&&(r=i.mul(r,n)),t=i.div(t,e),n=i.mul(n,n);return r}function mt(n){var t,e,r,i,u,l,s=J.Arithmetic,o=(s.num,s.O),m=s.I;if(s.equ(n,o)||s.equ(n,m))return n;if(s.isDefault()||s.lte(n,un))return s.num(F.floor(F.sqrt(s.val(n))));for(l=s.II,t=m,e=s.div(n,l),u=t;s.lte(t,e);){if(r=s.div(s.add(t,e),l),i=s.mul(r,r),s.equ(i,n))return r;s.lt(i,n)?(t=s.add(r,m),u=r):e=s.sub(r,m)}return u}function ct(n,t){var e,r;return 0===(t=+t)?null:(t<0&&(n=1/n,t=-t),1===t?n:(1==(e=1&t)&&n<0&&(n=-n),r=F.pow(n,1/t),t=F.pow(r,t),F.abs(n-t)<1&&0o&&(h++,i.terms.length>=e||e<=h))););return 0===h&&t.mod(a).equ(c)?i.abs():i}function ht(n,t){var e,r,i,u=J.Arithmetic,l=u.O,s=u.I,o=u.II,m=p.Epsilon();if(t.equ(l))return null;if(Nn(n,f)&&(n.equ(l)||n.equ(s))||u.isNumber(n)&&(u.equ(l,n)||u.equ(s,n)))return n;if(n=(u=u.isNumber(n)||Nn(n,Z)?p:n[X]).cast(n),Cn(u,p)&&n.lt(l)&&t.mod(o).equ(l)&&(n=(u=v).cast(n)),t.lt(l)&&(n=n.inv(),t=t.neg()),t.equ(s))return n;if(e=Cn(u,R)?new u(at(n.num,t),at(n.den,t)):Cn(u,p)?new u(ft(n.num,t.num),ft(n.den,t.num)):Cn(u,v)?!n.isReal()||!n.real().gte(l)&&t.mod(o).equ(l)?new u(s,s):new u(p(ft(n.real().num,t.num),ft(n.real().den,t.num)),p.Zero()):u.One(),i=t.sub(s),Cn(u,v))for(;;){if((r=n.div(e.pow(i)).sub(e).div(t)).real().abs().lte(m)&&r.imag().abs().lte(m))break;e=e.add(r)}else for(;;){if((r=n.div(e.pow(i)).sub(e).div(t)).abs().lte(m))break;e=e.add(r)}return e}function dt(n,t,e){var r,i,u,l,s,o,m=J.Arithmetic,c=m.num,f=m.O,a=m.J,h=m.I,d=m.II;if(m.lt(t,f)||m.equ(f,m.mod(t,d)))return null;if((m.lt(n,f)||m.gt(n,t))&&(n=m.mod(n,t)),m.equ(f,n))return m.equ(h,t)?h:f;if(m.equ(h,t)||m.equ(h,n))return h;if(null==e&&(e=Nt(n,t)),!m.equ(h,e))return f;for(u=c(3),l=c(4),s=c(5),o=c(8),r=h,m.lt(n,f)&&(n=m.mul(a,n),m.equ(m.mod(t,l),u)&&(r=m.mul(a,r)));!m.equ(f,n);){for(;m.gt(n,f)&&m.equ(f,m.mod(n,d));)n=m.div(n,d),i=m.mod(t,o),(m.equ(i,u)||m.equ(i,s))&&(r=m.mul(a,r));i=n,n=t,t=i,m.equ(u,m.mod(n,l))&&m.equ(u,m.mod(t,l))&&(r=m.mul(a,r)),n=m.mod(n,t)}return m.equ(h,t)||(r=f),r}function gt(n,t){var e=J.Arithmetic,r=(e.num,e.I),i=e.II;return st(n,e.div(e.sub(t,r),i),t)}function _t(n,t){var e,r,i,u,l,s,o,m,c,f,a,h,d=J.Arithmetic,g=(d.num,d.O),_=d.I;if(!d.equ(_,gt(n,t)))return null;for(e=d.II,i=r=d.sub(t,_),u=0;d.equ(g,d.mod(i,e));)i=d.div(i,e),u+=1;if(1===u)return st(n,d.div(d.add(t,_),4),t);for(l=g;d.lt(l,t)&&!d.equ(r,gt(l,t));l=d.add(l,_));for(s=st(l,i,t),o=st(n,d.div(d.add(i,_),e),t),m=st(n,i,t),c=u,f=g;!d.equ(g,d.mod(d.sub(m,_),t));){for(f=ut(m,m,t),h=1;hs&&(o.length=s),o}(wt(t),wt(e.div(n,t)))),r?t.map(function(n){return[new r(n[0]),new r(n[1])]}):t}function St(n,t){return n===t}function Ct(n,t,e){var r,i,u,l;for(e=e||St,r=n(t),i=n(r);!e(r,i);)r=n(r),i=n(n(i));for(u=0,r=t;!e(r,i);)r=n(r),i=n(i),u++;for(l=1,i=n(r);!e(r,i);)i=n(i),l++;return[l,u]}function Nt(){var n,t,e,r,i=arguments.length&&(qn(arguments[0])||An(arguments[0]))?arguments[0]:arguments,u=i.length,l=J.Arithmetic,s=(l.num,l.O),o=l.I;if(0===u)return s;for(r=0;r(n=_.cast(n)).length&&(n=n.concat(En(i-n.length,function(n){return v}))),s=(l=t.t().ref(!0))[0],_=l[3],o=l[1].length,c=_.t(),m=s.t(),d=new Array(u),g=new Array(u-o),f=0;f>>1;return i.mul(n(t,e,u),n(t,1+u,r))}(l,0,l.length-1)},u=function n(t,e){if(f.lt(t,d))return h;var r=n(f.div(t,d),e);return f.mul(f.mul(r,r),i(t,e))};return f.lt(t,d)?h:(n=f.sub(t,f.digits(t,2).split("").reduce(function(n,t){return f.add(n,"1"===t?h:a)},a)),e=(r=k()).get(function(n){return f.lte(n,t)}),r.dispose(),f.mul(u(t,e),Vt(n)))}function Kt(e,n){var t,r,i,u=J.Arithmetic,l=u.O,s=u.I,o=u.J,m=u.II,c=u.num,f=u.val,a=u.add,h=u.sub,d=u.div,g=u.mul,_=u.mod,v=l,b=J.Options.MAXMEM;if(Nn(e,Z))return new e[X](Kt(e.num,n));if(e=c(e),null==n){if(u.lte(e,12))return u.lt(e,l)?l:c([1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600][f(e)]);if(u.gte(e,100))return Ht(e);t=String(e),null==Kt.mem1[t]?(v=g(Kt(h(e,s)),e),u.lt(e,b)&&(Kt.mem1[t]=v)):v=Kt.mem1[t]}else if(!1===n){if(u.lte(e,12))return u.equ(e,l)?s:u.lte(e,s)?l:c([1,2,9,44,265,1854,14833,133496,1334961,14684570,176214841][f(h(e,m))]);if(t="!"+String(e),null==Kt.mem2[t]){if(u.gt(e,1e4))for(i=s,r=v=l;u.lte(r,e);r=a(r,s))v=a(v,g(i,g(Kt(e,r),Kt(h(e,r))))),i=u.neg(i);else v=a(u.equ(l,_(e,m))?s:o,g(Kt(h(e,s),!1),e));u.lt(e,b)&&(Kt.mem2[t]=v)}else v=Kt.mem2[t]}else if(!0===n){if(u.lte(e,18))return u.lt(e,l)?l:c([1,1,2,4,10,26,76,232,764,2620,9496,35696,140152,568504,2390480,10349536,46206736,211799312,997313824][f(e)]);t="I"+String(e),null==Kt.mem2[t]?(v=a(Kt(h(e,s),!0),g(Kt(h(e,m),!0),h(e,s))),u.lt(e,b)&&(Kt.mem2[t]=v)):v=Kt.mem2[t]}else if(qn(n)){if(!n.length)return u.lt(e,l)?l:Kt(e);if(u.lt(e,l))return l;if(qn(n[0])){if(!(n=n[0]).length)return u.lt(e,l)?l:Kt(e);if(1===n.length)return Kt(e,n[0]);if(v=Dn(function(n,t){return a(n,t)},l,n),u.equ(v,l))return e;if(u.gt(v,e))return l;if(t=String(e)+"@"+Wn(n.map(String),1,!0).join(",")+"@",null==Kt.mem3[t]){for(r=h(v,s),v=s;u.gte(r,l);)v=g(v,h(e,r)),r=h(r,s);v=Dn(function(n,t){return d(n,Kt(t))},v,n),u.lt(e,b)&&(Kt.mem3[t]=v)}else v=Kt.mem3[t]}else t=String(e)+"@"+Wn(n.map(String),1,!0).join(","),null==Kt.mem3[t]?(v=Dn(function(n,t){return d(n,Kt(t))},Kt(e),n),u.lt(e,b)&&(Kt.mem3[t]=v)):v=Kt.mem3[t]}else if(u.isNumber(n)||Nn(n,Z))if(n=Nn(n,Z)?n.num:c(n),u.lt(n,l)){if(u.lte(e,u.neg(n)))return u.equ(e,u.neg(n))?Kt(e):l;if(t=String(e)+"@"+String(n),null==Kt.mem3[t]){if(r=a(e,n),u.gt(h(e,r),500))v=d(Kt(e),Kt(r));else for(v=r=a(r,s);u.lt(r,e);)v=g(v,r=a(r,s));u.lt(e,b)&&(Kt.mem3[t]=v)}else v=Kt.mem3[t]}else{if(u.lt(n,l)||u.lt(e,l)||u.gt(n,e))return l;if(u.lt(e,g(n,m))&&(n=h(e,n)),u.equ(n,l)||u.equ(e,s))return s;if(u.equ(n,s))return e;if(t=String(e)+"@"+String(n),null==Kt.mem3[t]){if(u.lte(e,20))v=a(Kt(h(e,s),h(n,s)),Kt(h(e,s),n));else if(u.isDefault())v=F.round(Dn(function(n,t){return n*(1+e/t)},1+(e-=n),null,2,n));else if(r=h(e,n),u.gt(h(e,r),500))v=d(Kt(e),g(Kt(n),Kt(r)));else{for(v=r=a(r,s);u.lt(r,e);)v=g(v,r=a(r,s));v=d(v,Kt(n))}u.lt(e,b)&&(Kt.mem3[t]=v)}else v=Kt.mem3[t]}return v}function Yt(n,t){var e,r,i,u,l=J.Arithmetic,s=l.O,o=l.I,m=(l.J,l.num),c=l.add,f=l.sub,a=l.mul,h=J.Options.MAXMEM;if(Nn(n,Z))return new n[X](Yt(n.num,t));if(n=m(n),t=Nn(t,Z)?t.num:m(t),l.lt(n,s)||l.lt(t,s)||l.gt(t,n))return s;if(l.equ(t,s))return Kt(n);if(l.equ(t,n))return Kt(n,!1);if(m=String(n)+","+String(t),null==Yt.mem[m]){if(e=s,u=f(n,t),l.lt(u,t))for(r=s;l.lte(r,u);r=c(r,o))e=c(e,a(Kt(u,r),Kt(c(t,r),!1)));else for(i=o,r=s;l.lte(r,t);r=c(r,o))e=c(e,a(i,a(Kt(t,r),Kt(f(n,r))))),i=l.neg(i);l.lt(n,h)&&(Yt.mem[m]=e)}else e=Yt.mem[m];return e}function ne(n,t,e,r,i){for(var u=J.Arithmetic,l=u.O,s=0;s_&&(v.length=_),v}function he(n,t,e,r,i){r=!0===r,e=e===A?A:q,i=i||M.Q();for(var u,l=0,s=0,o=0,m=n.length,c=t.length,f=new Array(m+c),a=J.Arithmetic.O;lo&&(f.length=o),f}function de(t,e,r,i){r=r===A?A:q,i=i||M.Q();var n,u,l,s,o,m,c,f=J.Arithmetic.O;if(t.length>e.length&&(u=t,t=e,e=u),u=t.length,l=e.length,s=new Array(u*l),0n+1&&(s.length=n+1)}return s}function ge(n,t,e,r,i){r=!0===r,e=e===A?A:q,i=i||M.Q();var u,l,s,o=n.length,m=t.length,c=J.Arithmetic.O,f=g([],"max",function(n,t){return e.cmp(n.term,t.term)}),a=[],h=[],d=0;if(!t.length)return null;for(s=t[0].cast(i);(l=f.peek())||dl.n?f.replace({term:l.Q.mul(t[l.n].cast(i)),n:l.n+1,Q:l.Q}):f.pop(),d++):(u=l.term.neg(),m>l.n?f.replace({term:l.Q.mul(t[l.n].cast(i)),n:l.n+1,Q:l.Q}):f.pop()),u.equ(c)||(s.divides(u)?(a=he(a,[l=u.div(s)],e,!1,i),1=u&&(i=0,r+=u);if(!0===e)for(r=0;r=l&&(i=0,r++);else for(i=r=0;r=l&&(i=0,r++);return n}function Ie(e,n,t){var r=e?e.length:0,i=1,u=0,l=0,s=l>>1<<1]),s[r]+=1,r>>>=1;return s[r]+=1,n[e]=t,n},n||new Array(r),t)}function Se(n,t,e){for(var r,i,u=t.length,l=F.ceil(V(e||u)),s=1<=o[r<<=1]&&(t-=o[r],r++);return o[r]=0,n[e]=r-s,n},n||new Array(u),t)}function Ce(n,t){var e=n.length,r=new Array(e),i=!0===t?1:0,u=En(e,0,0),l=0,s=0,o=new Array(e),m=0,c=l++;for(u[o[m++]=c]=1;lt)return!1;return!0!==e||r===t}function Te(n){for(var t=n.length-1,e=-1,r=0,i=n[r];r>t},bor:function(n,t){return n|t},band:function(n,t){return n&t},xor:function(n,t){return n^t},abs:F.abs,min:F.min,max:F.max,rnd:$e},J.Arithmetic=r({},t,{isDefault:function(){return 0===this.O&&this.add===nt},neg:function(n){return J.Arithmetic.mul(J.Arithmetic.J,n)},abs:function(n){return J.Arithmetic.gt(J.Arithmetic.O,n)?J.Arithmetic.neg(n):n},min:function(n,t){return J.Arithmetic.lt(n,t)?n:t},max:function(n,t){return J.Arithmetic.gt(n,t)?n:t},divceil:function(n,t){if(null==t)return n;var e=J.Arithmetic,r=e.O,i=e.I,u=e.div(n,t);return!e.equ(r,e.mod(n,t))&&e.gt(n,r)===e.gt(t,r)?e.add(u,i):u}}),J.Math={rnd:F.random,rndInt:$e,factorial:Kt,stirling:te,partitions:ie,compositions:se,bell:me,catalan:oe,fibonacci:ce,polygonal:function n(t,e){var r=J.Arithmetic,i=(r.O,r.I,r.II),u=r.num;return Nn(e,Z)&&(e=e.num),e=u(e),r.lt(e,3)?null:Nn(t,Z)?new t[X](n(t.num,e)):(t=u(t),r.div(r.mul(t,r.sub(r.mul(t,r.sub(e,i)),r.sub(e,4))),i))},sum:tt,product:et,pow2:Vt,exp:Bt,powsq:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](ot(n.num,t)):ot(e.num(n),t)},addm:function(n,t,e){var r=J.Arithmetic;return e=Nn(e,Z)?e.num:r.num(e),t=Nn(t,Z)?t.num:r.num(t),Nn(n,Z)?new n[X](it(n.num,t,e)):it(r.num(n),t,e)},negm:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](rt(n.num,t)):rt(e.num(n),t)},mulm:function(n,t,e){var r=J.Arithmetic;return e=Nn(e,Z)?e.num:r.num(e),t=Nn(t,Z)?t.num:r.num(t),Nn(n,Z)?new n[X](ut(n.num,t,e)):ut(r.num(n),t,e)},invm:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](lt(n.num,t)):lt(e.num(n),t)},powm:function(n,t,e){var r=J.Arithmetic;return e=Nn(e,Z)?e.num:r.num(e),t=Nn(t,Z)?t.num:r.num(t),Nn(n,Z)?new n[X](st(n.num,t,e)):st(r.num(n),t,e)},isqrt:function(n){var t=J.Arithmetic;return Nn(n,Z)?new n[X](mt(n.num)):mt(t.num(n))},ikthroot:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](ft(n.num,t)):ft(e.num(n),t)},isqrtp:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](_t(n.num,t)):_t(e.num(n),t)},ilog:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](vt(n.num,t)):vt(e.num(n),t)},divisors:function(n,t){var e=J.Arithmetic;return Lt(Nn(n,Z)?n:e.num(n),!0===t)},legendre:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](gt(n.num,t)):gt(e.num(n),t)},jacobi:function(n,t){var e=J.Arithmetic;return t=Nn(t,Z)?t.num:e.num(t),Nn(n,Z)?new n[X](dt(n.num,t)):dt(e.num(n),t)},moebius:function(n){var t=J.Arithmetic;return Nn(n,Z)?new n[X](jt(n.num)):jt(t.num(n))},pollardRho:function(n,t,e,r,i,u){var l,s=J.Arithmetic.num;return null!=e&&(e=Nn(e,Z)?e.num:s(e)),null!=t&&(t=Nn(t,Z)?t.num:s(t)),Nn(n,Z)?null==(l=Ot(n.num,t,e,r,i||null,u||null))?l:new n[X](l):Ot(s(n),t,e,r,i||null,u||null)},factorize:function(n){var t=J.Arithmetic;return wt(Nn(n,Z)?n:t.num(n))},isProbablePrime:function(n){var t=J.Arithmetic;return qt(Nn(n,Z)?n.num:t.num(n))},isPrime:function(n){var t=J.Arithmetic;return It(Nn(n,Z)?n.num:t.num(n))},nextPrime:function(n,t){var e=J.Arithmetic;return function(n,t){var e,r=J.Arithmetic,i=(r.num,r.O),u=r.I,l=r.II;if((t=-1===t?-1:1)<0){if(r.lte(n,l))return null;if(r.equ(n,3))return l;for(e=r.sub(n,r.equ(i,r.mod(n,l))?u:l);;e=r.sub(e,l))if(qt(e)&&It(e))return e}else{if(r.lt(n,l))return l;for(e=r.add(n,r.equ(i,r.mod(n,l))?u:l);;e=r.add(e,l))if(qt(e)&&It(e))return e}}(Nn(n,Z)?n.num:e.num(n),-1===t?-1:1)},gcd:function(){var t=J.Arithmetic,n=G.call(arguments.length&&(qn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),e=null,n=Nt(n.map(function(n){return Nn(n,Z)?(e=e||n[X],n.num):t.num(n)}));return e?new e(n):n},xgcd:function(){var t=J.Arithmetic,n=G.call(arguments.length&&(qn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),e=null,n=Mt(n.map(function(n){return Nn(n,Z)?(e=e||n[X],n.num):t.num(n)}));return e&&n?n.map(function(n){return new e(n)}):n},lcm:function(){var t=J.Arithmetic,n=G.call(arguments.length&&(qn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),e=null,n=Zt(n.map(function(n){return Nn(n,Z)?(e=e||n[X],n.num):t.num(n)}));return e?new e(n):n},diophantine:function(n,t,e,r){var i=J.Arithmetic;return(qn(n)||An(n))&&n.length?Qt(i.nums(n),i.num(t||0),e,!0===r):null},diophantines:function(n,t,e,r){var i=M.Z();return(Nn(n,D)||qn(n)||An(n))&&(!Nn(n,D)||n.nr&&n.nc)&&(Nn(n,D)||n.length)?(Nn(t,D)||qn(t)||An(t)||(t=En(Nn(n,D)?n.nr:n.length,function(){return t||0})),Xt(n,t=Nn(t,D)?t:i.cast(t),e,!0===r)):null},congruence:function(n,t,e,r,i){var u,l,s,o,m,c,f=J.Arithmetic;return(qn(n)||An(n))&&n.length?(n=f.nums(n),t=f.num(t||0),u=f.num(e||0),l=r,i=!0===i,m=J.Arithmetic,c=m.O,n.length?(i=!0===i,(s=Qt(n.concat(u),t,l,i))&&i&&(o=s[1],s=s[0]),null==(s=null==s?null:En(s.length-1,function(n){n=s[n];return!1===l?m.gt(c,n)&&(n=m.add(n,u)):n.c().real().lt(c)&&(n=n.add(u)),n}))?null:i?[s,o]:s):null):null},congruences:function(n,t,e,r,i){var u,l,s,o,m,c,f,a,h=M.Z();return(Nn(n,D)||qn(n)||An(n))&&(!Nn(n,D)||n.nr&&n.nc)&&(Nn(n,D)||n.length)?(n=Nn(n,D)?n:h.cast(n),Nn(t,D)||qn(t)||An(t)||(t=En(Nn(n,D)?n.nr:n.length,function(){return t||0})),t=Nn(t,D)?t:h.cast(t),Nn(e,D)||qn(e)||An(e)||(e=En(Nn(n,D)?n.nr:n.length,function(){return e||0})),e=Nn(e,D)?e:h.cast(e),u=n,h=t,l=e,s=r,n=!0===i,r=M.Z(),f=J.Arithmetic,a=r.Zero(),Nn(u,D)&&Cn(u.ring.NumberClass,Z)||(u=D(r,u)),u.nr&&u.nc?(qn(l)||An(l)||Nn(l,D)||(l=En(u.nr,function(n){return l})),(qn(l)||An(l))&&(l=D(r,l)),(qn(h)||An(h))&&(h=D(r,h)),i=l.col(0),m=r.lcm(i),u=u.concat(l),n=!0===n,null!=(o=Xt(u,h,s,!0))&&(c=o[1],o=o[0]),null==(o=null==o?null:En(o.length-1,function(n){var t,e=o[n],r=!0;if(!1===s)f.gt(f.O,e)&&(e=f.add(e,m.num));else{for(t in e.terms)if(z.call(e.terms,t)&&"1"!==t&&f.equ(f.O,f.mod(m.num,e.terms[t].c().real().num))){r=!1;break}r&&(n=c.symbol+"_"+(c.length+1),c.push(n),e=e.add(C(S(n),m))),e.c().real().lt(a)&&(e=e.add(m))}return e}))?null:n?[o,c]:o):null):null},pythagorean:function(n,t){var e=J.Arithmetic;return(qn(n)||An(n))&&n.length?function(t,n){var e,r,i,u,l,s,o,m,c=J.Arithmetic,f=c.O,a=c.I,h=c.J,d=c.II,g=t.length,_=On(n)&&n.length?n:"i";if(!g)return null;if(m=t.filter(function(n){return 1===Gt(n)}).length,n=t.filter(function(n){return-1===Gt(n)}).length,1===g||0===m||0===n)return En(g,function(){return N()});if(o=En(g,function(n){return mt(c.abs(t[n]))}),g!==t.filter(function(n,t){return c.equ(c.abs(n),c.mul(o[t],o[t]))}).length)return En(g,function(){return N()});if(u=En(g-1,function(n){return _+"_"+(n+1)}),2===g)return[N(C(S(u[0]),o[1])),N(C(S(u[0]),o[0]))];for(Gt(t[0])+Gt(t[1])+Gt(t[2])<0&&(t=t.map(function(n){return c.neg(n)})),l=e=0;lr.length&&(r=r.concat(En(u.nc-r.length,function(n){return r[r.length-1].split("_")[0]+"_"+(r.length+n+1)}))),En(i.nr,function(t){return N(En(u.nc,function(n){return C(S(r[n]),u.val[t][n])})).add(i.val[t][0])})):null):null):null},lineqs:function(n,t,e){var r=M.Q();return(Nn(n,D)||qn(n)||An(n))&&(!Nn(n,D)||n.nr&&n.nc)&&(Nn(n,D)||n.length)?(Nn(t,D)||qn(t)||An(t)||(t=En(Nn(n,D)?n.nr:n.length,function(){return t||0})),function(t,e,r){var n,i,u,l,s,o,m,c,f,a,h,d;if(Nn(t,D)||(t=D(M.Q(),t)),!t.nr||!t.nc||t.ring!==M.Q())return null;for(e=D(t.ring,e).col(0),u=t.nc,l=t.nr,On(r=r||"x")?r=En(u,function(n){return r+"_"+(n+1)}):qn(r)&&u>r.length&&(r=r.concat(En(u-r.length,function(n){return r[r.length-1].split("_")[0]+"_"+(r.length+n+1)}))),i=[],n=En(l,function(n){return y.LTE(N(t.row(n).map(function(n,t){return C(S(r[t]),n)})),N(e[n]))}).slice(),s=u-1;0<=s;s--)if(c=[],f=[],a=[],n.forEach(function(n){var t=n.lhs.term(r[s]).c().sub(n.rhs.term(r[s]).c()),n=n.rhs.sub(n.rhs.term(r[s])).sub(n.lhs.sub(n.lhs.term(r[s])));t.gt(0)?c.push(n.div(t)):t.lt(0)?f.push(n.div(t)):a.push(n)}),c.length&&f.length){for(m=c.length*f.length+a.length,n=new Array(m),o=0;ol&&(u.length=l),u},intersection:function(n,t,e,r,i,u,l,s){r=-1===r?-1:1,null==i&&(i=0),null==u&&(u=t.length-1),null==l&&(l=0),null==s&&(s=e.length-1);var o=ue[h]?a+=o:(1===r&&t[a]>e[h]||-1===r&&t[a]r[a]?a+=m:(n[h++]=e[f],t[e[f]]--,f+=o);for(;0<=o*(u-f);)0>>1]))return s;l(o,n)?c=s-1:m=s+1}else for(;m>>1]))return s;l(n,o)?c=s-1:m=s+1}return-1},bisect:Kn,complementation:Pn,reflection:$n,reversion:kn,gray:Ln,igray:jn,grayn:Un,igrayn:Jn,finitedifference:Qn,partialsum:Xn,convolution:function(n,t,e){var r,i,u,l=n.length,s=t.length;if(!0===e)for(u=En(l+s-1,function(){return 0}),r=0;r>>5]&1<<(31&n))},set:function(n){return this.bits[n>>>5]|=1<<(31&n),this},unset:function(n){return this.bits[n>>>5]&=~(1<<(31&n)),this},toggle:function(n){return this.bits[n>>>5]^=1<<(31&n),this}}),b=J.Node=function n(t,e,r,i){var u=this;if(!Nn(u,n))return new n(t,e,r,i);u.v=t,u.l=e||null,u.r=r||null,u.t=i||null,u.dispose=function(){return u.v=null,u.l=null,u.r=null,u.t=null,u}},g=J.Heap=n({constructor:function n(t,e,r){var i=this;if(!Nn(i,n))return new n(t,e,r);e=String(e||"min").toLowerCase().slice(0,3),i.type="max"===e?"max":"min",Sn(r)||(r=n.CMP),i.cmp=r,t=t||[],i._h=n.heapify(t,i.type,i.cmp)},__static__:{CMP:function(n,t){return n>>1)-1;0<=r;r--)g._siftup_max(n,r,e);else for(r=(i>>>1)-1;0<=r;r--)g._siftup(n,r,e);return n},_siftdown:function(n,t,e,r){for(var i,u,l=n[e];t>>1])<0;)n[e]=u,e=i;n[e]=l},_siftup:function(n,t,e){for(var r,i=n.length,u=t,l=n[t],s=2*t+1;s>>1],l)<0;)n[e]=u,e=i;n[e]=l},_siftup_max:function(n,t,e){for(var r,i=n.length,u=t,l=n[t],s=2*t+1;s=_.length&&g.slice(-_.length)===_;)g=g.slice(0,-_.length);g.length||(g=null)}i=c.sub(c.pow(n,(g?g.length:0)+_.length),g?c.pow(n,g.length):a),r=c.add(c.mul(i,e),c.sub(h((g||"")+_),g?h(g):f))}else{for(;g&&"0"===g.slice(-1);)g=g.slice(0,-1);r=g&&g.length?(i=c.pow(n,g.length),c.add(c.mul(i,e),h(g))):(i=a,e),u[6]&&(s=h(u[6].slice(1)),c.lt(s,f)?i=c.mul(i,c.pow(n,c.neg(s))):r=c.mul(r,c.pow(n,s)))}return!1!==t&&(t=Nt(r,i),r=c.div(r,t),i=c.div(i,t)),o[0]=d?c.neg(r):r,o[1]=i,o}(n,!0);return n?p(n[0],n[1],!0):p.Zero()},fromString:function(n){var t,e,r,i=J.Arithmetic,u="+",l=p.Zero();if(!(n=H(String(n))).length)return l;if("+"!==n.charAt(0)&&"-"!==n.charAt(0)||(u=n.charAt(0),n=H(n.slice(1))),!n.length)return l;if("("===n.charAt(0)&&")"===n.charAt(n.length-1)&&(n=H(n.slice(1,-1))),!n.length)return l;if(-1!==n.indexOf(".")||-1!==n.indexOf("e"))return t=p.fromDec(n),"-"===u&&(t=t.neg()),t;if(-1!==n.indexOf("\\frac")){if(!(t=n.match(/^(-)?\\frac\{(-?\d+)\}\{(-?\d+)\}$/)))return l;"-"===t[1]&&(u="-"===u?"+":"-"),e=i.num(t[2]),r=i.num(t[3])}else n=String(n).split("/"),e=i.num(n[0].length?n[0]:"0"),r=1>=1,e=e.mul(e);return t},rad:function(n){var t=this,e=J.Arithmetic;return(n=Z.cast(n)).equ(e.I)?t:n.equ(e.II)?t.imag().equ(0)?t.real().lt(0)?v(p.Zero(),t.real().abs().rad(n)):v(t.real().rad(n),p.Zero()):(e=t.norm().rad(2),v(e.add(t.real()).div(2).rad(n),e.sub(t.real()).div(2).rad(n).mul(t.imag().lt(0)?-1:1))):ht(t,n)},simpl:function(){var n=this;return n._simpl||(n.re.simpl(),n.im.simpl(),n._str=null,n._strp=null,n._tex=null,n._simpl=!0),n},round:function(n){n=!1!==n;return v(this.re.round(n),this.im.round(n))},integer:function(){var n=this;return null==n._int&&(n._int=v(n.re.integer(),n.im.integer())),n._int},remainder:function(){var n=this;return null==n._rem&&(n._rem=v(n.re.remainder(),n.im.remainder())),n._rem},tuple:function(){return[this.re,this.im]},valueOf:function(){return this.re.valueOf()},toString:function(n){var t,e=this,r=J.Arithmetic,i=r.O;return null==e._str&&(t=e.re.equ(i),e._str=(t?"":e.re.toString())+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+v.Symbol),e._str.length||(e._str="0"),e._strp=(t?"":e.re.toString(!0))+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+v.Symbol),e._strp.length||(e._strp="0")),n?e._strp:e._str},toTex:function(){var n,t=this,e=J.Arithmetic,r=e.O;return null==t._tex&&(n=t.re.equ(r),t._tex=(n?"":t.re.toTex())+(t.im.equ(r)?"":(!t.im.gt(r)||n?"":"+")+(t.im.equ(e.I)?"":t.im.equ(e.J)?"-":t.im.toTex())+v.Symbol),t._tex.length||(t._tex="0")),t._tex},toDec:function(n){var t,e=this,r=J.Arithmetic,i=r.O;return null==e._dec&&(t=e.re.equ(i),e._dec=(t?"":e.re.toDec())+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toDec())+v.Symbol),e._dec.length||(e._dec="0")),wn(n)&&0<=n?((r=((t=e.re.equ(i))?"":e.re.toDec(n))+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toDec(n))+v.Symbol)).length||(r="0",0>=1,e=e.mul(e);return t},rad:function(n){var t=this,e=J.Arithmetic,r=e.O,e=e.I;return n=Z.cast(n),t.equ(r)?N():n.equ(r)?null:n.equ(e)?t:N(1===t.symbols().length?t.terms[1].rad(n):C(h(t,p(e,n.num)),e))},d:function(t,e){var r=this;return null==e&&(e=1),e=+e,t=String(t||"x"),e<0?null:N(r.symbols().map(function(n){return"1"===n?J.Arithmetic.O:r.terms[n].d(t,e)}))},evaluate:function(e){var r=this;J.Arithmetic.O;return e=e||{},r.symbols().reduce(function(n,t){return n.add(r.terms[t].evaluate(e))},v.Zero())},toString:function(){var n,t,e,r,i,u=this,l=J.Arithmetic.O,s="",o=!1;if(null==u._str){for(e=(n=u.symbols()).length,t=0;t"===n||"\\gt"===n?">":">="===n||"=>"===n||"\\le"===n?">=":"<="===n||"=<"===n||"\\ge"===n?"<=":"<>"===n||"!="===n||"\\ne"===n?"<>":"~"===n||"\\sim"===n?"~":"="},DUAL:function(n){return"<"===(n=y.OP(n))?">":">"===n?"<":">="===n?"<=":"<="===n?">=":n},EQU:function(n,t){return new y(n,"=",t)},NEQ:function(n,t){return new y(n,"<>",t)},LT:function(n,t){return new y(n,"<",t)},LTE:function(n,t){return new y(n,"<=",t)},GT:function(n,t){return new y(n,">",t)},GTE:function(n,t){return new y(n,">=",t)},SIM:function(n,t){return new y(n,"~",t)},fromString:function(r){var n=String(r).split(/\\sim|\\lt|\\gt|\\le|\\ge|\\ne|\\eq|=<|<=|>=|=>|<>|!=|<|>|=|~/gm),t=["\\sim","\\lt","\\gt","\\le","\\ge","\\ne","\\eq","=<","<=",">=","=>","<>","!=","<",">","=","~"].reduce(function(n,t){var e=r.indexOf(t);return-1"===t?e.gt(n):"<"===t?e.lt(n):">="===t?e.gte(n):"<="===t?e.lte(n):"<>"===t?!e.equ(n):"~"===t||e.equ(n)},toString:function(){var n=this.op;return this.lhs.toString()+" "+n+" "+this.rhs.toString()},toTex:function(){var n=this.op;return">="===n?n="\\ge":"<="===n?this.op="\\le":"<>"===n?this.op="\\ne":"~"===n&&(n="\\sim"),this.lhs.toTex()+" "+n+" "+this.rhs.toTex()}}),x=J.Func=n(t,{constructor:function t(n,e,r,i){if(!Nn(this,t))return new t(n,e,r,i);Nn(n,t)?(this.func=n.op,this.args=n.args,this._eval=r||n._eval,this._deriv=i||n._deriv):(n=String(n||"").toLowerCase(),null!=e&&e.length||(e=[]),this.op=n,this.args=e.map(function(n){return Nn(n,[N,d,t])||(n=d(n)),n}),this._eval=r||null,this._deriv=i||null)},__static__:{MIN:function(n){return x("min",n,Le)},MAX:function(n){return x("max",n,ke)}},args:null,_eval:null,_deriv:null,dispose:function(){return this._eval=null,this._deriv=null,this.args=null,this.op=null,this},clone:function(){return new this[X](this.op,this.args,this._eval,this._deriv)},isReal:function(){var n=self.args;return n.filter(function(n){return n.isReal()}).length===n.length},isImag:function(){var n=self.args;return n.filter(function(n){return n.isImag()}).length===n.length},real:function(){return x(this.op,this.args.map(function(n){return n.real()}),this._eval,this._deriv)},imag:function(){return x(this.op,this.args.map(function(n){return n.imag()}),this._eval,this._deriv)},equ:function(e){return Nn(e,x)?this.op===e.op&&this.args.filter(function(n,t){return tn.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],w.Add(w(n,r,t.ring),w(t,r,t.ring),e);n.terms.length&&(t.terms=he(t.terms,n.terms,q,!0===e,t.ring))}else(Nn(n,f)||i.isNumber(n))&&((n=q(n,0,t.ring)).equ(i.O)||(n=t.terms.length?he([t.terms.pop()],[n],q,!0===e,t.ring):[n],t.terms=t.terms.concat(n)));return t},Mul:function(n,t){var e,r,i=J.Arithmetic,u=i.O;if(!t.terms.length)return t;if(Nn(n,I)){if(n.symbol!==t.symbol)return r=t.symbol>n.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],w.Mul(w(n,r,n.ring),w(t,r,t.ring));t.terms=n.terms.length?de(t.terms,n.terms,q,t.ring):[]}else if(Nn(n,f)||i.isNumber(n))if((n=t.ring.cast(n)).equ(u))t.terms=[];else if(!n.equ(i.I))for(e=t.terms.length-1;0<=e;e--)t.terms[e]=t.terms[e].mul(n);return t},Div:function(t,e,n){var r,i,u=J.Arithmetic,l=u.O,s=u.I;if(n=!0===n,Nn(e,I)){if(!e.terms.length)throw new Error("Division by zero in Abacus.Polynomial!");return e.isConst()?(i=(e=e.cc()).equ(s)?t:I(En(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i):e.symbol===t.symbol?(i=ge(t.terms,e.terms,q,n,t.ring),n?[I(i[0],t.symbol,t.ring),I(i[1],t.symbol,t.ring)]:I(i,t.symbol,t.ring)):(r=t.symbol>e.symbol?[e.symbol,t.symbol]:[t.symbol,e.symbol],w.Div(w(t,r,t.ring),w(e,r,e.ring),n))}if(Nn(e,f)||u.isNumber(e)){if((e=t.ring.cast(e)).equ(l))throw new Error("Division by zero in Abacus.Polynomial!");return i=e.equ(s)?t:I(En(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i}return t},C:function(n,t,e){return new I(n||J.Arithmetic.O,t||"x",e||M.Q())},gcd:Tt,xgcd:Pt,lcm:kt,bezier:function(n,t){t=String(t||"x");var e,r,i,u,l,s=M.Q(),o=I.Zero(t,s);if(qn(n)&&n.length)for(e=n.length,l=I([1,-1],t,s),i=I.One(t,s).shift(e-1),u=I.One(t,s),o=o.add(i.mul(s.cast(n[e-1]))),r=e-2;0<=r;r--)i=i.shift(-1),u=u.mul(l),o=o.add(u.mul(i).mul(Kt(e-1,r)).mul(s.cast(n[r])));return o},bezierThrough:function(n,t){t=String(t||"x");var e,r,i,c=M.Q(),u=function(n){var t,e,r=n.length-1,i=new Array(r),u=new Array(r),l=new Array(r),s=new Array(r),o=new Array(r),m=new Array(r);for(l[0]=c.Zero(),s[0]=c.create(2),o[0]=c.One(),m[0]=n[0].add(n[1].mul(2)),t=1;tt.length+1&&t+"^"===r.slice(0,t.length+1)&&-1===r.indexOf("*")&&(s[r.slice(t.length+1)]=i));return new I(s,t,e)},fromString:function(n,t,e){var r,i,u,l,s=J.Arithmetic,o={},m=null,c=/(\(?(?:(?:[\+\-])?\s*\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))?\)?)(?:\s*(?:[\+\-])?\s*(?:\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))\)?\*?)?(?:[ij]))?\)?)?(?:\s*\*?\s*([a-zA-Z](?:_\{?\d+\}?)?)(?:\^\{?(\d+)\}?)?)?/g;if(e=e||M.Q(),!(n=H(String(n))).length)return I.Zero(t||"x",e);for(;u=c.exec(n);){if(!u[0].length){if(c.lastIndex>=1,e=I.Mul(e,e);return t},rad:function(n){var t=J.Arithmetic;return(n=Z.cast(n)).equ(t.I)?this:at(this,n)},compose:function(n){var t,e,r,i,u=this,l=J.Arithmetic;l.O;if(Nn(n,C)&&(n=N(n)),Nn(n,N)&&(n=I.fromExpr(n,u.symbol,u.ring)),l.isNumber(n)||Nn(n,f))return I(u.evaluate(n),u.symbol,u.ring);if(Nn(n,I)){if(!u.terms.length)return I.Zero(n.symbol,u.ring);if(0===u.deg())return I(u.terms.slice(),n.symbol,u.ring);if(0===n.deg())return I(u.evaluate(n.cc()),n.symbol,u.ring);for(r=(e=u.terms)[0].e,t=I(e[0].c,n.symbol,u.ring),i=1;0=i.terms[0].e?I.Zero(i.symbol,i.ring):I(i.terms.map(function(n){if(r>n.e)return null;for(var t=u.I,e=n.e;e+r>n.e;e--)t=u.mul(t,e);return q(n.c.mul(t),n.e-r,i.ring)}).filter(q.isNonZero),i.symbol,i.ring)},polarForm:function(t){t=String(t||"u");var i=this.ring.associatedField(),u=this.deg(),l=En(u,function(n){return t+"_"+(n+1)});return this.terms.reduce(function(n,e){if(!e.e)return n;var t=j(u,e.e),r=t.total();return t.get().reduce(function(n,t){return n.add(w(A(i.cast(e.c).div(r),En(u,function(n){return-1===t.indexOf(n)?0:1})),l,i))},n)},w(A(this.cc(),En(u,0)),l,i))},evaluate:function(n){var t,e,r,i=this.ring,u=J.Arithmetic,l=u.O,s=this.terms;if(!s.length)return i.Zero();for(Nn(n,f)||u.isNumber(n)||!In(n)||(n=n[this.symbol]),n=n||l,t=s[0].e,r=s[0].c,e=1;0=n.length&&e>=t.length?0:e>=t.length?0===n[e]?r(n,t,e+1):n[e]:e>=n.length?0===t[e]?r(n,t,e+1):-t[e]:n[e]===t[e]?r(n,t,e+1):n[e]-t[e]}if((qn(n)||An(n))&&(qn(t)||An(t)))return r(n,t,0);var i=r(n.e,t.e,0);return!0===e&&0===i?n.c.equ(t.c)?0:n.c.lt(t.c)?-1:1:i},sortDecr:function(n,t){return A.cmp(t,n)},gcd:function(t,e,n){return A(!0!==n||Nn(t.c,[w,R,d])||Nn(e.c,[w,R,d])||!t.ring.hasGCD()?t.ring.One():t.ring.gcd(t.c,e.c),En(F.max(t.e.length,e.e.length),function(n){return n=e.length);t++)if(t>=r.length){if(0r[t])return!1;return!0},pow:function(t){var e=this;return 1===(t=+t)?e:A(e.c.pow(t),En(e.e.length,function(n){return F.floor(e.e[n]*t)}),e.ring)},rad:function(t){var e=this;return 1===(t=+t)?e:A(e.c.rad(t),En(e.e.length,function(n){return F.max(F.floor(e.e[n]/t),F.min(1,e.e[n]))}),e.ring)},toTerm:function(n,t,e,r,i){var u,l=this.e,s=this.c,o=J.Arithmetic;if(!0===r){if(u=n.reduce(function(n,t,e){return 0t.e[e])&&(n=t),n},null,r),!0===n?w([t],u,i):t):!0===n?w([],u,i):A(i.Zero(),En(u.length,0),i):!0===n?w(r.length?[r[r.length-1]]:[],u,i):r.length?r[r.length-1]:A(0,En(u.length,0),i)},lm:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).e},lc:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).c},tm:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).e},tc:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).c},cc:function(){var n=this.terms;return n.length&&0===A.cmp(n[n.length-1].e,[0])?n[n.length-1].c:this.ring.Zero()},c:function(){return this.cc()},recur:function(u){var l,s,n,t=this,e=t.terms,o=t.symbol,m=t.ring,r=J.Arithmetic,i=null;if(!1===u)return null==t._flat&&(t._flat=o.length<=1||!t.isRecur()?t:Dn(function(n,t){return n._add(Nn(t.c,w)?w([A(m.One(),t.e,m)],o,m)._mul(t.c.recur(!1)):w([t],o,m))},w.Zero(o,m),e),t._flat._rsym=null,t._flat._flat=t._flat),t._flat;if(!0===u)return null==t._recur&&(t._recur=o.length<=1?t:Dn(function(n,t){return n.recur(t)},t.recur(!1),o),t._recur._flat=t.recur(!1),t._recur._recur=t._recur),t._recur;if(qn(u))return Dn(function(n,t){return n.recur(t)},t,u);if(u){if(o.length<=1)return t;if(u=String(u||"x"),-1===(l=o.indexOf(u))||t._rsym&&-1!==t._rsym.indexOf(u))return t;if(0===(s=t.maxdeg(u,!0)))return t._rsym=(t._rsym||[]).concat(u),t;for(n=w(Dn(function(n,t){var e,r=t.e[l],i=s-r,t=Nn(t.c,w)?t.c.isUni(u)?w([t],o,m):((e=t.clone()).c=t.c.recur(u),e.e[l]=0,w([e],o,m)):0!==r?((e=t.clone()).e[l]=0,w([e],o,m)):w([t],o,m);return n[i]=n[i]?n[i]._add(t):t,n},new Array(s+1),e).map(function(n,t){return n.equ(r.O)?null:A(n,En(o.length,function(n){return l===n?s-t:0}))}).filter(A.isNonZero),o,m);n.isConst()&&Nn(i=n.cc(),w);)n=i;return i===n&&(n=n.clone()),n._rsym=(t._rsym||[]).concat(u),n}return t},monic:function(){var n,t,e,r=this,i=J.Arithmetic,u=r.lc();if(u.equ(i.I)||u.equ(i.O)||Nn(u,w))return r;if(r.ring.isField())return w(r.terms.map(function(n){return n.div(u)}),r.symbol,r.ring);for(e=!0,n=(t=r.terms).length-1;0>=1,e=w.Mul(e,e,!1);return i&&(t=t.recur(i)),t},rad:function(n){var t=J.Arithmetic;return(n=Z.cast(n)).equ(t.I)?this:at(this,n)},compose:function(n){var f=this.symbol,a=this.ring,t=this._rsym,h=J.Arithmetic,d=w.Zero(f,a),g=c(),n=function n(t,e,r){for(r=r||0;r=f.length)return w(t.cc(),f,a);var i,u,l,s,o,m,c=t.terms;if(!c.length)return d;if(i=t.toString(),z.call(g,i))return g[i];for(o=z.call(e,f[r])?w(e[f[r]]||h.O,f,a):w([A(a.One(),En(f.length,function(n){return n===r?1:0}),a)],f,a),m=Nn(c[0].c,w)?n(c[0].c,e,r+1):w(c[0].c,f,a),u=c[0].e[r],s=m,l=1;0this.maxdeg(r,!0)?w.Zero(n,l):w(this.terms.map(function(n){var t,e;return Nn((n=n.clone()).c,w)?(e=n.e[u],t=i,0=-i?n.e[u]+=i:n.c=l.Zero(),n}).filter(A.isNonZero).sort(A.sortDecr),n,l):w(this.terms.map(function(n){return Nn((n=n.clone()).c,w)&&0this.maxdeg(r,!0)?w.Zero(n,t):w(this.terms.map(function(n){var t,e;if(Nn(n.c,w)){if(n.c.isConst(!0)){if(i>n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c._mul(t),n.e[u]-=i,n}for(n=n.clone(),e=i;e--,n.c=n.c.d(r,1)._add(n.c._mul(n.e[u])),n.e[u]=F.max(n.e[u]-1,0),0n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c.mul(t),n.e[u]-=i,n}).filter(A.isNonZero).sort(A.sortDecr),n,t))},evaluate:function(n){var f=this.symbol,a=this.ring,h=J.Arithmetic.O,d=c();return function n(t,e,r){for(r=r||0;r=f.length)return t.cc();var i,u,l,s,o,m,c=t.terms;if(!c.length)return a.Zero();if(i=t.toString(),z.call(d,i))return d[i];for(o=(z.call(e,f[r])?e[f[r]]:h)||h,m=Nn(c[0].c,w)?n(c[0].c,e,r+1):c[0].c,u=c[0].e[r],s=m,l=1;0r[t]&&(r[t]=n.length):n.length>r&&(r=n.length),n});n=String(n);return qn(r)?n.length>r[0]&&(r[0]=n.length):n.length>r&&(r=n.length),n})).map(function(n,t){return e+(qn(n)?n.map(function(n,t){return Yn(n,qn(r)?r[t]:r)}).join(" "):Yn(n,qn(r)?r[0]:r))+e}).join("\n")},toTex:function(n,t){return qn(n)?"\\begin{"+(t="pmatrix"===t?"pmatrix":"bmatrix")+"}"+n.map(function(n){return qn(n)?n.map(Mn).join(" & "):Mn(n)}).join(" \\\\ ")+"\\end{"+t+"}":Mn(n)},toDec:function(n,e,r){if(!qn(n))return Sn(n.toDec)?n.toDec(e):String(n);r=String(r||"|");var i=qn(n[0])?En(n[0].length,0):0;return(n=n.map(function(n,t){if(qn(n))return n.map(function(n,t){n=n.toDec(e);return qn(i)?n.length>i[t]&&(i[t]=n.length):n.length>i&&(i=n.length),n});n=n.toDec(e);return qn(i)?n.length>i[0]&&(i[0]=n.length):n.length>i&&(i=n.length),n})).map(function(n,t){return r+(qn(n)?n.map(function(n,t){return Yn(n,qn(i)?i[t]:i)}).join(" "):Yn(n,qn(i)?i[0]:i))+r}).join("\n")}},nr:0,nc:0,val:null,ring:null,_str:null,_tex:null,_n:null,_t:null,_h:null,_a:null,_i:null,_gi:null,_p:null,_snf:null,_lu:null,_qr:null,_ldl:null,_ref:null,_rref:null,_rf:null,_evd:null,_svd:null,_rn:null,_ln:null,_rs:null,_cs:null,_tr:null,_det:null,dispose:function(){var n=this;return n._n&&n===n._n._n&&(n._n._n=null),n._t&&n===n._t._t&&(n._t._t=null),n._h&&n===n._h._h&&(n._h._h=null),n._i&&n===n._i._i&&(n._i._i=null),n._gi&&n===n._gi._gi&&(n._gi._gi=null),n.nr=null,n.nc=null,n.val=null,n.ring=null,n._str=null,n._tex=null,n._n=null,n._t=null,n._h=null,n._a=null,n._i=null,n._gi=null,n._p=null,n._snf=null,n._lu=null,n._qr=null,n._ldl=null,n._ref=null,n._rref=null,n._rf=null,n._evd=null,n._svd=null,n._rn=null,n._ln=null,n._rs=null,n._cs=null,n._tr=null,n._det=null,n},clone:function(n){var t=this.val.map(function(n){return n.slice()});return!0===n?t:new D(this.ring,t)},map:function(r,n){var i=this,t=i.val.map(function(n,e){return n.map(function(n,t){return r(n,[e,t],i)})});return!0===n?t:new D(i.ring,t)},array:function(n){var t=this;return En(t.nr*t.nc,n?function(n){return t.val[n%t.nr][~~(n/t.nr)]}:function(n){return t.val[~~(n/t.nc)][n%t.nc]})},row:function(n){return 0<=n&&n=e.nr?r.val[t].slice():t>=r.nr?e.val[t].slice():En(F.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?e.val[t][n]:r.val[t][n].add(e.val[t][n])})})):((wn(e)||On(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.add(e)}))},sub:function(e){var r=this;return Nn(e,D)?D(r.ring,En(F.max(r.nr,e.nr),function(t){return t>=e.nr?r.val[t].slice():t>=r.nr?e.val[t].map(function(n){return Arithmetic.neg(n)}):En(F.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?Arithmetic.neg(e.val[t][n]):r.val[t][n].sub(e.val[t][n])})})):((wn(e)||On(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.sub(e)}))},mul:function(i){var u,l,s=this;return Nn(i,D)?(u=F.min(s.nc,i.nr),l=s.ring.Zero(),D(s.ring,En(s.nr,function(r){return En(i.nc,function(n){for(var t=l,e=0;e=r.nr?e.val[t].slice():t>=e.nr?r.val[t].slice():En(F.max(r.nc,e.nc),function(n){return n>=r.nc?e.val[t][n]:n>=e.nc?r.val[t][n]:r.val[t][n].mul(e.val[t][n])})})):((wn(e)||On(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.mul(e)}))},prod:function(i){var n,t,u,e,l,s=this;return Nn(i,D)?(e=s.nr,n=s.nc,t=i.nr,u=i.nc,e=e*t,l=n*u,D(s.ring,En(e,function(n){var e=~~(n/t),r=n%t;return En(l,function(n){var t=~~(n/u),n=n%u;return s.val[e][t].mul(i.val[r][n])})}))):((wn(i)||On(i))&&(i=s.ring.cast(i)),s.map(function(n){return n.mul(i)}))},div:function(t){return Nn(t,f)||J.Arithmetic.isNumber(t)||On(t)?((wn(t)||On(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.div(t)})):this},mod:function(t){return Nn(t,f)||J.Arithmetic.isNumber(t)||On(t)?((wn(t)||On(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.mod(t)})):this},divmod:function(n){return[this.div(n),this.mod(n)]},pow:function(n){var t,e,r=J.Arithmetic;if((n=Z.cast(n)).lt(r.O)||n.gt(un))return null;if(0===(n=r.val(n.num)))return D.I(this.ring,this.nc);if(1===n)return this;for(t=null,e=this;0!==n;)1&n&&(t=null==t?e:e.mul(t)),n>>=1,e=e.mul(e);return t},fwdsub:function(n,t){var e,r,i,u,l,s,o,m=this.ring,c=m.Zero(),f=this.val;for(Nn(n,D)&&(n=n.col(0)),Nn(t,D)&&(t=t.diag()),n=m.cast(n),t=t&&m.cast(t),u=F.min(this.nr,this.nc,n.length),l=new Array(u),e=0;eA&&(m.length=A),this._ref=[x,m,c,t]}return n?this._ref.slice():this._ref[0]},rref:function(n,t){var e,r,i,u,l,s,o,m,c,f,a,h,d,g,_,v;if(null==this._rref){for(r=(e=this.ring).Zero(),i=e.One(),u=e.MinusOne(),l=this.nr,v=s=this.nc,qn(t)&&(v=F.min(v,t[1])),g=(v=this.ref(!0,t))[0].concat(v[3]),o=v[1],t=v[2],m=o.length,f=0;f=r.nc?t=e.nc?t=r.nr?n=e.nr?n"===n?(n=-1,i=!0):"<="===n||"=<"===n?i=!(n=1):">="!==n&&"=>"!==n||(i=!(n=-1))),u(-1===(n=-1===(n=+n)?-1:1)?function(n){for(var t=n[0],e=1,r=n.length;e=n[e]||!i&&t>n[e])return!1;t=n[e]}return!0})},LEN:function(t,n){return t=+t,u(">="===(n=n||"==")?function(n){return n.length>=t}:">"===n?function(n){return n.length>t}:"<"===n?function(n){return n.length="===(n=n||"==")||"=>"===n?function(n){return 0<=t&&t=e}:">"===n?function(n){return 0<=t&&te}:"<"===n?function(n){return 0<=t&&t="===(t=t||"==")||"=>"===t?function(e){return Dn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>=n}:">"===t?function(e){return Dn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>n}:"<"===t?function(e){return Dn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)<=n}:"!="===t?function(e){return Dn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)!==n}:function(e){return Dn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)===n})},MIN:function(n,t){return n=+n,u(">="===(t=t||"==")||"=>"===t?function(e){return Dn(function(n,t){return e[t]=n}:">"===t?function(e){return Dn(function(n,t){return e[t]n}:"<"===t?function(e){return Dn(function(n,t){return e[t]i)return!1;return!0}:function(n){for(var t=0,e=n.length;t=i)return!1;return!0})},DIFF:function(t){return u(Nn(t,T)?function(n){return!t.has(n)}:function(n){return!0})},MOD:function(t,n){var e=null!=n&&Nn(t,T)?t.index(n):J.Arithmetic.O;return u(Nn(t,T)?function(n){return J.Arithmetic.equ(e,t.index(n))}:function(n){return!0})}},filter:null,dispose:function(){return this.filter=null,this},apply:function(n,t){var e=this.filter;return!e||!Sn(e)||Boolean(e.call(t||null,n))},NOT:function(){var t=this;return u(function(n){return!t.apply(n,this)})},OR:function(t){var e=this;return Sn(t)||Nn(t,u)?(Nn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)||t.apply(n,this)})):e},XOR:function(e){var r=this;return Sn(e)||Nn(e,u)?(Nn(e,u)||(e=u(e)),u(function(n){var t=r.apply(n,this),n=e.apply(n,this);return t&&!n||!t&&n})):r},AND:function(t){var e=this;return Sn(t)||Nn(t,u)?(Nn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)&&t.apply(n,this)})):e}}),E=J.Iterator=n({constructor:function n(t,e){var r=this,i=J.Arithmetic;if(!Nn(r,n))return new n(t,e);(qn(t)||An(t))&&(Nn(t[0],n)||Nn(t[t.length-1],n))?(r.name="Sequence",r.$=e||{},r.$.seq=G.call(t),r.$.count=Dn(function(n,t){return i.add(n,t.total())},i.O,r.$.seq),r.rewind()):qn(t)||An(t)?(r.name="List",r.$=e||{},r.$.seq=G.call(t),r.$.count=r.$.seq.length,r.rewind()):Sn(t)?(r.name="Generator",r.$={},r.$.generator=t,r.$.state=e||{},r.$.count=i.I,r.rewind()):(r.name=t||"Iterator",r.$=e||{},r.$.count=r.$.count||i.O)},__static__:{Iterable:function n(t,e){if(!Nn(this,n))return new n(t,e);e=-1===e?-1:1,this.next=function(){var n=t.hasNext(e)?t.next(e):null;return null==n?{done:!0}:{value:n}}}},name:"Iterator",$:null,__index:null,__item:null,_index:null,_item:null,__subindex:null,_subindex:null,__subitem:null,_subitem:null,dispose:function(){var n=this;return n.$.seq&&n.$.seq.length&&(Dn(function(n,t){t instanceof E&&t.dispose()},null,n.$.seq),n.$.seq=null),n.$=null,n.__index=null,n.__item=null,n._index=null,n._item=null,n.__subindex=null,n._subindex=null,n.__subitem=null,n._subitem=null,n},filterBy:function(n){var t=this.$;return!1===n?t.filter&&(t.filter=null):(Nn(n,u)||Sn(n))&&(t.filter=Nn(n,u)?n:u(n)),this},mapTo:function(n,t){var e,r,i,u=this.$;return!1===n?u.output&&(u.output=null):Sn(n)&&(e=u.output,u.output=t&&e?(r=e,i=n,function(n){return null==n?null:i(r(n))}):n),this._item=this.output(this.__item),this},fuse:function(n,t,e){var r=this.$;return 1===arguments.length&&!1===n?r.sub&&(r.sub=null,r.submethod=null,r.subcascade=null,r.subcount=null,this.rewind()):Nn(t,E)&&Sn(n)&&(r.sub=t,r.submethod=n,r.subcascade=-1===e?-1:1,r.subcount=J.Arithmetic.mul(r.count,t.total()),this.rewind()),this},unfuse:function(){return this.fuse(!1)},juxtaposeWith:function(n,t){return this.fuse(function(n,t){return[].concat(n).concat(t)},n,t)},state:function(n){return arguments.length?(this.$.state=n,this):this.$.state},output:function(n){var t=this.$.output;return null==n?null:Sn(t)?t(n):n},fusion:function(n,t){var e,r=this.$;return r.sub?(-1===r.subcascade&&(e=n,n=t,t=e),null==n||null==t?n||t||null:r.submethod.call(this,n,t)):n},order:function(){return this},rewind:function(n,t){var e,r,i,u=this,l=u.$;if(n=-1===n?-1:1,qn(l.seq)){for(e=0,r=l.seq.length;e=u.seq.length)&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),r=i.__item,i.__subitem=u.sub.next(n)),i.__item=r,i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null}while(u.filter&&null!=e&&!u.filter.apply(e,i));return e}if(Sn(u.generator)){for(;t=i.__item,e=u.sub?i._subitem:i._item,i.__item=u.generator.call(i,t,n,u.state,!1),null==i.__item&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),i.__subitem=u.sub.next(n)),i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null,u.filter&&null!=e&&!u.filter.apply(e,i););return e}return null},get:function(n){var t,e,r=[];if(Sn(n))for(;this.hasNext()&&null!=(t=this.next())&&n(t);)r.push(t);else for(e=!arguments.length||null==n,null!=n&&(n=+n);(e||r.length=o.$.mindimension&&u<=o.$.maxdimension){if(l=o[X].rank(n,o.n,o.$),c.gt(l,a)){m=!0;break}s=c.add(s,o.total())}return m?c.add(l,s):a}return yn()},unrank:function(n,t,e){if(e&&"sequence"===e.type){var r,i,u=J.Arithmetic,l=u.O,s=e.seq;if(!s||!s.length)return null;if(null==(n=null==n?null:u.num(n))||!u.inside(n,u.J,null!=e.count?e.count:this.count(t,e)))return null;for(i=s.length,r=0;u.gte(n,s[r].total())&&(n=u.sub(n,s[r].total()),!(i<=++r||u.lt(n,l))););return rm&&(m=e[n]+1),e[n]):m+r[n-e.length]}:function(n){return nu&&(e.length=u),d<0&&1n[1]&&(n[1]=t),n},[1/0,0],l),s.base=l,s.minbase=n[0],s.maxbase=n[1],s.dimension=l.length,"gray"===s.output?s.output=function(n,t){return e.gray(n,t)}:"inversion"===s.output?s.output=function(n,t){return e.inversion(n)}:qn(s.output)&&(i=s.output,s.output=function(n,t){return e.component(n,i)})),T.call(this,"Tensor",l,s,u?{method:"partial"===s.type?s.submethod||"complete":s.submethod,iter:u,pos:"partial"===s.type?s.subpos||s.position:s.subpos,cascade:s.subcascade}:null)},__static__:{C:T.C,P:T.P,T:T.T,DUAL:T.DUAL,count:function(n,t){var e=J.Arithmetic.O,r=t&&t.type?t.type:"tensor";return"partial"===r?t.data&&t.data.length?J.Arithmetic.num(t.data.length):e:"tuple"===r?!n||n[0]<=0?e:Bt(n[1],n[0]):n&&n.length?et(n):e},initial:function(t,n,e){var r,i=n&&n.type?n.type:"tensor",u=n&&n.order?n.order:dn;return e=-1===e?-1:1,(!(gn&u)&&an&u||gn&u&&!(an&u))&&(e=-e),r="partial"===i?n.data&&n.data.length?e<0?n.data[n.data.length-1]:n.data[0]:null:(r="tuple"===i?t[0]?En(t[0],e<0?t[1]-1:0,0):[]:t.length?e<0?En(t.length,function(n){return t[n]-1}):En(t.length,0,0):[],this.DUAL(r,t,n))},valid:function(n,t,e){var r,i,u=e&&e.type?e.type:"tensor";if(!n)return!1;if("partial"===u)return 0<=Pe(e.data,n,!0);if(n=this.DUAL(n.slice(),t,e),"tuple"===u){if(!(r=t[0])||r!==n.length)return!1;for(t=t[1],i=0;i=t)return!1}else{if(!(r=t.length)||r!==n.length)return!1;for(i=0;i=t[i])return!1}return!0},succ:function(n,t,e,r,i,u){if(!e||null==n)return null;var l=r&&r.type?r.type:"tensor",s=r&&null!=r.order?r.order:dn,o=J.Arithmetic;return i=-1===i?-1:1,"partial"===l?r.data&&r.data.length?(an&s&&(i=-i,null!=t&&(t=o.sub(o.num(r.data.length-1),t))),null==t&&(t=Pe(r.data,n,!0)),t=o.val(t),i<0?0<=t-1?r.data[t-1]:null:0<=t&&t+1=t)return a;f=o(c(f,t),n[i])}}else{if(!(r=t.length)||r!==n.length)return a;for(i=0;i=t[i])return a;f=o(c(f,t[i]),n[i])}}return(!(gn&l)&&an&l||gn&l&&!(an&l))&&(f=m(e&&null!=e.last?e.last:m(this.count(t,e),u.I),f)),f},unrank:function(n,t,e){var r,i,u,l,s,o,m=J.Arithmetic,c=e&&null!=e.order?e.order:dn,f=e&&e.type?e.type:"tensor",a=m.sub,h=m.mod,d=m.div,g=m.val;if(null==(n=null==n?null:m.num(n))||!m.inside(n,m.J,e&&null!=e.count?e.count:this.count(t,e)))return null;if((!(gn&c)&&an&c||gn&c&&!(an&c))&&(n=a(e&&null!=e.last?e.last:a(this.count(t,e),m.I),n)),"partial"===f){if(!e.data||!e.data.length)return null;s=0<=(n=g(n))&&n=t+e[i].length&&(t+=e[i++].length),t+e[i][n-t]})},component:function(t,e){return null==t?null:null==e?t:En(t.length,function(n){return n=r.length||null==r[n])return e[n];var t=r[n];return wn(t)?e[n]+t:t[0]*e[n]+(t[1]||0)})}:xn},conditional:ae,generate:function(n,t,i,u,l){l=l||{},i=i||En(t.length||0,0,1);for(var e,r,s,o,m,c,f,a,h,d=null==l.min?0:l.min,g=null==l.max?n-1:l.max,_=g-d+1,v=t,b=v.length,p=!1,y=[],x=[],q={},A=function(n){return d<=n&&n<=g},p=!(t=[]),I=m=0;Ie[1]?_e(n,En(e[0]-e[1]+1,e[1],1).filter(A)).reverse():_e(n,En(e[1]-e[0]+1,e[0],1).filter(A)):_e(n,e[1].split(",").map(Number).filter(A))).length){p=!0;break}t.push(s)}else if(e=r.match(Y)){if(!(s=(0e[1]?En(e[0]-e[1]+1,e[0],-1):En(e[1]-e[0]+1,e[0],1):e[1].split(",").map(Number)).filter(A)).length){p=!0;break}t.push(s)}else if(f=!0,c=[],a=null,r=r.replace(K,function(n,t){var e=parseInt(t,10),t="v"+String(e);return!isNaN(e)&&A(e)||(f=!1),f&&-1===c.indexOf(e)&&c.push(e),t}),f){c.sort(function(e){return!0===e?function(n,t){return n.equ(t)?0:n.lt(t)?-1:1}:e?function(n,t){return e.equ(n,t)?0:e.lt(n,t)?-1:1}:function(n,t){return n===t?0:n"===u?sn:"<"===u?on:"<="===u||"=<"===u?fn:">"===u?mn:(">="===u||"=>"===u)&&cn,h=Sn(l.extra_conditions)?function(n,t,e){var r=n[t];return!(rr||mn===u&&i[i.length-1]-i[t]>r)&&l.extra_conditions(n,t,e)}:function(n,t,e){n=n[t];return!(nn||mn===u&&i[i.length-1]-i[t]>n)},!0===l.lazy?t:ae(t,u,h))}}}),J.Permutation=n(T,{constructor:function n(t,e){var r=null;if(!Nn(this,n))return new n(t,e);(e=e||{}).type=String(e.type||"permutation").toLowerCase(),Nn(t=t||0,T)?t=(r=t).dimension():r=e.sub,e.base=t,e.dimension=F.max(0,t),e.rand=e.rand||{},e.rand.involution=1,"multiset"===e.type&&(e.multiplicity=qn(e.multiplicity)&&e.multiplicity.length?e.multiplicity.slice():En(e.dimension,1,0),e.multiplicity=e.multiplicity.concat(En(e.dimension-Dn(nt,0,e.multiplicity),1,0)),e.base=e.multiplicity.length,e.multiset=Ie(e.multiplicity,e.dimension)),T.call(this,"Permutation",t,e,r?{method:e.submethod,iter:r,pos:e.subpos,cascade:e.subcascade}:null)},__static__:{C:T.C,P:T.P,T:T.T,DUAL:T.DUAL,count:function(n,t){var e=J.Arithmetic,r=e.O,i=t&&t.type?t.type:"permutation",u=t&&null!=t["cycles="]?0|t["cycles="]:null,l=t&&null!=t["fixed="]?0|t["fixed="]:null;return n<0?r:"cyclic"===i?e.num(n):"multiset"===i?Kt(n,t.multiplicity):"derangement"===i?null!=l?e.mul(Kt(n,l),Kt(n-l,!1)):Kt(n,!1):"involution"===i?Kt(n,!0):"connected"===i?Kt(n-1):null!=u?te(n,u,1):Kt(n)},initial:function(n,t,e){var r,i=t&&t.type?t.type:"permutation",u=t&&null!=-t.order?t.order:dn,l=t&&null!=t["cycles="]?0|t["cycles="]:null,s=t&&null!=t["fixed="]?0|t["fixed="]:null;if(n<0)return null;if(0===n)return[];if(e=-1===e?-1:1,(!(gn&u)&&an&u||gn&u&&!(an&u))&&(e=-e),"cyclic"===i)r=e<0?[n-1].concat(En(n-1,0,1)):En(n,0,1);else if("derangement"===i){if(null!=s||n<2)return null;r=1&n?(s=F.floor(n/2),e<0?En(n-s-1,n-1,-1).concat([s-1,s]).concat(En(s-1,s-2,-1)):En(n-3,function(n){return 1&n?n-1:n+1}).concat([n-2,n-1,n-3])):e<0?En(n,n-1,-1):En(n,function(n){return 1&n?n-1:n+1})}else r="multiset"===i?e<0?t.multiset.slice().reverse():t.multiset.slice():"connected"===i?Ne([e<0?En(n,n-1,-1):[n-1].concat(En(n-1,0,1))],n):"involution"!==i&&null!=l?null:e<0?En(n,n-1,-1):En(n,0,1);return r=this.DUAL(r,n,t)},valid:function(n,t,e){var r,i,u,l,s,o=e&&e.type?e.type:"permutation",m=e&&null!=e["cycles="]?0|e["cycles="]:null,c=e&&null!=e["fixed="]?0|e["fixed="]:null;if(!n||t<0||t!==n.length)return!1;if(n=this.DUAL(n.slice(),t,e),"cyclic"===o){for(i=n[0],r=0;r=s.length||s[u]<=0)return!1;s[u]--}if(0!==s.filter(function(n){return 0!==n}).length)return!1}else{for(l={},r=0;r=_*t[o+g];)o-=g;if(0<=o&&o<=y){for(m=d;0<=m&&m<=y&&0=_*t[m];)m-=g;for(a=t[o],t[o]=t[m],t[m]=a,c=o+g,f=d;0<=c&&c<=y&&0<=f&&f<=y&&0=a.length||a[l]<=0)return I;a[l]--}if(0!==a.filter(function(n){return 0!==n}).length)return I;for(a=n.multiplicity.slice(),f=n&&null!=n.count?n.count:Kt(e,a),u=e-1,r=0;rl;for(u=g.O,m=e-1;0<=m&&(m===l||0<=i[m]&&i[m]="===e||"=>"===e?t<=s:s===t}},output:function(n){return n&&"connected"===this.$.type&&this.n-1===n.length&&(n=Ne([[this.n-1].concat(n)],this.n)),T[Q].output.call(this,n)},_update:function(){var t,e,r,n=this;return n.__item&&"connected"===n.$.type&&(r=n.n)===n.__item.length&&(t=Ce(n.__item)[0],e=t.indexOf(r-1),n.__item=En(r,function(n){return t[(n+e)%r]}).slice(1)),n.item__=(n.__item,n.n,n.$.order,n.$.type,null),n}}),(j=J.Combination=n(T,{constructor:function e(n,t,r){var i,u=null;if(!Nn(this,e))return new e(n,t,r);qn(n)||An(n)?(r=t||{},t=n[1]||0,n=n[0]||0):(r=r||{},n=n||0,t=t||0),r.type=String(r.type||"combination").toLowerCase(),-1=r)return!1}else if("repeated"===l||"combination+repeated"===l){for(r=t[0],i=0;i=r||i+1n[i+1])return!1}else if("ordered"===l||"variation"===l)for(r=t[0],u={},i=0;i=r||1===u[n[i]])return!1;u[n[i]]=1}else for(r=t[0],i=0;i=r||i+1=n[i+1])return!1;return!0},succ:function(n,t,e,r,i,u){return!e||!e[0]||e[0]<=0||e[1]<=0||null==n?null:function(n,t,e,r,i,u){var l,s,o,m,c,f,a,h,d,g,_,v,b=t[1],p=t[0];if(t[0]<0||t[1]<0)return null;t=f=b-1,d=a=c=1,g=h=0,gn&i&&(a=-a,h=p-1-h,c=-c,t=f-t,d=-d,g=f-g);hn&i&&(c=-c,t=f-t,d=-d,g=f-g);an&i&&(e=-e);if(e<0)if("ordered+repeated"===r||"variation+repeated"===r||"repeated+variation"===r){for(l=t;0<=l&&l<=f&&0===n[l];)l-=c;if(0<=l&&l<=f)for(--p,n[l]=n[l]-1,s=l+c;0<=s&&s<=f;s+=c)n[s]=p;else n=null}else if("ordered"===r||"variation"===r){for(null==u&&(u=Je(n,0,b,0,r)),l=t,o=-1;-1===o&&0<=l&&l<=f;){if(0<=a*n[l]+h-a)for(s=a*n[l]+h-a;0<=s&&sb||v&&0n[l-c]+_){o=l;break}if(!(0<=o&&o<=f)&&0=l)return g;_=c(a(_,l),n[r])}else if("repeated"===m||"combination+repeated"===m){for(l=t[0]+v-1,s=e&&e.count?e.count:Kt(l,v),r=1;r<=v;r++){if(n[r-1]<0||n[r-1]>=t[0]||rn[r])return g;(u=v+1-r)<=(i=l-1-n[r-1]-r+1)&&(_=c(_,Kt(i,u)))}_=f(f(s,d),_)}else if("ordered"===m||"variation"===m){for(l=t[0],o={},r=0;r=l||1===o[n[r]])return g;o[n[r]]=1}for(n=we(null,n,l),r=0;r=l||r=n[r])return g;(u=v+1-r)<=(i=l-1-n[r-1])&&(_=c(_,Kt(i,u)))}_=f(f(s,d),_)}return(!(gn&b)&&an&b||gn&b&&!(an&b))&&(_=f(e&&null!=e.last?e.last:f(this.count(t,e),d),_)),_},unrank:function(n,t,e){var r,i,u,l,s,o,m,c=J.Arithmetic,f=c.O,a=c.I,h=c.sub,d=c.div,g=c.mod,_=c.mul,v=c.lte,b=c.gt,p=c.val,y=t[1],x=e&&e.type?e.type:"combination",q=e&&null!=e.order?e.order:dn;if(null==(n=null==n?null:c.num(n))||!c.inside(n,c.J,e&&null!=e.count?e.count:this.count(t,e)))return null;if(t[0]<0||t[1]<0)return null;if(0===y)return[];if((!(gn&q)&&an&q||gn&q&&!(an&q))&&(n=h(e&&null!=e.last?e.last:h(this.count(t,e),c.I),n)),t=t[0],r=En(y),"ordered+repeated"===x||"variation+repeated"===x||"repeated+variation"===x)for(l=n,o=y-1;0<=o;o--)s=g(l,t),l=d(l,t),r[o]=p(s);else if("ordered"===x||"variation"===x){for(l=n,o=y-1;0<=o;o--)s=g(l,u=t-o),l=d(l,u),r[o]=p(s);Se(r,r,u)}else for(u=(m="repeated"===x||"combination+repeated"===x)?t+y-1:t,n=h(h(i=e&&e.count?e.count:Kt(u,y),a),n),i=d(_(i,u-y),u),s=u-y+1,l=y,o=u-1;v(i,n)?(r[y-l]=m?u-s-y+1:u-s-l+1,b(i,f)&&(n=h(n,i),i=d(_(i,l),o)),l--):(i=d(_(i,o-l),o),s--),o--,0=n[r+1])return!1;l[i]=1}return!0},succ:function(n,t,e,r,i,u){if(null==n)return null;var l,s,o=J.Arithmetic,m=r&&r.type?r.type:"subset",c=r&&null!=r.order?r.order:dn;if(e<=0)return null;if(_n&c){if(null!=t&&(s=null!=r.count?r.count:this.count(e,r),t=o.add(t,i<0?o.J:o.I),o.inside(t,o.J,s))){for(an&c&&(t=o.sub(o.sub(s,o.I),t)),t=Un(t),l=0,(n=new Array(e+1))[e]=0;ln[s-u]+1?(--n[s],n[s+u]=m,n[o]++):n[o]--:n[o]=0:n=null:0===n[o]?(n[i]=0,n[o]=1):+n[l]+0n.length||e.maxdimension=n[u+1])return f;_=a(_,Wt(t,r)),s[r]=1}_=Jn(_),an&g&&(_=h(e&&null!=e.last?e.last:h(this.count(t,e),c),_))}else if(o){for(l=n.length,s={},_=m,u=0;u=n[u+1])return f;_=a(_,zt(t,r,i)),s[r]=1,i=r}an&g&&(_=h(e&&null!=e.last?e.last:h(this.count(t,e),c),_))}return _},unrank:function(n,t,e){var r,i,u,l,s,o=J.Arithmetic,m=o.O,c=o.I,f=o.band,a=o.shr,h=o.gt,d=(o.add,o.sub),g=o.gte,_=e&&e.type?e.type:"subset",v=e&&null!=e.order?e.order:dn,b=e&&null!=e.count?e.count:this.count(t,e),p=m;if(n=null==n?null:o.num(n),!e||t<0||null==n||!o.inside(n,o.J,b))return null;if(((r=new Array(t+1))[t]=0)n.length||on[m]+1?(n[o]=n[m],n[m]=i):(i===n[o]&&n[y][1]--,u===n[m]&&n[y][2]--,n[o]--,n[m]++,i===n[m]&&n[y][1]++,u===n[o]&&n[y][2]++)}}else if(u)if(gn&s)n=null;else if((a=n[t])n[m]+1?(n[o]=n[m],n[m]=i):(i===n[o]&&n[y][1]--,n[o]--,n[m]++,i===n[m]&&n[y][1]++)}else if(gn&s)if((a=n[c])n[y][0]){for(o=t,_=0;v<=o&&o<=b&&1===n[o];)o-=x,_++;if(a=n[o]-1,n[o]=a,0<++_)if(v<=o+x&&o+x<=b)n[o+=x]=_,_=0,n[y][0]=x<0?l-o:o+1;else for(;0<_--;)n[o+=x]=1,n[y][0]++}else n=null}else if(r)if(gn&s)n=null;else if(i&&u){if(i===u)return null;for(f=1,o=(m=t)-x,d=i-n[m],_=n[m];v<=o&&o<=b&&(in[o]+1&&an[o]+1?(n[m]=n[o],n[o]=i):(i===n[m]&&n[y][1]--,u===n[o]&&n[y][2]--,n[o]++,n[m]--,u===n[m]&&n[y][2]++,i===n[o]&&n[y][1]++)}else if(u)if(p-u*(r-1)>n[c]){for(o=t;v<=o&&o<=b&&u===n[o];)o-=x;m=o-x,1===n[y][2]&&u===n[m]?(n[m]=n[o],n[o]=u):(u===n[m]&&n[y][2]--,n[o]--,n[m]++,u===n[o]&&n[y][2]++,a=n[o],n[o]=n[t],n[t]=a)}else n=null;else if(i){for(f=1,o=(m=t)-x,d=i-n[m],_=n[m];v<=o&&o<=b&&(i&&in[o]+1&&_-(f-1)-1n[o]+1?(n[m]=n[o],n[o]=i):(i===n[m]&&n[y][1]--,n[o]++,n[m]--,i===n[o]&&n[y][1]++)}else if(gn&s)if(p-r+1>n[t]){for(o=c;v<=o&&o<=b&&1===n[o];)o+=x;a=n[o],n[o]=1,n[c]=a-1,v<=o+x&&o+x<=b&&n[o+x]++}else n=null;else if(p-r+1>n[c]){for(o=t;v<=o&&o<=b&&1===n[o];)o-=x;a=n[o],n[o]=1,n[t]=a-1,v<=o-x&&o-x<=b&&n[o-x]++}else n=null;else if(gn&s)n=null;else if(i){if(i===u)return null;for(h=u||1,_=n[o=t],i===n[o]&&n[y][1]--,u&&u===n[o]&&n[y][2]--,n[y][0]--,o-=x;null!=u&&v<=o&&o<=b&&_<1+u;)_+=n[o],n[y][0]--,i===n[o]&&n[y][1]--,u===n[o]&&n[y][2]--,o-=x;if(on[c]){for(_=n[o=t],n[y][0]--,u&&u===n[o]&&n[y][2]--,o-=x,u&&u===n[o]&&n[y][2]--,n[o]++,_--;h<=_;)n[o+=x]=h,_-=h,n[y][0]++,u&&n[y][2]++;if(u&&0===n[y][2]&&(_+=n[o]-u,n[o]=u,n[y][2]++),0<_){if(u&&1===n[y][2]&&u===n[o])if(u<_){for(_+=n[o],n[y][0]--,n[y][2]--,n[o-=x]++,_--;h<=_;)n[o+=x]=h,_-=h,n[y][0]++,n[y][2]++;0<_&&(u===n[o]&&n[y][2]--,n[o]+=_)}else n[o-x]+=_;else u&&u===n[o]&&n[y][2]--,n[o]+=_;_=0}}else n=null;return n}:function(n,t,e,r,i,u,l,s){var o,m,c,f,a,h,d,g,_,v,b,p,y=t,x=l,q=1;if(y<=0||null!=r&&r<=0||null!=u&&u<=0||null!=i&&i<=0)return null;hn&s&&(q=-q);an&s&&(e=-e);t=q<0?(b=l-(n[x][0]||1),c=p=l-1,b):(b=0,p=n[x][0]-1,c=b,p);if(gn&s)return null;if(e<0)if(r){if(i&&u&&i===u)return null;for(h=u||1,v=y-(i||0)-(u||0),a=0h){for(o=t,_=g=v=0;b<=o&&o<=p&&0<=q*(o-m)&&h===n[o];)v+=n[o],i===n[o]&&g++,u===n[o]&&_++,o-=q;if(i===n[o]&&n[x][1]--,a=n[o]-1,v++,n[o]=a,n[x][0]=(q<0?l-o:o+1)+(u?1:0),n[x][1]-=g,n[x][2]-=_,u===n[o]&&n[x][2]++,af,m=c+q,t-=q}else u?(h=u,a=2f+1||n[c+(f-1)*q]n.length||e.maxdimensionn.length||f=set[u+1])return!1;m[s]=1}o+=r}return o===t},succ:function(n,t,e,r,i){return null==e||null==n||e<=0?null:(i=-1===i?-1:1,function(n,t,e,r,i){var u,l,s,o,m,c,f;if(t<=0||null!=e&&(e<=0||tn[0]&&(e-t+un[0]){for(n[u]--,m[u]=m[u-1],l=u+1;l>>1,c=new Array(i),f=0;f>>1,p=new Array(t),y=0;y>>1==(e+1&3)>>>1?v-r:r+1;else{for(i=n(b),m=(o=(s=l=b*b)<<1)+l,e=y=r=0;r>>1,e=0;e=i&&(a=0,i<=++c&&(o+=i,a=c=0,r<=++f&&(m++,s+=i,a=c=o=f=0),me[h]||-1===r&&ae[h]||-1===r&&t[a]e[g][0]?(n[v++]=_=t[d],d+=f):(1===r&&t[d][0]>e[g][0]||-1===r&&t[d][0]e[g][1]?(n[v++]=_=t[d],b&&(n[v++]=e[g])):(n[v++]=_=e[g],b&&(n[v++]=t[d])),d+=f),g+=a):1===r&&t[d]e[g]?(n[v++]=_=t[d],d+=f):(1===r&&t[d]>e[g]||-1===r&&t[d]>=1;return i?Pn(e,e,1):e}function Vn(n,t,e,r){var i,u,l,s=n.length;if(null==e&&(e=0),null==r&&(r=s-1),null==t||0===t){for(t=0,u=n[e],i=e+1;i<=r;i++){if(u<(l=n[i])){if(-1===t)return 0;0===t&&(t=1)}else if(l>>1],t)?r=l+1:i=l;else for(;r>>1])?i=l:r=l+1;return r}function nt(n,t,e){var r=n.length;return e=e||" ",r>=1,n=lt(n,n,e);else for(r=u.II;!u.equ(t,l);)u.equ(s,u.mod(t,r))&&(i=lt(i,n,e)),t=u.div(t,r),n=lt(n,n,e);return i}function mt(n,t){var e,r,i=F.Arithmetic,u=i.O,l=i.I;i.num;if(i.gt(u,t))return null;if(i.equ(u,t))return l;if(i.equ(l,t))return n;if(r=l,i.isDefault()||i.lte(t,ln))for(t=i.val(t);0!==t;)1&t&&(r=i.mul(r,n)),t>>=1,n=i.mul(n,n);else for(e=i.II;!i.equ(u,t);)i.equ(l,i.mod(t,e))&&(r=i.mul(r,n)),t=i.div(t,e),n=i.mul(n,n);return r}function ct(n){var t,e,r,i,u,l,s=F.Arithmetic,o=(s.num,s.O),m=s.I;if(s.equ(n,o)||s.equ(n,m))return n;if(s.isDefault()||s.lte(n,ln))return s.num(Q.floor(Q.sqrt(s.val(n))));for(l=s.II,t=m,e=s.div(n,l),u=t;s.lte(t,e);){if(r=s.div(s.add(t,e),l),i=s.mul(r,r),s.equ(i,n))return r;s.lt(i,n)?(t=s.add(r,m),u=r):e=s.sub(r,m)}return u}function ft(n,t){var e,r;return 0===(t=+t)?null:(t<0&&(n=1/n,t=-t),1===t?n:(1==(e=1&t)&&n<0&&(n=-n),r=Q.pow(n,1/t),t=Q.pow(r,t),Q.abs(n-t)<1&&0o&&(h++,i.terms.length>=e||e<=h))););return 0===h&&t.mod(a).equ(c)?i.abs():i}function dt(n,t){var e,r,i,u=F.Arithmetic,l=u.O,s=u.I,o=u.II,m=p.Epsilon();if(t.equ(l))return null;if(Rn(n,f)&&(n.equ(l)||n.equ(s))||u.isNumber(n)&&(u.equ(l,n)||u.equ(s,n)))return n;if(n=(u=u.isNumber(n)||Rn(n,M)?p:n[G]).cast(n),Nn(u,p)&&n.lt(l)&&t.mod(o).equ(l)&&(n=(u=_).cast(n)),t.lt(l)&&(n=n.inv(),t=t.neg()),t.equ(s))return n;if(e=Nn(u,Z)?new u(ht(n.num,t),ht(n.den,t)):Nn(u,p)?new u(at(n.num,t.num),at(n.den,t.num)):Nn(u,_)?!n.isReal()||!n.real().gte(l)&&t.mod(o).equ(l)?new u(s,s):new u(p(at(n.real().num,t.num),at(n.real().den,t.num)),p.Zero()):u.One(),i=t.sub(s),Nn(u,_))for(;;){if((r=n.div(e.pow(i)).sub(e).div(t)).real().abs().lte(m)&&r.imag().abs().lte(m))break;e=e.add(r)}else for(;;){if((r=n.div(e.pow(i)).sub(e).div(t)).abs().lte(m))break;e=e.add(r)}return e}function gt(n,t,e){var r,i,u,l,s,o,m=F.Arithmetic,c=m.num,f=m.O,a=m.J,h=m.I,d=m.II;if(m.lt(t,f)||m.equ(f,m.mod(t,d)))return null;if((m.lt(n,f)||m.gt(n,t))&&(n=m.mod(n,t)),m.equ(f,n))return m.equ(h,t)?h:f;if(m.equ(h,t)||m.equ(h,n))return h;if(null==e&&(e=Rt(n,t)),!m.equ(h,e))return f;for(u=c(3),l=c(4),s=c(5),o=c(8),r=h,m.lt(n,f)&&(n=m.mul(a,n),m.equ(m.mod(t,l),u)&&(r=m.mul(a,r)));!m.equ(f,n);){for(;m.gt(n,f)&&m.equ(f,m.mod(n,d));)n=m.div(n,d),i=m.mod(t,o),(m.equ(i,u)||m.equ(i,s))&&(r=m.mul(a,r));i=n,n=t,t=i,m.equ(u,m.mod(n,l))&&m.equ(u,m.mod(t,l))&&(r=m.mul(a,r)),n=m.mod(n,t)}return m.equ(h,t)||(r=f),r}function vt(n,t){var e=F.Arithmetic,r=(e.num,e.I),i=e.II;return ot(n,e.div(e.sub(t,r),i),t)}function _t(n,t){var e,r,i,u,l,s,o,m,c,f,a,h,d=F.Arithmetic,g=(d.num,d.O),v=d.I;if(!d.equ(v,vt(n,t)))return null;for(e=d.II,i=r=d.sub(t,v),u=0;d.equ(g,d.mod(i,e));)i=d.div(i,e),u+=1;if(1===u)return ot(n,d.div(d.add(t,v),4),t);for(l=g;d.lt(l,t)&&!d.equ(r,vt(l,t));l=d.add(l,v));for(s=ot(l,i,t),o=ot(n,d.div(d.add(i,v),e),t),m=ot(n,i,t),c=u,f=g;!d.equ(g,d.mod(d.sub(m,v),t));){for(f=lt(m,m,t),h=1;hs&&(o.length=s),o}(St(t),St(e.div(n,t)))),r?t.map(function(n){return[new r(n[0]),new r(n[1])]}):t}function Ct(n,t){return n===t}function Nt(n,t,e){var r,i,u,l;for(e=e||Ct,r=n(t),i=n(r);!e(r,i);)r=n(r),i=n(n(i));for(u=0,r=t;!e(r,i);)r=n(r),i=n(i),u++;for(l=1,i=n(r);!e(r,i);)i=n(i),l++;return[l,u]}function Rt(){var n,t,e,r,i=arguments.length&&(An(arguments[0])||In(arguments[0]))?arguments[0]:arguments,u=i.length,l=F.Arithmetic,s=(l.num,l.O),o=l.I;if(0===u)return s;for(r=0;r(n=v.cast(n)).length&&(n=n.concat(Tn(i-n.length,function(n){return _}))),s=(l=t.t().ref(!0))[0],v=l[3],o=l[1].length,c=v.t(),m=s.t(),d=new Array(u),g=new Array(u-o),f=0;f>>1;return i.mul(n(t,e,u),n(t,1+u,r))}(l,0,l.length-1)},u=function n(t,e){if(f.lt(t,d))return h;var r=n(f.div(t,d),e);return f.mul(f.mul(r,r),i(t,e))};return f.lt(t,d)?h:(n=f.sub(t,f.digits(t,2).split("").reduce(function(n,t){return f.add(n,"1"===t?h:a)},a)),e=(r=L()).get(function(n){return f.lte(n,t)}),r.dispose(),f.mul(u(t,e),Vt(n)))}function Yt(e,n){var t,r,i,u=F.Arithmetic,l=u.O,s=u.I,o=u.J,m=u.II,c=u.num,f=u.val,a=u.add,h=u.sub,d=u.div,g=u.mul,v=u.mod,_=l,b=F.Options.MAXMEM;if(Rn(e,M))return new e[G](Yt(e.num,n));if(e=c(e),null==n){if(u.lte(e,12))return u.lt(e,l)?l:c([1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600][f(e)]);if(u.gte(e,100))return Kt(e);t=String(e),null==Yt.mem1[t]?(_=g(Yt(h(e,s)),e),u.lt(e,b)&&(Yt.mem1[t]=_)):_=Yt.mem1[t]}else if(!1===n){if(u.lte(e,12))return u.equ(e,l)?s:u.lte(e,s)?l:c([1,2,9,44,265,1854,14833,133496,1334961,14684570,176214841][f(h(e,m))]);if(t="!"+String(e),null==Yt.mem2[t]){if(u.gt(e,1e4))for(i=s,r=_=l;u.lte(r,e);r=a(r,s))_=a(_,g(i,g(Yt(e,r),Yt(h(e,r))))),i=u.neg(i);else _=a(u.equ(l,v(e,m))?s:o,g(Yt(h(e,s),!1),e));u.lt(e,b)&&(Yt.mem2[t]=_)}else _=Yt.mem2[t]}else if(!0===n){if(u.lte(e,18))return u.lt(e,l)?l:c([1,1,2,4,10,26,76,232,764,2620,9496,35696,140152,568504,2390480,10349536,46206736,211799312,997313824][f(e)]);t="I"+String(e),null==Yt.mem2[t]?(_=a(Yt(h(e,s),!0),g(Yt(h(e,m),!0),h(e,s))),u.lt(e,b)&&(Yt.mem2[t]=_)):_=Yt.mem2[t]}else if(An(n)){if(!n.length)return u.lt(e,l)?l:Yt(e);if(u.lt(e,l))return l;if(An(n[0])){if(!(n=n[0]).length)return u.lt(e,l)?l:Yt(e);if(1===n.length)return Yt(e,n[0]);if(_=En(function(n,t){return a(n,t)},l,n),u.equ(_,l))return e;if(u.gt(_,e))return l;if(t=String(e)+"@"+Bn(n.map(String),1,!0).join(",")+"@",null==Yt.mem3[t]){for(r=h(_,s),_=s;u.gte(r,l);)_=g(_,h(e,r)),r=h(r,s);_=En(function(n,t){return d(n,Yt(t))},_,n),u.lt(e,b)&&(Yt.mem3[t]=_)}else _=Yt.mem3[t]}else t=String(e)+"@"+Bn(n.map(String),1,!0).join(","),null==Yt.mem3[t]?(_=En(function(n,t){return d(n,Yt(t))},Yt(e),n),u.lt(e,b)&&(Yt.mem3[t]=_)):_=Yt.mem3[t]}else if(u.isNumber(n)||Rn(n,M))if(n=Rn(n,M)?n.num:c(n),u.lt(n,l)){if(u.lte(e,u.neg(n)))return u.equ(e,u.neg(n))?Yt(e):l;if(t=String(e)+"@"+String(n),null==Yt.mem3[t]){if(r=a(e,n),u.gt(h(e,r),500))_=d(Yt(e),Yt(r));else for(_=r=a(r,s);u.lt(r,e);)_=g(_,r=a(r,s));u.lt(e,b)&&(Yt.mem3[t]=_)}else _=Yt.mem3[t]}else{if(u.lt(n,l)||u.lt(e,l)||u.gt(n,e))return l;if(u.lt(e,g(n,m))&&(n=h(e,n)),u.equ(n,l)||u.equ(e,s))return s;if(u.equ(n,s))return e;if(t=String(e)+"@"+String(n),null==Yt.mem3[t]){if(u.lte(e,20))_=a(Yt(h(e,s),h(n,s)),Yt(h(e,s),n));else if(u.isDefault())_=Q.round(En(function(n,t){return n*(1+e/t)},1+(e-=n),null,2,n));else if(r=h(e,n),u.gt(h(e,r),500))_=d(Yt(e),g(Yt(n),Yt(r)));else{for(_=r=a(r,s);u.lt(r,e);)_=g(_,r=a(r,s));_=d(_,Yt(n))}u.lt(e,b)&&(Yt.mem3[t]=_)}else _=Yt.mem3[t]}return _}function ne(n,t){var e,r,i,u,l=F.Arithmetic,s=l.O,o=l.I,m=(l.J,l.num),c=l.add,f=l.sub,a=l.mul,h=F.Options.MAXMEM;if(Rn(n,M))return new n[G](ne(n.num,t));if(n=m(n),t=Rn(t,M)?t.num:m(t),l.lt(n,s)||l.lt(t,s)||l.gt(t,n))return s;if(l.equ(t,s))return Yt(n);if(l.equ(t,n))return Yt(n,!1);if(m=String(n)+","+String(t),null==ne.mem[m]){if(e=s,u=f(n,t),l.lt(u,t))for(r=s;l.lte(r,u);r=c(r,o))e=c(e,a(Yt(u,r),Yt(c(t,r),!1)));else for(i=o,r=s;l.lte(r,t);r=c(r,o))e=c(e,a(i,a(Yt(t,r),Yt(f(n,r))))),i=l.neg(i);l.lt(n,h)&&(ne.mem[m]=e)}else e=ne.mem[m];return e}function te(n,t,e,r,i){for(var u=F.Arithmetic,l=u.O,s=i.first();s&&s.indexv&&(_.length=v),_}function ve(n,t,e,r,i){r=!0===r,e=e===A?A:q,i=i||D.Q();for(var u,l=0,s=0,o=0,m=n.length,c=t.length,f=new Array(m+c),a=F.Arithmetic.O;lo&&(f.length=o),f}function _e(t,e,r,i){r=r===A?A:q,i=i||D.Q();var n,u,l,s,o,m,c,f=F.Arithmetic.O;if(t.length>e.length&&(u=t,t=e,e=u),u=t.length,l=e.length,s=new Array(u*l),0n+1&&(s.length=n+1)}return s}function be(n,t,e,r,i){r=!0===r,e=e===A?A:q,i=i||D.Q();var u,l,s,o=n.length,m=t.length,c=F.Arithmetic.O,f=g([],"max",function(n,t){return e.cmp(n.term,t.term)}),a=[],h=[],d=0;if(!t.length)return null;for(s=t[0].cast(i);(l=f.peek())||dl.n?f.replace({term:l.Q.mul(t[l.n].cast(i)),n:l.n+1,Q:l.Q}):f.pop(),d++):(u=l.term.neg(),m>l.n?f.replace({term:l.Q.mul(t[l.n].cast(i)),n:l.n+1,Q:l.Q}):f.pop()),u.equ(c)||(s.divides(u)?(a=ve(a,[l=u.div(s)],e,!1,i),1>>1<<1]),s[r]+=1,r>>>=1;return s[r]+=1,n[e]=t,n},n||new Array(r),t)}function Ce(n,t,e){for(var r,i,u=t.length,l=Q.ceil(V(e||u)),s=1<=o[r<<=1]&&(t-=o[r],r++);return o[r]=0,n[e]=r-s,n},n||new Array(u),t)}function Ne(n,t,e,r){var i,u,l=F.Arithmetic,s=l.O;if(e+1===n)return l.I;for(r.rem(t),r.rem(e),i=r.last();i&&i.index>e;i=i.prev){for(r.rem(i),u=i.prev;u&&0<=u.index;u=u.prev)r.rem(u),s=l.add(s,l.add(Ne(n,u.index,i.index,r),i.index+1t)return!1;return!0!==e||r===t}function ke(n){for(var t=n.length-1,e=-1,r=0,i=n[r];r="===e||"=>"===e?t<=l:l===t}function Le(n,t,e){if(e){if(!n||!n.length)return-1;for(var r,i,u,l=n.length,s=t.length,o=0;o>t},bor:function(n,t){return n|t},band:function(n,t){return n&t},xor:function(n,t){return n^t},abs:Q.abs,min:Q.min,max:Q.max,rnd:je},F.Arithmetic=r({},t,{isDefault:function(){return 0===this.O&&this.add===tt},neg:function(n){return F.Arithmetic.mul(F.Arithmetic.J,n)},abs:function(n){return F.Arithmetic.gt(F.Arithmetic.O,n)?F.Arithmetic.neg(n):n},min:function(n,t){return F.Arithmetic.lt(n,t)?n:t},max:function(n,t){return F.Arithmetic.gt(n,t)?n:t},divceil:function(n,t){if(null==t)return n;var e=F.Arithmetic,r=e.O,i=e.I,u=e.div(n,t);return!e.equ(r,e.mod(n,t))&&e.gt(n,r)===e.gt(t,r)?e.add(u,i):u}}),F.Math={rnd:Q.random,rndInt:je,factorial:Yt,stirling:ee,partitions:ue,compositions:oe,bell:ce,catalan:me,fibonacci:fe,polygonal:ae,sum:et,product:rt,pow2:Vt,exp:Ht,powsq:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](mt(n.num,t)):mt(e.num(n),t)},addm:function(n,t,e){var r=F.Arithmetic;return e=Rn(e,M)?e.num:r.num(e),t=Rn(t,M)?t.num:r.num(t),Rn(n,M)?new n[G](ut(n.num,t,e)):ut(r.num(n),t,e)},negm:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](it(n.num,t)):it(e.num(n),t)},mulm:function(n,t,e){var r=F.Arithmetic;return e=Rn(e,M)?e.num:r.num(e),t=Rn(t,M)?t.num:r.num(t),Rn(n,M)?new n[G](lt(n.num,t,e)):lt(r.num(n),t,e)},invm:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](st(n.num,t)):st(e.num(n),t)},powm:function(n,t,e){var r=F.Arithmetic;return e=Rn(e,M)?e.num:r.num(e),t=Rn(t,M)?t.num:r.num(t),Rn(n,M)?new n[G](ot(n.num,t,e)):ot(r.num(n),t,e)},isqrt:function(n){var t=F.Arithmetic;return Rn(n,M)?new n[G](ct(n.num)):ct(t.num(n))},ikthroot:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](at(n.num,t)):at(e.num(n),t)},isqrtp:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](_t(n.num,t)):_t(e.num(n),t)},ilog:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](bt(n.num,t)):bt(e.num(n),t)},divisors:function(n,t){var e=F.Arithmetic;return jt(Rn(n,M)?n:e.num(n),!0===t)},legendre:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](vt(n.num,t)):vt(e.num(n),t)},jacobi:function(n,t){var e=F.Arithmetic;return t=Rn(t,M)?t.num:e.num(t),Rn(n,M)?new n[G](gt(n.num,t)):gt(e.num(n),t)},moebius:function(n){var t=F.Arithmetic;return Rn(n,M)?new n[G](Ut(n.num)):Ut(t.num(n))},pollardRho:function(n,t,e,r,i,u){var l,s=F.Arithmetic.num;return null!=e&&(e=Rn(e,M)?e.num:s(e)),null!=t&&(t=Rn(t,M)?t.num:s(t)),Rn(n,M)?null==(l=wt(n.num,t,e,r,i||null,u||null))?l:new n[G](l):wt(s(n),t,e,r,i||null,u||null)},factorize:function(n){var t=F.Arithmetic;return St(Rn(n,M)?n:t.num(n))},isProbablePrime:function(n){var t=F.Arithmetic;return At(Rn(n,M)?n.num:t.num(n))},isPrime:function(n){var t=F.Arithmetic;return Ot(Rn(n,M)?n.num:t.num(n))},nextPrime:function(n,t){var e=F.Arithmetic;return function(n,t){var e,r=F.Arithmetic,i=(r.num,r.O),u=r.I,l=r.II;if((t=-1===t?-1:1)<0){if(r.lte(n,l))return null;if(r.equ(n,3))return l;for(e=r.sub(n,r.equ(i,r.mod(n,l))?u:l);;e=r.sub(e,l))if(At(e)&&Ot(e))return e}else{if(r.lt(n,l))return l;for(e=r.add(n,r.equ(i,r.mod(n,l))?u:l);;e=r.add(e,l))if(At(e)&&Ot(e))return e}}(Rn(n,M)?n.num:e.num(n),-1===t?-1:1)},gcd:function(){var t=F.Arithmetic,n=z.call(arguments.length&&(An(arguments[0])||In(arguments[0]))?arguments[0]:arguments),e=null,n=Rt(n.map(function(n){return Rn(n,M)?(e=e||n[G],n.num):t.num(n)}));return e?new e(n):n},xgcd:function(){var t=F.Arithmetic,n=z.call(arguments.length&&(An(arguments[0])||In(arguments[0]))?arguments[0]:arguments),e=null,n=Dt(n.map(function(n){return Rn(n,M)?(e=e||n[G],n.num):t.num(n)}));return e&&n?n.map(function(n){return new e(n)}):n},lcm:function(){var t=F.Arithmetic,n=z.call(arguments.length&&(An(arguments[0])||In(arguments[0]))?arguments[0]:arguments),e=null,n=Zt(n.map(function(n){return Rn(n,M)?(e=e||n[G],n.num):t.num(n)}));return e?new e(n):n},diophantine:function(n,t,e,r){var i=F.Arithmetic;return(An(n)||In(n))&&n.length?Xt(i.nums(n),i.num(t||0),e,!0===r):null},diophantines:function(n,t,e,r){var i=D.Z();return(Rn(n,E)||An(n)||In(n))&&(!Rn(n,E)||n.nr&&n.nc)&&(Rn(n,E)||n.length)?(Rn(t,E)||An(t)||In(t)||(t=Tn(Rn(n,E)?n.nr:n.length,function(){return t||0})),Gt(n,t=Rn(t,E)?t:i.cast(t),e,!0===r)):null},congruence:function(n,t,e,r,i){var u,l,s,o,m,c,f=F.Arithmetic;return(An(n)||In(n))&&n.length?(n=f.nums(n),t=f.num(t||0),u=f.num(e||0),l=r,i=!0===i,m=F.Arithmetic,c=m.O,n.length?(i=!0===i,(s=Xt(n.concat(u),t,l,i))&&i&&(o=s[1],s=s[0]),null==(s=null==s?null:Tn(s.length-1,function(n){n=s[n];return!1===l?m.gt(c,n)&&(n=m.add(n,u)):n.c().real().lt(c)&&(n=n.add(u)),n}))?null:i?[s,o]:s):null):null},congruences:function(n,t,e,r,i){var u,l,s,o,m,c,f,a,h=D.Z();return(Rn(n,E)||An(n)||In(n))&&(!Rn(n,E)||n.nr&&n.nc)&&(Rn(n,E)||n.length)?(n=Rn(n,E)?n:h.cast(n),Rn(t,E)||An(t)||In(t)||(t=Tn(Rn(n,E)?n.nr:n.length,function(){return t||0})),t=Rn(t,E)?t:h.cast(t),Rn(e,E)||An(e)||In(e)||(e=Tn(Rn(n,E)?n.nr:n.length,function(){return e||0})),e=Rn(e,E)?e:h.cast(e),u=n,h=t,l=e,s=r,n=!0===i,r=D.Z(),f=F.Arithmetic,a=r.Zero(),Rn(u,E)&&Nn(u.ring.NumberClass,M)||(u=E(r,u)),u.nr&&u.nc?(An(l)||In(l)||Rn(l,E)||(l=Tn(u.nr,function(n){return l})),(An(l)||In(l))&&(l=E(r,l)),(An(h)||In(h))&&(h=E(r,h)),i=l.col(0),m=r.lcm(i),u=u.concat(l),n=!0===n,null!=(o=Gt(u,h,s,!0))&&(c=o[1],o=o[0]),null==(o=null==o?null:Tn(o.length-1,function(n){var t,e=o[n],r=!0;if(!1===s)f.gt(f.O,e)&&(e=f.add(e,m.num));else{for(t in e.terms)if(W.call(e.terms,t)&&"1"!==t&&f.equ(f.O,f.mod(m.num,e.terms[t].c().real().num))){r=!1;break}r&&(n=c.symbol+"_"+(c.length+1),c.push(n),e=e.add(C(S(n),m))),e.c().real().lt(a)&&(e=e.add(m))}return e}))?null:n?[o,c]:o):null):null},pythagorean:function(n,t){var e=F.Arithmetic;return(An(n)||In(n))&&n.length?function(t,n){var e,r,i,u,l,s,o,m,c=F.Arithmetic,f=c.O,a=c.I,h=c.J,d=c.II,g=t.length,v=wn(n)&&n.length?n:"i";if(!g)return null;if(m=t.filter(function(n){return 1===zt(n)}).length,n=t.filter(function(n){return-1===zt(n)}).length,1===g||0===m||0===n)return Tn(g,function(){return N()});if(o=Tn(g,function(n){return ct(c.abs(t[n]))}),g!==t.filter(function(n,t){return c.equ(c.abs(n),c.mul(o[t],o[t]))}).length)return Tn(g,function(){return N()});if(u=Tn(g-1,function(n){return v+"_"+(n+1)}),2===g)return[N(C(S(u[0]),o[1])),N(C(S(u[0]),o[0]))];for(zt(t[0])+zt(t[1])+zt(t[2])<0&&(t=t.map(function(n){return c.neg(n)})),l=e=0;lr.length&&(r=r.concat(Tn(u.nc-r.length,function(n){return r[r.length-1].split("_")[0]+"_"+(r.length+n+1)}))),Tn(i.nr,function(t){return N(Tn(u.nc,function(n){return C(S(r[n]),u.val[t][n])})).add(i.val[t][0])})):null):null):null},lineqs:function(n,t,e){var r=D.Q();return(Rn(n,E)||An(n)||In(n))&&(!Rn(n,E)||n.nr&&n.nc)&&(Rn(n,E)||n.length)?(Rn(t,E)||An(t)||In(t)||(t=Tn(Rn(n,E)?n.nr:n.length,function(){return t||0})),function(t,e,r){var n,i,u,l,s,o,m,c,f,a,h,d;if(Rn(t,E)||(t=E(D.Q(),t)),!t.nr||!t.nc||t.ring!==D.Q())return null;for(e=E(t.ring,e).col(0),u=t.nc,l=t.nr,wn(r=r||"x")?r=Tn(u,function(n){return r+"_"+(n+1)}):An(r)&&u>r.length&&(r=r.concat(Tn(u-r.length,function(n){return r[r.length-1].split("_")[0]+"_"+(r.length+n+1)}))),i=[],n=Tn(l,function(n){return x.LTE(N(t.row(n).map(function(n,t){return C(S(r[t]),n)})),N(e[n]))}).slice(),s=u-1;0<=s;s--)if(c=[],f=[],a=[],n.forEach(function(n){var t=n.lhs.term(r[s]).c().sub(n.rhs.term(r[s]).c()),n=n.rhs.sub(n.rhs.term(r[s])).sub(n.lhs.sub(n.lhs.term(r[s])));t.gt(0)?c.push(n.div(t)):t.lt(0)?f.push(n.div(t)):a.push(n)}),c.length&&f.length){for(m=c.length*f.length+a.length,n=new Array(m),o=0;ol&&(u.length=l),u},intersection:function(n,t,e,r,i,u,l,s){r=-1===r?-1:1,null==i&&(i=0),null==u&&(u=t.length-1),null==l&&(l=0),null==s&&(s=e.length-1);var o=ue[h]?a+=o:(1===r&&t[a]>e[h]||-1===r&&t[a]r[a]?a+=m:(n[h++]=e[f],t[e[f]]--,f+=o);for(;0<=o*(u-f);)0>>1]))return s;l(o,n)?c=s-1:m=s+1}else for(;m>>1]))return s;l(n,o)?c=s-1:m=s+1}return-1},bisect:Yn,complementation:kn,reflection:$n,reversion:Ln,gray:jn,igray:Un,grayn:Jn,igrayn:Fn,finitedifference:Xn,partialsum:Gn,convolution:function(n,t,e){var r,i,u,l=n.length,s=t.length;if(!0===e)for(u=Tn(l+s-1,function(){return 0}),r=0;r>>5]&1<<(31&n))},set:function(n){return this.bits[n>>>5]|=1<<(31&n),this},unset:function(n){return this.bits[n>>>5]&=~(1<<(31&n)),this},toggle:function(n){return this.bits[n>>>5]^=1<<(31&n),this}}),w=F.ListSet=function n(e){var t,r,i,u,l=this;if(!Rn(l,n))return new n(e);for(e=An(e)?e.slice():new Array(+e),r=e.length,t=0;t=r)return l;t=n}return t.incl&&(i===t&&(i=t.next),u===t&&(u=t.prev),t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),t.incl=!1),l},l.add=function(n){var t=null;if(n===+n){if(n<0||r<=n)return l;t=e[n]}else{if(!n||null==n.index)return l;if(n.index<0||n.index>=r)return l;t=n}return t.incl||(i===t.next&&(i=t),u===t.prev&&(u=t),t.prev&&(t.prev.next=t),t.next&&(t.next.prev=t),t.incl=!0),l},l.has=function(n){var t=null;if(n===+n){if(n<0||r<=n)return!1;t=e[n]}else{if(!n||null==n.index)return!1;if(n.index<0||n.index>=r)return!1;t=n}return t.incl},l.item=function(n){var t=null;if(n===+n){if(n<0||r<=n)return!1;t=e[n]}else{if(!n||null==n.index)return null;if(n.index<0||n.index>=r)return!1;t=n}return t},l.dispose=function(){return u=i=e=null,l}},b=F.Node=function n(t,e,r,i){var u=this;if(!Rn(u,n))return new n(t,e,r,i);u.v=t,u.l=e||null,u.r=r||null,u.t=i||null,u.dispose=function(){return u.v=null,u.l=null,u.r=null,u.t=null,u}},g=F.Heap=n({constructor:function n(t,e,r){var i=this;if(!Rn(i,n))return new n(t,e,r);e=String(e||"min").toLowerCase().slice(0,3),i.type="max"===e?"max":"min",Cn(r)||(r=n.CMP),i.cmp=r,t=t||[],i._h=n.heapify(t,i.type,i.cmp)},__static__:{CMP:function(n,t){return n>>1)-1;0<=r;r--)g._siftup_max(n,r,e);else for(r=(i>>>1)-1;0<=r;r--)g._siftup(n,r,e);return n},_siftdown:function(n,t,e,r){for(var i,u,l=n[e];t>>1])<0;)n[e]=u,e=i;n[e]=l},_siftup:function(n,t,e){for(var r,i=n.length,u=t,l=n[t],s=2*t+1;s>>1],l)<0;)n[e]=u,e=i;n[e]=l},_siftup_max:function(n,t,e){for(var r,i=n.length,u=t,l=n[t],s=2*t+1;s=v.length&&g.slice(-v.length)===v;)g=g.slice(0,-v.length);g.length||(g=null)}i=c.sub(c.pow(n,(g?g.length:0)+v.length),g?c.pow(n,g.length):a),r=c.add(c.mul(i,e),c.sub(h((g||"")+v),g?h(g):f))}else{for(;g&&"0"===g.slice(-1);)g=g.slice(0,-1);r=g&&g.length?(i=c.pow(n,g.length),c.add(c.mul(i,e),h(g))):(i=a,e),u[6]&&(s=h(u[6].slice(1)),c.lt(s,f)?i=c.mul(i,c.pow(n,c.neg(s))):r=c.mul(r,c.pow(n,s)))}return!1!==t&&(t=Rt(r,i),r=c.div(r,t),i=c.div(i,t)),o[0]=d?c.neg(r):r,o[1]=i,o}(n,!0);return n?p(n[0],n[1],!0):p.Zero()},fromString:function(n){var t,e,r,i=F.Arithmetic,u="+",l=p.Zero();if(!(n=K(String(n))).length)return l;if("+"!==n.charAt(0)&&"-"!==n.charAt(0)||(u=n.charAt(0),n=K(n.slice(1))),!n.length)return l;if("("===n.charAt(0)&&")"===n.charAt(n.length-1)&&(n=K(n.slice(1,-1))),!n.length)return l;if(-1!==n.indexOf(".")||-1!==n.indexOf("e"))return t=p.fromDec(n),"-"===u&&(t=t.neg()),t;if(-1!==n.indexOf("\\frac")){if(!(t=n.match(/^(-)?\\frac\{(-?\d+)\}\{(-?\d+)\}$/)))return l;"-"===t[1]&&(u="-"===u?"+":"-"),e=i.num(t[2]),r=i.num(t[3])}else n=String(n).split("/"),e=i.num(n[0].length?n[0]:"0"),r=1>=1,e=e.mul(e);return t},rad:function(n){var t=this,e=F.Arithmetic;return(n=M.cast(n)).equ(e.I)?t:n.equ(e.II)?t.imag().equ(0)?t.real().lt(0)?_(p.Zero(),t.real().abs().rad(n)):_(t.real().rad(n),p.Zero()):(e=t.norm().rad(2),_(e.add(t.real()).div(2).rad(n),e.sub(t.real()).div(2).rad(n).mul(t.imag().lt(0)?-1:1))):dt(t,n)},simpl:function(){var n=this;return n._simpl||(n.re.simpl(),n.im.simpl(),n._str=null,n._strp=null,n._tex=null,n._simpl=!0),n},round:function(n){n=!1!==n;return _(this.re.round(n),this.im.round(n))},integer:function(){var n=this;return null==n._int&&(n._int=_(n.re.integer(),n.im.integer())),n._int},remainder:function(){var n=this;return null==n._rem&&(n._rem=_(n.re.remainder(),n.im.remainder())),n._rem},tuple:function(){return[this.re,this.im]},valueOf:function(){return this.re.valueOf()},toString:function(n){var t,e=this,r=F.Arithmetic,i=r.O;return null==e._str&&(t=e.re.equ(i),e._str=(t?"":e.re.toString())+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+_.Symbol),e._str.length||(e._str="0"),e._strp=(t?"":e.re.toString(!0))+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+_.Symbol),e._strp.length||(e._strp="0")),n?e._strp:e._str},toTex:function(){var n,t=this,e=F.Arithmetic,r=e.O;return null==t._tex&&(n=t.re.equ(r),t._tex=(n?"":t.re.toTex())+(t.im.equ(r)?"":(!t.im.gt(r)||n?"":"+")+(t.im.equ(e.I)?"":t.im.equ(e.J)?"-":t.im.toTex())+_.Symbol),t._tex.length||(t._tex="0")),t._tex},toDec:function(n){var t,e=this,r=F.Arithmetic,i=r.O;return null==e._dec&&(t=e.re.equ(i),e._dec=(t?"":e.re.toDec())+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toDec())+_.Symbol),e._dec.length||(e._dec="0")),Sn(n)&&0<=n?((r=((t=e.re.equ(i))?"":e.re.toDec(n))+(e.im.equ(i)?"":(!e.im.gt(i)||t?"":"+")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toDec(n))+_.Symbol)).length||(r="0",0>=1,e=e.mul(e);return t},rad:function(n){var t=this,e=F.Arithmetic,r=e.O,e=e.I;return n=M.cast(n),t.equ(r)?N():n.equ(r)?null:n.equ(e)?t:N(1===t.symbols().length?t.terms[1].rad(n):C(h(t,p(e,n.num)),e))},d:function(t,e){var r=this;return null==e&&(e=1),e=+e,t=String(t||"x"),e<0?null:N(r.symbols().map(function(n){return"1"===n?F.Arithmetic.O:r.terms[n].d(t,e)}))},evaluate:function(e){var r=this;F.Arithmetic.O;return e=e||{},r.symbols().reduce(function(n,t){return n.add(r.terms[t].evaluate(e))},_.Zero())},toString:function(){var n,t,e,r,i,u=this,l=F.Arithmetic.O,s="",o=!1;if(null==u._str){for(e=(n=u.symbols()).length,t=0;t"===n||"\\gt"===n?">":">="===n||"=>"===n||"\\le"===n?">=":"<="===n||"=<"===n||"\\ge"===n?"<=":"<>"===n||"!="===n||"\\ne"===n?"<>":"~"===n||"\\sim"===n?"~":"="},DUAL:function(n){return"<"===(n=x.OP(n))?">":">"===n?"<":">="===n?"<=":"<="===n?">=":n},EQU:function(n,t){return new x(n,"=",t)},NEQ:function(n,t){return new x(n,"<>",t)},LT:function(n,t){return new x(n,"<",t)},LTE:function(n,t){return new x(n,"<=",t)},GT:function(n,t){return new x(n,">",t)},GTE:function(n,t){return new x(n,">=",t)},SIM:function(n,t){return new x(n,"~",t)},fromString:function(r){var n=String(r).split(/\\sim|\\lt|\\gt|\\le|\\ge|\\ne|\\eq|=<|<=|>=|=>|<>|!=|<|>|=|~/gm),t=["\\sim","\\lt","\\gt","\\le","\\ge","\\ne","\\eq","=<","<=",">=","=>","<>","!=","<",">","=","~"].reduce(function(n,t){var e=r.indexOf(t);return-1"===t?e.gt(n):"<"===t?e.lt(n):">="===t?e.gte(n):"<="===t?e.lte(n):"<>"===t?!e.equ(n):"~"===t||e.equ(n)},toString:function(){var n=this.op;return this.lhs.toString()+" "+n+" "+this.rhs.toString()},toTex:function(){var n=this.op;return">="===n?n="\\ge":"<="===n?this.op="\\le":"<>"===n?this.op="\\ne":"~"===n&&(n="\\sim"),this.lhs.toTex()+" "+n+" "+this.rhs.toTex()}}),y=F.Func=n(t,{constructor:function t(n,e,r,i){if(!Rn(this,t))return new t(n,e,r,i);Rn(n,t)?(this.func=n.op,this.args=n.args,this._eval=r||n._eval,this._deriv=i||n._deriv):(n=String(n||"").toLowerCase(),null!=e&&e.length||(e=[]),this.op=n,this.args=e.map(function(n){return Rn(n,[N,d,t])||(n=d(n)),n}),this._eval=r||null,this._deriv=i||null)},__static__:{MIN:function(n){return y("min",n,Fe)},MAX:function(n){return y("max",n,Je)}},args:null,_eval:null,_deriv:null,dispose:function(){return this._eval=null,this._deriv=null,this.args=null,this.op=null,this},clone:function(){return new this[G](this.op,this.args,this._eval,this._deriv)},isReal:function(){var n=self.args;return n.filter(function(n){return n.isReal()}).length===n.length},isImag:function(){var n=self.args;return n.filter(function(n){return n.isImag()}).length===n.length},real:function(){return y(this.op,this.args.map(function(n){return n.real()}),this._eval,this._deriv)},imag:function(){return y(this.op,this.args.map(function(n){return n.imag()}),this._eval,this._deriv)},equ:function(e){return Rn(e,y)?this.op===e.op&&this.args.filter(function(n,t){return tn.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],R.Add(R(n,r,t.ring),R(t,r,t.ring),e);n.terms.length&&(t.terms=ve(t.terms,n.terms,q,!0===e,t.ring))}else(Rn(n,f)||i.isNumber(n))&&((n=q(n,0,t.ring)).equ(i.O)||(n=t.terms.length?ve([t.terms.pop()],[n],q,!0===e,t.ring):[n],t.terms=t.terms.concat(n)));return t},Mul:function(n,t){var e,r,i=F.Arithmetic,u=i.O;if(!t.terms.length)return t;if(Rn(n,I)){if(n.symbol!==t.symbol)return r=t.symbol>n.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],R.Mul(R(n,r,n.ring),R(t,r,t.ring));t.terms=n.terms.length?_e(t.terms,n.terms,q,t.ring):[]}else if(Rn(n,f)||i.isNumber(n))if((n=t.ring.cast(n)).equ(u))t.terms=[];else if(!n.equ(i.I))for(e=t.terms.length-1;0<=e;e--)t.terms[e]=t.terms[e].mul(n);return t},Div:function(t,e,n){var r,i,u=F.Arithmetic,l=u.O,s=u.I;if(n=!0===n,Rn(e,I)){if(!e.terms.length)throw new Error("Division by zero in Abacus.Polynomial!");return e.isConst()?(i=(e=e.cc()).equ(s)?t:I(Tn(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i):e.symbol===t.symbol?(i=be(t.terms,e.terms,q,n,t.ring),n?[I(i[0],t.symbol,t.ring),I(i[1],t.symbol,t.ring)]:I(i,t.symbol,t.ring)):(r=t.symbol>e.symbol?[e.symbol,t.symbol]:[t.symbol,e.symbol],R.Div(R(t,r,t.ring),R(e,r,e.ring),n))}if(Rn(e,f)||u.isNumber(e)){if((e=t.ring.cast(e)).equ(l))throw new Error("Division by zero in Abacus.Polynomial!");return i=e.equ(s)?t:I(Tn(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i}return t},C:function(n,t,e){return new I(n||F.Arithmetic.O,t||"x",e||D.Q())},gcd:Pt,xgcd:kt,lcm:Lt,bezier:function(n,t){t=String(t||"x");var e,r,i,u,l,s=D.Q(),o=I.Zero(t,s);if(An(n)&&n.length)for(e=n.length,l=I([1,-1],t,s),i=I.One(t,s).shift(e-1),u=I.One(t,s),o=o.add(i.mul(s.cast(n[e-1]))),r=e-2;0<=r;r--)i=i.shift(-1),u=u.mul(l),o=o.add(u.mul(i).mul(Yt(e-1,r)).mul(s.cast(n[r])));return o},bezierThrough:function(n,t){t=String(t||"x");var e,r,i,c=D.Q(),u=function(n){var t,e,r=n.length-1,i=new Array(r),u=new Array(r),l=new Array(r),s=new Array(r),o=new Array(r),m=new Array(r);for(l[0]=c.Zero(),s[0]=c.create(2),o[0]=c.One(),m[0]=n[0].add(n[1].mul(2)),t=1;tt.length+1&&t+"^"===r.slice(0,t.length+1)&&-1===r.indexOf("*")&&(s[r.slice(t.length+1)]=i));return new I(s,t,e)},fromString:function(n,t,e){var r,i,u,l,s=F.Arithmetic,o={},m=null,c=/(\(?(?:(?:[\+\-])?\s*\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))?\)?)(?:\s*(?:[\+\-])?\s*(?:\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))\)?\*?)?(?:[ij]))?\)?)?(?:\s*\*?\s*([a-zA-Z](?:_\{?\d+\}?)?)(?:\^\{?(\d+)\}?)?)?/g;if(e=e||D.Q(),!(n=K(String(n))).length)return I.Zero(t||"x",e);for(;u=c.exec(n);){if(!u[0].length){if(c.lastIndex>=1,e=I.Mul(e,e);return t},rad:function(n){var t=F.Arithmetic;return(n=M.cast(n)).equ(t.I)?this:ht(this,n)},compose:function(n){var t,e,r,i,u=this,l=F.Arithmetic;l.O;if(Rn(n,C)&&(n=N(n)),Rn(n,N)&&(n=I.fromExpr(n,u.symbol,u.ring)),l.isNumber(n)||Rn(n,f))return I(u.evaluate(n),u.symbol,u.ring);if(Rn(n,I)){if(!u.terms.length)return I.Zero(n.symbol,u.ring);if(0===u.deg())return I(u.terms.slice(),n.symbol,u.ring);if(0===n.deg())return I(u.evaluate(n.cc()),n.symbol,u.ring);for(r=(e=u.terms)[0].e,t=I(e[0].c,n.symbol,u.ring),i=1;0=i.terms[0].e?I.Zero(i.symbol,i.ring):I(i.terms.map(function(n){if(r>n.e)return null;for(var t=u.I,e=n.e;e+r>n.e;e--)t=u.mul(t,e);return q(n.c.mul(t),n.e-r,i.ring)}).filter(q.isNonZero),i.symbol,i.ring)},polarForm:function(t){t=String(t||"u");var i=this.ring.associatedField(),u=this.deg(),l=Tn(u,function(n){return t+"_"+(n+1)});return this.terms.reduce(function(n,e){if(!e.e)return n;var t=U(u,e.e),r=t.total();return t.get().reduce(function(n,t){return n.add(R(A(i.cast(e.c).div(r),Tn(u,function(n){return-1===t.indexOf(n)?0:1})),l,i))},n)},R(A(this.cc(),Tn(u,0)),l,i))},evaluate:function(n){var t,e,r,i=this.ring,u=F.Arithmetic,l=u.O,s=this.terms;if(!s.length)return i.Zero();for(Rn(n,f)||u.isNumber(n)||!On(n)||(n=n[this.symbol]),n=n||l,t=s[0].e,r=s[0].c,e=1;0=n.length&&e>=t.length?0:e>=t.length?0===n[e]?r(n,t,e+1):n[e]:e>=n.length?0===t[e]?r(n,t,e+1):-t[e]:n[e]===t[e]?r(n,t,e+1):n[e]-t[e]}if((An(n)||In(n))&&(An(t)||In(t)))return r(n,t,0);var i=r(n.e,t.e,0);return!0===e&&0===i?n.c.equ(t.c)?0:n.c.lt(t.c)?-1:1:i},sortDecr:function(n,t){return A.cmp(t,n)},gcd:function(t,e,n){return A(!0!==n||Rn(t.c,[R,Z,d])||Rn(e.c,[R,Z,d])||!t.ring.hasGCD()?t.ring.One():t.ring.gcd(t.c,e.c),Tn(Q.max(t.e.length,e.e.length),function(n){return n=e.length);t++)if(t>=r.length){if(0r[t])return!1;return!0},pow:function(t){var e=this;return 1===(t=+t)?e:A(e.c.pow(t),Tn(e.e.length,function(n){return Q.floor(e.e[n]*t)}),e.ring)},rad:function(t){var e=this;return 1===(t=+t)?e:A(e.c.rad(t),Tn(e.e.length,function(n){return Q.max(Q.floor(e.e[n]/t),Q.min(1,e.e[n]))}),e.ring)},toTerm:function(n,t,e,r,i){var u,l=this.e,s=this.c,o=F.Arithmetic;if(!0===r){if(u=n.reduce(function(n,t,e){return 0t.e[e])&&(n=t),n},null,r),!0===n?R([t],u,i):t):!0===n?R([],u,i):A(i.Zero(),Tn(u.length,0),i):!0===n?R(r.length?[r[r.length-1]]:[],u,i):r.length?r[r.length-1]:A(0,Tn(u.length,0),i)},lm:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).e},lc:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).c},tm:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).e},tc:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).c},cc:function(){var n=this.terms;return n.length&&0===A.cmp(n[n.length-1].e,[0])?n[n.length-1].c:this.ring.Zero()},c:function(){return this.cc()},recur:function(u){var l,s,n,t=this,e=t.terms,o=t.symbol,m=t.ring,r=F.Arithmetic,i=null;if(!1===u)return null==t._flat&&(t._flat=o.length<=1||!t.isRecur()?t:En(function(n,t){return n._add(Rn(t.c,R)?R([A(m.One(),t.e,m)],o,m)._mul(t.c.recur(!1)):R([t],o,m))},R.Zero(o,m),e),t._flat._rsym=null,t._flat._flat=t._flat),t._flat;if(!0===u)return null==t._recur&&(t._recur=o.length<=1?t:En(function(n,t){return n.recur(t)},t.recur(!1),o),t._recur._flat=t.recur(!1),t._recur._recur=t._recur),t._recur;if(An(u))return En(function(n,t){return n.recur(t)},t,u);if(u){if(o.length<=1)return t;if(u=String(u||"x"),-1===(l=o.indexOf(u))||t._rsym&&-1!==t._rsym.indexOf(u))return t;if(0===(s=t.maxdeg(u,!0)))return t._rsym=(t._rsym||[]).concat(u),t;for(n=R(En(function(n,t){var e,r=t.e[l],i=s-r,t=Rn(t.c,R)?t.c.isUni(u)?R([t],o,m):((e=t.clone()).c=t.c.recur(u),e.e[l]=0,R([e],o,m)):0!==r?((e=t.clone()).e[l]=0,R([e],o,m)):R([t],o,m);return n[i]=n[i]?n[i]._add(t):t,n},new Array(s+1),e).map(function(n,t){return n.equ(r.O)?null:A(n,Tn(o.length,function(n){return l===n?s-t:0}))}).filter(A.isNonZero),o,m);n.isConst()&&Rn(i=n.cc(),R);)n=i;return i===n&&(n=n.clone()),n._rsym=(t._rsym||[]).concat(u),n}return t},monic:function(){var n,t,e,r=this,i=F.Arithmetic,u=r.lc();if(u.equ(i.I)||u.equ(i.O)||Rn(u,R))return r;if(r.ring.isField())return R(r.terms.map(function(n){return n.div(u)}),r.symbol,r.ring);for(e=!0,n=(t=r.terms).length-1;0>=1,e=R.Mul(e,e,!1);return i&&(t=t.recur(i)),t},rad:function(n){var t=F.Arithmetic;return(n=M.cast(n)).equ(t.I)?this:ht(this,n)},compose:function(n){var f=this.symbol,a=this.ring,t=this._rsym,h=F.Arithmetic,d=R.Zero(f,a),g=c(),n=function n(t,e,r){for(r=r||0;r=f.length)return R(t.cc(),f,a);var i,u,l,s,o,m,c=t.terms;if(!c.length)return d;if(i=t.toString(),W.call(g,i))return g[i];for(o=W.call(e,f[r])?R(e[f[r]]||h.O,f,a):R([A(a.One(),Tn(f.length,function(n){return n===r?1:0}),a)],f,a),m=Rn(c[0].c,R)?n(c[0].c,e,r+1):R(c[0].c,f,a),u=c[0].e[r],s=m,l=1;0this.maxdeg(r,!0)?R.Zero(n,l):R(this.terms.map(function(n){var t,e;return Rn((n=n.clone()).c,R)?(e=n.e[u],t=i,0=-i?n.e[u]+=i:n.c=l.Zero(),n}).filter(A.isNonZero).sort(A.sortDecr),n,l):R(this.terms.map(function(n){return Rn((n=n.clone()).c,R)&&0this.maxdeg(r,!0)?R.Zero(n,t):R(this.terms.map(function(n){var t,e;if(Rn(n.c,R)){if(n.c.isConst(!0)){if(i>n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c._mul(t),n.e[u]-=i,n}for(n=n.clone(),e=i;e--,n.c=n.c.d(r,1)._add(n.c._mul(n.e[u])),n.e[u]=Q.max(n.e[u]-1,0),0n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c.mul(t),n.e[u]-=i,n}).filter(A.isNonZero).sort(A.sortDecr),n,t))},evaluate:function(n){var f=this.symbol,a=this.ring,h=F.Arithmetic.O,d=c();return function n(t,e,r){for(r=r||0;r=f.length)return t.cc();var i,u,l,s,o,m,c=t.terms;if(!c.length)return a.Zero();if(i=t.toString(),W.call(d,i))return d[i];for(o=(W.call(e,f[r])?e[f[r]]:h)||h,m=Rn(c[0].c,R)?n(c[0].c,e,r+1):c[0].c,u=c[0].e[r],s=m,l=1;0r[t]&&(r[t]=n.length):n.length>r&&(r=n.length),n});n=String(n);return An(r)?n.length>r[0]&&(r[0]=n.length):n.length>r&&(r=n.length),n})).map(function(n,t){return e+(An(n)?n.map(function(n,t){return nt(n,An(r)?r[t]:r)}).join(" "):nt(n,An(r)?r[0]:r))+e}).join("\n")},toTex:function(n,t){return An(n)?"\\begin{"+(t="pmatrix"===t?"pmatrix":"bmatrix")+"}"+n.map(function(n){return An(n)?n.map(Dn).join(" & "):Dn(n)}).join(" \\\\ ")+"\\end{"+t+"}":Dn(n)},toDec:function(n,e,r){if(!An(n))return Cn(n.toDec)?n.toDec(e):String(n);r=String(r||"|");var i=An(n[0])?Tn(n[0].length,0):0;return(n=n.map(function(n,t){if(An(n))return n.map(function(n,t){n=n.toDec(e);return An(i)?n.length>i[t]&&(i[t]=n.length):n.length>i&&(i=n.length),n});n=n.toDec(e);return An(i)?n.length>i[0]&&(i[0]=n.length):n.length>i&&(i=n.length),n})).map(function(n,t){return r+(An(n)?n.map(function(n,t){return nt(n,An(i)?i[t]:i)}).join(" "):nt(n,An(i)?i[0]:i))+r}).join("\n")}},nr:0,nc:0,val:null,ring:null,_str:null,_tex:null,_n:null,_t:null,_h:null,_a:null,_i:null,_gi:null,_p:null,_snf:null,_lu:null,_qr:null,_ldl:null,_ref:null,_rref:null,_rf:null,_evd:null,_svd:null,_rn:null,_ln:null,_rs:null,_cs:null,_tr:null,_det:null,dispose:function(){var n=this;return n._n&&n===n._n._n&&(n._n._n=null),n._t&&n===n._t._t&&(n._t._t=null),n._h&&n===n._h._h&&(n._h._h=null),n._i&&n===n._i._i&&(n._i._i=null),n._gi&&n===n._gi._gi&&(n._gi._gi=null),n.nr=null,n.nc=null,n.val=null,n.ring=null,n._str=null,n._tex=null,n._n=null,n._t=null,n._h=null,n._a=null,n._i=null,n._gi=null,n._p=null,n._snf=null,n._lu=null,n._qr=null,n._ldl=null,n._ref=null,n._rref=null,n._rf=null,n._evd=null,n._svd=null,n._rn=null,n._ln=null,n._rs=null,n._cs=null,n._tr=null,n._det=null,n},clone:function(n){var t=this.val.map(function(n){return n.slice()});return!0===n?t:new E(this.ring,t)},map:function(r,n){var i=this,t=i.val.map(function(n,e){return n.map(function(n,t){return r(n,[e,t],i)})});return!0===n?t:new E(i.ring,t)},array:function(n){var t=this;return Tn(t.nr*t.nc,n?function(n){return t.val[n%t.nr][~~(n/t.nr)]}:function(n){return t.val[~~(n/t.nc)][n%t.nc]})},row:function(n){return 0<=n&&n=e.nr?r.val[t].slice():t>=r.nr?e.val[t].slice():Tn(Q.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?e.val[t][n]:r.val[t][n].add(e.val[t][n])})})):((Sn(e)||wn(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.add(e)}))},sub:function(e){var r=this;return Rn(e,E)?E(r.ring,Tn(Q.max(r.nr,e.nr),function(t){return t>=e.nr?r.val[t].slice():t>=r.nr?e.val[t].map(function(n){return Arithmetic.neg(n)}):Tn(Q.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?Arithmetic.neg(e.val[t][n]):r.val[t][n].sub(e.val[t][n])})})):((Sn(e)||wn(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.sub(e)}))},mul:function(i){var u,l,s=this;return Rn(i,E)?(u=Q.min(s.nc,i.nr),l=s.ring.Zero(),E(s.ring,Tn(s.nr,function(r){return Tn(i.nc,function(n){for(var t=l,e=0;e=r.nr?e.val[t].slice():t>=e.nr?r.val[t].slice():Tn(Q.max(r.nc,e.nc),function(n){return n>=r.nc?e.val[t][n]:n>=e.nc?r.val[t][n]:r.val[t][n].mul(e.val[t][n])})})):((Sn(e)||wn(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.mul(e)}))},prod:function(i){var n,t,u,e,l,s=this;return Rn(i,E)?(e=s.nr,n=s.nc,t=i.nr,u=i.nc,e=e*t,l=n*u,E(s.ring,Tn(e,function(n){var e=~~(n/t),r=n%t;return Tn(l,function(n){var t=~~(n/u),n=n%u;return s.val[e][t].mul(i.val[r][n])})}))):((Sn(i)||wn(i))&&(i=s.ring.cast(i)),s.map(function(n){return n.mul(i)}))},div:function(t){return Rn(t,f)||F.Arithmetic.isNumber(t)||wn(t)?((Sn(t)||wn(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.div(t)})):this},mod:function(t){return Rn(t,f)||F.Arithmetic.isNumber(t)||wn(t)?((Sn(t)||wn(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.mod(t)})):this},divmod:function(n){return[this.div(n),this.mod(n)]},pow:function(n){var t,e,r=F.Arithmetic;if((n=M.cast(n)).lt(r.O)||n.gt(ln))return null;if(0===(n=r.val(n.num)))return E.I(this.ring,this.nc);if(1===n)return this;for(t=null,e=this;0!==n;)1&n&&(t=null==t?e:e.mul(t)),n>>=1,e=e.mul(e);return t},fwdsub:function(n,t){var e,r,i,u,l,s,o,m=this.ring,c=m.Zero(),f=this.val;for(Rn(n,E)&&(n=n.col(0)),Rn(t,E)&&(t=t.diag()),n=m.cast(n),t=t&&m.cast(t),u=Q.min(this.nr,this.nc,n.length),l=new Array(u),e=0;eA&&(m.length=A),this._ref=[y,m,c,t]}return n?this._ref.slice():this._ref[0]},rref:function(n,t){var e,r,i,u,l,s,o,m,c,f,a,h,d,g,v,_;if(null==this._rref){for(r=(e=this.ring).Zero(),i=e.One(),u=e.MinusOne(),l=this.nr,_=s=this.nc,An(t)&&(_=Q.min(_,t[1])),g=(_=this.ref(!0,t))[0].concat(_[3]),o=_[1],t=_[2],m=o.length,f=0;f=r.nc?t=e.nc?t=r.nr?n=e.nr?n"===n?(n=-1,i=!0):"<="===n||"=<"===n?i=!(n=1):">="!==n&&"=>"!==n||(i=!(n=-1))),u(-1===(n=-1===(n=+n)?-1:1)?function(n){for(var t=n[0],e=1,r=n.length;e=n[e]||!i&&t>n[e])return!1;t=n[e]}return!0})},LEN:function(t,n){return t=+t,u(">="===(n=n||"==")?function(n){return n.length>=t}:">"===n?function(n){return n.length>t}:"<"===n?function(n){return n.length="===(n=n||"==")||"=>"===n?function(n){return 0<=t&&t=e}:">"===n?function(n){return 0<=t&&te}:"<"===n?function(n){return 0<=t&&t="===(t=t||"==")||"=>"===t?function(e){return En(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>=n}:">"===t?function(e){return En(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>n}:"<"===t?function(e){return En(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)<=n}:"!="===t?function(e){return En(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)!==n}:function(e){return En(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)===n})},MIN:function(n,t){return n=+n,u(">="===(t=t||"==")||"=>"===t?function(e){return En(function(n,t){return e[t]=n}:">"===t?function(e){return En(function(n,t){return e[t]n}:"<"===t?function(e){return En(function(n,t){return e[t]i)return!1;return!0}:function(n){for(var t=0,e=n.length;t=i)return!1;return!0})},DIFF:function(t){return u(Rn(t,P)?function(n){return!t.has(n)}:function(n){return!0})},MOD:function(t,n){var e=null!=n&&Rn(t,P)?t.index(n):F.Arithmetic.O;return u(Rn(t,P)?function(n){return F.Arithmetic.equ(e,t.index(n))}:function(n){return!0})}},filter:null,dispose:function(){return this.filter=null,this},apply:function(n,t){var e=this.filter;return!e||!Cn(e)||Boolean(e.call(t||null,n))},NOT:function(){var t=this;return u(function(n){return!t.apply(n,this)})},OR:function(t){var e=this;return Cn(t)||Rn(t,u)?(Rn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)||t.apply(n,this)})):e},XOR:function(e){var r=this;return Cn(e)||Rn(e,u)?(Rn(e,u)||(e=u(e)),u(function(n){var t=r.apply(n,this),n=e.apply(n,this);return t&&!n||!t&&n})):r},AND:function(t){var e=this;return Cn(t)||Rn(t,u)?(Rn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)&&t.apply(n,this)})):e}}),T=F.Iterator=n({constructor:function n(t,e){var r=this,i=F.Arithmetic;if(!Rn(r,n))return new n(t,e);(An(t)||In(t))&&(Rn(t[0],n)||Rn(t[t.length-1],n))?(r.name="Sequence",r.$=e||{},r.$.seq=z.call(t),r.$.count=En(function(n,t){return i.add(n,t.total())},i.O,r.$.seq),r.rewind()):An(t)||In(t)?(r.name="List",r.$=e||{},r.$.seq=z.call(t),r.$.count=r.$.seq.length,r.rewind()):Cn(t)?(r.name="Generator",r.$={},r.$.generator=t,r.$.state=e||{},r.$.count=i.I,r.rewind()):(r.name=t||"Iterator",r.$=e||{},r.$.count=r.$.count||i.O)},__static__:{Iterable:function n(t,e){if(!Rn(this,n))return new n(t,e);e=-1===e?-1:1,this.next=function(){var n=t.hasNext(e)?t.next(e):null;return null==n?{done:!0}:{value:n}}}},name:"Iterator",$:null,__index:null,__item:null,_index:null,_item:null,__subindex:null,_subindex:null,__subitem:null,_subitem:null,dispose:function(){var n=this;return n.$.seq&&n.$.seq.length&&(En(function(n,t){t instanceof T&&t.dispose()},null,n.$.seq),n.$.seq=null),n.$=null,n.__index=null,n.__item=null,n._index=null,n._item=null,n.__subindex=null,n._subindex=null,n.__subitem=null,n._subitem=null,n},filterBy:function(n){var t=this.$;return!1===n?t.filter&&(t.filter=null):(Rn(n,u)||Cn(n))&&(t.filter=Rn(n,u)?n:u(n)),this},mapTo:function(n,t){var e,r,i,u=this.$;return!1===n?u.output&&(u.output=null):Cn(n)&&(e=u.output,u.output=t&&e?(r=e,i=n,function(n){return null==n?null:i(r(n))}):n),this._item=this.output(this.__item),this},fuse:function(n,t,e){var r=this.$;return 1===arguments.length&&!1===n?r.sub&&(r.sub=null,r.submethod=null,r.subcascade=null,r.subcount=null,this.rewind()):Rn(t,T)&&Cn(n)&&(r.sub=t,r.submethod=n,r.subcascade=-1===e?-1:1,r.subcount=F.Arithmetic.mul(r.count,t.total()),this.rewind()),this},unfuse:function(){return this.fuse(!1)},juxtaposeWith:function(n,t){return this.fuse(function(n,t){return[].concat(n).concat(t)},n,t)},state:function(n){return arguments.length?(this.$.state=n,this):this.$.state},output:function(n){var t=this.$.output;return null==n?null:Cn(t)?t(n):n},fusion:function(n,t){var e,r=this.$;return r.sub?(-1===r.subcascade&&(e=n,n=t,t=e),null==n||null==t?n||t||null:r.submethod.call(this,n,t)):n},order:function(){return this},rewind:function(n,t){var e,r,i,u=this,l=u.$;if(n=-1===n?-1:1,An(l.seq)){for(e=0,r=l.seq.length;e=u.seq.length)&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),r=i.__item,i.__subitem=u.sub.next(n)),i.__item=r,i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null}while(u.filter&&null!=e&&!u.filter.apply(e,i));return e}if(Cn(u.generator)){for(;t=i.__item,e=u.sub?i._subitem:i._item,i.__item=u.generator.call(i,t,n,u.state,!1),null==i.__item&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),i.__subitem=u.sub.next(n)),i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null,u.filter&&null!=e&&!u.filter.apply(e,i););return e}return null},get:function(n){var t,e,r=[];if(Cn(n))for(;this.hasNext()&&null!=(t=this.next())&&n(t);)r.push(t);else for(e=!arguments.length||null==n,null!=n&&(n=+n);(e||r.length=o.$.mindimension&&u<=o.$.maxdimension){if(l=o[G].rank(n,o.n,o.$),c.gt(l,a)){m=!0;break}s=c.add(s,o.total())}return m?c.add(l,s):a}return yn()},unrank:function(n,t,e){if(e&&"sequence"===e.type){var r,i,u=F.Arithmetic,l=u.O,s=e.seq;if(!s||!s.length)return null;if(null==(n=null==n?null:u.num(n))||!u.inside(n,u.J,null!=e.count?e.count:this.count(t,e)))return null;for(i=s.length,r=0;u.gte(n,s[r].total())&&(n=u.sub(n,s[r].total()),!(i<=++r||u.lt(n,l))););return rm&&(m=e[n]+1),e[n]):m+r[n-e.length]}:function(n){return nu&&(e.length=u),d<0&&1n[1]&&(n[1]=t),n},[1/0,0],l),s.base=l,s.minbase=n[0],s.maxbase=n[1],s.dimension=l.length,"gray"===s.output?s.output=function(n,t){return e.toGray(n,t)}:"inversion"===s.output?s.output=function(n,t){return e.inversion(n)}:An(s.output)&&(i=s.output,s.output=function(n,t){return e.component(n,i)})),P.call(this,"Tensor",l,s,u?{method:"partial"===s.type?s.submethod||"complete":s.submethod,iter:u,pos:"partial"===s.type?s.subpos||s.position:s.subpos,cascade:s.subcascade}:null)},__static__:{C:P.C,P:P.P,T:P.T,DUAL:P.DUAL,count:function(n,t){var e=F.Arithmetic.O,r=t&&t.type?t.type:"tensor";return"partial"===r?t.data&&t.data.length?F.Arithmetic.num(t.data.length):e:"tuple"===r?!n||n[0]<=0?e:Ht(n[1],n[0]):n&&n.length?rt(n):e},initial:function(t,n,e){var r,i=n&&n.type?n.type:"tensor",u=n&&n.order?n.order:gn;return e=-1===e?-1:1,(!(vn&u)&&hn&u||vn&u&&!(hn&u))&&(e=-e),r="partial"===i?n.data&&n.data.length?e<0?n.data[n.data.length-1]:n.data[0]:null:(r="tuple"===i?t[0]?Tn(t[0],e<0?t[1]-1:0,0):[]:t.length?e<0?Tn(t.length,function(n){return t[n]-1}):Tn(t.length,0,0):[],this.DUAL(r,t,n))},valid:function(n,t,e){var r,i,u=e&&e.type?e.type:"tensor";if(!n)return!1;if("partial"===u)return 0<=Le(e.data,n,!0);if(n=this.DUAL(n.slice(),t,e),"tuple"===u){if(!(r=t[0])||r!==n.length)return!1;for(t=t[1],i=0;i=t)return!1}else{if(!(r=t.length)||r!==n.length)return!1;for(i=0;i=t[i])return!1}return!0},succ:function(n,t,e,r,i,u){if(!e||null==n)return null;var l=r&&r.type?r.type:"tensor",s=r&&null!=r.order?r.order:gn,o=F.Arithmetic;return i=-1===i?-1:1,"partial"===l?r.data&&r.data.length?(hn&s&&(i=-i,null!=t&&(t=o.sub(o.num(r.data.length-1),t))),null==t&&(t=Le(r.data,n,!0)),t=o.val(t),i<0?0<=t-1?r.data[t-1]:null:0<=t&&t+1=t)return a;f=o(c(f,t),n[i])}}else{if(!(r=t.length)||r!==n.length)return a;for(i=0;i=t[i])return a;f=o(c(f,t[i]),n[i])}}return(!(vn&l)&&hn&l||vn&l&&!(hn&l))&&(f=m(e&&null!=e.last?e.last:m(this.count(t,e),u.I),f)),f},unrank:function(n,t,e){var r,i,u,l,s,o,m=F.Arithmetic,c=e&&null!=e.order?e.order:gn,f=e&&e.type?e.type:"tensor",a=m.sub,h=m.mod,d=m.div,g=m.val;if(null==(n=null==n?null:m.num(n))||!m.inside(n,m.J,e&&null!=e.count?e.count:this.count(t,e)))return null;if((!(vn&c)&&hn&c||vn&c&&!(hn&c))&&(n=a(e&&null!=e.last?e.last:a(this.count(t,e),m.I),n)),"partial"===f){if(!e.data||!e.data.length)return null;s=0<=(n=g(n))&&n=t+e[i].length&&(t+=e[i++].length),t+e[i][n-t]})},component:function(t,e){return null==t?null:null==e?t:Tn(t.length,function(n){return n=r.length||null==r[n])return e[n];var t=r[n];return Sn(t)?e[n]+t:t[0]*e[n]+(t[1]||0)})}:qn},conditional:ge,generate:function(n,t,i,u,l){l=l||{},i=i||Tn(t.length||0,0,1);for(var e,r,s,o,m,c,f,a,h,d=null==l.min?0:l.min,g=null==l.max?n-1:l.max,v=g-d+1,_=t,b=_.length,p=!1,x=[],y=[],q={},A=function(n){return d<=n&&n<=g},p=!(t=[]),I=m=0;Ie[1]?pe(n,Tn(e[0]-e[1]+1,e[1],1).filter(A)).reverse():pe(n,Tn(e[1]-e[0]+1,e[0],1).filter(A)):pe(n,e[1].split(",").map(Number).filter(A))).length){p=!0;break}t.push(s)}else if(e=r.match(nn)){if(!(s=(0e[1]?Tn(e[0]-e[1]+1,e[0],-1):Tn(e[1]-e[0]+1,e[0],1):e[1].split(",").map(Number)).filter(A)).length){p=!0;break}t.push(s)}else if(f=!0,c=[],a=null,r=r.replace(Y,function(n,t){var e=parseInt(t,10),t="v"+String(e);return!isNaN(e)&&A(e)||(f=!1),f&&-1===c.indexOf(e)&&c.push(e),t}),f){c.sort(function(e){return!0===e?function(n,t){return n.equ(t)?0:n.lt(t)?-1:1}:e?function(n,t){return e.equ(n,t)?0:e.lt(n,t)?-1:1}:function(n,t){return n===t?0:n"===u?on:"<"===u?mn:"<="===u||"=<"===u?an:">"===u?cn:(">="===u||"=>"===u)&&fn,h=Cn(l.extra_conditions)?function(n,t,e){var r=n[t];return!(rr||cn===u&&i[i.length-1]-i[t]>r)&&l.extra_conditions(n,t,e)}:function(n,t,e){n=n[t];return!(nn||cn===u&&i[i.length-1]-i[t]>n)},!0===l.lazy?t:ge(t,u,h))}}}),F.Permutation=n(P,{constructor:function n(t,e){var r=null;if(!Rn(this,n))return new n(t,e);(e=e||{}).type=String(e.type||"permutation").toLowerCase(),Rn(t=t||0,P)?t=(r=t).dimension():r=e.sub,e.base=t,e.dimension=Q.max(0,t),e.rand=e.rand||{},"multiset"===e.type&&(e.multiplicity=An(e.multiplicity)&&e.multiplicity.length?e.multiplicity.slice():Tn(e.dimension,1,0),e.multiplicity=e.multiplicity.concat(Tn(e.dimension-En(tt,0,e.multiplicity),1,0)),e.base=e.multiplicity.length,e.multiset=Oe(e.multiplicity,e.dimension)),P.call(this,"Permutation",t,e,r?{method:e.submethod,iter:r,pos:e.subpos,cascade:e.subcascade}:null)},__static__:{C:P.C,P:P.P,T:P.T,DUAL:P.DUAL,count:function(n,t){var e=F.Arithmetic,r=e.O,i=t&&t.type?t.type:"permutation",u=t&&null!=t["cycles="]?0|t["cycles="]:null,l=t&&null!=t["fixed="]?0|t["fixed="]:null;return n<0?r:"cyclic"===i?e.num(n):"multiset"===i?Yt(n,t.multiplicity):"derangement"===i?null!=l?e.mul(Yt(n,l),Yt(n-l,!1)):Yt(n,!1):"involution"===i?Yt(n,!0):"connected"===i?Yt(n-1):null!=u?ee(n,u,1):Yt(n)},initial:function(t,n,e){var r,i,u=n&&n.type?n.type:"permutation",l=n&&null!=-n.order?n.order:gn,s=n&&null!=n["cycles="]?0|n["cycles="]:null,o=n&&null!=n["fixed="]?0|n["fixed="]:null;if(t<0)return null;if(0===t)return[];if(e=-1===e?-1:1,(!(vn&l)&&hn&l||vn&l&&!(hn&l))&&(e=-e),"cyclic"===u)r=e<0?[t-1].concat(Tn(t-1,0,1)):Tn(t,0,1);else if("derangement"===u)if(null!=o){if((l=t-o)<0)return null;r=1&l?(i=Q.floor(l/2),e<0?Tn(l-i-1,l-1,-1).concat(1<=i?[i-1,i]:[]).concat(Tn(i-1,i-2,-1)).concat(Tn(o,l,1)):Tn(o,0,1).concat(Tn(l-3,function(n){return o+(1&n?n-1:n+1)}).concat(3<=l?[t-2,t-1,t-3]:[]))):e<0?Tn(l,l-1,-1).concat(Tn(o,l,1)):Tn(o,0,1).concat(Tn(l,function(n){return o+(1&n?n-1:n+1)}))}else{if(t<2)return null;r=1&t?(i=Q.floor(t/2),e<0?Tn(t-i-1,t-1,-1).concat([i-1,i]).concat(Tn(i-1,i-2,-1)):Tn(t-3,function(n){return 1&n?n-1:n+1}).concat([t-2,t-1,t-3])):e<0?Tn(t,t-1,-1):Tn(t,function(n){return 1&n?n-1:n+1})}else if("multiset"===u)r=e<0?n.multiset.slice().reverse():n.multiset.slice();else if("connected"===u)r=Ze([e<0?Tn(t,t-1,-1):[t-1].concat(Tn(t-1,0,1))],t);else if("involution"===u)r=e<0?Tn(t,function(n){return 1&n?n-1:n+1=s.length||s[u]<=0)return!1;s[u]--}if(0!==s.filter(function(n){return 0!==n}).length)return!1}else{for(l={},r=0;r=v*t[o+g];)o-=g;if(0<=o&&o<=x){for(m=d;0<=m&&m<=x&&0=v*t[m];)m-=g;for(a=t[o],t[o]=t[m],t[m]=a,c=o+g,f=d;0<=c&&c<=x&&0<=f&&f<=x&&0=i.length)return h;if(r+1===t)return a.I;for(c=i[u][0],f=i[u][1],l.rem(e),l.rem(r),s=l.last();s&&s.index>r;s=s.prev){for(m=!1,l.rem(s),o=s.prev;o&&0<=o.index&&(l.rem(o),o.index===c&&s.index===f?(h=a.add(a.add(h,n(t,o.index,s.index,i,u+1,l)),a.I),m=!0):h=a.add(h,a.add(Ne(t,o.index,s.index,l),s.index+1=h.length||h[l]<=0)return O;h[l]--}if(0!==h.filter(function(n){return 0!==n}).length)return O;for(h=n.multiplicity.slice(),a=n&&null!=n.count?n.count:Yt(e,h),u=e-1,r=0;rr;l=l.prev){for(c=!1,u.rem(l),s=l.prev;s&&0<=s.index;s=s.prev)if(u.rem(s),m=o,o=f.add(o,f.add(Ne(t,s.index,l.index,u),l.index+1l),i),!v.lte(u,t)));c=c.prev);if(null==c)break;t=I(t,u),r[l]=c.index,i.rem(c.index),c.index>l+1&&s.offset(c.index-1,1).offset(l,-1),l++}i.dispose(),s.dispose()}else if("multiset"===_)for(g=n.multiplicity.slice(),r=Tn(e),d=n&&null!=n.count?n.count:Yt(e,g),l=0;l=u&&(i=0,r+=u);if(!0===e)for(r=0;r=l&&(i=0,r++);else for(i=r=0;r=l&&(i=0,r++);return n}(null,n,t)},parity:yn,isPermutation:function(n,t){if((t=t||n.length)!==n.length)return!1;for(var e,r=Tn(t,0,0),i=0;i=r)return!1}else if("repeated"===l||"combination+repeated"===l){for(r=t[0],i=0;i=r||i+1n[i+1])return!1}else if("ordered"===l||"variation"===l)for(r=t[0],u={},i=0;i=r||1===u[n[i]])return!1;u[n[i]]=1}else for(r=t[0],i=0;i=r||i+1=n[i+1])return!1;return!0},succ:function(n,t,e,r,i,u){return!e||!e[0]||e[0]<=0||e[1]<=0||null==n?null:function(n,t,e,r,i,u){var l,s,o,m,c,f,a,h,d,g,v,_,b=t[1],p=t[0];if(t[0]<0||t[1]<0)return null;t=f=b-1,d=a=c=1,g=h=0,vn&i&&(a=-a,h=p-1-h,c=-c,t=f-t,d=-d,g=f-g);dn&i&&(c=-c,t=f-t,d=-d,g=f-g);hn&i&&(e=-e);if(e<0)if("ordered+repeated"===r||"variation+repeated"===r||"repeated+variation"===r){for(l=t;0<=l&&l<=f&&0===n[l];)l-=c;if(0<=l&&l<=f)for(--p,n[l]=n[l]-1,s=l+c;0<=s&&s<=f;s+=c)n[s]=p;else n=null}else if("ordered"===r||"variation"===r){for(null==u&&(u=Ge(n,0,b,0,r)),l=t,o=-1;-1===o&&0<=l&&l<=f;){if(0<=a*n[l]+h-a)for(s=a*n[l]+h-a;0<=s&&sb||_&&0n[l-c]+v){o=l;break}if(!(0<=o&&o<=f)&&0=l)return g;v=c(a(v,l),n[r])}else if("repeated"===m||"combination+repeated"===m){for(l=t[0]+_-1,s=e&&e.count?e.count:Yt(l,_),r=1;r<=_;r++){if(n[r-1]<0||n[r-1]>=t[0]||r<_&&n[r-1]>n[r])return g;(u=_+1-r)<=(i=l-1-n[r-1]-r+1)&&(v=c(v,Yt(i,u)))}v=f(f(s,d),v)}else if("ordered"===m||"variation"===m){for(l=t[0],o={},r=0;r<_;r++){if(n[r]<0||n[r]>=l||1===o[n[r]])return g;o[n[r]]=1}for(n=Se(null,n,l),r=0;r<_;r++)v=c(a(v,l-r),n[r])}else{for(l=t[0],s=e&&e.count?e.count:Yt(l,_),r=1;r<=_;r++){if(n[r-1]<0||n[r-1]>=l||r<_&&n[r-1]>=n[r])return g;(u=_+1-r)<=(i=l-1-n[r-1])&&(v=c(v,Yt(i,u)))}v=f(f(s,d),v)}return(!(vn&b)&&hn&b||vn&b&&!(hn&b))&&(v=f(e&&null!=e.last?e.last:f(this.count(t,e),d),v)),v},unrank:function(n,t,e){var r,i,u,l,s,o,m,c=F.Arithmetic,f=c.O,a=c.I,h=c.sub,d=c.div,g=c.mod,v=c.mul,_=c.lte,b=c.gt,p=c.val,x=t[1],y=e&&e.type?e.type:"combination",q=e&&null!=e.order?e.order:gn;if(null==(n=null==n?null:c.num(n))||!c.inside(n,c.J,e&&null!=e.count?e.count:this.count(t,e)))return null;if(t[0]<0||t[1]<0)return null;if(0===x)return[];if((!(vn&q)&&hn&q||vn&q&&!(hn&q))&&(n=h(e&&null!=e.last?e.last:h(this.count(t,e),c.I),n)),t=t[0],r=Tn(x),"ordered+repeated"===y||"variation+repeated"===y||"repeated+variation"===y)for(l=n,o=x-1;0<=o;o--)s=g(l,t),l=d(l,t),r[o]=p(s);else if("ordered"===y||"variation"===y){for(l=n,o=x-1;0<=o;o--)s=g(l,u=t-o),l=d(l,u),r[o]=p(s);Ce(r,r,u)}else for(u=(m="repeated"===y||"combination+repeated"===y)?t+x-1:t,n=h(h(i=e&&e.count?e.count:Yt(u,x),a),n),i=d(v(i,u-x),u),s=u-x+1,l=x,o=u-1;_(i,n)?(r[x-l]=m?u-s-x+1:u-s-l+1,b(i,f)&&(n=h(n,i),i=d(v(i,l),o)),l--):(i=d(v(i,o-l),o),s--),o--,0=n[r+1])return!1;l[i]=1}return!0},succ:function(n,t,e,r,i,u){if(null==n)return null;var l,s,o=F.Arithmetic,m=r&&r.type?r.type:"subset",c=r&&null!=r.order?r.order:gn;if(e<=0)return null;if(_n&c){if(null!=t&&(s=null!=r.count?r.count:this.count(e,r),t=o.add(t,i<0?o.J:o.I),o.inside(t,o.J,s))){for(hn&c&&(t=o.sub(o.sub(s,o.I),t)),t=Jn(t),l=0,(n=new Array(e+1))[e]=0;ln[s-u]+1?(--n[s],n[s+u]=m,n[o]++):n[o]--:n[o]=0:n=null:0===n[o]?(n[i]=0,n[o]=1):+n[l]+0n.length||e.maxdimension=n[u+1])return f;v=a(v,Bt(t,r)),s[r]=1}v=Fn(v),hn&g&&(v=h(e&&null!=e.last?e.last:h(this.count(t,e),c),v))}else if(o){for(l=n.length,s={},v=m,u=0;u=n[u+1])return f;v=a(v,Wt(t,r,i)),s[r]=1,i=r}hn&g&&(v=h(e&&null!=e.last?e.last:h(this.count(t,e),c),v))}return v},unrank:function(n,t,e){var r,i,u,l,s,o=F.Arithmetic,m=o.O,c=o.I,f=o.band,a=o.shr,h=o.gt,d=(o.add,o.sub),g=o.gte,v=e&&e.type?e.type:"subset",_=e&&null!=e.order?e.order:gn,b=e&&null!=e.count?e.count:this.count(t,e),p=m;if(n=null==n?null:o.num(n),!e||t<0||null==n||!o.inside(n,o.J,b))return null;if(((r=new Array(t+1))[t]=0)n.length||on[m]+1?(n[o]=n[m],n[m]=i):(i===n[o]&&n[x][1]--,u===n[m]&&n[x][2]--,n[o]--,n[m]++,i===n[m]&&n[x][1]++,u===n[o]&&n[x][2]++)}}else if(u)if(vn&s)n=null;else if((a=n[t])n[m]+1?(n[o]=n[m],n[m]=i):(i===n[o]&&n[x][1]--,n[o]--,n[m]++,i===n[m]&&n[x][1]++)}else if(vn&s)if((a=n[c])n[x][0]){for(o=t,v=0;_<=o&&o<=b&&1===n[o];)o-=y,v++;if(a=n[o]-1,n[o]=a,0<++v)if(_<=o+y&&o+y<=b)n[o+=y]=v,v=0,n[x][0]=y<0?l-o:o+1;else for(;0n[o]+1&&an[o]+1?(n[m]=n[o],n[o]=i):(i===n[m]&&n[x][1]--,u===n[o]&&n[x][2]--,n[o]++,n[m]--,u===n[m]&&n[x][2]++,i===n[o]&&n[x][1]++)}else if(u)if(p-u*(r-1)>n[c]){for(o=t;_<=o&&o<=b&&u===n[o];)o-=y;m=o-y,1===n[x][2]&&u===n[m]?(n[m]=n[o],n[o]=u):(u===n[m]&&n[x][2]--,n[o]--,n[m]++,u===n[o]&&n[x][2]++,a=n[o],n[o]=n[t],n[t]=a)}else n=null;else if(i){for(f=1,o=(m=t)-y,d=i-n[m],v=n[m];_<=o&&o<=b&&(i&&in[o]+1&&v-(f-1)-1n[o]+1?(n[m]=n[o],n[o]=i):(i===n[m]&&n[x][1]--,n[o]++,n[m]--,i===n[o]&&n[x][1]++)}else if(vn&s)if(p-r+1>n[t]){for(o=c;_<=o&&o<=b&&1===n[o];)o+=y;a=n[o],n[o]=1,n[c]=a-1,_<=o+y&&o+y<=b&&n[o+y]++}else n=null;else if(p-r+1>n[c]){for(o=t;_<=o&&o<=b&&1===n[o];)o-=y;a=n[o],n[o]=1,n[t]=a-1,_<=o-y&&o-y<=b&&n[o-y]++}else n=null;else if(vn&s)n=null;else if(i){if(i===u)return null;for(h=u||1,v=n[o=t],i===n[o]&&n[x][1]--,u&&u===n[o]&&n[x][2]--,n[x][0]--,o-=y;null!=u&&_<=o&&o<=b&&v<1+u;)v+=n[o],n[x][0]--,i===n[o]&&n[x][1]--,u===n[o]&&n[x][2]--,o-=y;if(o<_||bn[c]){for(v=n[o=t],n[x][0]--,u&&u===n[o]&&n[x][2]--,o-=y,u&&u===n[o]&&n[x][2]--,n[o]++,v--;h<=v;)n[o+=y]=h,v-=h,n[x][0]++,u&&n[x][2]++;if(u&&0===n[x][2]&&(v+=n[o]-u,n[o]=u,n[x][2]++),0h){for(o=t,v=g=_=0;b<=o&&o<=p&&0<=q*(o-m)&&h===n[o];)_+=n[o],i===n[o]&&g++,u===n[o]&&v++,o-=q;if(i===n[o]&&n[y][1]--,a=n[o]-1,_++,n[o]=a,n[y][0]=(q<0?l-o:o+1)+(u?1:0),n[y][1]-=g,n[y][2]-=v,u===n[o]&&n[y][2]++,a<_){for(m=_%a,_=Q.floor(_/a);0<_--;)n[o+=q]=a,n[y][0]++,i===n[o]&&n[y][1]++,u===n[o]&&n[y][2]++;_=m}if(h<=_&&(n[o+=q]=_,_=0,n[y][0]++,i===n[o]&&n[y][1]++,u===n[o]&&n[y][2]++),0<_)return null;u&&(n[o+=q]=u)}else n=null;else if(r){if(i&&u&&i===u)return null;for(o=u?(h=u,t-q):(h=1,t),f=_=0;b<=o&&o<=p&&h===n[o];)_+=n[o],f++,o-=q;if(of,m=c+q,t-=q}else u?(h=u,a=2f+1||n[c+(f-1)*q]n.length||e.maxdimensionn.length||f=set[u+1])return!1;m[s]=1}o+=r}return o===t},succ:function(n,t,e,r,i){return null==e||null==n||e<=0?null:(i=-1===i?-1:1,function(n,t,e,r,i){var u,l,s,o,m,c,f;if(t<=0||null!=e&&(e<=0||tn[0]&&(e-t+un[0]){for(n[u]--,m[u]=m[u-1],l=u+1;l>>1,c=new Array(i),f=0;f>>1,p=new Array(t),x=0;x>>1==(e+1&3)>>>1?_-r:r+1;else{for(i=n(b),m=(o=(s=l=b*b)<<1)+l,e=x=r=0;r>>1,e=0;e=i&&(a=0,i<=++c&&(o+=i,a=c=0,r<=++f&&(m++,s+=i,a=c=o=f=0),m