diff --git a/README.md b/README.md index 6ffe85c..e5bc129 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A combinatorics library for Node/XPCOM/JS, PHP, Python, C/C++, Java (php/python/java/c implementations in progress) -**version 0.7.5** (~ 40kB minified, ~ 12kB zipped) +**version 0.7.5** (~ 39kB minified, ~ 12kB zipped) ![abacus combinatorial numbers](/abacus.jpg) diff --git a/src/js/Abacus.js b/src/js/Abacus.js index 7bf6786..93d7ab2 100644 --- a/src/js/Abacus.js +++ b/src/js/Abacus.js @@ -673,13 +673,14 @@ function binary2subset( item, n ) for(n=n-1,i=0; i<=n; i++) if ( 0 < item[i] ) subset.push(n-i); return subset; } -function conjugatepartition( partition, packed ) +function conjugatepartition( partition ) { if ( null == partition ) return null; // http://mathworld.wolfram.com/ConjugatePartition.html var l = partition.length, n, i, j, p, conjpartition; - if ( true === packed ) + if ( is_array(partition[0]) ) { + // packed representation p = partition[j]; conjpartition = [[p[1], p[0]]]; for(j=1; jdir?Arithmetic.J:Arithmetic.I), n, $) - ; + return klass.unrank(Arithmetic.add(index, 0>dir?Arithmetic.J:Arithmetic.I), n, $); } ,rand: function( n, $ ) { var klass = this, Arithmetic = Abacus.Arithmetic, N = Arithmetic.sub($ && $.count ? $.count : klass.count(n, $), Arithmetic.I), O = Arithmetic.O, index = Arithmetic.rnd(O, N); - return Arithmetic.equ(O, index) ? klass.initial(1, n, $) : (Arithmetic.equ(N, index) ? klass.initial(-1, n, $) : klass.unrank(index, n, $)); + return Arithmetic.equ(O, index) ? ( + klass.initial(1, n, $) + ) : (Arithmetic.equ(N, index) ? ( + klass.initial(-1, n, $) + ) : ( + klass.unrank(index, n, $) + )); } ,rank: NotImplemented ,unrank: NotImplemented @@ -1856,12 +1864,14 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ return self; } - ,base: function( ) { - return this.$.base || 0; + ,base: function( non_recursive ) { + var $ = this.$; + return $.sub && true!==non_recursive ? ($.subbase || $.base || 0) : ($.base || 0); } - ,dimension: function( ) { - return this.$.dimension || 0; + ,dimension: function( non_recursive ) { + var $ = this.$; + return $.sub && true!==non_recursive ? ($.subdimension || $.dimension || 0) : ($.dimension || 0); } ,total: function( non_recursive ) { @@ -2481,16 +2491,20 @@ Tensor = Abacus.Tensor = Class(CombinatorialIterator, { } else { - $.base = operate(function(m, k){return k > m ? k : m;}, 0, n); + var m_M = operate(function(m_M, k){ + if ( k < m_M[0] ) m_M[0] = k; + if ( k > m_M[1] ) m_M[1] = k; + return m_M; + }, [Infinity,0], n); + $.base = n; + $.minbase = m_M[0]; $.maxbase = m_M[1]; $.dimension = n.length; } CombinatorialIterator.call(self, "Tensor", n, $); } ,__static__: { - C: function( item, n ) { - return conjugation( item, n[1] ); - } + C: CombinatorialIterator.C ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T @@ -2508,16 +2522,7 @@ Tensor = Abacus.Tensor = Class(CombinatorialIterator, { return item; } ,cascade: CombinatorialIterator.cascade - ,dual: function( item, index, n, $ ) { - if ( null == item ) return null; - // some C-P-T processes at play here - var klass = this, order = $ && $.order ? $.order : 0, - C = $ && "tuple"===$.type ? klass.C : CombinatorialIterator.C, P = klass.P, T = klass.T; - if ( RANDOM & order ) return REFLECTED & order ? P( item, n ) : item.slice( ); - else if ( MINIMAL & order ) return REFLECTED & order ? P( item, n ) : item.slice( ); - else if ( COLEX & order ) return REFLECTED & order ? C( item, n ) : P( C( item, n ), n ); - else/*if ( LEX & order )*/return REFLECTED & order ? P( item, n ) : item.slice( ); - } + ,dual: CombinatorialIterator.dual ,succ: function( dir, item, index, n, $ ) { return next_tensor( item, n, dir, $ && $.type ? $.type : "tensor" ); } @@ -2620,7 +2625,10 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { // is based on random generation, instead of random unranking $.rand = {"multiset":1,"derangement":1,"involution":1}; if ( "multiset" === $.type ) + { $.multiplicity = is_array($.multiplicity) && $.multiplicity.length ? $.multiplicity.slice() : array(n, 1, 0); + $.base = $.multiplicity.length; + } CombinatorialIterator.call(self, "Permutation", n, $); } @@ -2686,19 +2694,7 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { return item; } ,cascade: CombinatorialIterator.cascade - ,dual: function( item, index, n, $ ) { - if ( null == item ) return null; - // some C-P-T processes at play here - var klass = this, type = $ && $.type ? $.type : "permutation", - order = $ && $.order ? $.order : 0, - nm = "multiset" === type ? $.multiplicity.length : n, - C = klass.C, P = klass.P, T = klass.T; - if ( RANDOM & order ) item = REFLECTED & order ? P( item, n ) : item.slice( ); - else if (MINIMAL & order ) item = REFLECTED & order ? P( item, n ) : item.slice( ); - else if ( COLEX & order ) item = REFLECTED & order ? C( item, nm ) : P( C( item, nm ), n ); - else/*if ( LEX & order )*/item = REFLECTED & order ? P( item, n ) : item.slice( ); - return item; - } + ,dual: CombinatorialIterator.dual ,succ: function( dir, item, index, n, $ ) { var type = $ && $.type ? $.type : "permutation"; if ( "involution" === type ) return null; @@ -2926,9 +2922,7 @@ Combination = Abacus.Combination = Class(CombinatorialIterator, { } ,__static__: { - C: function( item, n ) { - return conjugation( item, n[0] ); - } + C: CombinatorialIterator.C ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T @@ -3163,14 +3157,14 @@ Subset = Abacus.Powerset = Abacus.Subset = Class(CombinatorialIterator, { n = $.sub.base(); } $.base = n; - $.dimension = {from:0, to:n}; + $.dimension = n; + $.mindimension = 0; + $.maxdimension = n; CombinatorialIterator.call(self, "Subset", n, $); } ,__static__: { - C: function( item, n ) { - return difference( n, item ); - } + C: function( item, n ) { return difference( n, item ); } ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T @@ -3187,7 +3181,7 @@ Subset = Abacus.Powerset = Abacus.Subset = Class(CombinatorialIterator, { if ( null == item ) return null; // some C-P-T processes at play here var klass = this, order = $ && $.order ? $.order : 0, - C = klass.C, P = klass.P, T = klass.T; + C = klass.C, P = klass.P/*, T = klass.T*/; if ( RANDOM & order ) item = REFLECTED & order ? item.slice( ) : P( item, n ); else if ( MINIMAL & order ) item = REFLECTED & order ? item.slice( ) : P( item, n ); else if ( COLEX & order ) item = REFLECTED & order ? P( C( item, n ), n ) : C( item, n ); @@ -3258,14 +3252,14 @@ Partition = Abacus.Partition = Class(CombinatorialIterator, { var M = $["max="] ? $["max="]|0 : null, K = $["parts="] ? $["parts="]|0 : null, k1 = K ? K : (M ? n-M+1 : n), k0 = K ? K : (M ? stdMath.ceil(n/M) : 1); $.base = n; - $.dimension = "constant"===$["length"] ? (K||n) : (k1===k0 ? k0 : {from:stdMath.min(k0,k1), to:stdMath.max(k0,k1)}); + $.dimension = K || n; + $.mindimension = stdMath.min(k0,k1); + $.maxdimension = stdMath.max(k0,k1); CombinatorialIterator.call(self, "Partition", n, $); } ,__static__: { - C: function( item, n, packed ) { - return conjugatepartition( item, true===packed ); - } + C: function( item/*, n*/ ) { return conjugatepartition( item ); } ,P: CombinatorialIterator.P ,T: CombinatorialIterator.T @@ -3347,14 +3341,10 @@ Partition = Abacus.Partition = Class(CombinatorialIterator, { if ( null == item ) return null; var klass = this, order = $ && $.order ? $.order : 0, M = $ && $["max="] ? $["max="]|0 : null, - K = $ && $["parts="] ? $["parts="]|0 : null, - C = klass.C, P = klass.P, T = klass.T; + K = $ && $["parts="] ? $["parts="]|0 : null; if ( K && !M ) item = conjugatepartition(item); - if ( RANDOM & order ) item = REFLECTED & order ? P( item, n ) : item.slice( ); - else if ( MINIMAL & order ) item = REFLECTED & order ? P( item, n ) : item.slice( ); - else if ( COLEX & order ) item = REFLECTED & order ? P( C( item, n ), n ) : C( item, n ); - else/*if ( LEX & order )*/item = REFLECTED & order ? P( item, n ) : item.slice( ); if ( $ && "unpacked"===$.type ) item = unpackpartition(item); + item = CombinatorialIterator.dual.call(klass, item, index, n, $); if ( $ && "set"===$.type ) return partition2sets(item); if ( ($ && "constant"===$['length']) && (item.length < n) ) item = item.concat(array(n-item.length, 0, 0)); if ( $ && "packed"===$.type ) item = packpartition(item); diff --git a/src/js/Abacus.min.js b/src/js/Abacus.min.js index 8274dfc..5bd1bbb 100644 --- a/src/js/Abacus.min.js +++ b/src/js/Abacus.min.js @@ -5,5 +5,5 @@ * @version: 0.7.5 * https://github.com/foo123/Abacus **/ -!function(n,e,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?(n.$deps=n.$deps||{})&&(n.EXPORTED_SYMBOLS=[e])&&(n[e]=n.$deps[e]=t.call(n)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[e]=t.call(n)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(e,[],function(r){r(e,t.call(n))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(e)?define(e,["module"],function(e){return t.moduleUri=e.uri,t.call(n)}):e in n||(n[e]=t.call(n)||1)&&"function"==typeof define&&define.amd&&define(function(){return n[e]})}(this,"Abacus",function(n){"use strict";function e(){throw new Error("Method not implemented!")}function t(n){if(!arguments.length||null==n)return vn;if(sn(n)){var e,t=0,r=n.toUpperCase().split(","),i=r.length;for(e=0;i>e;e++)t|=un.call(nn.ORDER,r[e])?nn.ORDER[r[e]]:0;return t>0&&!(t&(An|yn))&&(t|=vn),t&yn&&(t&=~bn),t>0?t:vn}return n&yn&&(n&=~bn),wn&n?n:vn}function r(n,e,t){n=0|n;var r,i,u,l,o,a=n>0?new Array(n):[];if(n>0&&null!=e)if(i=15&n,r=1&i,e===+e){for(t=t||0,o=e,r&&(a[0]=o,o+=t),l=r;i>l;l+=2)u=l,a[u]=o,o+=t,u+=1,a[u]=o,o+=t;for(l=i;n>l;l+=16)u=l,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t}else if("function"==typeof e){for(r&&(a[0]=e(0)),l=r;i>l;l+=2)u=l,a[u]=e(u),u+=1,a[u]=e(u);for(l=i;n>l;l+=16)u=l,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u)}else{for(r&&(a[0]=e),l=r;i>l;l+=2)u=l,a[u]=e,u+=1,a[u]=e;for(l=i;n>l;l+=16)u=l,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e}return a}function i(n,e,t,r,i,u){var l,o,a=e;if(t&&an(t)){if(l=t.length,null==r&&(r=0),null==i&&(i=l-1),null==u&&(u=1),l>0)if(0>u)for(o=r;o>=i;o+=u)a=n(a,t[o],o);else for(o=r;i>=o;o+=u)a=n(a,t[o],o)}else if(u=u||1,l=(i-r)/u+1,l>0)if(0>u)for(o=r;o>=i;o+=u)a=n(a,o,o);else for(o=r;i>=o;o+=u)a=n(a,o,o);return a}function u(){var n,e,t,r,i,u,l,o,a,s,c=arguments,f=c.length;if(!f)return[];if(!0===c[0]){for(a=c[1].length,n=2;f>n;n++)a*=c[n].length;for(s=new Array(a),n=0;a>n;n++){for(o=0,u=1,t=n,e=1;f>e;e++)r=c[e].length,i=t%r,t=~~(t/r),l=c[e][i],o+=u*l,u*=r;s[n]=o}}else{for(a=c[0].length,n=1;f>n;n++)a*=c[n].length;for(s=new Array(a),n=0;a>n;n++){for(o=[],t=n,e=f-1;e>=0;e--)if(r=c[e].length,i=t%r,t=~~(t/r),l=c[e][i],an(l))for(u=l.length-1;u>=0;u--)o.unshift(l[u]);else o.unshift(l);s[n]=o}}return s}function l(n){return i(nn.Arithmetic.add,nn.Arithmetic.O,n)}function o(n){return i(nn.Arithmetic.mul,nn.Arithmetic.I,n)}function a(n){var e=nn.Arithmetic;return e.shl(e.I,e.N(n))}function s(n,e){var t=nn.Arithmetic,r=t.N;return t.pow(r(n),r(e))}function c(n,e){var t,r,u,l=nn.Arithmetic,o=l.O,a=l.I,s=l.J,f=l.N,d=l.add,_=(l.sub,l.div),m=l.mul;if(null==e)return 4>n?0>n?o:2>n?a:l.shl(f(n),n-2):(u=String(n),null==c.mem1[u]&&(c.mem1[u]=i(m,a,null,2,n)),c.mem1[u]);if(!1===e)return 3>n?2===n?a:o:(u=String(n),null==c.mem2[u]&&(c.mem2[u]=i(function(n,e){return d(1&e?s:a,m(n,e))},a,null,3,n)),c.mem2[u]);if(an(e)){if(!e.length)return 0>n?o:c(n);if(0>n)return o;if(u=String(n)+"@"+e.join(","),null==c.mem3[u]){for(t=c(e[e.length-1]),r=e.length-2;r>=0;r--)t=m(t,c(e[r]));c.mem3[u]=_(c(n),t)}return c.mem3[u]}return e===+e?0>e?-e>n?o:(u=String(n)+"@"+String(e),null==c.mem3[u]&&(c.mem3[u]=i(m,a,null,n+e+1,n)),c.mem3[u]):(e+e>n&&(e=n-e),0>e||1>n?o:0===e||1===n?a:1===e?f(n):(u=String(n)+"@"+String(e),null==c.mem3[u]&&(c.mem3[u]=_(c(n,-e),c(e))),c.mem3[u])):o}function f(n,e,t){var r,i,u,l,o=nn.Arithmetic,a=o.add,s=o.O;if(t===n&&1===e||e===n&&1===t)return o.I;if(t+e>n+1||n>e*t)return s;if(r=String(n)+","+String(e)+","+String(t),null==f.mem[r]){for(l=cn.max(1,cn.ceil((n-t)/(e-1))),u=cn.min(t,n-t-e+2),i=l;u>=i;i++)s=a(s,f(n-t,e-1,i));f.mem[r]=s}return f.mem[r]}function d(n,e){if(null==n)return null;if(!n.length)return[];var t,r=n.length,i=new Array(r);if(an(e))for(t=0;r>t;t++)i[t]=e[t]-1-n[t];else if(0>e)for(t=0;r>t;t++)i[t]=r-1-n[t];else for(e-=1,t=0;r>t;t++)i[t]=e-n[t];return i}function _(n){if(null==n)return null;for(var e=n.length-1,t=new Array(e+1),r=0;e>=r;r++)t[r]=n[e-r];return t}function m(n,e){if(null==e&&(e=0),an(n)){for(var t=n.length,r=new Array(t),i=0;t>i;i++)r[i]=e-n[i];return r}return n===+n&&e===+e?e-n:nn.Arithmetic.sub(nn.Arithmetic.N(e),n)}function h(n,e,t,r,i,u,l){null==t&&(t=0),null==r&&(r=n.length-1),null==i&&(i=0),null==u&&(u=e.length-1);var o=t>r?-1:1,a=i>u?-1:1,s=o*(r-t)+1,c=a*(u-i)+1,f=t,d=i,_=0;if(null===l&&(l=new Array(cn.min(s,c))),0===l.length)return l;for(;o*(r-f)>=0&&a*(u-d)>=0;)n[f]e[d]?d+=a:(l[_++]=n[f],f+=o,d+=a);return _i?-1:1,s=u>l?-1:1,c=a*(i-t)+1,f=t,d=t,_=0;if(!e||!e.length)return n===+n?r(n,t,a):n?n.slice():n;if(null==o&&(o=new Array(c)),n===+n){for(;a*(i-f)>=0&&s*(l-d)>=0;)f===e[d]?(f+=a,d+=a):f>e[d]?d+=s:(o[_++]=f,f+=a);for(;a*(i-f)>=0;)o[_++]=f,f+=a}else{for(;a*(i-f)>=0&&s*(l-d)>=0;)n[f]===e[d]?(f+=a,d+=a):n[f]>e[d]?d+=s:(o[_++]=n[f],f+=a);for(;a*(i-f)>=0;)o[_++]=n[f],f+=a}return _r?-1:1,f=i>u?-1:1,d=c*(r-t)+1,_=f*(u-i)+1,m=d+_,h=t,b=i,p=0,v=!l;if(null==a&&(a=new Array(m)),0===a.length)return!0===o?n:a;for(;c*(r-h)>=0&&f*(u-b)>=0;){if(l&&p){if(n[h]===s){h+=c;continue}if(e[b]===s){b+=f;continue}}n[h]e[b]?(a[p++]=s=e[b],b+=f):(a[p++]=s=n[h],v&&(a[p++]=e[b]),h+=c,b+=f)}for(;c*(r-h)>=0;)(v||n[h]!==s)&&(a[p++]=s=n[h]),h+=c;for(;f*(u-b)>=0;)(v||e[b]!==s)&&(a[p++]=s=e[b]),b+=f;if(!0===o){for(h=t,p=0;m>p;p++,h+=c)n[h]=a[p];return n}return pt?-1:1,i=r*(t-e)+1;if(1>=i)return n;for(var u,l,o=i,a=1,s=2,c=cn.min,f=new Array(i);o;){for(l=i-a,u=0;l>u;u+=s)p(n,n,e+r*u,e+r*(u+a-1),e+r*(u+a),e+r*c(u+s-1,i-1),!1,!0,f);a<<=1,s<<=1,o>>=1}return n}function g(n,e,t,r){var i,u,l,o,a=nn.Math.rndInt,s=!0===e?1:0;if(an(t))for(o=t,i=o.length;sa;a++)o[a]=n[u+f(0,d)];return t&&v(o),o}for(a=0;e>a;a++)s=f(0,--d),c=n[u+s],n[u+s]=n[u+d],n[u+d]=c,o[a]=c,i&&(i[a]=s);if(i)for(a=e-1;a>=0;a--)s=i[a],c=n[u+d],n[u+d]=n[u+s],n[u+s]=c,d++;return t&&v(o),o}function y(n,e){if(0>e)return[];var t,i=r(e,0,0),u=n.length;for(e-=1,t=0;u>t;t++)i[e-n[t]]=1;return i}function A(n,e){e=cn.min(e||n.length,n.length);var t,r=[];for(e-=1,t=0;e>=t;t++)0u;u++)l=n[u],l[1]===o[u-1][0]?o[u-1][1]+=l[0]:o.push([l[1],l[0]]);else for(t=n[0],o=r(t,1,0),u=1;a>u;u++)for(i=0,l=n[u];t>i&&l>0;)o[i++]++,l--;return o}function M(n){if(null==n)return null;var e,t=[],r=n.length,i=n[0],u=[i,1];for(e=1;r>e;e++)i===n[e]?u[1]++:(t.push(u),i=n[e],u=[i,1]);return t.push(u),t}function I(n){if(null==n)return null;var e,t,r,i,u,l=[],o=n.length;for(e=0;o>e;e++)if(u=n[e],1===u[1])l.push(u[0]);else for(r=u[1],i=u[0],t=0;r>t;t++)l.push(i);return l}function C(n){if(null==n)return null;var e=0;return r(n.length,function(t){var i=n[t],u=r(i,e,1);return e+=i,u})}function O(n){return null==n?null:r(n.length,function(e){return n[e].length})}function E(n,e,t){e=e||n.length;var r,i,u,l,o,a=n.length,s=new Array(a),c=nn.Math.ceil(fn(e)),f=(1<<1+c)-1,d=new Array(f),_=1<r;r++)d[r]=0;for(i=m,r=0;a>r;r++,i+=h){for(o=n[r],l=_+o,u=0;c>u;u++)1&l&&(o-=d[l>>>1<<1]),d[l]+=1,l>>>=1;d[l]+=1,s[i]=o}return s}function R(n,e,t){e=e||n.length;var r,i,u,l,o,a,s,c,f,d,_=n.length,m=new Array(_),h=-1===t?_-1:0,b=-1===t?-1:1;for(s=nn.Math.ceil(fn(e)),c=(1<<1+s)-1,f=new Array(c),d=1<=r;r++)for(u=1,l=1<=u;u++)f[l-1+u]=1<r;r++,i+=b){for(o=n[r],a=1,u=0;s>u;u++)f[a]-=1,a<<=1,o>=f[a]&&(o-=f[a],a++);f[a]=0,m[i]=a-d}return m}function k(n,e,t){var r,i=n.length,u=null==e;if(i>1)for(u&&(e=new Array(i-1),t=0),r=i-1;r>=1;r--)e[t++]=[n[0],n[r]];else u&&(e=[]);return u?e:t}function S(n,e){var t,r,i,u,l=n.length,o=new Array(l),a=!0===e?1:0,s=new Array(l),c=0,f=0;for(t=0;l>t;t++)s[t]=0;for(i=new Array(l),u=0,r=c++,i[u++]=r,s[r]=1;l>c;){if(r=n[r],s[r])for(u>a&&(i.length=u,o[f++]=i),i=new Array(l),u=0;l>c&&s[r=c];)++c;s[r]||(i[u++]=r,s[r]=1)}return u>a&&(i.length=u,o[f++]=i),fe;e++)u=k(l[e],i,u);return ut;t++)l[t]=t;for(t=0;u>t;t++)swap=r[t],i=l[r[0]],l[r[0]]=l[r[1]],l[r[1]]=i;return l}function L(n,e){var t,r,i=n.length,u=i*i,l=new Array(u);for(t=0,r=0;u>t;)l[t+r]=0,++r>=i&&(r=0,t+=i);if(!0===e)for(t=0;i>t;t++)l[i*n[t]+t]=1;else for(t=0,r=0;i>r;r++,t+=i)l[t+n[t]]=1;return l}function T(n,e){var t,r,i=n.length,u=cn.floor(cn.sqrt(i)),l=new Array(u);if(!0===e)for(t=0,r=0;u>t;)n[u*t+r]&&(l[r]=t),++r>=u&&(r=0,t++);else for(t=0,r=0;u>t;)n[t+r]&&(l[t]=r),++r>=u&&(r=0,t++);return l}function N(n){var e,t=n.length,r=new Array(t);for(e=0;t>e;e++)r[n[e]]=e;return r}function j(n){var e,t,r,i=n,u=i.length,l=u?i[0]:[],o=l.length;for(t=1;u>t;t++)for(r=l.slice(),e=0;o>e;e++)l[e]=r[i[t][e]];return l}function q(n){var e,t,r,i,u,l,o=n,a=o.length,s=0;for(r=0;a>r;r++)s+=o[r].length;for(e=new Array(s),i=0,r=0;a>r;r++){for(u=o[r],l=u.length,t=0;l>t;t++)e[i+t]=i+u[t];i+=l}return e}function X(n,e){if(e=e||n.length,e!==n.length)return!1;var t,r,i=new Array(e);for(t=0;e>t;t++)i[t]=0;for(t=0;e>t;t++){if(r=n[t],0>r||r>=e||0!==i[r])return!1;i[r]++}for(t=0;e>t;t++)if(1!==i[t])return!1;return!0}function D(n){for(var e=n.length,t=0;e>t;t++)if(n[t]!==t)return!1;return!0}function V(n){for(var e=n.length,t=1,r=n[0];e>t;t++)if(n[t]!==(r+t)%e)return!1;return!0}function J(n,e){e=e||1;var t,r=new Array(e+1);for(t=0;e>=t;t++)r[t]=n;return D(j(r))}function G(n,e,t){e=0|e;for(var r=0,i=n.length,u=0;i>u;u++)if(n[u]===u&&r++,r>e)return!1;return!0===t?r===e:!0}function H(n,e,t,r){if(n){var i,u,l,o=e,a=o.length;if(0>t)if("tuple"===r){for(i=o[0],o=o[1],u=i-1;u>=0&&n[u]<1;)u--;if(u>=0)for(n[u]--,o-=1,l=u+1;i>l;l++)n[l]=o;else n=null}else{for(u=a-1;u>=0&&n[u]<1;)u--;if(u>=0)for(n[u]--,l=u+1;a>l;l++)n[l]=o[l]-1;else n=null}else if("tuple"===r){for(i=o[0],o=o[1],u=i-1;u>=0&&n[u]+1===o;)u--;if(u>=0)for(n[u]++,l=u+1;i>l;l++)n[l]=0;else n=null}else{for(u=a-1;u>=0&&n[u]+1===o[u];)u--;if(u>=0)for(n[u]++,l=u+1;a>l;l++)n[l]=0;else n=null}return n}return null}function F(n,e,t,r){if(n){var i,u,l,o,a,s,c=e;if(0>t)if("cyclic"===r)n=n[0]>0?[n[c-1]].concat(n.slice(0,-1)):null;else do{for(s=!1,i=c-2;i>=0&&n[i]<=n[i+1];)i--;if(i>=0){for(u=c-1;u>i&&n[i]<=n[u];)u--;for(a=n[i],n[i]=n[u],n[u]=a,l=i+1,o=c-1;o>l;)a=n[l],n[l]=n[o],n[o]=a,s=s||l===n[l]||o===n[o],l++,o--;if(s=s||i===n[i]||o===n[o],"derangement"===r){if(!s)for(l=i-1;l>=0;l--)if(l===n[l]){s=!0;break}}else s=!1}else n=null}while(n&&s);else if("cyclic"===r)n=n[0]+1=0&&n[i]>=n[i+1];)i--;if(i>=0){for(u=c-1;u>i&&n[i]>=n[u];)u--;for(a=n[i],n[i]=n[u],n[u]=a,l=i+1,o=c-1;o>l;)a=n[l],n[l]=n[o],n[o]=a,s=s||l===n[l]||o===n[o],l++,o--;if(s=s||i===n[i]||o===n[o],"derangement"===r){if(!s)for(l=i-1;l>=0;l--)if(l===n[l]){s=!0;break}}else s=!1}else n=null}while(n&&s);return n}return null}function U(n,e,t,r){if(n){var i,u,l,o,a,s,c,f=e[1],d=e[0];if(0>t)if("ordered+repeated"===r){for(u=f-1;u>=0&&n[u]<1;)u--;if(u>=0)for(n[u]--,d-=1,l=u+1;f>l;l++)n[l]=d;else n=null}else if("ordered"===r){for(i={},u=0;f>u;u++)i[n[u]]=u;for(u=f-1,o=-1;-1===o&&u>=0;){if(n[u]-1>=0)for(l=n[u]-1;l>=0;l--)if(null==i[l]){o=u,i[l]=o;break}i[n[u]]=null,u--}if(o>-1)for(n[o]=l,l=d-1,u=o+1;f>u;u++){for(;l>=0&&null!=i[l];)l--;n[u]=l,i[l]=u}else n=null}else{for(c="repeated"===r?0:1,u=f-1,o=-1;u>0;){if(n[u]>n[u-1]+c){o=u;break}u--}if(-1===o&&0-1){for(s=d-1+c,u=f-1;u>o;u--)s-=c,n[u]=s;n[o]--}else n=null}else if("ordered+repeated"===r){for(u=f-1;u>=0&&n[u]+1===d;)u--;if(u>=0)for(n[u]++,l=u+1;f>l;l++)n[l]=0;else n=null}else if("ordered"===r){for(i={},u=0;f>u;u++)i[n[u]]=u;for(u=f-1,o=-1;-1===o&&u>=0;){if(n[u]+1l;l++)if(null==i[l]){o=u,i[l]=o;break}i[n[u]]=null,u--}if(o>-1)for(n[o]=l,l=0,u=o+1;f>u;u++){for(;d>l&&null!=i[l];)l++;n[u]=l,i[l]=u}else n=null}else{if(u=f-1,o=-1,"repeated"===r)for(c=0;u>=0;){if(n[u]+1=0;){if(n[u]-1)for(s=n[o]+1-c,u=o;f>u;u++)s+=c,n[u]=s;else n=null}return n}return null}function B(n,e,t,i,u){if(i&&u)return null;if(n){var l,o,a,s,c,f,d=e;if(0>t)if(i&&(u=i,i=null),o=u?1:0,n.length>o&&n[o]>1){for(l=n.length-1,f=0;l>=o&&1===n[l];)f+=n[l],l--;c=n[l]-1,f++,n[l]=c,n=n.slice(0,l+1),f>c?n=n.concat(r(cn.floor(f/c),c),(f%=c)?[f]:[]):f>0&&(n=n.concat([f]))}else n=null;else if(i&&(u=i,i=null),o=u?1:0,a=u?n.length-1:0,c=u?d%u||u:d,n.length>o&&n[a]1?(l=s-2,f=n[s-1]):(l=s-1,f=0);l>o&&n[l]===n[l-1];)f+=n[l],l--;n[l]++,f--,n=f>0?n.slice(0,l+1).concat(r(f,1)):n.slice(0,l+1)}else n=null;return n}return null}var Y,z,K,Q,W,Z,nn={VERSION:"0.7.5"},en="prototype",tn="constructor",rn=Array.prototype.slice,un=Object[en].hasOwnProperty,ln=Object[en].toString,on=/^\s+|\s+$/g,an=(String.prototype.trim?function(n){return n.trim()}:function(n){return n.replace(on,"")},function(n){return n instanceof Array||"[object Array]"===ln.call(n)}),sn=function(n){return n instanceof String||"[object String]"===ln.call(n)},cn=Math,fn=cn.log2||function(n){return cn.log(n)/cn.LN2},dn=function(n){var e=n.toString(2),t=32-e.length;return t>0?new Array(t+1).join("0")+e:e},_n=Object.create,mn=function(n,e){for(var t in e)un.call(e,t)&&(n[t]=e[t]);return n},hn=function(n,e){1===arguments.length&&(e=n,n=Object);var t=e[tn];return un.call(e,"__static__")&&(t=mn(t,e.__static__),delete e.__static__),t[en]=mn(_n(n[en]),e),t},bn=1,pn=2,vn=4,gn=8,xn=16,yn=32,An=vn|gn|xn,wn=An|yn|bn|pn;return c.mem1={},c.mem2={},c.mem3={},f.mem={},nn.$={MAXMEM:1e6,RANDOM:"index"},nn.ORDER={LEX:vn,LEXICOGRAPHIC:vn,REVLEX:vn|bn,ANTILEX:vn|bn,REVERSELEXICOGRAPHIC:vn|bn,ANTILEXICOGRAPHIC:vn|bn,REFLEX:vn|pn,REFLECTEDLEXICOGRAPHIC:vn|pn,COLEX:gn,COLEXICOGRAPHIC:gn,REVCOLEX:gn|bn,ANTICOLEX:gn|bn,REVERSECOLEXICOGRAPHIC:gn|bn,ANTICOLEXICOGRAPHIC:gn|bn,REFCOLEX:gn|pn,REFLECTEDCOLEXICOGRAPHIC:gn|pn,REV:bn,REVERSE:bn,REVERSED:bn,REF:pn,REFLECT:pn,REFLECTED:pn,RANDOM:yn,GRAY:xn,MINIMAL:xn},nn.Util={array:r,operate:i,intersect:h,difference:b,merge:p,conjugation:d,parity:_,inversion:m,mergesort:v,shuffle:g,pick:x},nn.Math={O:0,I:1,J:-1,N:function(n){return nn.Arithmetic.add(nn.Arithmetic.O,n)},V:function(n){return nn.Arithmetic.sub(nn.Arithmetic.O,n)},rnd:cn.random,rndInt:function(n,e){return nn.Math.round((e-n)*nn.Math.rnd()+n)},equ:function(n,e){return n===e},gte:function(n,e){return n>=e},lte:function(n,e){return e>=n},gt:function(n,e){return n>e},lt:function(n,e){return e>n},inside:function(n,e,t,r){return r?n>=e&&t>=n:n>e&&t>n},clamp:function(n,e,t){return e>n?e:n>t?t:n},wrap:function(n,e,t){return e>n?t:n>t?e:n},wrapR:function(n,e){return 0>n?n+e:n},add:function(n,e){return n+e},sub:function(n,e){return n-e},mul:function(n,e){return n*e},div:function(n,e){return nn.Math.floor(n/e)},mod:function(n,e){return n%e},pow:cn.pow,shl:function(n,e){return n<>e},bor:function(n,e){return n|e},band:function(n,e){return n&e},xor:function(n,e){return n^e},abs:cn.abs,min:cn.min,max:cn.max,floor:cn.floor,ceil:cn.ceil,round:cn.round,num:function(n){return"number"==typeof n?nn.Math.floor(n):parseInt(n,10)},val:function(n){return nn.Math.floor(n.valueOf())},sum:l,product:o,pow2:a,exp:s,factorial:c,partitions:f},nn.Arithmetic={O:0,I:1,J:-1,N:nn.Math.N,V:nn.Math.V,equ:nn.Math.equ,gte:nn.Math.gte,lte:nn.Math.lte,gt:nn.Math.gt,lt:nn.Math.lt,inside:nn.Math.inside,clamp:nn.Math.clamp,wrap:nn.Math.wrap,wrapR:nn.Math.wrapR,add:nn.Math.add,sub:nn.Math.sub,mul:nn.Math.mul,div:nn.Math.div,mod:nn.Math.mod,pow:nn.Math.pow,shl:nn.Math.shl,shr:nn.Math.shr,bor:nn.Math.bor,band:nn.Math.band,xor:nn.Math.xor,abs:nn.Math.abs,min:nn.Math.min,max:nn.Math.max,floor:nn.Math.floor,ceil:nn.Math.ceil,round:nn.Math.round,rnd:nn.Math.rndInt,num:nn.Math.num,val:nn.Math.val},nn.Class=hn,nn.BitArray=hn({constructor:function Mn(n){var e=this;return e instanceof Mn?(e.length=n,void(e.bits=new Uint32Array(nn.Math.ceil(n/32)))):new Mn(n)},length:0,bits:null,dispose:function(){var n=this;return n.length=null,n.bits=null,n},clone:function(){var n=this,e=new nn.BitArray(n.length);return e.bits=new Uint32Array(n.bits),e},fromArray:function(n){var e=this;return e.bits=new Uint32Array(n),e},toArray:function(){return rn.call(this.bits)},toString:function(){var n,e,t=this.toArray();for(n=0,e=t.length;e>n;n++)t[n]=dn(t[n]);return t.join("")},reset:function(){var n,e=this,t=e.bits,r=t.length;for(n=0;r>n;n++)t[n]=0;return e},isset:function(n){return!!(this.bits[n>>>5]&1<<(31&n))},set:function(n){var e=this;return e.bits[n>>>5]|=1<<(31&n),e},unset:function(n){var e=this;return e.bits[n>>>5]&=~(1<<(31&n)),e},toggle:function(n){var e=this;return e.bits[n>>>5]^=1<<(31&n),e}}),Y=nn.CombinatorialIterator=hn({constructor:function In(n,e,t){var r=this,i=r[tn];r.name=n||"CombinatorialIterator",r.n=e||0,r.$=t=t||{},t.type=String(t.type||"default").toLowerCase(),t.order=t.order||vn,t.base=t.base||0,t.dimension=t.dimension||0,t.rand=t.rand||{},t.count=i.count(r.n,r.$),t.sub instanceof In&&(t.subcount=nn.Arithmetic.mul(t.count,t.sub.total()),t.submethod=String(t.submethod||"project").toLowerCase(),t.subcascade=-1===t.subcascade?-1:1,"concatenate"===t.submethod?t.dimension=t.dimension+t.sub.dimension():"compose"===t.submethod&&(t.dimension=t.dimension*t.sub.dimension())),r.order(t.order)},__static__:{Iterable:function Cn(n,e){var t=this;return t instanceof Cn?(e=-1===e?-1:1,void(t.next=function(){return n.hasNext(e)?{value:n.next(e)}:{done:!0}})):new Cn(n)},C:function(n,e){return d(n,e)},P:function(n,e){return _(n)},T:function(n,e){return m(n,e)},count:e,initial:e,cascade:function(n,e,t,i){if(-1===i){var l=n;n=e,e=l}return"concatenate"===t?n&&e?n.concat(e):n||e||null:"compose"===t?n&&e?u(!0,n,e):n||e||null:null==n||null==e?null:r(n.length,function(t){return n[t]n?l.J:l.I),r,i)},rand:function(n,e){var t=this,r=nn.Arithmetic,i=r.sub(e&&e.count?e.count:t.count(n,e),r.I),u=r.O,l=r.rnd(u,i);return r.equ(u,l)?t.initial(1,n,e):r.equ(i,l)?t.initial(-1,n,e):t.unrank(l,n,e)},rank:e,unrank:e},name:"CombinatorialIterator",n:0,$:null,__index:null,_index:null,__item:null,_item:null,__subindex:null,_subindex:null,__subitem:null,_subitem:null,_prev:null,_next:null,_traversed:null,dispose:function(n){var e=this;return!0!==n&&e.$.sub&&(e.$.sub.dispose(),e.$.sub=null),e.name=null,e.n=null,e.$=null,e.__index=null,e._index=null,e.__item=null,e._item=null,e.__subindex=null,e._subindex=null,e.__subitem=null,e._subitem=null,e._prev=null,e._next=null,e._traversed&&(e._traversed.dispose(),e._traversed=null),e},base:function(){return this.$.base||0},dimension:function(){return this.$.dimension||0},total:function(n){var e=this.$;return e.sub&&!0!==n?e.subcount||e.count||0:e.count||0},_init:function(n,e){var t,r,i,u=this,l=u[tn],o=u.$,a=u.n,s=nn.Arithmetic,c=s.O,f=s.I,d=o.order;return u.__index=u._index=c,u._item=u.__item=null,u._prev=!1,u._next=!1,r=o.count,i=s.sub(r,f),yn&d?"gen"===nn.$.RANDOM||1===o.rand[o.type]||s.gt(r,nn.$.MAXMEM)?(u.__item=l.rand(a,o),u.__index=null):(u._traversed&&u._traversed.dispose(),u._traversed=new nn.BitArray(s.val(r)),t=u.random("index"),u._traversed.set(+t),u.__item=l.unrank(t,a,o),null!=u.__item&&(u.__index=t)):gn&d?(u.__item=l.initial(-n,a,o),null!=u.__item&&(u.__index=-1===n?c:i)):(u.__item=l.initial(n,a,o),null!=u.__item&&(u.__index=-1===n?i:c)),u._item=null==u.__item?null:l.dual(u.__item,u.__index,a,o),u._index=!e||yn&d?c:i,null===u.__index&&(u.__index=c),u._prev=yn&d||!e?!1:null!=u.__item,u._next=!e||yn&d?null!=u.__item:!1,u},order:function(n,e){if(!arguments.length)return this._order;var r,i,u,l,o,a=this,s=a[tn],c=nn.Arithmetic,f=(c.O,c.I,!0===n);return e=-1===e,u=a.n,l=a.$,a._traversed&&(a._traversed.dispose(),a._traversed=null),f?n=l.order:sn(n)&&-1<(i=n.indexOf("|"))?(r=n.substr(i+1),n=t(n.substr(0,i))):r=n=t(n),o=bn&n?-1:1,o=e?-o:o,l.order=n,l.sub?(f?l.sub.rewind(e?-1:1):l.sub.order(r,e?-1:1),a.__subindex=l.sub.index(),a.__subitem=l.sub.next(e?-1:1),a._subindex=null,a._subitem=null):(a.__subindex=null,a.__subitem=null,a._subindex=null,a._subitem=null),a._init(o,e),l.sub&&(a._prev=a._prev&&null!=a.__subitem,a._next=a._next&&null!=a.__subitem,a._subindex=c.add(c.mul(a._index,l.sub.total()),a.__subindex),a._subitem=s.cascade(a._item,a.__subitem,l.submethod,l.subcascade)),a},index:function(n,e){if(e=!0===e,!arguments.length)return this.$.sub?this._subindex:this._index;var t,r=this,i=r[tn],u=nn.Arithmetic,l=u.O,o=u.I,a=u.J,s=r.n,c=r.$,f=c.sub&&!e?c.subcount:c.count,d=c.sub&&!e?r._subindex:r._index,_=c.order,m=bn&_?-1:1;return n=u.wrapR(u.N(n),f),!u.equ(n,d)&&u.inside(n,a,f)&&(c.sub&&!e&&(c.sub.index(u.mod(n,c.sub.total())),r.__subindex=c.sub.index(),r.__subitem=c.sub.item(),n=u.div(n,c.sub.total()),f=c.count),t=u.sub(f,o),gn&_?(r.__index=-1===m?n:u.sub(t,n),r._index=n,r.__item=u.equ(l,n)?i.initial(-m,s,c):u.equ(t,n)?i.initial(m,s,c):i.unrank(r.__index,s,c),r._item=i.dual(r.__item,r.__index,s,c),r._prev=null!=r.__item,r._next=null!=r.__item):yn&_||(r.__index=-1===m?u.sub(t,n):n,r._index=n,r.__item=u.equ(l,n)?i.initial(m,s,c):u.equ(t,n)?i.initial(-m,s,c):i.unrank(r.__index,s,c),r._item=i.dual(r.__item,r.__index,s,c),r._prev=null!=r.__item,r._next=null!=r.__item),c.sub&&(r._prev=r._prev&&null!=r.__subitem,r._next=r._next&&null!=r.__subitem,r._subindex=u.add(u.mul(r._index,c.sub.total()),r.__subindex),r._subitem=i.cascade(r._item,r.__subitem,c.submethod,c.subcascade))),r},item:function(n,e){if(!arguments.length)return this.$.sub?this._subitem:this._item;var r,i,u,l,o,a,s,c=this,f=c[tn],d=c.n,_=c.$,m=_.sub?_.subcount:_.count,h=_.sub?c._subindex:c._index,b=nn.Arithmetic,p=b.O,v=b.I,g=b.J,x=null;return sn(e)?-1<(s=e.indexOf("|"))?(x=e.substr(s+1),e=t(e.substr(0,s))):x=e=t(e):null!=e?x=e=t(e):(e=_.order,x=null),_.sub||(x=null),an(n)?(m=_.count,u=bn&e?-1:1,r=b.sub(m,v),c.__item=n.slice(),c.__index=f.rank(c.__item,d,_),yn&e?(c._index=c.__index,l=_.order,_.order=e,c._item=f.dual(c.__item,c.__index,d,_),_.order=l):gn&e?(c._index=-1===u?c.__index:b.sub(r,c.__index),l=_.order,_.order=e,c._item=f.dual(c.__item,c.__index,d,_),_.order=l):(c._index=-1===u?b.sub(r,c.__index):c.__index,l=_.order,_.order=e,c._item=f.dual(c.__item,c.__index,d,_),_.order=l),c):(n=b.wrapR(b.N(n),m),e===_.order&&null===x&&b.equ(n,h)?_.sub?c._subitem:c._item:b.inside(n,g,m)?(a=null,_.sub&&(a=_.sub.item(b.mod(n,_.sub.total()),x),n=b.div(n,_.sub.total()),m=_.count),u=bn&e?-1:1,r=b.sub(m,v),yn&e?(i=null,l=_.order,_.order=e,o=f.dual(f.rand(d,_),i,d,_),_.order=l,_.sub&&(o=f.cascade(o,a,_.submethod,_.subcascade)),o):gn&e?(i=-1===u?n:b.sub(r,n),l=_.order,_.order=e,o=f.dual(b.equ(p,n)?f.initial(-u,d,_):b.equ(r,n)?f.initial(u,d,_):f.unrank(i,d,_),i,d,_),_.order=l,_.sub&&(o=f.cascade(o,a,_.submethod,_.subcascade)),o):(i=-1===u?b.sub(r,n):n,l=_.order,_.order=e,o=f.dual(b.equ(p,n)?f.initial(u,d,_):b.equ(r,n)?f.initial(-u,d,_):f.unrank(i,d,_),i,d,_),_.order=l,_.sub&&(o=f.cascade(o,a,_.submethod,_.subcascade)),o)):null)},random:function(n,e,t,r){var i,u=this,l=u[tn],o=u.$,a=o.order;if(r=!0===r,"index"===n){var s,c=nn.Arithmetic,f=c.N,d=c.O,_=c.I;return e===!!e&&(r=e,e=null,t=null),s=o.sub&&!r?o.subcount:o.count,null==e&&null==t?(e=d,t=c.sub(s,_)):null==t?(e=f(e||0),t=c.sub(s,_)):(e=f(e),t=f(t)),c.rnd(e,t)}return o.order|=yn,i=l.rand(u.n,o),o.order=a,i=l.dual(i,null,u.n,o),o.sub&&!r?l.cascade(i,o.sub.random(),o.submethod,o.subcascade):i},rewind:function(n){var e=this;return e.order(!0,-1===n?-1:1)},hasNext:function(n){var e=this;return-1===n?yn&e.$.order?!1:e._prev:e._next},next:function(n){var e,t,r,i,u,l=this,o=l[tn],a=nn.Arithmetic,s=a.O,c=a.I,f=a.J,d=l.n,_=l.$,m=_.order,h=_.count,b=_.sub?l._subitem:l._item;if(r=-1===n,n=bn&m?-1:1,r)return yn&m?null:(gn&m?(l.__item=o.succ(n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,0>n?f:c))):(l.__item=o.succ(-n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,n>0?f:c))),l._prev=null!=l.__item,l._prev?l._index=a.sub(l._index,c):_.sub&&_.sub.hasNext(-1)?(l.__subindex=_.sub.index(),l.__subitem=_.sub.next(-1),l._init(-n,r)):(l.__subindex=null,l.__subitem=null),l._item=null==l.__item?null:o.dual(l.__item,l.__index,d,_),_.sub&&(l._prev=l._prev&&null!=l.__subitem,l._subindex=l._prev?a.add(a.mul(l._index,_.sub.total()),l.__subindex):null,l._subitem=l._prev?o.cascade(l._item,l.__subitem,_.submethod,_.subcascade):null),b);if(yn&m)if(i=a.sub(h,c),a.lt(l._index,i))if(e=l._traversed){for(t=l.random("index"),u=nn.Math.rnd()>.5?f:c;e.isset(+t);)t=a.wrap(a.add(t,u),s,i);e.set(+t),l.__item=o.unrank(t,d,_),null!=l.__item&&(l.__index=t)}else l.__item=o.rand(d,_),l.__index=null;else l._item=l.__item=null,l._traversed&&(l._traversed.dispose(),l._traversed=null);else gn&m?(l.__item=o.succ(-n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,n>0?f:c))):(l.__item=o.succ(n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,0>n?f:c)));return l._next=null!=l.__item,l._next?(l._index=a.add(l._index,c),null===l.__index&&(l.__index=l._index)):_.sub&&_.sub.hasNext()?(l.__subindex=_.sub.index(),l.__subitem=_.sub.next(),l._init(n,r)):(l.__subindex=null,l.__subitem=null),l._item=null==l.__item?null:o.dual(l.__item,l.__index,d,_),_.sub&&(l._next=l._next&&null!=l.__subitem,l._subindex=l._next?a.add(a.mul(l._index,_.sub.total()),l.__subindex):null,l._subitem=l._next?o.cascade(l._item,l.__subitem,_.submethod,_.subcascade):null),b},range:function(n,e){var t,r,i,u,l,o=this,a=nn.Arithmetic,s=a.N,c=a.O,f=a.I,d=o.$,_=d.sub?d.subcount:d.count,m=1,h=arguments.length,b=a.sub(_,f),p=!(yn&d.order);if(1>h?(n=c,e=b):2>h?(n=s(n),e=b):(n=s(n),e=s(e)),n=a.wrapR(n,_),e=a.wrapR(e,_),a.gt(n,e)&&(t=n,n=e,e=t,m=-1),n=a.clamp(n,c,b),p&&(e=a.clamp(e,c,b)),a.lte(n,e)){if(l=[o.$.order,o.__index,o._index,o.__item&&o.__item.slice(),o._item&&o._item.slice(),o.__subindex,o._subindex,o.__subitem&&o.__subitem.slice(),o._subitem&&o._subitem.slice(),o._prev,o._next],p&&o.index(n),i=a.val(a.sub(e,n)),r=new Array(i+1),0>m)for(u=i;u>=0;u--)r[u]=o.next();else for(u=0;i>=u;u++)r[u]=o.next();o.$.order=l[0],o.__index=l[1],o._index=l[2],o.__item=l[3],o._item=l[4],o.__subindex=l[5],o._subindex=l[6],o.__subitem=l[7],o._subitem=l[8],o._prev=l[9],o._next=l[10]}else r=[];return r},__iter__:function(){return new Y.Iterable(this)}}),"undefined"!=typeof Symbol&&"undefined"!=typeof Symbol.iterator&&(Y[en][Symbol.iterator]=Y[en].__iter__),z=nn.Tensor=hn(Y,{constructor:function On(){var n,e=this,t=rn.call(arguments);return n=!t.length||t[t.length-1]instanceof Y||an(t[t.length-1])||t[t.length-1]===+t[t.length-1]?{}:t.pop()||{},n.type=String(n.type||"tensor").toLowerCase(),n.order=n.order||vn,t.length&&an(t[0])&&(t=t[0]),t&&t.length||(t=[]),e instanceof On?("tuple"===n.type?(t[0]=t[0]||1,t[1]=t[1]||1,t[0]instanceof Y?(n.sub=t[0],t[0]=n.sub.dimension()):t[1]instanceof Y&&(n.sub=t[1],t[1]=n.sub.base()),n.base=t[1],n.dimension=t[0]):(n.base=i(function(n,e){return e>n?e:n},0,t),n.dimension=t.length),void Y.call(e,"Tensor",t,n)):new On(t,n)},__static__:{C:function(n,e){return d(n,e[1])},P:Y.P,T:Y.T,count:function(n,e){var t=nn.Arithmetic.O;return e&&"tuple"===e.type?!n||0>=n[0]?t:nn.Math.exp(n[0],n[1]):n&&n.length?nn.Math.product(n):t},initial:function(n,e,t){var i=t&&"tuple"===t.type?e[0]?0>n?r(e[0],e[1]-1,0):r(e[0],0,0):[]:e.length?0>n?r(e.length,function(n){return e[n]-1}):r(e.length,0,0):[];return i},cascade:Y.cascade,dual:function(n,e,t,r){if(null==n)return null;var i=this,u=r&&r.order?r.order:0,l=r&&"tuple"===r.type?i.C:Y.C,o=i.P;i.T;return yn&u?pn&u?o(n,t):n.slice():xn&u?pn&u?o(n,t):n.slice():gn&u?pn&u?l(n,t):o(l(n,t),t):pn&u?o(n,t):n.slice()},succ:function(n,e,t,r,i){return H(e,r,n,i&&i.type?i.type:"tensor")},rand:function(n,e){var t,i=nn.Math.rndInt;return t=e&&"tuple"===e.type?n[0]?r(n[0],function(e){return i(0,n[1]-1)}):[]:n.length?r(n.length,function(e){return i(0,n[e]-1)}):[]},randu:Y.rand,rank:function(n,e,t){var r,i,u,l=nn.Arithmetic,o=l.add,a=l.mul,r=l.O,s=l.J;if(t&&"tuple"===t.type){if(i=e[0],!i)return s;for(e=e[1],u=0;i>u;u++)r=o(a(r,e),n[u])}else{if(i=e.length,!i)return s;for(u=0;i>u;u++)r=o(a(r,e[u]),n[u])}return r},unrank:function(n,e,t){var r,i,u,l,o,a,s=nn.Arithmetic,c=s.mod,f=s.div,d=s.val;if(t&&"tuple"===t.type){if(a=e[0],!a)return[];for(o=new Array(a),i=e[1],r=n,u=a-1;u>=0;u--)l=c(r,i),r=f(r,i),o[u]=d(l)}else{if(a=e.length,!a)return[];for(o=new Array(a),r=n,u=a-1;u>=0;u--)i=e[u],l=c(r,i),r=f(r,i),o[u]=d(l)}return o},product:u,component:function(n,e){var t,r,i,u,l,o,a=[],s=e,c=s.length;for(t=0;c>t;t++)if(i=s[t],l=n[t],u=i[l],u instanceof Array)for(r=0,o=u.length;o>r;r++)a.push(u[r]);else a.push(u);return a}}}),K=nn.Permutation=hn(Y,{constructor:function En(n,e){var t=this;return t instanceof En?(e=e||{},e.type=String(e.type||"permutation").toLowerCase(),n=n||1,n instanceof Y&&(e.sub=n,n=e.sub.dimension()),e.base=e.dimension=n,e.rand={multiset:1,derangement:1,involution:1},"multiset"===e.type&&(e.multiplicity=an(e.multiplicity)&&e.multiplicity.length?e.multiplicity.slice():r(n,1,0)),void Y.call(t,"Permutation",n,e)):new En(n,e)},__static__:{C:Y.C,P:Y.P,T:Y.T,count:function(n,e){var t=nn.Arithmetic.O,r=nn.Math.factorial,i=e&&e.type?e.type:"permutation";return 0>=n?t:"cyclic"===i?nn.Arithmetic.N(n):"multiset"===i?r(n,e.multiplicity):"derangement"===i?2>n?t:r(n,!1):"involution"===i?t:r(n)},initial:function(n,e,t){var i,u=t&&t.type?t.type:"permutation";if(0>=e)return null;if("cyclic"===u)i=0>n?[e-1].concat(r(e-1,0,1)):r(e,0,1);else if("derangement"===u){if(2>e)return null;if(1&e){var l=cn.floor(e/2);i=0>n?r(e-l-1,e-1,-1).concat([l-1,l]).concat(r(l-1,l-2,-1)):r(e-3,function(n){return 1&n?n-1:n+1}).concat([e-2,e-1,e-3])}else i=0>n?r(e,e-1,-1):r(e,function(n){return 1&n?n-1:n+1})}else if("multiset"===u){var o,a=t.multiplicity,s=a.length,c=0,f=1,d=0,_=s>c?a[c]:1;0>n&&(f=-1,d=s-1),o=d,i=r(e,function(){return 0>=_&&(c++,o+=f,_=s>c?a[c]:1),_--,o})}else i=0>n?r(e,e-1,-1):r(e,0,1);return i},cascade:Y.cascade,dual:function(n,e,t,r){if(null==n)return null;var i=this,u=r&&r.type?r.type:"permutation",l=r&&r.order?r.order:0,o="multiset"===u?r.multiplicity.length:t,a=i.C,s=i.P;i.T;return n=yn&l?pn&l?s(n,t):n.slice():xn&l?pn&l?s(n,t):n.slice():gn&l?pn&l?a(n,o):s(a(n,o),t):pn&l?s(n,t):n.slice()},succ:function(n,e,t,r,i){var u=i&&i.type?i.type:"permutation"; -return"involution"===u?null:F(e,r,n,u)},rand:function(n,t){var i=nn.Math.rndInt,u=t&&t.type?t.type:"permutation";if("cyclic"===u){var l=i(0,n-1);return l>0?r(n-l,l,1).concat(r(l,0,1)):r(n,0,1)}if("derangement"===u){var o,a,s,c=!1,f=new Array(n);do{for(o=0;n>o;o++)f[o]=o;for(o=n-1,c=!1;o>=0;){if(s=i(0,o),f[s]===o){c=!0;break}a=f[o],f[o]=f[s],f[s]=a,o--}c=c||0===f[0]}while(c);return f}if("multiset"===u){var d=t.multiplicity,_=d.length,l=0,m=d[l];return g(r(n,function(){return 0>=m&&(l++,m=_>l?d[l]:1),m--,l}))}return"involution"===u?e():g(r(n,0,1))},randu:Y.rand,rank:function(n,t,r){var i,u,l=nn.Arithmetic,o=r&&r.type?r.type:"permutation",a=l.add,s=l.mul,c=l.O;if(t=t||n.length,!t)return l.J;if("cyclic"===o)return n[0];if("derangement"===o)return e();if("involution"===o||"multiset"===o)return e();for(n=E(n),u=t-1,i=0;u>i;i++)c=a(s(c,t-i),n[i]);return c},unrank:function(n,t,i){var u,l,o,a,s,c=nn.Arithmetic,f=i&&i.type?i.type:"permutation",d=c.mod,_=c.div,m=c.val;if(!t)return[];if("cyclic"===f)return n=m(n),r(t,function(e){return(n+e)%t});if("derangement"===f)return e();if("involution"===f||"multiset"===f)return e();for(u=r(t),u[t-1]=0,l=n,o=t-2;o>=0;o--)a=t-o,s=d(l,a),l=_(l,a),u[o]=m(s);return R(u)},permute:function(n,e,t){var i,u,l,o=n.length;for(!0===t?(u=r(o),l=n):(u=n,l=n.slice()),i=0;o>i;i++)u[i]=l[e[i]];return u},shuffle:function(n,e){if(!0===e){var t=n.length,r=nn.Math.rndInt(0,t-1);return r>0&&n.push.apply(n,n.splice(0,r)),n}return g(n)},compose:function(){return j(rn.call(arguments))},concatenate:function(){return q(rn.call(arguments))},inverse:function(n){return N(n)},cycles:function(n,e){return-1===e?cycles2permutation(n):S(n)},swaps:function(n,e){return-1===e?P(n):$(n)},inversion:function(n,e){return-1===e?R(n):E(n)},matrix:function(n,e,t){return-1===t?T(n,e):L(n,e)},parity:e,is_permutation:X,is_identity:D,is_cyclic:V,is_derangement:G,is_involution:function(n){return J(n,1)},is_kthroot:function(n,e){return e>1?J(n,e-1):!1},is_connected:function(n){var e,t=n.length,r=-1;for(e=0;t-1>e;e++)if(n[e]>r&&(r=n[e]),e>=r)return!1;return!0}}}),Q=nn.Combination=hn(Y,{constructor:function Rn(n,e,t){var r=this;if(!(r instanceof Rn))return new Rn(n,e,t);if(an(n)?(t=e||{},e=n[1]||1,n=n[0]||1):(t=t||{},n=n||1,e=e||1),t.type=String(t.type||"unordered").toLowerCase(),-1n?r(e[1],e[0]-1,0):r(e[1],0,0):"ordered"===i?0>n?r(e[1],e[0]-1,-1):r(e[1],0,1):0>n?r(e[1],e[0]-e[1],1):r(e[1],0,1);return u},cascade:Y.cascade,dual:function(n,e,t,r){return n=Y.dual.call(this,n,e,t,r),r&&"binary"===r.type&&(n=y(n,t[0])),n},succ:function(n,e,t,r,i){return U(e,r,n,i&&i.type?i.type:"unordered")},rand:function(n,e){var t,i,u,l,o=e&&e.type?e.type:"unordered",a=n[1],s=nn.Math.rndInt;return n=n[0],i=n-a,u=n-1,"repeated"===o||"ordered+repeated"===o?(t=1===a?[s(0,u)]:r(a,function(){return s(0,u)}),a>1&&"repeated"===o&&v(t)):"ordered"===o?(l={},t=1===a?[s(0,u)]:n===a?g(r(a,0,1)):r(a,function(){for(var e=s(0,u);1===l[e];)e=(e+1)%n;return l[e]=1,e})):(l={},t=1===a?[s(0,u)]:n===a?r(a,0,1):a>i?b(n,v(r(i,function(){for(var e=s(0,u);1===l[e];)e=(e+1)%n;return l[e]=1,e}))):v(r(a,function(){for(var e=s(0,u);1===l[e];)e=(e+1)%n;return l[e]=1,e}))),t},randu:Y.rand,rank:function(n,e,t){var r,i,u,l,o,a=nn.Arithmetic,s=a.add,c=a.sub,f=a.mul,d=a.O,_=(a.I,d),m=e[1],h=t&&t.type?t.type:"unordered",b=nn.Math.factorial;if("ordered+repeated"===h)for(l=e[0],r=0;m>r;r++)_=s(f(_,l),n[r]);else if("repeated"===h){for(l=e[0]+m-1,o=t&&t.count?t.count:b(l,m),r=1;m>=r;r++)i=l-1-n[r-1]-r+1,u=m+1-r,i>=u&&(_=s(_,b(i,u)));_=c(c(o,a.I),_)}else{if("ordered"===h){for(l=e[0],n=E(n,l),r=0;m>r;r++)_=s(f(_,l-r),n[r]);return _}for(l=e[0],o=t&&t.count?t.count:b(l,m),r=1;m>=r;r++)i=l-1-n[r-1],u=m+1-r,i>=u&&(_=s(_,b(i,u)));_=c(c(o,a.I),_)}return _},unrank:function(n,e,t){var i,u,l,o,a,s,c,f=nn.Arithmetic,d=f.O,_=f.I,m=f.sub,h=f.div,b=f.mod,p=f.mul,v=f.lte,g=f.gt,x=f.val,y=e[1],A=t&&t.type?t.type:"unordered";if(e=e[0],i=r(y),"ordered+repeated"===A)for(o=n,s=y-1;s>=0;s--)a=b(o,e),o=h(o,e),i[s]=x(a);else if("ordered"===A){for(o=n,s=y-1;s>=0;s--)l=e-s,a=b(o,l),o=h(o,l),i[s]=x(a);i=R(i,e)}else{c="repeated"===A,l=c?e+y-1:e,u=t&&t.count?t.count:nn.Math.factorial(l,y),n=m(m(u,_),n),u=h(p(u,l-y),l),a=l-y+1,o=y,s=l-1;do v(u,n)?(i[y-o]=c?l-a-y+1:l-a-o+1,g(u,d)&&(n=m(n,u),u=h(p(u,o),s)),o--,s--):(u=h(p(u,s-o),s),a--,s--);while(o>0)}return i},complement:function(n,e,t){return!0===t?g(b(e,v(n))):b(e,n)},binary:function(n,e,t){return-1===t?A(n,e):y(n,e)},pick:function(n,e,t){return e>0&&n.length?x(n,e,"ordered+repeated"!==t&&"ordered"!==t,"ordered+repeated"===t||"repeated"===t,new Array(e)):[]},choose:function(n,e){return r(e.length,function(t){return n[e[t]]})}}}),Q.conjugate=Q.complement,Q.project=Q.choose,W=nn.Powerset=nn.Subset=hn(Y,{constructor:function kn(n,e){var t=this;return t instanceof kn?(e=e||{},e.type=e.type||"subset",n=n||1,n instanceof Y&&(e.sub=n,n=e.sub.base()),e.base=n,e.dimension={from:0,to:n},void Y.call(t,"Subset",n,e)):new kn(n,e)},__static__:{C:function(n,e){return b(e,n)},P:Y.P,T:Y.T,count:function(n,e){return nn.Math.pow2(n)},initial:function(n,e,t){var i=0>n?r(e,0,1):[];return i},cascade:Y.cascade,dual:function(n,e,t,r){if(null==n)return null;var i=this,u=r&&r.order?r.order:0,l=i.C,o=i.P;i.T;return n=yn&u?pn&u?n.slice():o(n,t):xn&u?pn&u?n.slice():o(n,t):gn&u?pn&u?o(l(n,t),t):l(n,t):pn&u?n.slice():o(n,t),r&&"binary"===r.type&&(n=y(n,t)),n},succ:Y.succ,rand:function(n,e){for(var t,i=nn.Math.rndInt,u=null,l=n-1;l>=0;l--)i(0,1)&&(u={len:u?u.len+1:1,k:l,next:u});return t=u?r(u.len,function(n){var e=u.k;return u=u.next,e}):[]},randu:Y.rand,rank:function(n,e,t){for(var r=nn.Arithmetic,i=r.O,u=r.I,l=r.add,o=r.shl,a=i,s=0,c=subset.length;c>s;)a=l(a,o(u,subset[s++]));return a},unrank:function(n,e,t){var r=this,i=nn.Arithmetic,u=i.O,l=i.J,o=i.band,a=i.shr,s=i.gt,c=[],f=0;if(!i.inside(n,l,t&&t.count?t.count:r.count(e,t)))return null;for(;s(n,u);)s(o(n,1),u)&&c.push(f),s(o(n,2),u)&&c.push(f+1),s(o(n,4),u)&&c.push(f+2),s(o(n,8),u)&&c.push(f+3),s(o(n,16),u)&&c.push(f+4),s(o(n,32),u)&&c.push(f+5),s(o(n,64),u)&&c.push(f+6),s(o(n,128),u)&&c.push(f+7),f+=8,n=a(n,8);return c},binary:function(n,e,t){return-1===t?A(n,e):y(n,e)}}}),Z=nn.Partition=hn(Y,{constructor:function Sn(n,e){var t=this;if(!(t instanceof Sn))return new Sn(n,e);e=e||{},e.type=e.type||"partition",n=n||1,n instanceof Y&&(e.sub=n,n=e.sub.base());var r=e["max="]?0|e["max="]:null,i=e["parts="]?0|e["parts="]:null,u=i?i:r?n-r+1:n,l=i?i:r?cn.ceil(n/r):1;e.base=n,e.dimension="constant"===e.length?i||n:u===l?l:{from:cn.min(l,u),to:cn.max(l,u)},Y.call(t,"Partition",n,e)},__static__:{C:function(n,e,t){return w(n,!0===t)},P:Y.P,T:Y.T,count:function(n,e){var t,r,i=nn.Arithmetic.add,u=nn.Math.partitions,l=e&&e["max="]?0|e["max="]:null,o=e&&e["parts="]?0|e["parts="]:null,a=nn.Arithmetic.O,s=l?l:0,c=l?l:1,f=o?o:1,d=o?o:n;if(0>n||o&&l&&(o+l>n+1||n>o*l)||l&&l>n||o&&o>n)return a;for(l&&!o&&(s=0,c=1,f=l,d=l),t=f;d>=t;t++)for(r=s?s:n-t+1;r>=c;r--)a=i(a,u(n,t,r));return a},initial:function(n,e,t){var i,u,l,o=t&&t["max="]?0|t["max="]:null,a=t&&t["parts="]?0|t["parts="]:null;if(0>e)return null;if(a&&o)return null;if(a&&(o=a,a=null),o){if(o>e)return null;u=cn.floor(e/o),l=e%o,i=0>n?r(u,o,0).concat(l?[l]:[]):[o].concat(r(e-o,1,0))}else i=0>n?[e]:r(e,1,0);return i},cascade:Y.cascade,dual:function(n,e,t,i){if(null==n)return null;var u=this,l=i&&i.order?i.order:0,o=i&&i["max="]?0|i["max="]:null,a=i&&i["parts="]?0|i["parts="]:null,s=u.C,c=u.P;u.T;return a&&!o&&(n=w(n)),n=yn&l?pn&l?c(n,t):n.slice():xn&l?pn&l?c(n,t):n.slice():gn&l?pn&l?c(s(n,t),t):s(n,t):pn&l?c(n,t):n.slice(),i&&"unpacked"===i.type&&(n=I(n)),i&&"set"===i.type?C(n):(i&&"constant"===i.length&&n.lengthr||l&&u&&(l+u>r+1||r>l*u)||l&&l>r||u&&u>r?null:B(e,r,n,l,u)},rand:Y.rand,randu:Y.rand,rank:e,unrank:e,conjugate:w,sets:function(n,e){return-1===e?O(n):C(n)},pack:function(n,e){return-1===e?I(n):M(n)}}}),Z.transpose=Z.conjugate,nn}); \ No newline at end of file +!function(n,e,t){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?(n.$deps=n.$deps||{})&&(n.EXPORTED_SYMBOLS=[e])&&(n[e]=n.$deps[e]=t.call(n)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[e]=t.call(n)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System["import"]?System.register(e,[],function(r){r(e,t.call(n))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(e)?define(e,["module"],function(e){return t.moduleUri=e.uri,t.call(n)}):e in n||(n[e]=t.call(n)||1)&&"function"==typeof define&&define.amd&&define(function(){return n[e]})}(this,"Abacus",function(n){"use strict";function e(){throw new Error("Method not implemented!")}function t(n){if(!arguments.length||null==n)return vn;if(sn(n)){var e,t=0,r=n.toUpperCase().split(","),i=r.length;for(e=0;i>e;e++)t|=un.call(nn.ORDER,r[e])?nn.ORDER[r[e]]:0;return t>0&&!(t&(An|yn))&&(t|=vn),t&yn&&(t&=~bn),t>0?t:vn}return n&yn&&(n&=~bn),wn&n?n:vn}function r(n,e,t){n=0|n;var r,i,u,l,o,a=n>0?new Array(n):[];if(n>0&&null!=e)if(i=15&n,r=1&i,e===+e){for(t=t||0,o=e,r&&(a[0]=o,o+=t),l=r;i>l;l+=2)u=l,a[u]=o,o+=t,u+=1,a[u]=o,o+=t;for(l=i;n>l;l+=16)u=l,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t,u+=1,a[u]=o,o+=t}else if("function"==typeof e){for(r&&(a[0]=e(0)),l=r;i>l;l+=2)u=l,a[u]=e(u),u+=1,a[u]=e(u);for(l=i;n>l;l+=16)u=l,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u),u+=1,a[u]=e(u)}else{for(r&&(a[0]=e),l=r;i>l;l+=2)u=l,a[u]=e,u+=1,a[u]=e;for(l=i;n>l;l+=16)u=l,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e,u+=1,a[u]=e}return a}function i(n,e,t,r,i,u){var l,o,a=e;if(t&&an(t)){if(l=t.length,null==r&&(r=0),null==i&&(i=l-1),null==u&&(u=1),l>0)if(0>u)for(o=r;o>=i;o+=u)a=n(a,t[o],o);else for(o=r;i>=o;o+=u)a=n(a,t[o],o)}else if(u=u||1,l=(i-r)/u+1,l>0)if(0>u)for(o=r;o>=i;o+=u)a=n(a,o,o);else for(o=r;i>=o;o+=u)a=n(a,o,o);return a}function u(){var n,e,t,r,i,u,l,o,a,s,f=arguments,c=f.length;if(!c)return[];if(!0===f[0]){for(a=f[1].length,n=2;c>n;n++)a*=f[n].length;for(s=new Array(a),n=0;a>n;n++){for(o=0,u=1,t=n,e=1;c>e;e++)r=f[e].length,i=t%r,t=~~(t/r),l=f[e][i],o+=u*l,u*=r;s[n]=o}}else{for(a=f[0].length,n=1;c>n;n++)a*=f[n].length;for(s=new Array(a),n=0;a>n;n++){for(o=[],t=n,e=c-1;e>=0;e--)if(r=f[e].length,i=t%r,t=~~(t/r),l=f[e][i],an(l))for(u=l.length-1;u>=0;u--)o.unshift(l[u]);else o.unshift(l);s[n]=o}}return s}function l(n){return i(nn.Arithmetic.add,nn.Arithmetic.O,n)}function o(n){return i(nn.Arithmetic.mul,nn.Arithmetic.I,n)}function a(n){var e=nn.Arithmetic;return e.shl(e.I,e.N(n))}function s(n,e){var t=nn.Arithmetic,r=t.N;return t.pow(r(n),r(e))}function f(n,e){var t,r,u,l=nn.Arithmetic,o=l.O,a=l.I,s=l.J,c=l.N,d=l.add,_=(l.sub,l.div),m=l.mul;if(null==e)return 4>n?0>n?o:2>n?a:l.shl(c(n),n-2):(u=String(n),null==f.mem1[u]&&(f.mem1[u]=i(m,a,null,2,n)),f.mem1[u]);if(!1===e)return 3>n?2===n?a:o:(u=String(n),null==f.mem2[u]&&(f.mem2[u]=i(function(n,e){return d(1&e?s:a,m(n,e))},a,null,3,n)),f.mem2[u]);if(an(e)){if(!e.length)return 0>n?o:f(n);if(0>n)return o;if(u=String(n)+"@"+e.join(","),null==f.mem3[u]){for(t=f(e[e.length-1]),r=e.length-2;r>=0;r--)t=m(t,f(e[r]));f.mem3[u]=_(f(n),t)}return f.mem3[u]}return e===+e?0>e?-e>n?o:(u=String(n)+"@"+String(e),null==f.mem3[u]&&(f.mem3[u]=i(m,a,null,n+e+1,n)),f.mem3[u]):(e+e>n&&(e=n-e),0>e||1>n?o:0===e||1===n?a:1===e?c(n):(u=String(n)+"@"+String(e),null==f.mem3[u]&&(f.mem3[u]=_(f(n,-e),f(e))),f.mem3[u])):o}function c(n,e,t){var r,i,u,l,o=nn.Arithmetic,a=o.add,s=o.O;if(t===n&&1===e||e===n&&1===t)return o.I;if(t+e>n+1||n>e*t)return s;if(r=String(n)+","+String(e)+","+String(t),null==c.mem[r]){for(l=fn.max(1,fn.ceil((n-t)/(e-1))),u=fn.min(t,n-t-e+2),i=l;u>=i;i++)s=a(s,c(n-t,e-1,i));c.mem[r]=s}return c.mem[r]}function d(n,e){if(null==n)return null;if(!n.length)return[];var t,r=n.length,i=new Array(r);if(an(e))for(t=0;r>t;t++)i[t]=e[t]-1-n[t];else if(0>e)for(t=0;r>t;t++)i[t]=r-1-n[t];else for(e-=1,t=0;r>t;t++)i[t]=e-n[t];return i}function _(n){if(null==n)return null;for(var e=n.length-1,t=new Array(e+1),r=0;e>=r;r++)t[r]=n[e-r];return t}function m(n,e){if(null==e&&(e=0),an(n)){for(var t=n.length,r=new Array(t),i=0;t>i;i++)r[i]=e-n[i];return r}return n===+n&&e===+e?e-n:nn.Arithmetic.sub(nn.Arithmetic.N(e),n)}function h(n,e,t,r,i,u,l){null==t&&(t=0),null==r&&(r=n.length-1),null==i&&(i=0),null==u&&(u=e.length-1);var o=t>r?-1:1,a=i>u?-1:1,s=o*(r-t)+1,f=a*(u-i)+1,c=t,d=i,_=0;if(null===l&&(l=new Array(fn.min(s,f))),0===l.length)return l;for(;o*(r-c)>=0&&a*(u-d)>=0;)n[c]e[d]?d+=a:(l[_++]=n[c],c+=o,d+=a);return _i?-1:1,s=u>l?-1:1,f=a*(i-t)+1,c=t,d=t,_=0;if(!e||!e.length)return n===+n?r(n,t,a):n?n.slice():n;if(null==o&&(o=new Array(f)),n===+n){for(;a*(i-c)>=0&&s*(l-d)>=0;)c===e[d]?(c+=a,d+=a):c>e[d]?d+=s:(o[_++]=c,c+=a);for(;a*(i-c)>=0;)o[_++]=c,c+=a}else{for(;a*(i-c)>=0&&s*(l-d)>=0;)n[c]===e[d]?(c+=a,d+=a):n[c]>e[d]?d+=s:(o[_++]=n[c],c+=a);for(;a*(i-c)>=0;)o[_++]=n[c],c+=a}return _r?-1:1,c=i>u?-1:1,d=f*(r-t)+1,_=c*(u-i)+1,m=d+_,h=t,b=i,p=0,v=!l;if(null==a&&(a=new Array(m)),0===a.length)return!0===o?n:a;for(;f*(r-h)>=0&&c*(u-b)>=0;){if(l&&p){if(n[h]===s){h+=f;continue}if(e[b]===s){b+=c;continue}}n[h]e[b]?(a[p++]=s=e[b],b+=c):(a[p++]=s=n[h],v&&(a[p++]=e[b]),h+=f,b+=c)}for(;f*(r-h)>=0;)(v||n[h]!==s)&&(a[p++]=s=n[h]),h+=f;for(;c*(u-b)>=0;)(v||e[b]!==s)&&(a[p++]=s=e[b]),b+=c;if(!0===o){for(h=t,p=0;m>p;p++,h+=f)n[h]=a[p];return n}return pt?-1:1,i=r*(t-e)+1;if(1>=i)return n;for(var u,l,o=i,a=1,s=2,f=fn.min,c=new Array(i);o;){for(l=i-a,u=0;l>u;u+=s)p(n,n,e+r*u,e+r*(u+a-1),e+r*(u+a),e+r*f(u+s-1,i-1),!1,!0,c);a<<=1,s<<=1,o>>=1}return n}function g(n,e,t,r){var i,u,l,o,a=nn.Math.rndInt,s=!0===e?1:0;if(an(t))for(o=t,i=o.length;sa;a++)o[a]=n[u+c(0,d)];return t&&v(o),o}for(a=0;e>a;a++)s=c(0,--d),f=n[u+s],n[u+s]=n[u+d],n[u+d]=f,o[a]=f,i&&(i[a]=s);if(i)for(a=e-1;a>=0;a--)s=i[a],f=n[u+d],n[u+d]=n[u+s],n[u+s]=f,d++;return t&&v(o),o}function y(n,e){if(0>e)return[];var t,i=r(e,0,0),u=n.length;for(e-=1,t=0;u>t;t++)i[e-n[t]]=1;return i}function A(n,e){e=fn.min(e||n.length,n.length);var t,r=[];for(e-=1,t=0;e>=t;t++)0i;i++)u=n[i],u[1]===l[i-1][0]?l[i-1][1]+=u[0]:l.push([u[1],u[0]]);else for(e=n[0],l=r(e,1,0),i=1;o>i;i++)for(t=0,u=n[i];e>t&&u>0;)l[t++]++,u--;return l}function M(n){if(null==n)return null;var e,t=[],r=n.length,i=n[0],u=[i,1];for(e=1;r>e;e++)i===n[e]?u[1]++:(t.push(u),i=n[e],u=[i,1]);return t.push(u),t}function I(n){if(null==n)return null;var e,t,r,i,u,l=[],o=n.length;for(e=0;o>e;e++)if(u=n[e],1===u[1])l.push(u[0]);else for(r=u[1],i=u[0],t=0;r>t;t++)l.push(i);return l}function O(n){if(null==n)return null;var e=0;return r(n.length,function(t){var i=n[t],u=r(i,e,1);return e+=i,u})}function C(n){return null==n?null:r(n.length,function(e){return n[e].length})}function E(n,e,t){e=e||n.length;var r,i,u,l,o,a=n.length,s=new Array(a),f=nn.Math.ceil(cn(e)),c=(1<<1+f)-1,d=new Array(c),_=1<r;r++)d[r]=0;for(i=m,r=0;a>r;r++,i+=h){for(o=n[r],l=_+o,u=0;f>u;u++)1&l&&(o-=d[l>>>1<<1]),d[l]+=1,l>>>=1;d[l]+=1,s[i]=o}return s}function R(n,e,t){e=e||n.length;var r,i,u,l,o,a,s,f,c,d,_=n.length,m=new Array(_),h=-1===t?_-1:0,b=-1===t?-1:1;for(s=nn.Math.ceil(cn(e)),f=(1<<1+s)-1,c=new Array(f),d=1<=r;r++)for(u=1,l=1<=u;u++)c[l-1+u]=1<r;r++,i+=b){for(o=n[r],a=1,u=0;s>u;u++)c[a]-=1,a<<=1,o>=c[a]&&(o-=c[a],a++);c[a]=0,m[i]=a-d}return m}function k(n,e,t){var r,i=n.length,u=null==e;if(i>1)for(u&&(e=new Array(i-1),t=0),r=i-1;r>=1;r--)e[t++]=[n[0],n[r]];else u&&(e=[]);return u?e:t}function S(n,e){var t,r,i,u,l=n.length,o=new Array(l),a=!0===e?1:0,s=new Array(l),f=0,c=0;for(t=0;l>t;t++)s[t]=0;for(i=new Array(l),u=0,r=f++,i[u++]=r,s[r]=1;l>f;){if(r=n[r],s[r])for(u>a&&(i.length=u,o[c++]=i),i=new Array(l),u=0;l>f&&s[r=f];)++f;s[r]||(i[u++]=r,s[r]=1)}return u>a&&(i.length=u,o[c++]=i),ce;e++)u=k(l[e],i,u);return ut;t++)l[t]=t;for(t=0;u>t;t++)swap=r[t],i=l[r[0]],l[r[0]]=l[r[1]],l[r[1]]=i;return l}function P(n,e){var t,r,i=n.length,u=i*i,l=new Array(u);for(t=0,r=0;u>t;)l[t+r]=0,++r>=i&&(r=0,t+=i);if(!0===e)for(t=0;i>t;t++)l[i*n[t]+t]=1;else for(t=0,r=0;i>r;r++,t+=i)l[t+n[t]]=1;return l}function N(n,e){var t,r,i=n.length,u=fn.floor(fn.sqrt(i)),l=new Array(u);if(!0===e)for(t=0,r=0;u>t;)n[u*t+r]&&(l[r]=t),++r>=u&&(r=0,t++);else for(t=0,r=0;u>t;)n[t+r]&&(l[t]=r),++r>=u&&(r=0,t++);return l}function T(n){var e,t=n.length,r=new Array(t);for(e=0;t>e;e++)r[n[e]]=e;return r}function j(n){var e,t,r,i=n,u=i.length,l=u?i[0]:[],o=l.length;for(t=1;u>t;t++)for(r=l.slice(),e=0;o>e;e++)l[e]=r[i[t][e]];return l}function q(n){var e,t,r,i,u,l,o=n,a=o.length,s=0;for(r=0;a>r;r++)s+=o[r].length;for(e=new Array(s),i=0,r=0;a>r;r++){for(u=o[r],l=u.length,t=0;l>t;t++)e[i+t]=i+u[t];i+=l}return e}function X(n,e){if(e=e||n.length,e!==n.length)return!1;var t,r,i=new Array(e);for(t=0;e>t;t++)i[t]=0;for(t=0;e>t;t++){if(r=n[t],0>r||r>=e||0!==i[r])return!1;i[r]++}for(t=0;e>t;t++)if(1!==i[t])return!1;return!0}function D(n){for(var e=n.length,t=0;e>t;t++)if(n[t]!==t)return!1;return!0}function V(n){for(var e=n.length,t=1,r=n[0];e>t;t++)if(n[t]!==(r+t)%e)return!1;return!0}function J(n,e){e=e||1;var t,r=new Array(e+1);for(t=0;e>=t;t++)r[t]=n;return D(j(r))}function G(n,e,t){e=0|e;for(var r=0,i=n.length,u=0;i>u;u++)if(n[u]===u&&r++,r>e)return!1;return!0===t?r===e:!0}function H(n,e,t,r){if(n){var i,u,l,o=e,a=o.length;if(0>t)if("tuple"===r){for(i=o[0],o=o[1],u=i-1;u>=0&&n[u]<1;)u--;if(u>=0)for(n[u]--,o-=1,l=u+1;i>l;l++)n[l]=o;else n=null}else{for(u=a-1;u>=0&&n[u]<1;)u--;if(u>=0)for(n[u]--,l=u+1;a>l;l++)n[l]=o[l]-1;else n=null}else if("tuple"===r){for(i=o[0],o=o[1],u=i-1;u>=0&&n[u]+1===o;)u--;if(u>=0)for(n[u]++,l=u+1;i>l;l++)n[l]=0;else n=null}else{for(u=a-1;u>=0&&n[u]+1===o[u];)u--;if(u>=0)for(n[u]++,l=u+1;a>l;l++)n[l]=0;else n=null}return n}return null}function F(n,e,t,r){if(n){var i,u,l,o,a,s,f=e;if(0>t)if("cyclic"===r)n=n[0]>0?[n[f-1]].concat(n.slice(0,-1)):null;else do{for(s=!1,i=f-2;i>=0&&n[i]<=n[i+1];)i--;if(i>=0){for(u=f-1;u>i&&n[i]<=n[u];)u--;for(a=n[i],n[i]=n[u],n[u]=a,l=i+1,o=f-1;o>l;)a=n[l],n[l]=n[o],n[o]=a,s=s||l===n[l]||o===n[o],l++,o--;if(s=s||i===n[i]||o===n[o],"derangement"===r){if(!s)for(l=i-1;l>=0;l--)if(l===n[l]){s=!0;break}}else s=!1}else n=null}while(n&&s);else if("cyclic"===r)n=n[0]+1=0&&n[i]>=n[i+1];)i--;if(i>=0){for(u=f-1;u>i&&n[i]>=n[u];)u--;for(a=n[i],n[i]=n[u],n[u]=a,l=i+1,o=f-1;o>l;)a=n[l],n[l]=n[o],n[o]=a,s=s||l===n[l]||o===n[o],l++,o--;if(s=s||i===n[i]||o===n[o],"derangement"===r){if(!s)for(l=i-1;l>=0;l--)if(l===n[l]){s=!0;break}}else s=!1}else n=null}while(n&&s);return n}return null}function U(n,e,t,r){if(n){var i,u,l,o,a,s,f,c=e[1],d=e[0];if(0>t)if("ordered+repeated"===r){for(u=c-1;u>=0&&n[u]<1;)u--;if(u>=0)for(n[u]--,d-=1,l=u+1;c>l;l++)n[l]=d;else n=null}else if("ordered"===r){for(i={},u=0;c>u;u++)i[n[u]]=u;for(u=c-1,o=-1;-1===o&&u>=0;){if(n[u]-1>=0)for(l=n[u]-1;l>=0;l--)if(null==i[l]){o=u,i[l]=o;break}i[n[u]]=null,u--}if(o>-1)for(n[o]=l,l=d-1,u=o+1;c>u;u++){for(;l>=0&&null!=i[l];)l--;n[u]=l,i[l]=u}else n=null}else{for(f="repeated"===r?0:1,u=c-1,o=-1;u>0;){if(n[u]>n[u-1]+f){o=u;break}u--}if(-1===o&&0-1){for(s=d-1+f,u=c-1;u>o;u--)s-=f,n[u]=s;n[o]--}else n=null}else if("ordered+repeated"===r){for(u=c-1;u>=0&&n[u]+1===d;)u--;if(u>=0)for(n[u]++,l=u+1;c>l;l++)n[l]=0;else n=null}else if("ordered"===r){for(i={},u=0;c>u;u++)i[n[u]]=u;for(u=c-1,o=-1;-1===o&&u>=0;){if(n[u]+1l;l++)if(null==i[l]){o=u,i[l]=o;break}i[n[u]]=null,u--}if(o>-1)for(n[o]=l,l=0,u=o+1;c>u;u++){for(;d>l&&null!=i[l];)l++;n[u]=l,i[l]=u}else n=null}else{if(u=c-1,o=-1,"repeated"===r)for(f=0;u>=0;){if(n[u]+1=0;){if(n[u]-1)for(s=n[o]+1-f,u=o;c>u;u++)s+=f,n[u]=s;else n=null}return n}return null}function B(n,e,t,i,u){if(i&&u)return null;if(n){var l,o,a,s,f,c,d=e;if(0>t)if(i&&(u=i,i=null),o=u?1:0,n.length>o&&n[o]>1){for(l=n.length-1,c=0;l>=o&&1===n[l];)c+=n[l],l--;f=n[l]-1,c++,n[l]=f,n=n.slice(0,l+1),c>f?n=n.concat(r(fn.floor(c/f),f),(c%=f)?[c]:[]):c>0&&(n=n.concat([c]))}else n=null;else if(i&&(u=i,i=null),o=u?1:0,a=u?n.length-1:0,f=u?d%u||u:d,n.length>o&&n[a]1?(l=s-2,c=n[s-1]):(l=s-1,c=0);l>o&&n[l]===n[l-1];)c+=n[l],l--;n[l]++,c--,n=c>0?n.slice(0,l+1).concat(r(c,1)):n.slice(0,l+1)}else n=null;return n}return null}var Y,z,K,Q,W,Z,nn={VERSION:"0.7.5"},en="prototype",tn="constructor",rn=Array.prototype.slice,un=Object[en].hasOwnProperty,ln=Object[en].toString,on=/^\s+|\s+$/g,an=(String.prototype.trim?function(n){return n.trim()}:function(n){return n.replace(on,"")},function(n){return n instanceof Array||"[object Array]"===ln.call(n)}),sn=function(n){return n instanceof String||"[object String]"===ln.call(n)},fn=Math,cn=fn.log2||function(n){return fn.log(n)/fn.LN2},dn=function(n){var e=n.toString(2),t=32-e.length;return t>0?new Array(t+1).join("0")+e:e},_n=Object.create,mn=function(n,e){for(var t in e)un.call(e,t)&&(n[t]=e[t]);return n},hn=function(n,e){1===arguments.length&&(e=n,n=Object);var t=e[tn];return un.call(e,"__static__")&&(t=mn(t,e.__static__),delete e.__static__),t[en]=mn(_n(n[en]),e),t},bn=1,pn=2,vn=4,gn=8,xn=16,yn=32,An=vn|gn|xn,wn=An|yn|bn|pn;return f.mem1={},f.mem2={},f.mem3={},c.mem={},nn.$={MAXMEM:1e6,RANDOM:"index"},nn.ORDER={LEX:vn,LEXICOGRAPHIC:vn,REVLEX:vn|bn,ANTILEX:vn|bn,REVERSELEXICOGRAPHIC:vn|bn,ANTILEXICOGRAPHIC:vn|bn,REFLEX:vn|pn,REFLECTEDLEXICOGRAPHIC:vn|pn,COLEX:gn,COLEXICOGRAPHIC:gn,REVCOLEX:gn|bn,ANTICOLEX:gn|bn,REVERSECOLEXICOGRAPHIC:gn|bn,ANTICOLEXICOGRAPHIC:gn|bn,REFCOLEX:gn|pn,REFLECTEDCOLEXICOGRAPHIC:gn|pn,REV:bn,REVERSE:bn,REVERSED:bn,REF:pn,REFLECT:pn,REFLECTED:pn,RANDOM:yn,GRAY:xn,MINIMAL:xn},nn.Util={array:r,operate:i,intersect:h,difference:b,merge:p,conjugation:d,parity:_,inversion:m,mergesort:v,shuffle:g,pick:x},nn.Math={O:0,I:1,J:-1,N:function(n){return nn.Arithmetic.add(nn.Arithmetic.O,n)},V:function(n){return nn.Arithmetic.sub(nn.Arithmetic.O,n)},rnd:fn.random,rndInt:function(n,e){return nn.Math.round((e-n)*nn.Math.rnd()+n)},equ:function(n,e){return n===e},gte:function(n,e){return n>=e},lte:function(n,e){return e>=n},gt:function(n,e){return n>e},lt:function(n,e){return e>n},inside:function(n,e,t,r){return r?n>=e&&t>=n:n>e&&t>n},clamp:function(n,e,t){return e>n?e:n>t?t:n},wrap:function(n,e,t){return e>n?t:n>t?e:n},wrapR:function(n,e){return 0>n?n+e:n},add:function(n,e){return n+e},sub:function(n,e){return n-e},mul:function(n,e){return n*e},div:function(n,e){return nn.Math.floor(n/e)},mod:function(n,e){return n%e},pow:fn.pow,shl:function(n,e){return n<>e},bor:function(n,e){return n|e},band:function(n,e){return n&e},xor:function(n,e){return n^e},abs:fn.abs,min:fn.min,max:fn.max,floor:fn.floor,ceil:fn.ceil,round:fn.round,num:function(n){return"number"==typeof n?nn.Math.floor(n):parseInt(n,10)},val:function(n){return nn.Math.floor(n.valueOf())},sum:l,product:o,pow2:a,exp:s,factorial:f,partitions:c},nn.Arithmetic={O:0,I:1,J:-1,N:nn.Math.N,V:nn.Math.V,equ:nn.Math.equ,gte:nn.Math.gte,lte:nn.Math.lte,gt:nn.Math.gt,lt:nn.Math.lt,inside:nn.Math.inside,clamp:nn.Math.clamp,wrap:nn.Math.wrap,wrapR:nn.Math.wrapR,add:nn.Math.add,sub:nn.Math.sub,mul:nn.Math.mul,div:nn.Math.div,mod:nn.Math.mod,pow:nn.Math.pow,shl:nn.Math.shl,shr:nn.Math.shr,bor:nn.Math.bor,band:nn.Math.band,xor:nn.Math.xor,abs:nn.Math.abs,min:nn.Math.min,max:nn.Math.max,floor:nn.Math.floor,ceil:nn.Math.ceil,round:nn.Math.round,rnd:nn.Math.rndInt,num:nn.Math.num,val:nn.Math.val},nn.Class=hn,nn.BitArray=hn({constructor:function Mn(n){var e=this;return e instanceof Mn?(e.length=n,void(e.bits=new Uint32Array(nn.Math.ceil(n/32)))):new Mn(n)},length:0,bits:null,dispose:function(){var n=this;return n.length=null,n.bits=null,n},clone:function(){var n=this,e=new nn.BitArray(n.length);return e.bits=new Uint32Array(n.bits),e},fromArray:function(n){var e=this;return e.bits=new Uint32Array(n),e},toArray:function(){return rn.call(this.bits)},toString:function(){var n,e,t=this.toArray();for(n=0,e=t.length;e>n;n++)t[n]=dn(t[n]);return t.join("")},reset:function(){var n,e=this,t=e.bits,r=t.length;for(n=0;r>n;n++)t[n]=0;return e},isset:function(n){return!!(this.bits[n>>>5]&1<<(31&n))},set:function(n){var e=this;return e.bits[n>>>5]|=1<<(31&n),e},unset:function(n){var e=this;return e.bits[n>>>5]&=~(1<<(31&n)),e},toggle:function(n){var e=this;return e.bits[n>>>5]^=1<<(31&n),e}}),Y=nn.CombinatorialIterator=hn({constructor:function In(n,e,t){var r=this,i=r[tn];r.name=n||"CombinatorialIterator",r.n=e||0,r.$=t=t||{},t.type=String(t.type||"default").toLowerCase(),t.order=t.order||vn,t.base=t.base||0,t.minbase=null!=t.minbase?t.minbase:t.base,t.maxbase=null!=t.maxbase?t.maxbase:t.base,t.dimension=t.dimension||0,t.mindimension=null!=t.mindimension?t.mindimension:t.dimension,t.maxdimension=null!=t.maxdimension?t.maxdimension:t.dimension,t.rand=t.rand||{},t.count=i.count(r.n,r.$),t.sub instanceof In&&(t.subcount=nn.Arithmetic.mul(t.count,t.sub.total()),t.submethod=String(t.submethod||"project").toLowerCase(),t.subcascade=-1===t.subcascade?-1:1,"concatenate"===t.submethod?t.subdimension=t.dimension+t.sub.dimension():"compose"===t.submethod?t.subdimension=t.dimension*t.sub.dimension():t.subdimension=t.dimension),r.order(t.order)},__static__:{Iterable:function On(n,e){var t=this;return t instanceof On?(e=-1===e?-1:1,void(t.next=function(){return n.hasNext(e)?{value:n.next(e)}:{done:!0}})):new On(n)},C:function(n,e){return d(n,e)},P:function(n){return _(n)},T:function(n,e){return m(n,e)},count:e,initial:e,cascade:function(n,e,t,i){if(-1===i){var l=n;n=e,e=l}return"concatenate"===t?n&&e?n.concat(e):n||e||null:"compose"===t?n&&e?u(!0,n,e):n||e||null:null==n||null==e?null:r(n.length,function(t){return n[t]n?l.J:l.I),r,i)},rand:function(n,e){var t=this,r=nn.Arithmetic,i=r.sub(e&&e.count?e.count:t.count(n,e),r.I),u=r.O,l=r.rnd(u,i);return r.equ(u,l)?t.initial(1,n,e):r.equ(i,l)?t.initial(-1,n,e):t.unrank(l,n,e)},rank:e,unrank:e},name:"CombinatorialIterator",n:0,$:null,__index:null,_index:null,__item:null,_item:null,__subindex:null,_subindex:null,__subitem:null,_subitem:null,_prev:null,_next:null,_traversed:null,dispose:function(n){var e=this;return!0!==n&&e.$.sub&&(e.$.sub.dispose(),e.$.sub=null),e.name=null,e.n=null,e.$=null,e.__index=null,e._index=null,e.__item=null,e._item=null,e.__subindex=null,e._subindex=null,e.__subitem=null,e._subitem=null,e._prev=null,e._next=null,e._traversed&&(e._traversed.dispose(),e._traversed=null),e},base:function(n){var e=this.$;return e.sub&&!0!==n?e.subbase||e.base||0:e.base||0},dimension:function(n){var e=this.$;return e.sub&&!0!==n?e.subdimension||e.dimension||0:e.dimension||0},total:function(n){var e=this.$;return e.sub&&!0!==n?e.subcount||e.count||0:e.count||0},_init:function(n,e){var t,r,i,u=this,l=u[tn],o=u.$,a=u.n,s=nn.Arithmetic,f=s.O,c=s.I,d=o.order;return u.__index=u._index=f,u._item=u.__item=null,u._prev=!1,u._next=!1,r=o.count,i=s.sub(r,c),yn&d?"gen"===nn.$.RANDOM||1===o.rand[o.type]||s.gt(r,nn.$.MAXMEM)?(u.__item=l.rand(a,o),u.__index=null):(u._traversed&&u._traversed.dispose(),u._traversed=new nn.BitArray(s.val(r)),t=u.random("index"),u._traversed.set(+t),u.__item=l.unrank(t,a,o),null!=u.__item&&(u.__index=t)):gn&d?(u.__item=l.initial(-n,a,o),null!=u.__item&&(u.__index=-1===n?f:i)):(u.__item=l.initial(n,a,o),null!=u.__item&&(u.__index=-1===n?i:f)),u._item=null==u.__item?null:l.dual(u.__item,u.__index,a,o),u._index=!e||yn&d?f:i,null===u.__index&&(u.__index=f),u._prev=yn&d||!e?!1:null!=u.__item,u._next=!e||yn&d?null!=u.__item:!1,u},order:function(n,e){if(!arguments.length)return this._order;var r,i,u,l,o,a=this,s=a[tn],f=nn.Arithmetic,c=(f.O,f.I,!0===n);return e=-1===e,u=a.n,l=a.$,a._traversed&&(a._traversed.dispose(),a._traversed=null),c?n=l.order:sn(n)&&-1<(i=n.indexOf("|"))?(r=n.substr(i+1),n=t(n.substr(0,i))):r=n=t(n),o=bn&n?-1:1,o=e?-o:o,l.order=n,l.sub?(c?l.sub.rewind(e?-1:1):l.sub.order(r,e?-1:1),a.__subindex=l.sub.index(),a.__subitem=l.sub.next(e?-1:1),a._subindex=null,a._subitem=null):(a.__subindex=null,a.__subitem=null,a._subindex=null,a._subitem=null),a._init(o,e),l.sub&&(a._prev=a._prev&&null!=a.__subitem,a._next=a._next&&null!=a.__subitem,a._subindex=f.add(f.mul(a._index,l.sub.total()),a.__subindex),a._subitem=s.cascade(a._item,a.__subitem,l.submethod,l.subcascade)),a},index:function(n,e){if(e=!0===e,!arguments.length)return this.$.sub?this._subindex:this._index;var t,r=this,i=r[tn],u=nn.Arithmetic,l=u.O,o=u.I,a=u.J,s=r.n,f=r.$,c=f.sub&&!e?f.subcount:f.count,d=f.sub&&!e?r._subindex:r._index,_=f.order,m=bn&_?-1:1;return n=u.wrapR(u.N(n),c),!u.equ(n,d)&&u.inside(n,a,c)&&(f.sub&&!e&&(f.sub.index(u.mod(n,f.sub.total())),r.__subindex=f.sub.index(),r.__subitem=f.sub.item(),n=u.div(n,f.sub.total()),c=f.count),t=u.sub(c,o),gn&_?(r.__index=-1===m?n:u.sub(t,n),r._index=n,r.__item=u.equ(l,n)?i.initial(-m,s,f):u.equ(t,n)?i.initial(m,s,f):i.unrank(r.__index,s,f),r._item=i.dual(r.__item,r.__index,s,f),r._prev=null!=r.__item,r._next=null!=r.__item):yn&_||(r.__index=-1===m?u.sub(t,n):n,r._index=n,r.__item=u.equ(l,n)?i.initial(m,s,f):u.equ(t,n)?i.initial(-m,s,f):i.unrank(r.__index,s,f),r._item=i.dual(r.__item,r.__index,s,f),r._prev=null!=r.__item,r._next=null!=r.__item),f.sub&&(r._prev=r._prev&&null!=r.__subitem,r._next=r._next&&null!=r.__subitem,r._subindex=u.add(u.mul(r._index,f.sub.total()),r.__subindex),r._subitem=i.cascade(r._item,r.__subitem,f.submethod,f.subcascade))),r},item:function(n,e){if(!arguments.length)return this.$.sub?this._subitem:this._item;var r,i,u,l,o,a,s,f=this,c=f[tn],d=f.n,_=f.$,m=_.sub?_.subcount:_.count,h=_.sub?f._subindex:f._index,b=nn.Arithmetic,p=b.O,v=b.I,g=b.J,x=null;return sn(e)?-1<(s=e.indexOf("|"))?(x=e.substr(s+1),e=t(e.substr(0,s))):x=e=t(e):null!=e?x=e=t(e):(e=_.order,x=null),_.sub||(x=null),an(n)?(m=_.count,u=bn&e?-1:1,r=b.sub(m,v),f.__item=n.slice(),f.__index=c.rank(f.__item,d,_),yn&e?(f._index=f.__index,l=_.order,_.order=e,f._item=c.dual(f.__item,f.__index,d,_),_.order=l):gn&e?(f._index=-1===u?f.__index:b.sub(r,f.__index),l=_.order,_.order=e,f._item=c.dual(f.__item,f.__index,d,_),_.order=l):(f._index=-1===u?b.sub(r,f.__index):f.__index,l=_.order,_.order=e,f._item=c.dual(f.__item,f.__index,d,_),_.order=l),f):(n=b.wrapR(b.N(n),m),e===_.order&&null===x&&b.equ(n,h)?_.sub?f._subitem:f._item:b.inside(n,g,m)?(a=null,_.sub&&(a=_.sub.item(b.mod(n,_.sub.total()),x),n=b.div(n,_.sub.total()),m=_.count),u=bn&e?-1:1,r=b.sub(m,v),yn&e?(i=null,l=_.order,_.order=e,o=c.dual(c.rand(d,_),i,d,_),_.order=l,_.sub&&(o=c.cascade(o,a,_.submethod,_.subcascade)),o):gn&e?(i=-1===u?n:b.sub(r,n),l=_.order,_.order=e,o=c.dual(b.equ(p,n)?c.initial(-u,d,_):b.equ(r,n)?c.initial(u,d,_):c.unrank(i,d,_),i,d,_),_.order=l,_.sub&&(o=c.cascade(o,a,_.submethod,_.subcascade)),o):(i=-1===u?b.sub(r,n):n,l=_.order,_.order=e,o=c.dual(b.equ(p,n)?c.initial(u,d,_):b.equ(r,n)?c.initial(-u,d,_):c.unrank(i,d,_),i,d,_),_.order=l,_.sub&&(o=c.cascade(o,a,_.submethod,_.subcascade)),o)):null)},random:function(n,e,t,r){var i,u=this,l=u[tn],o=u.$,a=o.order;if(r=!0===r,"index"===n){var s,f=nn.Arithmetic,c=f.N,d=f.O,_=f.I;return e===!!e&&(r=e,e=null,t=null),s=o.sub&&!r?o.subcount:o.count,null==e&&null==t?(e=d,t=f.sub(s,_)):null==t?(e=c(e||0),t=f.sub(s,_)):(e=c(e),t=c(t)),f.rnd(e,t)}return o.order|=yn,i=l.rand(u.n,o),o.order=a,i=l.dual(i,null,u.n,o),o.sub&&!r?l.cascade(i,o.sub.random(),o.submethod,o.subcascade):i},rewind:function(n){var e=this;return e.order(!0,-1===n?-1:1)},hasNext:function(n){var e=this;return-1===n?yn&e.$.order?!1:e._prev:e._next},next:function(n){var e,t,r,i,u,l=this,o=l[tn],a=nn.Arithmetic,s=a.O,f=a.I,c=a.J,d=l.n,_=l.$,m=_.order,h=_.count,b=_.sub?l._subitem:l._item;if(r=-1===n,n=bn&m?-1:1,r)return yn&m?null:(gn&m?(l.__item=o.succ(n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,0>n?c:f))):(l.__item=o.succ(-n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,n>0?c:f))),l._prev=null!=l.__item,l._prev?l._index=a.sub(l._index,f):_.sub&&_.sub.hasNext(-1)?(l.__subindex=_.sub.index(),l.__subitem=_.sub.next(-1),l._init(-n,r)):(l.__subindex=null,l.__subitem=null),l._item=null==l.__item?null:o.dual(l.__item,l.__index,d,_),_.sub&&(l._prev=l._prev&&null!=l.__subitem,l._subindex=l._prev?a.add(a.mul(l._index,_.sub.total()),l.__subindex):null,l._subitem=l._prev?o.cascade(l._item,l.__subitem,_.submethod,_.subcascade):null),b);if(yn&m)if(i=a.sub(h,f),a.lt(l._index,i))if(e=l._traversed){for(t=l.random("index"),u=nn.Math.rnd()>.5?c:f;e.isset(+t);)t=a.wrap(a.add(t,u),s,i);e.set(+t),l.__item=o.unrank(t,d,_),null!=l.__item&&(l.__index=t)}else l.__item=o.rand(d,_),l.__index=null;else l._item=l.__item=null,l._traversed&&(l._traversed.dispose(),l._traversed=null);else gn&m?(l.__item=o.succ(-n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,n>0?c:f))):(l.__item=o.succ(n,l.__item,l.__index,d,_),null!=l.__item&&(l.__index=a.add(l.__index,0>n?c:f)));return l._next=null!=l.__item,l._next?(l._index=a.add(l._index,f),null===l.__index&&(l.__index=l._index)):_.sub&&_.sub.hasNext()?(l.__subindex=_.sub.index(),l.__subitem=_.sub.next(),l._init(n,r)):(l.__subindex=null,l.__subitem=null),l._item=null==l.__item?null:o.dual(l.__item,l.__index,d,_),_.sub&&(l._next=l._next&&null!=l.__subitem,l._subindex=l._next?a.add(a.mul(l._index,_.sub.total()),l.__subindex):null,l._subitem=l._next?o.cascade(l._item,l.__subitem,_.submethod,_.subcascade):null),b},range:function(n,e){var t,r,i,u,l,o=this,a=nn.Arithmetic,s=a.N,f=a.O,c=a.I,d=o.$,_=d.sub?d.subcount:d.count,m=1,h=arguments.length,b=a.sub(_,c),p=!(yn&d.order);if(1>h?(n=f,e=b):2>h?(n=s(n),e=b):(n=s(n),e=s(e)),n=a.wrapR(n,_),e=a.wrapR(e,_),a.gt(n,e)&&(t=n,n=e,e=t,m=-1),n=a.clamp(n,f,b),p&&(e=a.clamp(e,f,b)),a.lte(n,e)){if(l=[o.$.order,o.__index,o._index,o.__item&&o.__item.slice(),o._item&&o._item.slice(),o.__subindex,o._subindex,o.__subitem&&o.__subitem.slice(),o._subitem&&o._subitem.slice(),o._prev,o._next],p&&o.index(n),i=a.val(a.sub(e,n)),r=new Array(i+1),0>m)for(u=i;u>=0;u--)r[u]=o.next();else for(u=0;i>=u;u++)r[u]=o.next();o.$.order=l[0],o.__index=l[1],o._index=l[2],o.__item=l[3],o._item=l[4],o.__subindex=l[5],o._subindex=l[6],o.__subitem=l[7],o._subitem=l[8],o._prev=l[9],o._next=l[10]}else r=[];return r},__iter__:function(){return new Y.Iterable(this)}}),"undefined"!=typeof Symbol&&"undefined"!=typeof Symbol.iterator&&(Y[en][Symbol.iterator]=Y[en].__iter__),z=nn.Tensor=hn(Y,{constructor:function Cn(){var n,e=this,t=rn.call(arguments);if(n=!t.length||t[t.length-1]instanceof Y||an(t[t.length-1])||t[t.length-1]===+t[t.length-1]?{}:t.pop()||{},n.type=String(n.type||"tensor").toLowerCase(),n.order=n.order||vn,t.length&&an(t[0])&&(t=t[0]),t&&t.length||(t=[]),!(e instanceof Cn))return new Cn(t,n);if("tuple"===n.type)t[0]=t[0]||1,t[1]=t[1]||1,t[0]instanceof Y?(n.sub=t[0],t[0]=n.sub.dimension()):t[1]instanceof Y&&(n.sub=t[1],t[1]=n.sub.base()),n.base=t[1],n.dimension=t[0];else{var r=i(function(n,e){return en[1]&&(n[1]=e),n},[1/0,0],t);n.base=t,n.minbase=r[0],n.maxbase=r[1],n.dimension=t.length}Y.call(e,"Tensor",t,n)},__static__:{C:Y.C,P:Y.P,T:Y.T,count:function(n,e){var t=nn.Arithmetic.O;return e&&"tuple"===e.type?!n||0>=n[0]?t:nn.Math.exp(n[0],n[1]):n&&n.length?nn.Math.product(n):t},initial:function(n,e,t){var i=t&&"tuple"===t.type?e[0]?0>n?r(e[0],e[1]-1,0):r(e[0],0,0):[]:e.length?0>n?r(e.length,function(n){return e[n]-1}):r(e.length,0,0):[];return i},cascade:Y.cascade,dual:Y.dual,succ:function(n,e,t,r,i){return H(e,r,n,i&&i.type?i.type:"tensor")},rand:function(n,e){var t,i=nn.Math.rndInt;return t=e&&"tuple"===e.type?n[0]?r(n[0],function(e){return i(0,n[1]-1)}):[]:n.length?r(n.length,function(e){return i(0,n[e]-1)}):[]},randu:Y.rand,rank:function(n,e,t){var r,i,u,l=nn.Arithmetic,o=l.add,a=l.mul,r=l.O,s=l.J;if(t&&"tuple"===t.type){if(i=e[0],!i)return s;for(e=e[1],u=0;i>u;u++)r=o(a(r,e),n[u])}else{if(i=e.length,!i)return s;for(u=0;i>u;u++)r=o(a(r,e[u]),n[u])}return r},unrank:function(n,e,t){var r,i,u,l,o,a,s=nn.Arithmetic,f=s.mod,c=s.div,d=s.val;if(t&&"tuple"===t.type){if(a=e[0],!a)return[];for(o=new Array(a),i=e[1],r=n,u=a-1;u>=0;u--)l=f(r,i),r=c(r,i),o[u]=d(l)}else{if(a=e.length,!a)return[];for(o=new Array(a),r=n,u=a-1;u>=0;u--)i=e[u],l=f(r,i),r=c(r,i),o[u]=d(l)}return o},product:u,component:function(n,e){var t,r,i,u,l,o,a=[],s=e,f=s.length;for(t=0;f>t;t++)if(i=s[t],l=n[t],u=i[l],u instanceof Array)for(r=0,o=u.length;o>r;r++)a.push(u[r]);else a.push(u);return a}}}),K=nn.Permutation=hn(Y,{constructor:function En(n,e){var t=this;return t instanceof En?(e=e||{},e.type=String(e.type||"permutation").toLowerCase(),n=n||1,n instanceof Y&&(e.sub=n,n=e.sub.dimension()),e.base=e.dimension=n,e.rand={multiset:1,derangement:1,involution:1},"multiset"===e.type&&(e.multiplicity=an(e.multiplicity)&&e.multiplicity.length?e.multiplicity.slice():r(n,1,0),e.base=e.multiplicity.length),void Y.call(t,"Permutation",n,e)):new En(n,e)},__static__:{C:Y.C,P:Y.P,T:Y.T,count:function(n,e){var t=nn.Arithmetic.O,r=nn.Math.factorial,i=e&&e.type?e.type:"permutation";return 0>=n?t:"cyclic"===i?nn.Arithmetic.N(n):"multiset"===i?r(n,e.multiplicity):"derangement"===i?2>n?t:r(n,!1):"involution"===i?t:r(n)},initial:function(n,e,t){var i,u=t&&t.type?t.type:"permutation";if(0>=e)return null;if("cyclic"===u)i=0>n?[e-1].concat(r(e-1,0,1)):r(e,0,1);else if("derangement"===u){if(2>e)return null;if(1&e){var l=fn.floor(e/2);i=0>n?r(e-l-1,e-1,-1).concat([l-1,l]).concat(r(l-1,l-2,-1)):r(e-3,function(n){return 1&n?n-1:n+1}).concat([e-2,e-1,e-3])}else i=0>n?r(e,e-1,-1):r(e,function(n){return 1&n?n-1:n+1})}else if("multiset"===u){var o,a=t.multiplicity,s=a.length,f=0,c=1,d=0,_=s>f?a[f]:1;0>n&&(c=-1,d=s-1),o=d,i=r(e,function(){return 0>=_&&(f++,o+=c,_=s>f?a[f]:1),_--,o})}else i=0>n?r(e,e-1,-1):r(e,0,1);return i},cascade:Y.cascade,dual:Y.dual,succ:function(n,e,t,r,i){var u=i&&i.type?i.type:"permutation"; +return"involution"===u?null:F(e,r,n,u)},rand:function(n,t){var i=nn.Math.rndInt,u=t&&t.type?t.type:"permutation";if("cyclic"===u){var l=i(0,n-1);return l>0?r(n-l,l,1).concat(r(l,0,1)):r(n,0,1)}if("derangement"===u){var o,a,s,f=!1,c=new Array(n);do{for(o=0;n>o;o++)c[o]=o;for(o=n-1,f=!1;o>=0;){if(s=i(0,o),c[s]===o){f=!0;break}a=c[o],c[o]=c[s],c[s]=a,o--}f=f||0===c[0]}while(f);return c}if("multiset"===u){var d=t.multiplicity,_=d.length,l=0,m=d[l];return g(r(n,function(){return 0>=m&&(l++,m=_>l?d[l]:1),m--,l}))}return"involution"===u?e():g(r(n,0,1))},randu:Y.rand,rank:function(n,t,r){var i,u,l=nn.Arithmetic,o=r&&r.type?r.type:"permutation",a=l.add,s=l.mul,f=l.O;if(t=t||n.length,!t)return l.J;if("cyclic"===o)return n[0];if("derangement"===o)return e();if("involution"===o||"multiset"===o)return e();for(n=E(n),u=t-1,i=0;u>i;i++)f=a(s(f,t-i),n[i]);return f},unrank:function(n,t,i){var u,l,o,a,s,f=nn.Arithmetic,c=i&&i.type?i.type:"permutation",d=f.mod,_=f.div,m=f.val;if(!t)return[];if("cyclic"===c)return n=m(n),r(t,function(e){return(n+e)%t});if("derangement"===c)return e();if("involution"===c||"multiset"===c)return e();for(u=r(t),u[t-1]=0,l=n,o=t-2;o>=0;o--)a=t-o,s=d(l,a),l=_(l,a),u[o]=m(s);return R(u)},permute:function(n,e,t){var i,u,l,o=n.length;for(!0===t?(u=r(o),l=n):(u=n,l=n.slice()),i=0;o>i;i++)u[i]=l[e[i]];return u},shuffle:function(n,e){if(!0===e){var t=n.length,r=nn.Math.rndInt(0,t-1);return r>0&&n.push.apply(n,n.splice(0,r)),n}return g(n)},compose:function(){return j(rn.call(arguments))},concatenate:function(){return q(rn.call(arguments))},inverse:function(n){return T(n)},cycles:function(n,e){return-1===e?cycles2permutation(n):S(n)},swaps:function(n,e){return-1===e?L(n):$(n)},inversion:function(n,e){return-1===e?R(n):E(n)},matrix:function(n,e,t){return-1===t?N(n,e):P(n,e)},parity:e,is_permutation:X,is_identity:D,is_cyclic:V,is_derangement:G,is_involution:function(n){return J(n,1)},is_kthroot:function(n,e){return e>1?J(n,e-1):!1},is_connected:function(n){var e,t=n.length,r=-1;for(e=0;t-1>e;e++)if(n[e]>r&&(r=n[e]),e>=r)return!1;return!0}}}),Q=nn.Combination=hn(Y,{constructor:function Rn(n,e,t){var r=this;if(!(r instanceof Rn))return new Rn(n,e,t);if(an(n)?(t=e||{},e=n[1]||1,n=n[0]||1):(t=t||{},n=n||1,e=e||1),t.type=String(t.type||"unordered").toLowerCase(),-1n?r(e[1],e[0]-1,0):r(e[1],0,0):"ordered"===i?0>n?r(e[1],e[0]-1,-1):r(e[1],0,1):0>n?r(e[1],e[0]-e[1],1):r(e[1],0,1);return u},cascade:Y.cascade,dual:function(n,e,t,r){return n=Y.dual.call(this,n,e,t,r),r&&"binary"===r.type&&(n=y(n,t[0])),n},succ:function(n,e,t,r,i){return U(e,r,n,i&&i.type?i.type:"unordered")},rand:function(n,e){var t,i,u,l,o=e&&e.type?e.type:"unordered",a=n[1],s=nn.Math.rndInt;return n=n[0],i=n-a,u=n-1,"repeated"===o||"ordered+repeated"===o?(t=1===a?[s(0,u)]:r(a,function(){return s(0,u)}),a>1&&"repeated"===o&&v(t)):"ordered"===o?(l={},t=1===a?[s(0,u)]:n===a?g(r(a,0,1)):r(a,function(){for(var e=s(0,u);1===l[e];)e=(e+1)%n;return l[e]=1,e})):(l={},t=1===a?[s(0,u)]:n===a?r(a,0,1):a>i?b(n,v(r(i,function(){for(var e=s(0,u);1===l[e];)e=(e+1)%n;return l[e]=1,e}))):v(r(a,function(){for(var e=s(0,u);1===l[e];)e=(e+1)%n;return l[e]=1,e}))),t},randu:Y.rand,rank:function(n,e,t){var r,i,u,l,o,a=nn.Arithmetic,s=a.add,f=a.sub,c=a.mul,d=a.O,_=(a.I,d),m=e[1],h=t&&t.type?t.type:"unordered",b=nn.Math.factorial;if("ordered+repeated"===h)for(l=e[0],r=0;m>r;r++)_=s(c(_,l),n[r]);else if("repeated"===h){for(l=e[0]+m-1,o=t&&t.count?t.count:b(l,m),r=1;m>=r;r++)i=l-1-n[r-1]-r+1,u=m+1-r,i>=u&&(_=s(_,b(i,u)));_=f(f(o,a.I),_)}else{if("ordered"===h){for(l=e[0],n=E(n,l),r=0;m>r;r++)_=s(c(_,l-r),n[r]);return _}for(l=e[0],o=t&&t.count?t.count:b(l,m),r=1;m>=r;r++)i=l-1-n[r-1],u=m+1-r,i>=u&&(_=s(_,b(i,u)));_=f(f(o,a.I),_)}return _},unrank:function(n,e,t){var i,u,l,o,a,s,f,c=nn.Arithmetic,d=c.O,_=c.I,m=c.sub,h=c.div,b=c.mod,p=c.mul,v=c.lte,g=c.gt,x=c.val,y=e[1],A=t&&t.type?t.type:"unordered";if(e=e[0],i=r(y),"ordered+repeated"===A)for(o=n,s=y-1;s>=0;s--)a=b(o,e),o=h(o,e),i[s]=x(a);else if("ordered"===A){for(o=n,s=y-1;s>=0;s--)l=e-s,a=b(o,l),o=h(o,l),i[s]=x(a);i=R(i,e)}else{f="repeated"===A,l=f?e+y-1:e,u=t&&t.count?t.count:nn.Math.factorial(l,y),n=m(m(u,_),n),u=h(p(u,l-y),l),a=l-y+1,o=y,s=l-1;do v(u,n)?(i[y-o]=f?l-a-y+1:l-a-o+1,g(u,d)&&(n=m(n,u),u=h(p(u,o),s)),o--,s--):(u=h(p(u,s-o),s),a--,s--);while(o>0)}return i},complement:function(n,e,t){return!0===t?g(b(e,v(n))):b(e,n)},binary:function(n,e,t){return-1===t?A(n,e):y(n,e)},pick:function(n,e,t){return e>0&&n.length?x(n,e,"ordered+repeated"!==t&&"ordered"!==t,"ordered+repeated"===t||"repeated"===t,new Array(e)):[]},choose:function(n,e){return r(e.length,function(t){return n[e[t]]})}}}),Q.conjugate=Q.complement,Q.project=Q.choose,W=nn.Powerset=nn.Subset=hn(Y,{constructor:function kn(n,e){var t=this;return t instanceof kn?(e=e||{},e.type=e.type||"subset",n=n||1,n instanceof Y&&(e.sub=n,n=e.sub.base()),e.base=n,e.dimension=n,e.mindimension=0,e.maxdimension=n,void Y.call(t,"Subset",n,e)):new kn(n,e)},__static__:{C:function(n,e){return b(e,n)},P:Y.P,T:Y.T,count:function(n,e){return nn.Math.pow2(n)},initial:function(n,e,t){var i=0>n?r(e,0,1):[];return i},cascade:Y.cascade,dual:function(n,e,t,r){if(null==n)return null;var i=this,u=r&&r.order?r.order:0,l=i.C,o=i.P;return n=yn&u?pn&u?n.slice():o(n,t):xn&u?pn&u?n.slice():o(n,t):gn&u?pn&u?o(l(n,t),t):l(n,t):pn&u?n.slice():o(n,t),r&&"binary"===r.type&&(n=y(n,t)),n},succ:Y.succ,rand:function(n,e){for(var t,i=nn.Math.rndInt,u=null,l=n-1;l>=0;l--)i(0,1)&&(u={len:u?u.len+1:1,k:l,next:u});return t=u?r(u.len,function(n){var e=u.k;return u=u.next,e}):[]},randu:Y.rand,rank:function(n,e,t){for(var r=nn.Arithmetic,i=r.O,u=r.I,l=r.add,o=r.shl,a=i,s=0,f=subset.length;f>s;)a=l(a,o(u,subset[s++]));return a},unrank:function(n,e,t){var r=this,i=nn.Arithmetic,u=i.O,l=i.J,o=i.band,a=i.shr,s=i.gt,f=[],c=0;if(!i.inside(n,l,t&&t.count?t.count:r.count(e,t)))return null;for(;s(n,u);)s(o(n,1),u)&&f.push(c),s(o(n,2),u)&&f.push(c+1),s(o(n,4),u)&&f.push(c+2),s(o(n,8),u)&&f.push(c+3),s(o(n,16),u)&&f.push(c+4),s(o(n,32),u)&&f.push(c+5),s(o(n,64),u)&&f.push(c+6),s(o(n,128),u)&&f.push(c+7),c+=8,n=a(n,8);return f},binary:function(n,e,t){return-1===t?A(n,e):y(n,e)}}}),Z=nn.Partition=hn(Y,{constructor:function Sn(n,e){var t=this;if(!(t instanceof Sn))return new Sn(n,e);e=e||{},e.type=e.type||"partition",n=n||1,n instanceof Y&&(e.sub=n,n=e.sub.base());var r=e["max="]?0|e["max="]:null,i=e["parts="]?0|e["parts="]:null,u=i?i:r?n-r+1:n,l=i?i:r?fn.ceil(n/r):1;e.base=n,e.dimension=i||n,e.mindimension=fn.min(l,u),e.maxdimension=fn.max(l,u),Y.call(t,"Partition",n,e)},__static__:{C:function(n){return w(n)},P:Y.P,T:Y.T,count:function(n,e){var t,r,i=nn.Arithmetic.add,u=nn.Math.partitions,l=e&&e["max="]?0|e["max="]:null,o=e&&e["parts="]?0|e["parts="]:null,a=nn.Arithmetic.O,s=l?l:0,f=l?l:1,c=o?o:1,d=o?o:n;if(0>n||o&&l&&(o+l>n+1||n>o*l)||l&&l>n||o&&o>n)return a;for(l&&!o&&(s=0,f=1,c=l,d=l),t=c;d>=t;t++)for(r=s?s:n-t+1;r>=f;r--)a=i(a,u(n,t,r));return a},initial:function(n,e,t){var i,u,l,o=t&&t["max="]?0|t["max="]:null,a=t&&t["parts="]?0|t["parts="]:null;if(0>e)return null;if(a&&o)return null;if(a&&(o=a,a=null),o){if(o>e)return null;u=fn.floor(e/o),l=e%o,i=0>n?r(u,o,0).concat(l?[l]:[]):[o].concat(r(e-o,1,0))}else i=0>n?[e]:r(e,1,0);return i},cascade:Y.cascade,dual:function(n,e,t,i){if(null==n)return null;var u=this,l=(i&&i.order?i.order:0,i&&i["max="]?0|i["max="]:null),o=i&&i["parts="]?0|i["parts="]:null;return o&&!l&&(n=w(n)),i&&"unpacked"===i.type&&(n=I(n)),n=Y.dual.call(u,n,e,t,i),i&&"set"===i.type?O(n):(i&&"constant"===i.length&&n.lengthr||l&&u&&(l+u>r+1||r>l*u)||l&&l>r||u&&u>r?null:B(e,r,n,l,u)},rand:Y.rand,randu:Y.rand,rank:e,unrank:e,conjugate:w,sets:function(n,e){return-1===e?C(n):O(n)},pack:function(n,e){return-1===e?I(n):M(n)}}}),Z.transpose=Z.conjugate,nn}); \ No newline at end of file