(function(){function D(P){function c(a,b){this.value=a;this.sign=b;this.isSmall=!1}function e(a){this.value=a;this.sign=0>a;this.isSmall=!0}function p(a){return-9007199254740992a}function v(a){return 1E7>a?[a]:1E14>a?[a%1E7,Math.floor(a/1E7)]:[a%1E7,Math.floor(a/1E7)%1E7,Math.floor(a/1E14)]}function y(a){B(a);var b=a.length;if(4>b&&0>A(a,Q))switch(b){case 0:return 0;case 1:return a[0];case 2:return a[0]+1E7*a[1];default:return a[0]+1E7*(a[1]+1E7*a[2])}return a}function B(a){for(var b=
a.length;0===a[--b];);a.length=b+1}function K(a){for(var b=Array(a),d=-1;++d=b.length?x(a,b):x(b,a)}function L(a,b){var d=a.length,f=Array(d),c;for(c=0;cl?(l+=1E7,e=1):e=0;c[g]=l}for(g=f;gl)l+=1E7;else{c[g++]=l;break}c[g]=l}for(;gg?g+1E7:g}n=y(n);return"number"===typeof n?(d&&(n=-n),new e(n)):new c(n,d)}function R(a,b){var d=
a.length,f=b.length,c=K(d+f),e;for(e=0;e=d)return R(a,b);d=Math.ceil(d/2);var f=a.slice(d);
a=a.slice(0,d);var c=b.slice(d),e=b.slice(0,d);b=N(a,e);var g=N(f,c);f=N(E(a,f),E(e,c));d=E(E(b,D(F(F(f,b),g),d)),D(g,2*d));B(d);return d}function J(a,b,d){return 1E7>a?new c(G(b,a),d):new c(R(b,v(a)),d)}function T(a){var b=a.length,d=K(b+b),f;for(f=0;ff)return f=U(d,f),d=y(f[0]),f=f[1],a.sign&&(f=-f),"number"===typeof d?(a.sign!==b.sign&&(d=-d),[new e(d),new e(f)]):[new c(d,a.sign!==b.sign),new e(f)];f=v(f)}var n=A(d,f);if(-1===n)return[k[0],a];if(0===n)return[k[a.sign===b.sign?1:-1],k[0]];if(200>=
d.length+f.length){var h=f,g=d.length;f=h.length;n=K(h.length);var l=h[f-1],z=Math.ceil(1E7/(2*l));d=G(d,z);h=G(h,z);var q,r,t;d.length<=g&&d.push(0);h.push(0);l=h[f-1];for(q=g-f;0<=q;q--){g=9999999;d[q+f]!==l&&(g=Math.floor((1E7*d[q+f]+d[q+f-1])/l));var p=r=0;var u=h.length;for(t=0;tp?(d[q+t]=p+1E7,p=-1):(d[q+t]=p,p=0)}for(;0!==p;){--g;for(t=r=0;tr?(d[q+t]=r+1E7,r=0):(d[q+t]=r,r=1);p+=r}n[q]=g}d=U(d,z)[0];
f=[y(n),y(d)]}else{n=d.length;l=f.length;z=[];for(h=[];n;)if(h.unshift(d[--n]),0>A(h,f))z.push(0);else{g=h.length;q=1E7*h[g-1]+h[g-2];r=1E7*f[l-1]+f[l-2];g>l&&(q=1E7*(q+1));g=Math.ceil(q/r);do{q=G(f,g);if(0>=A(q,h))break;g--}while(g);z.push(g);h=F(h,q)}z.reverse();f=[y(z),y(h)]}d=f[0];b=a.sign!==b.sign;f=f[1];a=a.sign;"number"===typeof d?(b&&(d=-d),d=new e(d)):d=new c(d,b);"number"===typeof f?(a&&(f=-f),f=new e(f)):f=new c(f,a);return[d,f]}function A(a,b){if(a.length!==b.length)return a.length>b.length?
1:-1;for(var d=a.length-1;0<=d;d--)if(a[d]!==b[d])return a[d]>b[d]?1:-1;return 0}function V(a){a=a.abs();if(a.isUnit())return!1;if(a.equals(2)||a.equals(3)||a.equals(5))return!0;if(a.isEven()||a.isDivisibleBy(3)||a.isDivisibleBy(5))return!1;if(a.lesser(25))return!0}function W(a){return("number"===typeof a||"string"===typeof a)&&1E7>=+Math.abs(a)||a instanceof c&&1>=a.value.length}function S(a,b,d){b=m(b);var c=a.isNegative(),e=b.isNegative(),h=c?a.not():a,g=e?b.not():b;b=[];a=[];for(var l=!1,k=!1;!l||
!k;)h.isZero()?(l=!0,b.push(c?1:0)):c?b.push(h.isEven()?1:0):b.push(h.isEven()?0:1),g.isZero()?(k=!0,a.push(e?1:0)):e?a.push(g.isEven()?1:0):a.push(g.isEven()?0:1),h=h.over(2),g=g.over(2);c=[];for(e=0;e=a[0]?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(a[0]):"<"+a+">"}function ba(a,b){b=bigInt(b);if(b.isZero()){if(a.isZero())return"0";throw Error("Cannot convert nonzero numbers to base 0.");}if(b.equals(-1))return a.isZero()?"0":a.isNegative()?Array(1-a).join("10"):"1"+Array(+a).join("01");var d="";a.isNegative()&&b.isPositive()&&(d="-",a=a.abs());if(b.equals(1))return a.isZero()?"0":d+Array(+a+1).join(1);for(var c=[],e;a.isNegative()||0<=a.compareAbs(b);)e=a.divmod(b),a=e.quotient,
e=e.remainder,e.isNegative()&&(e=b.minus(e).abs(),a=a.next()),c.push(aa(e));c.push(aa(a));return d+c.reverse().join("")}function ca(a){if(p(+a)){var b=+a;if(b===C(b))return new e(b);throw"Invalid integer: "+a;}(b="-"===a[0])&&(a=a.slice(1));var d=a.split(/e/i);if(2a)throw Error("Cannot include negative exponent part for integers");a=f+=Array(a+1).join("0")}if(!/^([0-9][0-9]*)$/.test(a))throw Error("Invalid integer: "+a);f=[];d=a.length;for(var k=d-7;0k&&(k=0),d-=7;B(f);return new c(f,b)}function m(a){return"number"===typeof a?(a=p(a)?new e(a):ca(a.toString()),a):"string"===typeof a?ca(a):a}var Q=v(9007199254740992),ea=Math.log(9007199254740992);c.prototype.add=function(a){a=m(a);if(this.sign!==
a.sign)return this.subtract(a.negate());var b=this.value,d=a.value;return a.isSmall?new c(L(b,Math.abs(d)),this.sign):new c(E(b,d),this.sign)};c.prototype.plus=c.prototype.add;e.prototype.add=function(a){a=m(a);var b=this.value;if(0>b!==a.sign)return this.subtract(a.negate());var d=a.value;if(a.isSmall){if(p(b+d))return new e(b+d);d=v(Math.abs(d))}return new c(L(d,Math.abs(b)),0>b)};e.prototype.plus=e.prototype.add;c.prototype.subtract=function(a){var b=m(a);if(this.sign!==b.sign)return this.add(b.negate());
a=this.value;var d=b.value;if(b.isSmall)return M(a,Math.abs(d),this.sign);b=this.sign;0<=A(a,d)?a=F(a,d):(a=F(d,a),b=!b);a=y(a);"number"===typeof a?(b&&(a=-a),a=new e(a)):a=new c(a,b);return a};c.prototype.minus=c.prototype.subtract;e.prototype.subtract=function(a){a=m(a);var b=this.value;if(0>b!==a.sign)return this.add(a.negate());var d=a.value;return a.isSmall?new e(b-d):M(d,Math.abs(b),0<=b)};e.prototype.minus=e.prototype.subtract;c.prototype.negate=function(){return new c(this.value,!this.sign)};
e.prototype.negate=function(){var a=this.sign,b=new e(-this.value);b.sign=!a;return b};c.prototype.abs=function(){return new c(this.value,!1)};e.prototype.abs=function(){return new e(Math.abs(this.value))};c.prototype.multiply=function(a){var b=m(a);a=this.value;var d=b.value,e=this.sign!==b.sign;if(b.isSmall){if(0===d)return k[0];if(1===d)return this;if(-1===d)return this.negate();b=Math.abs(d);if(1E7>b)return new c(G(a,b),e);d=v(b)}return 4E3d?1:-1):-1};c.prototype.compare=function(a){if(Infinity===a)return-1;if(-Infinity===a)return 1;a=m(a);return this.sign!==
a.sign?a.sign?1:-1:a.isSmall?this.sign?-1:1:A(this.value,a.value)*(this.sign?-1:1)};c.prototype.compareTo=c.prototype.compare;e.prototype.compare=function(a){if(Infinity===a)return-1;if(-Infinity===a)return 1;a=m(a);var b=this.value,d=a.value;return a.isSmall?b==d?0:b>d?1:-1:0>b!==a.sign?0>b?-1:1:0>b?1:-1};e.prototype.compareTo=e.prototype.compare;c.prototype.equals=function(a){return 0===this.compare(a)};e.prototype.eq=e.prototype.equals=c.prototype.eq=c.prototype.equals;c.prototype.notEquals=function(a){return 0!==
this.compare(a)};e.prototype.neq=e.prototype.notEquals=c.prototype.neq=c.prototype.notEquals;c.prototype.greater=function(a){return 0this.compare(a)};e.prototype.lt=e.prototype.lesser=c.prototype.lt=c.prototype.lesser;c.prototype.greaterOrEquals=function(a){return 0<=this.compare(a)};e.prototype.geq=e.prototype.greaterOrEquals=c.prototype.geq=c.prototype.greaterOrEquals;
c.prototype.lesserOrEquals=function(a){return 0>=this.compare(a)};e.prototype.leq=e.prototype.lesserOrEquals=c.prototype.leq=c.prototype.lesserOrEquals;c.prototype.isEven=function(){return 0===(this.value[0]&1)};e.prototype.isEven=function(){return 0===(this.value&1)};c.prototype.isOdd=function(){return 1===(this.value[0]&1)};e.prototype.isOdd=function(){return 1===(this.value&1)};c.prototype.isPositive=function(){return!this.sign};e.prototype.isPositive=function(){return 0this.value};c.prototype.isUnit=function(){return 1===Math.abs(this.value)};e.prototype.isUnit=function(){return 1===Math.abs(this.value)};c.prototype.isZero=function(){return!1};e.prototype.isZero=function(){return 0===this.value};c.prototype.isDivisibleBy=function(a){a=m(a);var b=a.value;return 0===b?!1:1===b?!0:2===b?this.isEven():this.mod(a).equals(k[0])};e.prototype.isDivisibleBy=c.prototype.isDivisibleBy;c.prototype.isPrime=
function(){var a=V(this);if(void 0!==a)return a;a=this.abs();for(var b=a.prev(),d=[2,3,5,7,11,13,17,19],c=b,e,h,g,l;c.isEven();)c=c.divide(2);for(g=0;ga+1?new e(a+1):new c(Q,!1)};c.prototype.prev=function(){var a=this.value;return this.sign?new c(L(a,1),!0):M(a,1,this.sign)};e.prototype.prev=function(){var a=this.value;return-9007199254740992=u[u.length-1];)u.push(2*u[u.length-1]);var I=u.length,da=u[I-1];c.prototype.shiftLeft=function(a){if(!W(a))throw Error(String(a)+" is too large for shifting.");a=+a;if(0>a)return this.shiftRight(-a);for(var b=this;a>=I;)b=b.multiply(da),a-=I-1;return b.multiply(u[a])};e.prototype.shiftLeft=c.prototype.shiftLeft;c.prototype.shiftRight=function(a){var b;if(!W(a))throw Error(String(a)+" is too large for shifting.");a=+a;if(0>a)return this.shiftLeft(-a);for(b=this;a>=I;){if(b.isZero())return b;
b=H(b,da);b=b[1].isNegative()?b[0].prev():b[0];a-=I-1}b=H(b,u[a]);return b[1].isNegative()?b[0].prev():b[0]};e.prototype.shiftRight=c.prototype.shiftRight;c.prototype.not=function(){return this.negate().prev()};e.prototype.not=c.prototype.not;c.prototype.and=function(a){return S(this,a,function(a,d){return a&d})};e.prototype.and=c.prototype.and;c.prototype.or=function(a){return S(this,a,function(a,d){return a|d})};e.prototype.or=c.prototype.or;c.prototype.xor=function(a){return S(this,a,function(a,
d){return a^d})};e.prototype.xor=c.prototype.xor;c.prototype.toString=function(a){void 0===a&&(a=10);if(10!==a)return ba(this,a);a=this.value;for(var b=a.length,d=String(a[--b]),c;0<=--b;)c=String(a[b]),d+="0000000".slice(c.length)+c;return(this.sign?"-":"")+d};e.prototype.toString=function(a){void 0===a&&(a=10);return 10!=a?ba(this,a):String(this.value)};c.prototype.valueOf=function(){return+this.toString()};c.prototype.toJSNumber=c.prototype.valueOf;e.prototype.valueOf=function(){return this.value};
e.prototype.toJSNumber=e.prototype.valueOf;for(var k=function(a,b){if("undefined"===typeof a)return k[0];if("undefined"!==typeof b){if(10===+b)a=m(a);else{var d=k[0],c=k[1],n=a.length;if(2<=b&&36>=b&&n<=ea/Math.log(b))a=new e(parseInt(a,b));else{b=m(b);n=[];var h,g="-"===a[0];for(h=g?1:0;h=p)n.push(m(l));else if(97<=p&&122>=p)n.push(m(l.charCodeAt(0)-87));else if("<"===l){l=h;do h++;while(">"!==a[h]);n.push(m(a.slice(l+1,h)))}else throw Error(l+
" is not a valid character");}n.reverse();for(h=0;hw;w++)k[w]=new e(w),0