UNPKG

jscofhe

Version:
1 lines 68.5 kB
var t=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,e=Math.ceil,n=Math.floor,r="[BigNumber Error] ",i=r+"Number primitive has more than 15 significant digits: ",s=1e14,o=14,a=9007199254740991,_=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],c=1e7,u=1e9;function l(t){var e=0|t;return t>0||t===e?e:e-1}function h(t){for(var e,n,r=1,i=t.length,s=t[0]+"";r<i;){for(e=t[r++]+"",n=o-e.length;n--;e="0"+e);s+=e}for(i=s.length;48===s.charCodeAt(--i););return s.slice(0,i+1||1)}function m(t,e){var n,r,i=t.c,s=e.c,o=t.s,a=e.s,_=t.e,c=e.e;if(!o||!a)return null;if(n=i&&!i[0],r=s&&!s[0],n||r)return n?r?0:-a:o;if(o!=a)return o;if(n=o<0,r=_==c,!i||!s)return r?0:!i^n?1:-1;if(!r)return _>c^n?1:-1;for(a=(_=i.length)<(c=s.length)?_:c,o=0;o<a;o++)if(i[o]!=s[o])return i[o]>s[o]^n?1:-1;return _==c?0:_>c^n?1:-1}function f(t,e,i,s){if(t<e||t>i||t!==n(t))throw Error(r+(s||"Argument")+("number"==typeof t?t<e||t>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function d(t){var e=t.c.length-1;return l(t.e/o)==e&&t.c[e]%2!=0}function p(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function g(t,e,n){var r,i;if(e<0){for(i=n+".";++e;i+=n);t=i+t}else if(++e>(r=t.length)){for(i=n,e-=r;--e;i+=n);t+=i}else e<r&&(t=t.slice(0,e)+"."+t.slice(e));return t}var w=function w(y){var E,b,I,B,v,k,N,A,x,R,S=G.prototype={constructor:G,toString:null,valueOf:null},O=new G(1),T=20,D=4,C=-7,z=21,U=-1e7,P=1e7,M=!1,L=1,q=0,F={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},H="0123456789abcdefghijklmnopqrstuvwxyz",Q=!0;function G(e,r){var s,_,c,u,l,h,m,d,p=this;if(!(p instanceof G))return new G(e,r);if(null==r){if(e&&!0===e._isBigNumber)return p.s=e.s,void(!e.c||e.e>P?p.c=p.e=null:e.e<U?p.c=[p.e=0]:(p.e=e.e,p.c=e.c.slice()));if((h="number"==typeof e)&&0*e==0){if(p.s=1/e<0?(e=-e,-1):1,e===~~e){for(u=0,l=e;l>=10;l/=10,u++);return void(u>P?p.c=p.e=null:(p.e=u,p.c=[e]))}d=String(e)}else{if(!t.test(d=String(e)))return I(p,d,h);p.s=45==d.charCodeAt(0)?(d=d.slice(1),-1):1}(u=d.indexOf("."))>-1&&(d=d.replace(".","")),(l=d.search(/e/i))>0?(u<0&&(u=l),u+=+d.slice(l+1),d=d.substring(0,l)):u<0&&(u=d.length)}else{if(f(r,2,H.length,"Base"),10==r&&Q)return K(p=new G(e),T+p.e+1,D);if(d=String(e),h="number"==typeof e){if(0*e!=0)return I(p,d,h,r);if(p.s=1/e<0?(d=d.slice(1),-1):1,G.DEBUG&&d.replace(/^0\.0*|\./,"").length>15)throw Error(i+e)}else p.s=45===d.charCodeAt(0)?(d=d.slice(1),-1):1;for(s=H.slice(0,r),u=l=0,m=d.length;l<m;l++)if(s.indexOf(_=d.charAt(l))<0){if("."==_){if(l>u){u=m;continue}}else if(!c&&(d==d.toUpperCase()&&(d=d.toLowerCase())||d==d.toLowerCase()&&(d=d.toUpperCase()))){c=!0,l=-1,u=0;continue}return I(p,String(e),h,r)}h=!1,(u=(d=b(d,r,10,p.s)).indexOf("."))>-1?d=d.replace(".",""):u=d.length}for(l=0;48===d.charCodeAt(l);l++);for(m=d.length;48===d.charCodeAt(--m););if(d=d.slice(l,++m)){if(m-=l,h&&G.DEBUG&&m>15&&(e>a||e!==n(e)))throw Error(i+p.s*e);if((u=u-l-1)>P)p.c=p.e=null;else if(u<U)p.c=[p.e=0];else{if(p.e=u,p.c=[],l=(u+1)%o,u<0&&(l+=o),l<m){for(l&&p.c.push(+d.slice(0,l)),m-=o;l<m;)p.c.push(+d.slice(l,l+=o));l=o-(d=d.slice(l)).length}else l-=m;for(;l--;d+="0");p.c.push(+d)}}else p.c=[p.e=0]}function $(t,e,n,r){var i,s,o,a,_;if(null==n?n=D:f(n,0,8),!t.c)return t.toString();if(i=t.c[0],o=t.e,null==e)_=h(t.c),_=1==r||2==r&&(o<=C||o>=z)?p(_,o):g(_,o,"0");else if(s=(t=K(new G(t),e,n)).e,a=(_=h(t.c)).length,1==r||2==r&&(e<=s||s<=C)){for(;a<e;_+="0",a++);_=p(_,s)}else if(e-=o,_=g(_,s,"0"),s+1>a){if(--e>0)for(_+=".";e--;_+="0");}else if((e+=s-a)>0)for(s+1==a&&(_+=".");e--;_+="0");return t.s<0&&i?"-"+_:_}function V(t,e){for(var n,r,i=1,s=new G(t[0]);i<t.length;i++)(!(r=new G(t[i])).s||(n=m(s,r))===e||0===n&&s.s===e)&&(s=r);return s}function j(t,e,n){for(var r=1,i=e.length;!e[--i];e.pop());for(i=e[0];i>=10;i/=10,r++);return(n=r+n*o-1)>P?t.c=t.e=null:n<U?t.c=[t.e=0]:(t.e=n,t.c=e),t}function K(t,r,i,a){var c,u,l,h,m,f,d,p=t.c,g=_;if(p){t:{for(c=1,h=p[0];h>=10;h/=10,c++);if((u=r-c)<0)u+=o,l=r,m=p[f=0],d=n(m/g[c-l-1]%10);else if((f=e((u+1)/o))>=p.length){if(!a)break t;for(;p.length<=f;p.push(0));m=d=0,c=1,l=(u%=o)-o+1}else{for(m=h=p[f],c=1;h>=10;h/=10,c++);d=(l=(u%=o)-o+c)<0?0:n(m/g[c-l-1]%10)}if(a=a||r<0||null!=p[f+1]||(l<0?m:m%g[c-l-1]),a=i<4?(d||a)&&(0==i||i==(t.s<0?3:2)):d>5||5==d&&(4==i||a||6==i&&(u>0?l>0?m/g[c-l]:0:p[f-1])%10&1||i==(t.s<0?8:7)),r<1||!p[0])return p.length=0,a?(r-=t.e+1,p[0]=g[(o-r%o)%o],t.e=-r||0):p[0]=t.e=0,t;if(0==u?(p.length=f,h=1,f--):(p.length=f+1,h=g[o-u],p[f]=l>0?n(m/g[c-l]%g[l])*h:0),a)for(;;){if(0==f){for(u=1,l=p[0];l>=10;l/=10,u++);for(l=p[0]+=h,h=1;l>=10;l/=10,h++);u!=h&&(t.e++,p[0]==s&&(p[0]=1));break}if(p[f]+=h,p[f]!=s)break;p[f--]=0,h=1}for(u=p.length;0===p[--u];p.pop());}t.e>P?t.c=t.e=null:t.e<U&&(t.c=[t.e=0])}return t}function Y(t){var e,n=t.e;return null===n?t.toString():(e=h(t.c),e=n<=C||n>=z?p(e,n):g(e,n,"0"),t.s<0?"-"+e:e)}return G.clone=w,G.ROUND_UP=0,G.ROUND_DOWN=1,G.ROUND_CEIL=2,G.ROUND_FLOOR=3,G.ROUND_HALF_UP=4,G.ROUND_HALF_DOWN=5,G.ROUND_HALF_EVEN=6,G.ROUND_HALF_CEIL=7,G.ROUND_HALF_FLOOR=8,G.EUCLID=9,G.config=G.set=function(t){var e,n;if(null!=t){if("object"!=typeof t)throw Error(r+"Object expected: "+t);if(t.hasOwnProperty(e="DECIMAL_PLACES")&&(f(n=t[e],0,u,e),T=n),t.hasOwnProperty(e="ROUNDING_MODE")&&(f(n=t[e],0,8,e),D=n),t.hasOwnProperty(e="EXPONENTIAL_AT")&&((n=t[e])&&n.pop?(f(n[0],-1e9,0,e),f(n[1],0,u,e),C=n[0],z=n[1]):(f(n,-1e9,u,e),C=-(z=n<0?-n:n))),t.hasOwnProperty(e="RANGE"))if((n=t[e])&&n.pop)f(n[0],-1e9,-1,e),f(n[1],1,u,e),U=n[0],P=n[1];else{if(f(n,-1e9,u,e),!n)throw Error(r+e+" cannot be zero: "+n);U=-(P=n<0?-n:n)}if(t.hasOwnProperty(e="CRYPTO")){if((n=t[e])!==!!n)throw Error(r+e+" not true or false: "+n);if(n){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw M=!n,Error(r+"crypto unavailable");M=n}else M=n}if(t.hasOwnProperty(e="MODULO_MODE")&&(f(n=t[e],0,9,e),L=n),t.hasOwnProperty(e="POW_PRECISION")&&(f(n=t[e],0,u,e),q=n),t.hasOwnProperty(e="FORMAT")){if("object"!=typeof(n=t[e]))throw Error(r+e+" not an object: "+n);F=n}if(t.hasOwnProperty(e="ALPHABET")){if("string"!=typeof(n=t[e])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(r+e+" invalid: "+n);Q="0123456789"==n.slice(0,10),H=n}}return{DECIMAL_PLACES:T,ROUNDING_MODE:D,EXPONENTIAL_AT:[C,z],RANGE:[U,P],CRYPTO:M,MODULO_MODE:L,POW_PRECISION:q,FORMAT:F,ALPHABET:H}},G.isBigNumber=function(t){if(!t||!0!==t._isBigNumber)return!1;if(!G.DEBUG)return!0;var e,i,a=t.c,_=t.e,c=t.s;t:if("[object Array]"=={}.toString.call(a)){if((1===c||-1===c)&&_>=-1e9&&_<=u&&_===n(_)){if(0===a[0]){if(0===_&&1===a.length)return!0;break t}if((e=(_+1)%o)<1&&(e+=o),String(a[0]).length==e){for(e=0;e<a.length;e++)if((i=a[e])<0||i>=s||i!==n(i))break t;if(0!==i)return!0}}}else if(null===a&&null===_&&(null===c||1===c||-1===c))return!0;throw Error(r+"Invalid BigNumber: "+t)},G.maximum=G.max=function(){return V(arguments,-1)},G.minimum=G.min=function(){return V(arguments,1)},G.random=(B=9007199254740992,v=Math.random()*B&2097151?function(){return n(Math.random()*B)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(t){var i,s,a,c,l,h=0,m=[],d=new G(O);if(null==t?t=T:f(t,0,u),c=e(t/o),M)if(crypto.getRandomValues){for(i=crypto.getRandomValues(new Uint32Array(c*=2));h<c;)(l=131072*i[h]+(i[h+1]>>>11))>=9e15?(s=crypto.getRandomValues(new Uint32Array(2)),i[h]=s[0],i[h+1]=s[1]):(m.push(l%1e14),h+=2);h=c/2}else{if(!crypto.randomBytes)throw M=!1,Error(r+"crypto unavailable");for(i=crypto.randomBytes(c*=7);h<c;)(l=281474976710656*(31&i[h])+1099511627776*i[h+1]+4294967296*i[h+2]+16777216*i[h+3]+(i[h+4]<<16)+(i[h+5]<<8)+i[h+6])>=9e15?crypto.randomBytes(7).copy(i,h):(m.push(l%1e14),h+=7);h=c/7}if(!M)for(;h<c;)(l=v())<9e15&&(m[h++]=l%1e14);for(c=m[--h],t%=o,c&&t&&(l=_[o-t],m[h]=n(c/l)*l);0===m[h];m.pop(),h--);if(h<0)m=[a=0];else{for(a=-1;0===m[0];m.splice(0,1),a-=o);for(h=1,l=m[0];l>=10;l/=10,h++);h<o&&(a-=o-h)}return d.e=a,d.c=m,d}),G.sum=function(){for(var t=1,e=arguments,n=new G(e[0]);t<e.length;)n=n.plus(e[t++]);return n},b=function(){var t="0123456789";function e(t,e,n,r){for(var i,s,o=[0],a=0,_=t.length;a<_;){for(s=o.length;s--;o[s]*=e);for(o[0]+=r.indexOf(t.charAt(a++)),i=0;i<o.length;i++)o[i]>n-1&&(null==o[i+1]&&(o[i+1]=0),o[i+1]+=o[i]/n|0,o[i]%=n)}return o.reverse()}return function(n,r,i,s,o){var a,_,c,u,l,m,f,d,p=n.indexOf("."),w=T,y=D;for(p>=0&&(u=q,q=0,n=n.replace(".",""),m=(d=new G(r)).pow(n.length-p),q=u,d.c=e(g(h(m.c),m.e,"0"),10,i,t),d.e=d.c.length),c=u=(f=e(n,r,i,o?(a=H,t):(a=t,H))).length;0==f[--u];f.pop());if(!f[0])return a.charAt(0);if(p<0?--c:(m.c=f,m.e=c,m.s=s,f=(m=E(m,d,w,y,i)).c,l=m.r,c=m.e),p=f[_=c+w+1],u=i/2,l=l||_<0||null!=f[_+1],l=y<4?(null!=p||l)&&(0==y||y==(m.s<0?3:2)):p>u||p==u&&(4==y||l||6==y&&1&f[_-1]||y==(m.s<0?8:7)),_<1||!f[0])n=l?g(a.charAt(1),-w,a.charAt(0)):a.charAt(0);else{if(f.length=_,l)for(--i;++f[--_]>i;)f[_]=0,_||(++c,f=[1].concat(f));for(u=f.length;!f[--u];);for(p=0,n="";p<=u;n+=a.charAt(f[p++]));n=g(n,c,a.charAt(0))}return n}}(),E=function(){function t(t,e,n){var r,i,s,o,a=0,_=t.length,u=e%c,l=e/c|0;for(t=t.slice();_--;)a=((i=u*(s=t[_]%c)+(r=l*s+(o=t[_]/c|0)*u)%c*c+a)/n|0)+(r/c|0)+l*o,t[_]=i%n;return a&&(t=[a].concat(t)),t}function e(t,e,n,r){var i,s;if(n!=r)s=n>r?1:-1;else for(i=s=0;i<n;i++)if(t[i]!=e[i]){s=t[i]>e[i]?1:-1;break}return s}function r(t,e,n,r){for(var i=0;n--;)t[n]-=i,i=t[n]<e[n]?1:0,t[n]=i*r+t[n]-e[n];for(;!t[0]&&t.length>1;t.splice(0,1));}return function(i,a,_,c,u){var h,m,f,d,p,g,w,y,E,b,I,B,v,k,N,A,x,R=i.s==a.s?1:-1,S=i.c,O=a.c;if(!(S&&S[0]&&O&&O[0]))return new G(i.s&&a.s&&(S?!O||S[0]!=O[0]:O)?S&&0==S[0]||!O?0*R:R/0:NaN);for(E=(y=new G(R)).c=[],R=_+(m=i.e-a.e)+1,u||(u=s,m=l(i.e/o)-l(a.e/o),R=R/o|0),f=0;O[f]==(S[f]||0);f++);if(O[f]>(S[f]||0)&&m--,R<0)E.push(1),d=!0;else{for(k=S.length,A=O.length,f=0,R+=2,(p=n(u/(O[0]+1)))>1&&(O=t(O,p,u),S=t(S,p,u),A=O.length,k=S.length),v=A,I=(b=S.slice(0,A)).length;I<A;b[I++]=0);x=O.slice(),x=[0].concat(x),N=O[0],O[1]>=u/2&&N++;do{if(p=0,(h=e(O,b,A,I))<0){if(B=b[0],A!=I&&(B=B*u+(b[1]||0)),(p=n(B/N))>1)for(p>=u&&(p=u-1),w=(g=t(O,p,u)).length,I=b.length;1==e(g,b,w,I);)p--,r(g,A<w?x:O,w,u),w=g.length,h=1;else 0==p&&(h=p=1),w=(g=O.slice()).length;if(w<I&&(g=[0].concat(g)),r(b,g,I,u),I=b.length,-1==h)for(;e(O,b,A,I)<1;)p++,r(b,A<I?x:O,I,u),I=b.length}else 0===h&&(p++,b=[0]);E[f++]=p,b[0]?b[I++]=S[v]||0:(b=[S[v]],I=1)}while((v++<k||null!=b[0])&&R--);d=null!=b[0],E[0]||E.splice(0,1)}if(u==s){for(f=1,R=E[0];R>=10;R/=10,f++);K(y,_+(y.e=f+m*o-1)+1,c,d)}else y.e=m,y.r=+d;return y}}(),k=/^(-?)0([xbo])(?=\w[\w.]*$)/i,N=/^([^.]+)\.$/,A=/^\.([^.]+)$/,x=/^-?(Infinity|NaN)$/,R=/^\s*\+(?=[\w.])|^\s+|\s+$/g,I=function(t,e,n,i){var s,o=n?e:e.replace(R,"");if(x.test(o))t.s=isNaN(o)?null:o<0?-1:1;else{if(!n&&(o=o.replace(k,(function(t,e,n){return s="x"==(n=n.toLowerCase())?16:"b"==n?2:8,i&&i!=s?t:e})),i&&(s=i,o=o.replace(N,"$1").replace(A,"0.$1")),e!=o))return new G(o,s);if(G.DEBUG)throw Error(r+"Not a"+(i?" base "+i:"")+" number: "+e);t.s=null}t.c=t.e=null},S.absoluteValue=S.abs=function(){var t=new G(this);return t.s<0&&(t.s=1),t},S.comparedTo=function(t,e){return m(this,new G(t,e))},S.decimalPlaces=S.dp=function(t,e){var n,r,i,s=this;if(null!=t)return f(t,0,u),null==e?e=D:f(e,0,8),K(new G(s),t+s.e+1,e);if(!(n=s.c))return null;if(r=((i=n.length-1)-l(this.e/o))*o,i=n[i])for(;i%10==0;i/=10,r--);return r<0&&(r=0),r},S.dividedBy=S.div=function(t,e){return E(this,new G(t,e),T,D)},S.dividedToIntegerBy=S.idiv=function(t,e){return E(this,new G(t,e),0,1)},S.exponentiatedBy=S.pow=function(t,i){var s,a,_,c,u,l,h,m,f=this;if((t=new G(t)).c&&!t.isInteger())throw Error(r+"Exponent not an integer: "+Y(t));if(null!=i&&(i=new G(i)),u=t.e>14,!f.c||!f.c[0]||1==f.c[0]&&!f.e&&1==f.c.length||!t.c||!t.c[0])return m=new G(Math.pow(+Y(f),u?t.s*(2-d(t)):+Y(t))),i?m.mod(i):m;if(l=t.s<0,i){if(i.c?!i.c[0]:!i.s)return new G(NaN);(a=!l&&f.isInteger()&&i.isInteger())&&(f=f.mod(i))}else{if(t.e>9&&(f.e>0||f.e<-1||(0==f.e?f.c[0]>1||u&&f.c[1]>=24e7:f.c[0]<8e13||u&&f.c[0]<=9999975e7)))return c=f.s<0&&d(t)?-0:0,f.e>-1&&(c=1/c),new G(l?1/c:c);q&&(c=e(q/o+2))}for(u?(s=new G(.5),l&&(t.s=1),h=d(t)):h=(_=Math.abs(+Y(t)))%2,m=new G(O);;){if(h){if(!(m=m.times(f)).c)break;c?m.c.length>c&&(m.c.length=c):a&&(m=m.mod(i))}if(_){if(0===(_=n(_/2)))break;h=_%2}else if(K(t=t.times(s),t.e+1,1),t.e>14)h=d(t);else{if(0===(_=+Y(t)))break;h=_%2}f=f.times(f),c?f.c&&f.c.length>c&&(f.c.length=c):a&&(f=f.mod(i))}return a?m:(l&&(m=O.div(m)),i?m.mod(i):c?K(m,q,D,undefined):m)},S.integerValue=function(t){var e=new G(this);return null==t?t=D:f(t,0,8),K(e,e.e+1,t)},S.isEqualTo=S.eq=function(t,e){return 0===m(this,new G(t,e))},S.isFinite=function(){return!!this.c},S.isGreaterThan=S.gt=function(t,e){return m(this,new G(t,e))>0},S.isGreaterThanOrEqualTo=S.gte=function(t,e){return 1===(e=m(this,new G(t,e)))||0===e},S.isInteger=function(){return!!this.c&&l(this.e/o)>this.c.length-2},S.isLessThan=S.lt=function(t,e){return m(this,new G(t,e))<0},S.isLessThanOrEqualTo=S.lte=function(t,e){return-1===(e=m(this,new G(t,e)))||0===e},S.isNaN=function(){return!this.s},S.isNegative=function(){return this.s<0},S.isPositive=function(){return this.s>0},S.isZero=function(){return!!this.c&&0==this.c[0]},S.minus=function(t,e){var n,r,i,a,_=this,c=_.s;if(e=(t=new G(t,e)).s,!c||!e)return new G(NaN);if(c!=e)return t.s=-e,_.plus(t);var u=_.e/o,h=t.e/o,m=_.c,f=t.c;if(!u||!h){if(!m||!f)return m?(t.s=-e,t):new G(f?_:NaN);if(!m[0]||!f[0])return f[0]?(t.s=-e,t):new G(m[0]?_:3==D?-0:0)}if(u=l(u),h=l(h),m=m.slice(),c=u-h){for((a=c<0)?(c=-c,i=m):(h=u,i=f),i.reverse(),e=c;e--;i.push(0));i.reverse()}else for(r=(a=(c=m.length)<(e=f.length))?c:e,c=e=0;e<r;e++)if(m[e]!=f[e]){a=m[e]<f[e];break}if(a&&(i=m,m=f,f=i,t.s=-t.s),(e=(r=f.length)-(n=m.length))>0)for(;e--;m[n++]=0);for(e=s-1;r>c;){if(m[--r]<f[r]){for(n=r;n&&!m[--n];m[n]=e);--m[n],m[r]+=s}m[r]-=f[r]}for(;0==m[0];m.splice(0,1),--h);return m[0]?j(t,m,h):(t.s=3==D?-1:1,t.c=[t.e=0],t)},S.modulo=S.mod=function(t,e){var n,r,i=this;return t=new G(t,e),!i.c||!t.s||t.c&&!t.c[0]?new G(NaN):!t.c||i.c&&!i.c[0]?new G(i):(9==L?(r=t.s,t.s=1,n=E(i,t,0,3),t.s=r,n.s*=r):n=E(i,t,0,L),(t=i.minus(n.times(t))).c[0]||1!=L||(t.s=i.s),t)},S.multipliedBy=S.times=function(t,e){var n,r,i,a,_,u,h,m,f,d,p,g,w,y,E,b=this,I=b.c,B=(t=new G(t,e)).c;if(!(I&&B&&I[0]&&B[0]))return!b.s||!t.s||I&&!I[0]&&!B||B&&!B[0]&&!I?t.c=t.e=t.s=null:(t.s*=b.s,I&&B?(t.c=[0],t.e=0):t.c=t.e=null),t;for(r=l(b.e/o)+l(t.e/o),t.s*=b.s,(h=I.length)<(d=B.length)&&(w=I,I=B,B=w,i=h,h=d,d=i),i=h+d,w=[];i--;w.push(0));for(y=s,E=c,i=d;--i>=0;){for(n=0,p=B[i]%E,g=B[i]/E|0,a=i+(_=h);a>i;)n=((m=p*(m=I[--_]%E)+(u=g*m+(f=I[_]/E|0)*p)%E*E+w[a]+n)/y|0)+(u/E|0)+g*f,w[a--]=m%y;w[a]=n}return n?++r:w.splice(0,1),j(t,w,r)},S.negated=function(){var t=new G(this);return t.s=-t.s||null,t},S.plus=function(t,e){var n,r=this,i=r.s;if(e=(t=new G(t,e)).s,!i||!e)return new G(NaN);if(i!=e)return t.s=-e,r.minus(t);var a=r.e/o,_=t.e/o,c=r.c,u=t.c;if(!a||!_){if(!c||!u)return new G(i/0);if(!c[0]||!u[0])return u[0]?t:new G(c[0]?r:0*i)}if(a=l(a),_=l(_),c=c.slice(),i=a-_){for(i>0?(_=a,n=u):(i=-i,n=c),n.reverse();i--;n.push(0));n.reverse()}for((i=c.length)-(e=u.length)<0&&(n=u,u=c,c=n,e=i),i=0;e;)i=(c[--e]=c[e]+u[e]+i)/s|0,c[e]=s===c[e]?0:c[e]%s;return i&&(c=[i].concat(c),++_),j(t,c,_)},S.precision=S.sd=function(t,e){var n,r,i,s=this;if(null!=t&&t!==!!t)return f(t,1,u),null==e?e=D:f(e,0,8),K(new G(s),t,e);if(!(n=s.c))return null;if(r=(i=n.length-1)*o+1,i=n[i]){for(;i%10==0;i/=10,r--);for(i=n[0];i>=10;i/=10,r++);}return t&&s.e+1>r&&(r=s.e+1),r},S.shiftedBy=function(t){return f(t,-9007199254740991,a),this.times("1e"+t)},S.squareRoot=S.sqrt=function(){var t,e,n,r,i,s=this,o=s.c,a=s.s,_=s.e,c=T+4,u=new G("0.5");if(1!==a||!o||!o[0])return new G(!a||a<0&&(!o||o[0])?NaN:o?s:1/0);if(0==(a=Math.sqrt(+Y(s)))||a==1/0?(((e=h(o)).length+_)%2==0&&(e+="0"),a=Math.sqrt(+e),_=l((_+1)/2)-(_<0||_%2),n=new G(e=a==1/0?"5e"+_:(e=a.toExponential()).slice(0,e.indexOf("e")+1)+_)):n=new G(a+""),n.c[0])for((a=(_=n.e)+c)<3&&(a=0);;)if(i=n,n=u.times(i.plus(E(s,i,c,1))),h(i.c).slice(0,a)===(e=h(n.c)).slice(0,a)){if(n.e<_&&--a,"9999"!=(e=e.slice(a-3,a+1))&&(r||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(K(n,n.e+T+2,1),t=!n.times(n).eq(s));break}if(!r&&(K(i,i.e+T+2,0),i.times(i).eq(s))){n=i;break}c+=4,a+=4,r=1}return K(n,n.e+T+1,D,t)},S.toExponential=function(t,e){return null!=t&&(f(t,0,u),t++),$(this,t,e,1)},S.toFixed=function(t,e){return null!=t&&(f(t,0,u),t=t+this.e+1),$(this,t,e)},S.toFormat=function(t,e,n){var i,s=this;if(null==n)null!=t&&e&&"object"==typeof e?(n=e,e=null):t&&"object"==typeof t?(n=t,t=e=null):n=F;else if("object"!=typeof n)throw Error(r+"Argument not an object: "+n);if(i=s.toFixed(t,e),s.c){var o,a=i.split("."),_=+n.groupSize,c=+n.secondaryGroupSize,u=n.groupSeparator||"",l=a[0],h=a[1],m=s.s<0,f=m?l.slice(1):l,d=f.length;if(c&&(o=_,_=c,c=o,d-=o),_>0&&d>0){for(o=d%_||_,l=f.substr(0,o);o<d;o+=_)l+=u+f.substr(o,_);c>0&&(l+=u+f.slice(o)),m&&(l="-"+l)}i=h?l+(n.decimalSeparator||"")+((c=+n.fractionGroupSize)?h.replace(new RegExp("\\d{"+c+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):h):l}return(n.prefix||"")+i+(n.suffix||"")},S.toFraction=function(t){var e,n,i,s,a,c,u,l,m,f,d,p,g=this,w=g.c;if(null!=t&&(!(u=new G(t)).isInteger()&&(u.c||1!==u.s)||u.lt(O)))throw Error(r+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+Y(u));if(!w)return new G(g);for(e=new G(O),m=n=new G(O),i=l=new G(O),p=h(w),a=e.e=p.length-g.e-1,e.c[0]=_[(c=a%o)<0?o+c:c],t=!t||u.comparedTo(e)>0?a>0?e:m:u,c=P,P=1/0,u=new G(p),l.c[0]=0;f=E(u,e,0,1),1!=(s=n.plus(f.times(i))).comparedTo(t);)n=i,i=s,m=l.plus(f.times(s=m)),l=s,e=u.minus(f.times(s=e)),u=s;return s=E(t.minus(n),i,0,1),l=l.plus(s.times(m)),n=n.plus(s.times(i)),l.s=m.s=g.s,d=E(m,i,a*=2,D).minus(g).abs().comparedTo(E(l,n,a,D).minus(g).abs())<1?[m,i]:[l,n],P=c,d},S.toNumber=function(){return+Y(this)},S.toPrecision=function(t,e){return null!=t&&f(t,1,u),$(this,t,e,2)},S.toString=function(t){var e,n=this,r=n.s,i=n.e;return null===i?r?(e="Infinity",r<0&&(e="-"+e)):e="NaN":(null==t?e=i<=C||i>=z?p(h(n.c),i):g(h(n.c),i,"0"):10===t&&Q?e=g(h((n=K(new G(n),T+i+1,D)).c),n.e,"0"):(f(t,2,H.length,"Base"),e=b(g(h(n.c),i,"0"),10,t,r,!0)),r<0&&n.c[0]&&(e="-"+e)),e},S.valueOf=S.toJSON=function(){return Y(this)},S._isBigNumber=!0,S[Symbol.toStringTag]="BigNumber",S[Symbol.for("nodejs.util.inspect.custom")]=S.valueOf,null!=y&&G.set(y),G}();const y=window.crypto;function E(t,e){if(0n===e)throw new Error("Division by zero");const n=w(t).dividedBy(e),r=BigInt(n.integerValue(w.ROUND_FLOOR).toFixed());return[r,BigInt(t-r*e)]}function b(t,e){if(0n===e)throw new Error("Division by zero");const n=t%e;return n<0n?n+e:n}function I(t,e){return b(k(t),e)}function B(t){return E(t,2n)[0]}function v(t,e){if(e<0)throw new Error(`Negative exponent ${e}`);return E(t,2n**BigInt(e))[0]}function k(t){return t<0n?BigInt(-t):BigInt(t)}function N(t,e){const n=k(t),r=k(e);return n<r?-1:n>r?1:0}function A(t){return k(t).toString(2).length}function x(t){return 0n===t?2**50:k(t).toString(2).split("").reverse().join("").indexOf("1")}function R(t){return k(t).toString(2).length}function S(t,e){if(e<0)throw new Error("Negative bit index");return 0n!=(t&1n<<BigInt(e))}function O(t,e){if(e<0)throw new Error("Negative bit index");return t|1n<<BigInt(e)}function T(t,e,n){if(e<0)throw new Error("Index cannot be negative.");const r=t<0n?-t:t,i=BigInt(e)-BigInt(n)+1n;let s;s=i>=0n?r>>i:r<<-i;return s&(1n<<BigInt(n))-1n}function D(t,e){return function(t,e){return 0n===e?t:D(e,t%e)}(k(t),k(e))}function C(t,e){const n=t<0n?-1n:1n,r=e<0n?-1n:1n;let i=k(t),s=k(e);const[o,a,_]=function(t,e){if(0n===e)return[1n,0n,t];const[n,r,i]=C(e,t%e),s=r,o=n-t/e*r;return[s,o,i]}(i,s);return[o*n,a*r,_]}function z(t,e){let n=BigInt(t);if(e<1)throw new Error("k must be greater than or equal to 1");if(n%2n==0n)throw new Error("a must be odd.");const r=2n**BigInt(e);if(n%=r,n<0n&&(n+=r),0n===n)throw new Error("Inverse does not exist");if(1n===n)return 1n;let i=1n;for(let t=1;t<e;t<<=1){let e=2n-i*n;e*=i,i=e%2n**(BigInt(t)<<1n)}return i<0n&&(i+=r),i}function U(t){if(t<0n)throw new Error("Square root of negative number");return 0n===t||1n===t?t:BigInt(w(t).squareRoot().integerValue(w.ROUND_DOWN).toFixed())}function P(t){return function(t){return U(U(t))}(k(t))}function M(t){const e=new Uint8Array(Math.ceil(A(t)/8));y.getRandomValues(e);let n=BigInt(0);for(let t=0;t<e.length;t++)n=n<<BigInt(8)|BigInt(e[t]);return n%t}function L(t,e,n){if(e<0n)throw new Error("Negative exponent not supported");let r=1n;for(t%=n;e>0n;)e%2n==1n&&(r=r*t%n),e>>=1n,t=t*t%n;return r}function q(t){return!(t<=1n)&&(2n===t||3n===t||t%2n!=0n&&t%3n!=0n&&(t<10000n?function(t){for(let e=5n;e*e<=t;e+=6n)if(t%e===0n||t%(e+2n)===0n)return!1;return!0}(t):function(t,e){let n=t-1n,r=0n;for(;n%2n==0n;)n/=2n,r++;for(let i=0;i<e;i++){let e=L(M(t-3n)+2n,n,t);if(1n===e||e===t-1n)continue;let i=!0;for(let n=1n;n<r;n++){if(e=L(e,2n,t),e===t-1n){i=!1;break}if(1n===e)return!1}if(i)return!1}return!0}(t,20)))}function F(t){if(t<2n)return 2n;if(2n===t)return 3n;let e=t%2n==0n?t+1n:t+2n;for(;;){if(q(e))return e;e+=2n}}function H(t,e){let n=BigInt(t),r=BigInt(e);if(0n===r)return 1n===k(n)?1:0;let i=1;if(n%2n==0n&&r%2n==0n)return 0;{let t=0;for(;r%2n==0n;)r/=2n,t++;if(t%2!=0){const t=(n%8n+8n)%8n;3n!==t&&5n!==t||(i=-1)}}for(r<0n&&(r=-r,n<0n&&(i=-i));;){if(0n===n)return 1n===r?i:0;let t=0;for(;n%2n==0n;)n/=2n,t++;if(t%2!=0){const t=r%8n;3n!==t&&5n!==t||(i=-i)}3n===(n%4n+4n)%4n&&3n===r%4n&&(i=-i),[n,r]=[r%k(n),k(n)]}}const Q=64,G=BigInt(2)**BigInt(Q),$=32,V=BigInt(1)<<BigInt($),j=BigInt(1)<<BigInt(33);function K(t,e,n,r){const i=t=>(t%G+G)%G,s=(t,e)=>(t+e)%G,o=(t,e)=>((t-e)%G+G)%G,a=(t,e)=>t*e%G,_=(t,e,n,r)=>{let i=t,s=e;const a=s<r?1n:0n;return s=o(s,r),i=o(i,n),i=o(i,a),[i,s]},c=(t,e,n,r)=>{const i=t*G+e,s=n*G+r;if(0n===s)throw new Error("Division by zero in div2");const o=i%s;return{q:i/s,rh:o/G,rl:o%G}},u=(t,e)=>{const n=t,r=e;if(0n===r)throw new Error("Division by zero in div1_simple");return{q:n/r,r:n%r}},l=t=>{if(!t)throw new Error("Assertion failed")};let h=i(t),m=i(e),f=i(n),d=i(r),p=0n,g=0n,w=0n,y=0n;const E=()=>[1,p,g,w,y];if(h<2n||f<2n)return[0,0n,0n,0n,0n];if(h>f||h==f&&m>d){if([h,m]=_(h,m,f,d),h<2)return[0,0n,0n,0n,0n];p=1n,g=1n,y=1n,w=0n}else{if([f,d]=_(f,d,h,m),f<2)return[0,0n,0n,0n,0n];p=1n,g=0n,w=1n,y=1n}let b=!1,I=!1;for(h<f&&(b=!0);;){if(!1===b){if(l(h>=f),h==f)return E();if(h<BigInt(V)){h=s(h<<BigInt($),m>>BigInt($)),f=s(f<<BigInt($),d>>BigInt($));break}if(l(h>f),[h,m]=_(h,m,f,d),h<2n)return E();if(h<=f)g=s(g,p),y=s(y,w);else{const t=c(h,m,f,d);let e=t.q;if(m=t.rl,h=t.rh,h<2n)return g=s(g,a(e,p)),y=s(y,a(e,w)),E();e++,g=s(g,a(e,p)),y=s(y,a(e,w))}}else b=!1;if(l(f>=h),h==f)return E();if(f<V){h=s(h<<BigInt($),m>>BigInt($)),f=s(f<<BigInt($),d>>BigInt($)),I=!0;break}if([f,d]=_(f,d,h,m),f<2n)return E();if(f<=h)p=s(p,g),w=s(w,y);else{const t=c(f,d,h,m);let e=t.q;if(d=t.rl,f=t.rh,f<2)return p=s(p,a(e,g)),w=s(w,a(e,y)),E();e++,p=s(p,a(e,g)),w=s(w,a(e,y))}}for(;;){if(0==I){if(l(h>=f),h=o(h,f),h<j)break;if(h<=f)g=s(g,p),y=s(y,w);else{const t=u(h,f);let e=t.q;if(h=t.r,h<j){g=s(g,a(e,p)),y=s(y,a(e,w));break}e++,g=s(g,a(e,p)),y=s(y,a(e,w))}}else I=!1;if(l(f>=h),f=o(f,h),f<j)break;if(f<=h)p=s(p,g),w=s(w,y);else{const t=u(f,h);let e=t.q;if(f=t.r,f<j){p=s(p,a(e,g)),w=s(w,a(e,y));break}e++,p=s(p,a(e,g)),w=s(w,a(e,y))}}return E()}function Y(t,e,n,r=!1){r&&(n*=Q);const i=(t,e)=>{const n=t=>{let e=0;for(let n=0;n<t.length&&"0"===t[n];n++)e++;return e};let r=t.toString(2),i=e.toString(2);r.length>i.length?i="0".repeat(r.length-i.length)+i:i.length>r.length&&(r="0".repeat(i.length-r.length)+r),r.length<128&&(r="0".repeat(128-r.length)+r),i.length<128&&(i="0".repeat(128-i.length)+i);let s=Math.min(n(r),n(i));return r=r.slice(s)+"0".repeat(s),i=i.slice(s)+"0".repeat(s),[BigInt("0b"+r.slice(0,Q)),BigInt("0b"+r.slice(Q,128)),BigInt("0b"+i.slice(0,Q)),BigInt("0b"+i.slice(Q,128))]},s=(t,e)=>k(t)>=BigInt(2)**BigInt(e);let o=BigInt(t),a=BigInt(e),_=!1;k(o)>k(a)&&([o,a]=[a,o],_=!0);let c=o<0n,u=a<0n;if(o=k(o),a=k(a),o<2n**BigInt(Q))return[o,a,1n,0n,0n,1n];let l=1n,h=0n,m=0n,f=1n,d=!0;for(;d;){let[t,e,r,_]=i(o,a),[c,u,p,g,w]=K(t,e,r,_);if(0!==c){if([o,a]=[BigInt(w)*o-BigInt(p)*a,BigInt(u)*a-BigInt(g)*o],o<0n||a<0n)throw new Error("Assertion failed");d=s(o,n)||s(a,n);let t=BigInt(u)*l+BigInt(g)*h,e=BigInt(p)*l+BigInt(w)*h,r=BigInt(u)*m+BigInt(g)*f,i=BigInt(p)*m+BigInt(w)*f;l=t,h=e,m=r,f=i}else if(r<2){let t=o/a,e=o%a;o-=t*a,a=e,d=s(a,n),h+=t*l,f+=t*m}else if(t<2){let t=a/o,e=a%o;a-=t*o,o=e,d=s(o,n),l+=t*h,m+=t*f}else o<a?([o,a]=[o,a-o],d=s(a,n),l+=h,m+=f):([o,a]=[o-a,a],d=s(o,n),h+=l,f+=m)}return o=c?-o:o,a=u?-a:a,m=u!==c?-m:m,h=u!==c?-h:h,_&&([m,h]=[h,m],[l,f]=[f,l],[o,a]=[a,o]),[o,a,l,h,m,f]}class J{vec;constructor(t,e){this.vec=new Uint8Array(Math.max(A(t),A(e))+1);let n=0,r=0,i=S(t,0)?1:0,s=S(t,1)?1:0,o=S(t,2)?1:0,a=S(e,0)?1:0,_=S(e,1)?1:0,c=S(e,2)?1:0;for(let u=0;u<this.vec.length;u++){let l,h,m=Number(n==i)&&s^n,f=Number(r==a)&&_^r;n==i?l=0:(l=s^(o^s)&f?3:1,n=l>>1),r==a?h=0:(h=_^(c^_)&m?3:1,r=h>>1),this.set(u,l,h),i=s,s=o,o=S(t,u+3)?1:0,a=_,_=c,c=S(e,u+3)?1:0}0==this.vec[this.vec.length-1]&&(this.vec=this.vec.slice(0,this.vec.length-1))}size(){return this.vec.length}get(t){return t<0||t>=this.vec.length?0:this.vec[t]??0}set(t,e,n){t<0||t>=this.vec.length||(this.vec[t]=e|n<<4)}}class W{Ax;Bx;Ay;By;Cx;Cy;Dx;Dy;m00;m01;m10;m11;t0;t1;m;s;F;u;v;x;y;H;l;q;by;constructor(){this.Ax=0n,this.Bx=0n,this.Ay=0n,this.By=0n,this.Cx=0n,this.Cy=0n,this.Dx=0n,this.Dy=0n,this.m00=0n,this.m01=0n,this.m10=0n,this.m11=0n,this.t0=0n,this.t1=0n,this.m=0n,this.s=0n,this.F=0n,this.u=0n,this.v=0n,this.x=0n,this.y=0n,this.H=0n,this.l=0n,this.q=0n,this.by=0n}}class X{a_m;b_m;c_m;constructor(t,e,n){this.a_m=t,this.b_m=e,this.c_m=n}clone(){return new X(this.a_m,this.b_m,this.c_m)}a(){return this.a_m}b(){return this.b_m}c(){return this.c_m}discriminant(){return this.b_m**2n-4n*this.a_m*this.c_m}is_one(){return 1n==this.a_m}neg(){this.a_m!=this.c_m&&this.a_m!=this.b_m&&(this.b_m=-this.b_m)}eval(t,e){return this.a_m*t**2n+this.b_m*t*e+this.c_m*e**2n}lift(t){this.prime_to(t),this.b_m*=t,this.c_m*=t**2n,this.reduction()}lift_2exp(t){this.prime_to_2exp();let e=BigInt(t);this.b_m*=2n**e,this.c_m*=2n**(2n*e),this.reduction()}to_maximal_order(t,e,n=!0){if(t<=1n||0n==(t&t-1n))throw new Error("l must be a prime power.");if(0n===I(e,2n))throw new Error("deltaK must be odd.");this.prime_to(t);let[r,i,s]=C(t,this.a_m);this.b_m=this.b_m*r+this.a_m*i,this.set_c_from_disc(e),n&&this.reduction()}to_maximal_order_2exp(t,e,n=!0){if(0n!==I(e,2n))throw new Error("deltaK must be even.");this.prime_to_2exp();let r=BigInt(t),i=(1n-this.a_m*z(this.a_m,t))/2n**r;this.b_m=this.b_m*i,this.set_c_from_disc(e),n&&this.reduction()}kernel_representative(t,e){let n=1n,r=0n;const i=this.clone();for(i.to_maximal_order(t,e,!1),i.normalize();N(i.a_m,i.c_m)>0;){let t=r*e;r=r*i.b_m+n,n=n*i.b_m+t,i.rho()}if(1n!==i.a_m||1n!==i.b_m)throw new Error("The form is not in the kernel.");const s=D(n,r);n/=s,r/=s;return r=-r,b(function(t,e){let n=BigInt(t),r=BigInt(e);if(r<=0n)throw new Error("Modulus must be positive");if(1n===r)return 0n;if(n%=r,n<0n&&(n+=r),0n===n)throw new Error("Inverse does not exist");if(1n===n)return 1n;const[i,s,o]=C(n,r);if(1n!==o)throw new Error("Inverse does not exist");return(i%r+r)%r}(n,t)*r,t)}kernel_representative_2exp(t,e){let n=1n,r=0n;const i=new X(this.a_m,this.b_m,this.c_m);for(i.to_maximal_order_2exp(t,e,!1),i.normalize();N(i.a_m,i.c_m)>0;){let t=r*e;r=r*i.b_m+n,n=n*i.b_m+t,i.rho()}if(1n!==i.a_m||0n!==i.b_m)throw new Error("The form is not in the kernel.");const s=x(n),o=2n**BigInt(s);n/=o,r/=o;const a=b(z(n,t),2n**BigInt(t));return r=-r,b(a*r,2n**BigInt(t))}set_c_from_disc(t){this.c_m=(this.b_m*this.b_m-t)/(4n*this.a_m)}normalize(){let[t,e]=function(t,e){if(0n===e)throw new Error("Division by zero");const n=w(t).dividedBy(e),r=BigInt(n.integerValue(w.ROUND_CEIL).toFixed());return[r,BigInt(t-r*e)]}(this.b_m,this.a_m);1n===I(t,2n)&&(e+=this.a_m),t=B(t),[this.b_m,e]=[e,this.b_m],e+=this.b_m,e=B(e),this.c_m-=t*e}rho(){[this.a_m,this.c_m]=[this.c_m,this.a_m],this.b_m=-this.b_m,this.normalize()}reduction(){let t=0;for(this.normalize();(t=N(this.a_m,this.c_m))>0;)this.rho();0==t&&this.b_m<0n&&(this.b_m=-this.b_m)}prime_to(t){let e=D(this.a_m,t);if(e>1n)if(e=D(this.c_m,t),e>1n){const t=this.a_m,e=this.b_m,n=this.c_m;this.a_m=t+e+n,this.b_m=-e-2n*t,this.c_m=t}else{const t=this.a_m;this.a_m=this.c_m,this.c_m=t,this.b_m=-this.b_m}}prime_to_2exp(){if(0n===I(this.a_m,2n))if(0n===I(this.c_m,2n)){const t=this.a_m,e=this.b_m,n=this.c_m;this.a_m=t+e+n,this.b_m=-e-2n*t,this.c_m=t}else{const t=this.a_m;this.a_m=this.c_m,this.c_m=t,this.b_m=-this.b_m}}static nucomp(t,e,n,r){let i=new W,s=new X(0n,0n,0n);i.s=B(t.b_m+e.b_m),i.m=e.b_m-i.s,r&&([i.m,i.s]=[-i.s,-i.m]),[i.u,i.v,i.F]=C(t.a_m,e.a_m),1n==i.F?(i.Ax=1n,i.Bx=i.m*i.v,i.By=t.a()):0n===I(i.s,i.F)?(i.Ax=i.F,i.Bx=i.m*i.v,i.By=t.a()/i.Ax):([i.x,i.y,i.Ax]=C(i.F,i.s),i.H=i.F/i.Ax,i.t0=b(t.c_m,i.H),i.t1=b(e.c_m,i.H),i.t0=b(i.t0*i.v+i.t1*i.u,i.H),i.l=b(i.t0*i.y,i.H),i.By=t.a_m/i.Ax,i.Bx=(i.v*i.m+i.l*i.By)/i.H),i.Cy=e.a_m/i.Ax,i.Dy=i.s/i.Ax,i.Bx=b(i.Bx,i.By),i.by=i.By;const o=Math.ceil(R(n)/Q);return[i.Bx,i.by,i.m00,i.m01,i.m10,i.m11]=Y(i.Bx,i.by,o),i.Ay=i.m10*i.Ax*-1n,i.Cx=(i.Bx*i.Cy-i.m*i.m11)/i.By,0n==i.Bx?i.Cy=(e.a_m*i.by-i.Ay*i.m)/t.a_m:i.Cy=(i.Cx*i.by+i.m)/i.Bx,i.Dx=(i.Bx*i.Dy-e.c_m*i.m11)/i.By,i.Dy-=i.Dx*i.m10,i.Dy/=i.m11,i.Ax*=i.m11,s.a_m=i.by*i.Cy-i.Ay*i.Dy,s.c_m=i.Bx*i.Cx-i.Ax*i.Dx,s.b_m=i.Ax*i.Dy+i.Ay*i.Dx-i.Bx*i.Cy-i.by*i.Cx,s.reduction(),s}static nudupl(t,e){let n=new W,r=new X(0n,0n,0n);[n.m11,n.m01,n.Ax]=C(t.a_m,t.b_m),1n!==n.Ax?(r.a_m=t.a_m/n.Ax,r.b_m=t.b_m/n.Ax):(r.a_m=t.a_m,r.b_m=t.b_m),n.Dx=-t.c_m*n.m11,r.c_m=t.c_m*n.m01,[n.t0,r.c_m]=E(r.c_m,r.a_m),n.Dx=n.Dx-n.t0*r.b_m;const i=Math.ceil(R(e)/Q);return[r.c_m,r.a_m,n.m00,n.m01,n.m10,n.m11]=Y(r.c_m,r.a_m,i),n.t1=-n.Ax*n.m10,n.Ax=n.Ax*n.m11,n.t0=n.Dx*n.m11-r.b_m*n.m01,r.b_m=r.b_m*n.m00-n.Dx*n.m10,[n.Dx,n.t0]=[n.t0,n.Dx],n.t0=r.a_m*r.c_m,r.a_m=r.a_m**2n-n.t1*r.b_m,r.c_m=r.c_m**2n-n.Ax*n.Dx,r.b_m=n.Ax*r.b_m+n.t1*n.Dx-2n*n.t0,r.reduction(),r}static nupow(t,e,n){let r=new X(0n,0n,0n);if(0n===e)return new Z(t.discriminant()).one();let i=this.nudupl(t,n),s=[];s.push(new X(t.a_m,t.b_m,t.c_m));for(let t=1;t<32;t++)s.push(this.nucomp(s[t-1],i,n,!1));let o=A(e)-1,a=0n;{let t=T(e,o,7);a=0x1n&t;let _=t+(0x1n&t),c=_.toString(2).split("").reverse().join("").indexOf("1"),u=c<7?c:6;_>>=BigInt(u),r=2n==_?i:s[Math.floor(Number(_)/2)];let l=o<6?u+1+o-7:u;for(let t=0;t<l;t++)r=this.nudupl(r,n);o-=7}for(;o>=0;){let t=T(e,o,7),_=0x1n&t;if(a==(t>>BigInt(6)&0x1n))r=this.nudupl(r,n),o-=1;else{let e=!!a,c=t+_;c=a?BigInt(128)-c:c,a=_;let u=c>0n?c.toString(2).split("").reverse().join("").indexOf("1"):6,l=u<7?u:6;c>>=BigInt(l);for(let t=0;t<7-l;t++)r=this.nudupl(r,n);r=this.nucomp(r,2n==c?i:s[Number(c>>1n)],n,e);let h=o<6?l+1+o-7:l;for(let t=0;t<h;t++)r=this.nudupl(r,n);o-=7}}return 0n!==a&&(r=this.nucomp(r,s[0],n,!0)),e<0n&&r.neg(),r}static nupow_2_forms(t,e,n,r,i){if(0n==e&&0n==r)return new Z(t.discriminant()).one();if(0n==e)return X.nupow(n,r,i);if(0n==r)return X.nupow(t,e,i);{let s=new X(0n,0n,0n),o=[];o.push(new X(t.a_m,t.b_m,t.c_m)),o.push(new X(n.a_m,n.b_m,n.c_m)),o.push(X.nucomp(t,n,i,!1)),o.push(X.nucomp(t,n,i,!0));let a=new J(e,r),_=a.get(a.size()-1);1==_?s=o[0]:16==_?s=o[1]:17==_&&(s=o[2]);for(let t=a.size()-1;t>0;t--){let e=a.get(t-1);X.nudupl(s,i),1==e?s=X.nucomp(s,o[0],i,!1):3==e?s=X.nucomp(s,o[0],i,!0):16==e?s=X.nucomp(s,o[1],i,!1):48==e?s=X.nucomp(s,o[1],i,!0):17==e?s=X.nucomp(s,o[2],i,!1):19==e?s=X.nucomp(s,o[3],i,!0):49==e?s=X.nucomp(s,o[3],i,!1):51==e&&(s=X.nucomp(s,o[2],i,!0))}return s}}static nupow_2_forms_2exp(t,e,n,r,i,s,o,a){if(0n===e)return new Z(t.discriminant()).one();if(A(e)<r)return X.nupow(t,e,a);let _=b(e,2n**BigInt(n)),c=v(e,n),u=new J(_,c),l=new Array(40);l[0]=t,l[2]=s,l[8]=i,l[26]=o;for(let t=1,e=3,n=0;n<3;n++,t+=e,e*=3)for(let n=0;n<t;n++)l[e+n]=X.nucomp(l[e-1],l[n],a,!1),l[e-n-2]=X.nucomp(l[e-1],l[n],a,!0);let h=new Z(t.discriminant()).one();for(let t=u.size();t>2*r;t--){let e=u.get(t-1);if(h=X.nudupl(h,a),0!=e){let t=0;t+=2&e?-9:1&e?9:0,t+=32&e?-27:16&e?27:0;let n=t<0;t=t<0?-t:t,h=X.nucomp(h,l[t-1],a,n)}}for(let t=2*r;t>r;t--){let e=u.get(t-1),n=u.get(t-r-1);if(h=X.nudupl(h,a),0!=e||0!=n){let t=0;t+=2&n?-1:1&n?1:0,t+=32&n?-3:16&n?3:0,t+=2&e?-9:1&e?9:0,t+=32&e?-27:16&e?27:0;let r=t<0;t=t<0?-t:t,h=X.nucomp(h,l[t-1],a,r)}}return h}}class Z{kronecker(t){throw new Error("Method not implemented.")}disc_m;default_nucomp_bound_m;class_number_bound_m;constructor(t,e=0n){let n=BigInt(t);if(this.disc_m=n,this.default_nucomp_bound_m=0n,this.class_number_bound_m=e,n>0n)throw new Error("The discriminant must be negative.");let r=b(this.disc_m,4n);if(0n!=r&&1n!=r)throw new Error(`The discriminant must be congruent to 0 or 1 mod 4, disc = ${this.disc_m}`);this.default_nucomp_bound_m=P(this.disc_m)}disc(){return this.disc_m}default_nucomp_bound(){return this.default_nucomp_bound_m}one(){return new X(1n,I(this.disc_m,2n),(I(this.disc_m,2n)-this.disc_m)/4n)}primeform(t){let e=new X(t,function(t,e){let n=e-1n,r=0n;for(;0n===b(n,2n);)n=B(n),++r;let i=1n;for(;-1!==H(i,e);)i+=1n;let s=b(i**n,e),o=b(t**n,e),a=B(n+1n),_=b(t**a,e);for(;0n!==o&&1n!==o;){let t=0n;for(a=o;1n!==a;)t+=1n,a=b(a**2n,e);a=1n,a<<=r-t-1n;let n=b(s**a,e);r=t,s=b(n**2n,e),o=b(o*s,e),_=b(_*n,e)}return 0n===o&&(_=0n),_}(this.disc_m,t),0n);return I(e.b(),2n)!=I(this.disc_m,2n)&&(e=new X(e.a(),t-e.b(),e.c())),e.set_c_from_disc(this.disc_m),e.reduction(),e}class_number_bound(){return 0n==this.class_number_bound_m&&(this.class_number_bound_m=this.calc_class_number_bound()),this.class_number_bound_m}calc_class_number_bound(){let t=function(t){const{precisionMargin:e=A(t),maxIterations:n=1e5,tolerance:r="1e-15"}={},i=w.config({});w.config({DECIMAL_PLACES:e});let s=w(t);if(s.isZero())throw new Error("Logarithm of zero is undefined.");const o=s.abs();if(o.isEqualTo(1))return BigInt(0);let a;try{let t=o,e=0;for(;t.comparedTo(new w(2))>=0;)t=t.sqrt(),e+=1;const i=new w(1).minus(t);let s=new w(0),_=i.times(i),c=new w(1),u=new w(0);for(let t=1;t<n;t++){const e=new w(t+1),n=new w(1).dividedBy(e);if(u=_.times(c).times(new w(2)).times(n),s=s.plus(u),_=_.times(i),c=c.plus(n),!s.isZero()&&u.dividedBy(s).abs().comparedTo(new w(r))<=0)break}s=s.times(new w(4).pow(e)),a=s.integerValue(w.ROUND_CEIL)}finally{w.config(i)}return BigInt(a.toFixed())}(this.disc_m),e=A(this.disc_m);w.config({DECIMAL_PLACES:e,POW_PRECISION:e});let n=new w(1),r=new w(0),i=new w(0);for(let e=2n;e<t;e=F(e)){let t=H(this.disc_m,e),s=0n;s=t<0?e+BigInt(-t):e-BigInt(t),r=new w(e),i=new w(s),r=r.div(i),n=n.multipliedBy(r)}let s=21n*U(k(this.disc_m));return n=n.div(88n),r=new w(s),r=r.multipliedBy(n),r=r.integerValue(w.ROUND_CEIL),this.class_number_bound_m=BigInt(r.toFixed()),this.class_number_bound_m}nucomp(t,e){return X.nucomp(t,e,this.default_nucomp_bound_m,!1)}nucompinv(t,e){return X.nucomp(t,e,this.default_nucomp_bound_m,!0)}nudupl(t){return X.nudupl(t,this.default_nucomp_bound_m)}nudupl_niter(t,e){let n=this.default_nucomp_bound_m;if(e>0)for(let r=0;r<e;r++)t=X.nudupl(t,n);return t}nupow(t,e){return X.nupow(t,e,this.default_nucomp_bound_m)}nupow_2_forms(t,e,n,r){return X.nupow_2_forms(t,e,n,r,this.default_nucomp_bound_m)}nupow_2_forms_2exp(t,e,n,r,i,s,o){return X.nupow_2_forms_2exp(t,e,n,r,i,s,o,this.default_nucomp_bound_m)}}class tt{random_bigint(t){if(t<0n)throw new Error("n must be greater than or equal to 0");if(0n===t)return 0n;const e=tt.get_bytes(Math.ceil(A(t)/8));let n=BigInt(0);for(let t=0;t<e.length;t++)n=n<<BigInt(8)|BigInt(e[t]);return n%(t+1n)}random_bigint_2exp(t){return this.random_bigint(BigInt(2n**BigInt(t)))}random_bytes(t){if(t<0)throw new Error("n must be greater than or equal to 0");if(t>65536)throw new Error("n must be less than 65536");return 0===t?new Uint8Array(0):tt.get_bytes(t)}random_bool(){return tt.get_bytes(1)[0]%2==0}random_prime(t){if(t<=0)throw new Error("nbits_ must be greater than 0");if(t<=1)return 2n;if(2===t)return this.random_bool()?3n:2n;{let e;do{e=this.random_bigint_2exp(t),O(e,t-1),e=F(e)}while(A(e)!==t);return e}}static get_bytes(t){const e=new Uint8Array(t);return y.getRandomValues(e),e}}class et{sk_m;constructor(t){this.sk_m=t}get sk(){return BigInt(this.sk_m)}static create_new(t,e){return new et(e.random_bigint(t.secretkey_bound))}}class nt{pk_m;d_m;e_m;pk_e_precomp_m;pk_d_precomp_m;pk_de_precomp_m;constructor(t,e){this.pk_m=t,this.d_m=Math.floor((A(e.encrypt_randomness_bound)+1)/2),this.e_m=Math.floor(this.d_m/2)+1,this.pk_de_precomp_m=t.clone(),this.pk_d_precomp_m=t.clone(),this.pk_e_precomp_m=t.clone();for(let t=0;t<this.d_m+this.e_m;t++)t===this.e_m&&(this.pk_e_precomp_m=this.pk_de_precomp_m.clone()),t===this.d_m&&(this.pk_d_precomp_m=this.pk_de_precomp_m.clone()),this.pk_de_precomp_m=e.cl_g.nudupl(this.pk_de_precomp_m)}get pk(){return this.pk_m.clone()}exponentiation(t,e){return t.cl_g.nupow_2_forms_2exp(this.pk_m,e,this.d_m,this.e_m,this.pk_e_precomp_m,this.pk_d_precomp_m,this.pk_de_precomp_m)}static create_new(t,e){return new nt(t.power_of_h(e.sk),t)}}class rt{m_m;constructor(t){this.m_m=t}get m(){return this.m_m}static create_new(t){return new rt(t)}static decrypt(t,e,n){return new rt(t.dlog_in_F(t.cl_delta.nucompinv(n.c2,t.cl_g.nupow(n.c1,e.sk))))}}class it{c1_m;c2_m;constructor(t,e){this.c1_m=t,this.c2_m=e}get c1(){return this.c1_m.clone()}get c2(){return this.c2_m.clone()}static create_new(t,e,n,r){let i=t.power_of_h(r),s=t.cl_delta.nucomp(t.power_of_f(n.m),e.exponentiation(t,r));return new it(i,s)}static add_ciphertexts(t,e,n,r,i){let s=t.cl_g.nucomp(t.cl_g.nucomp(n.c1,r.c1),t.power_of_h(i)),o=t.cl_delta.nucomp(t.cl_delta.nucomp(n.c2,r.c2),e.exponentiation(t,i));return new it(s,o)}static scal_ciphertexts(t,e,n,r,i){let s=t.cl_g.nucomp(t.power_of_h(i),t.cl_g.nupow(r.c1,n.m)),o=t.cl_delta.nucomp(t.cl_delta.nupow(r.c2,n.m),e.exponentiation(t,i));return new it(s,o)}}class st{t_m;n_m;constructor(t,e){if(t<1)throw new Error("t must be greater than or equal to 1");if(e<t)throw new Error("n must be greater than or equal to t");if(!1===Number.isInteger(t))throw new Error("t must be an integer");if(!1===Number.isInteger(e))throw new Error("n must be an integer");this.t_m=t,this.n_m=e}get t(){return this.t_m}get n(){return this.n_m}}class ot{M_m;Sie_m;constructor(t,e){if(t.length<1)throw new Error("M and Sie must have at least one row");this.M_m=t,this.Sie_m=e}get M(){return this.M_m}get Sie(){return this.Sie_m}get rows(){return this.M_m.length}get cols(){return this.M_m[0].length}}function at(t,e){const n=t.length,r=t[0].length,i=e.length,s=e[0].length,o=n+i,a=r+s-1,_=Array.from({length:o},(()=>Array(a).fill(0)));for(let e=0;e<n;++e)_[e][0]=t[e][0];for(let t=0;t<i;++t)_[n+t][0]=e[t][0];for(let e=0;e<n;++e)for(let n=1;n<r;++n)_[e][n]=t[e][n];for(let t=0;t<i;++t)for(let i=1;i<s;++i)_[n+t][r+i-1]=e[t][i];return _}function _t(t,e){const n=t.length,r=t[0].length,i=e.length,s=e[0].length,o=n+i,a=r+s,_=Array.from({length:o},(()=>Array(a).fill(0)));for(let e=0;e<n;++e)_[e][0]=t[e][0],_[e][1]=t[e][0];for(let t=0;t<i;++t)_[n+t][1]=e[t][0];for(let e=0;e<n;++e)for(let n=1;n<r;++n)_[e][n+1]=t[e][n];for(let t=0;t<i;++t)for(let i=1;i<s;++i)_[n+t][r+i]=e[t][i];return _}function ct(t,e){if(e>t)return 0;if(0===e||e===t)return 1;e>t-e&&(e=t-e);let n=1;for(let r=0;r<e;r++)n*=t-r,n/=r+1;return n}function ut(t){const e=t.n,n=t.t,r=ct(e,n),i=function(t,e,n){const r=[[1]];let i=[[1]];for(let t=1;t<e;t++)i=_t(i,r);let s=i;for(let t=1;t<n;t++)s=at(s,i);return s}(0,n,r),s=Array.from({length:r},(()=>Array(n).fill(0)));let o=0;for(let t=0;t<r;t++)for(let e=0;e<n;e++)s[t][e]=o++;return new ot(i,s)}function lt(t,e,n,r){const i=function(t,e,n,r){const i=new Array(e);i[0]=t;for(let t=1;t<e;t++)i[t]=r.random_bigint(n.encrypt_randomness_bound);return i}(r,n.cols,t,e);return function(t,e){const n=t.M,r=t.Sie,i=t.rows,s=t.cols,o=Array.from({length:i},(()=>Array(s).fill(0n)));let a=0;for(const t of r){let r=0;for(const i of t){let t=BigInt(0);if(-1!==i)for(let r=0;r<s;r++)t+=e[r]*BigInt(n[i][r]);o[a][r]=t,r++}a++}return o}(n,i)}function ht(t,e,n){const r=function(t,e,n){let r=new X(1n,1n,1n);for(let i=0;i<e.length;i++){const s=t.cl_delta.nupow(e[i],n[i]);r=t.cl_delta.nucomp(r,s)}return r}(t,n,function(t){const e=[BigInt(1)];for(let n=0;n<t;n++)e.push(BigInt(-1));return e}(n.length));let i=t.cl_delta.nucompinv(e.c2,r);return new rt(t.dlog_in_F(i))}function mt(t,e,n){const r=[...t];let i=n-1;for(;i>=0&&r[i]===e-n+i;)i--;if(i>=0){r[i]++;for(let t=i+1;t<n;t++)r[t]=r[i]+t-i}return r}class ft{randgen;large_message_variant_used_m;n_m;k_m;m_m;cl_delta_k_m;cl_delta_m;h_m;distance_m;exponent_bound_m;d_m;e_m;h_e_precomp_m;h_d_precomp_m;h_de_precomp_m;constructor(t,e,n=0n){if(e<1)throw new Error("k must be greater than or equal to 1");this.randgen=new tt,this.n_m=t,this.k_m=e,this.cl_delta_k_m=new Z(this.compute_delta_k(this.n_m),n),this.cl_delta_m=new Z(this.compute_delta(this.cl_delta_k_m.disc(),e)),this.distance_m=0n,this.m_m=2n**BigInt(this.k_m),this.large_message_variant_used_m=this.m_m**2n-1n+this.delta_k>0n;let r=2n;for(;1!==H(r,this.delta);)r=F(r);this.h_m=this.cl_delta_m.primeform(r),this.h_m=this.cl_delta_m.nudupl(this.h_m),this.h_m=this.raise_to_power_m(this.cl_delta_m,this.h_m),this.exponent_bound_m=this.cl_delta_k_m.class_number_bound(),this.distance_m=this.distance_m<2n?42n:this.distance_m,this.exponent_bound_m=this.exponent_bound_m*2n**(this.distance_m-2n),this.d_m=Math.floor((A(this.exponent_bound_m)+1)/2),this.e_m=Math.floor(this.d_m/2)+1,this.h_de_precomp_m=this.h_m.clone(),this.h_d_precomp_m=this.h_m.clone(),this.h_e_precomp_m=this.h_m.clone();for(let t=0;t<this.d_m+this.e_m;t++)t===this.e_m&&(this.h_e_precomp_m=this.h_de_precomp_m.clone()),t===this.d_m&&(this.h_d_precomp_m=this.h_de_precomp_m.clone()),this.h_de_precomp_m=this.cl_g.nudupl(this.h_de_precomp_m)}static create(t,e){return new ft(ft.random_n(t,new tt),e)}get large_message_variant_used(){return this.large_message_variant_used_m}get n(){return this.n_m}get k(){return this.k_m}get m(){return this.m_m}get delta_k(){return this.cl_delta_k_m.disc()}get delta(){return this.cl_delta_m.disc()}get cl_delta_k(){return this.cl_delta_k_m}get cl_delta(){return this.cl_delta_m}get cl_g(){return this.cl_delta_m}get h(){return this.h_m}get secretkey_bound(){return this.exponent_bound_m}get cleartext_bound(){return this.m_m}get encrypt_randomness_bound(){return this.exponent_bound_m}get lambda_distance(){return this.distance_m}power_of_h(t){return this.cl_g.nupow_2_forms_2exp(this.h_m,t,this.d_m,this.e_m,this.h_e_precomp_m,this.h_d_precomp_m,this.h_de_precomp_m)}power_of_f(t){const e=x(t);if(e>=this.k_m)return this.cl_delta_m.one();{let n=1n,r=0n,i=0n,s=1n,o=this.delta_k-1n;for(let e=Number(this.k_m);e>0;e--){const a=b(n*n+r*i,this.m_m),_=b(n*r+r*s,this.m_m),c=b(i*n+s*i,this.m_m),u=b(i*r+s*s,this.m_m);n=a,r=_,i=c,s=u,S(t,e-1)&&(n=b(n*o+2n*i,this.m_m),r=b(r*o+2n*s,this.m_m),[n,i]=[i,n],[r,s]=[s,r])}let a=n+r,_=v(r,e),c=z(_,this.k_m-e);a=function(t,e){if(e<0)throw new Error("Negative exponent");const n=b(t,2n**BigInt(e));return S(n,e-1)?b(n-2n**BigInt(e),2n**BigInt(e)):n}(a*c,this.k_m-e),_=2n**BigInt(2*(this.k_m-e)),c=2n**BigInt(this.k_m-e+1)*a;let u=2n**BigInt(2*e+3)*this.n_m;return u+=a**2n,new X(_,c,u)}}dlog_in_F(t){if(t.is_one())return 0n;let e=0n,n=0n;if(this.large_message_variant_used)n=t.kernel_representative_2exp(this.k_m+1,this.delta_k);else{const e=x(t.b())-1;n=z(v(t.b(),e+1),e)*2n**BigInt(this.k_m-e)}n=b(n,this.m_m);let r=1n;for(let t=0;t<this.k_m;t++){(n>0n?x(n):Number.MAX_SAFE_INTEGER)===t&&(e=O(e,t),n=this.F_kerphi_div(n,r)),r=this.F_kerphi_square(r)}return e}from_Cl_DeltaK_to_Cl_Delta(t){let e=t.clone();return e.lift_2exp(this.k_m+1),e=this.raise_to_power_m(this.cl_delta_m,e),3n!==b(e.a(),4n)&&3n!==b(e.c(),4n)||(e=this.cl_delta_m.nucomp(e,new X(4n,4n,this.delta_k*2n**BigInt(2*(this.k_m-1))-1n))),e}keygen(t,e,n){if(void 0===t)return et.create_new(this,this.randgen);if(void 0===e||void 0===n)return nt.create_new(this,t);let r=ut(new st(e,n)),i=lt(this,this.randgen,r,t.sk),s=Array.from({length:n},(()=>Array())),o=Array.from({length:n},((t,e)=>e));for(let t=0;t<ct(n,e);t++){for(let n=0;n<e;n++)s[o[n]].push(i[t][n]);o=mt(o,n,e)}return s}create_cleartext(t){if(t<0n||t>=this.cleartext_bound)throw new Error("Cleartext out of bounds");return rt.create_new(t)}encrypt(t,e,n){return void 0===n&&(n=this.randgen.random_bigint(this.encrypt_randomness_bound)),it.create_new(this,t,e,n)}decrypt(t,e){return rt.decrypt(this,t,e)}partial_decryption(t,e){return function(t,e,n){return t.cl_g.nupow(e.c1,n)}(this,e,t)}combine_partial_decryption_results(t,e){return ht(this,t,e)}add_ciphertexts(t,e,n){return it.add_ciphertexts(this,t,e,n,this.randgen.random_bigint(this.encrypt_randomness_bound))}scal_ciphertexts(t,e,n){return it.scal_ciphertexts(this,t,e,n,this.randgen.random_bigint(this.encrypt_randomness_bound))}static random_n(t,e){let n=e.random_prime(Math.floor((t+1)/2));for(;3n!==b(n,8n)&&5n!==b(n,8n);)n=F(n);let r=e.random_prime(Math.floor(t/2));const i=3n===b(n,8n)?5n:3n;for(;b(r,8n)!==i;)r=F(r);return n*r}compute_delta_k(t){return-8n*t}compute_delta(t,e){return 2n**BigInt(2*(e+1))*t}raise_to_power_m(t,e){let n=e.clone();for(let e=0;e<this.k_m;e++)n=t.nudupl(n);return n}F_kerphi_square(t){return b(2n*t*z(b(b(t**2n,this.m_m)*this.delta_k+1n,this.m_m),this.k_m),this.m_m)}F_kerphi_div(t,e){return b((t-e)*z(b(1n-b(t*e,this.m_m)*this.delta_k,this.m_m),this.k_m),this.m_m)}}class dt{k_m;clhsm2k;constructor(t,e,n){if(this.k_m=e,n){if(n.k!==e)throw new Error(`CLHSM2k instance provided has k=${n.k} but expected k=${e}`);this.clhsm2k=n}else this.clhsm2k=ft.create(t,e)}static create_from_n(t,e,n=0n){return new dt(0,e,new ft(t,e,n))}keygen(t,e,n){return this.clhsm2k.keygen(t,e,n)}make_plaintext(t){return this.clhsm2k.create_cleartext(t)}get_plaintext_value(t){return new w(t.m)}encrypt(t,e){return this.clhsm2k.encrypt(t,e)}combine_partial_decryption_results(t,e){return this.clhsm2k.combine_partial_decryption_results(t,e)}deserialize_public_key(t){return new nt(this.deserialize_qfi_binary(t),this.clhsm2k)}serialize_partial_decryption_result(t){return this.serialize_qfi_binary(t)}deserialize_partial_decryption_result(t){return this.deserialize_qfi_binary(t)}serialize_ciphertext(t){const e=this.serialize_qfi_binary(t.c1),n=this.serialize_qfi_binary(t.c2),r=8+e.length+n.length,i=new Uint8Array(r);let s=BigInt(e.length);for(let t=0;t<8;t++)i[t]=Number(s&BigInt(255)),s>>=BigInt(8);for(let t=0;t<e.length;t++)i[t+8]=e[t];for(let t=0;t<n.length;t++)i[t+8+e.length]=n[t];return i}deserialize_ciphertext(t){let e=BigInt(0);for(let n=0;n<8;n++)e|=BigInt(t[n])<<BigInt(8*n);const n=Number(e),r=t.length-8-n;let i=new Uint8Array(n),s=new Uint8Array(r);for(let e=0;e<n;e++)i[e]=t[e+8];for(let e=0;e<r;e++)s[e]=t[e+8+n];return new it(this.deserialize_qfi_binary(i),this.deserialize_qfi_binary(s))}serialize_qfi_binary(t){const e=Math.ceil(R(t.a())/8),n=Math.ceil(R(t.b())/8),r=Math.ceil(R(t.c())/8),i=new Uint8Array(8+e+n+r);let s=BigInt(t.a()>0n?0:1)<<BigInt(63)|BigInt(t.b()>0n?0:1)<<BigInt(62)|BigInt(t.c()>0n?0:1)<<BigInt(61)|BigInt(e)<<BigInt(31)|BigInt(n)<<BigInt(1);for(let t=0;t<8;t++)i[t]=Number(s&BigInt(255)),s>>=BigInt(8);let o=k(t.a()),a=k(t.b()),_=k(t.c());for(let t=0;t<e;t++)i[t+8]=Number(o&BigInt(255)),o>>=BigInt(8);for(let t=0;t<n;t++)i[t+8+e]=Number(a&BigInt(255)),a>>=BigInt(8);for(let t=0;t<r;t++)i[t+8+e+n]=Number(_&BigInt(255)),_>>=BigInt(8);return i}deserialize_qfi_binary(t){let e=BigInt(0);for(let n=0;n<8;n++)e|=BigInt(t[n])<<BigInt(8*n);const n=!!Boolean(e>>BigInt(63)&BigInt(1)),r=!!Boolean(e>>BigInt(62)&BigInt(1)),i=!!Boolean(e>>BigInt(61)&BigInt(1)),s=Number(e>>BigInt(31)&BigInt(1073741823)),o=Number(e>>BigInt(1)&BigInt(1073741823)),a=t.length-8-s-o;let _=BigInt(0),c=BigInt(0),u=BigInt(0);for(let e=0;e<s;e++)_|=BigInt(t[e+8])<<BigInt(8*e);for(let e=0;e<o;e++)c|=BigInt(t[e+8+s])<<BigInt(8*e);for(let e=0;e<a;e++)u|=BigInt(t[e+8+s+o])<<BigInt(8*e);return n&&(_=-_),r&&(c=-c),i&&(u=-u),new X(_,c,u)}}async function pt(t){const e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"get_cl_delta_k_class_number_bound",data:""})});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);const n=await e.json();if(200!==n.status)throw new Error(`Addon service error! status: ${n.status}`);const r=n.data,i=BigInt(r);if(i<=0n)throw new Error(`Invalid class bound: ${i}`);return i}class gt{constructor(t,e,n=!1){if("undefined"!=typeof window)throw new Error("NodeJsTCPComputer can only be used in Node.js");throw new Error("Shouldnt happen")}get usable(){return!1}async connect(){throw new Error("Shouldnt happen")}async compute(t){throw new Error("Shouldnt happen")}async fetch_network_details(){throw new Error("Shouldnt happen")}}function wt(t,e,n,r){const i=[];let s=0,o=0;for(let r=0;r<t.length;r++)if(t[r]===e.charCodeAt(0)&&o<n-1){const e=r;i.push(t.slice(s,e)),s=r+1,o++}return s<t.length&&i.push(t.slice(s)),i}function yt(t,e,n=!1){const r=t.reduce(((t,e)=>t+e.length),0),i=new Uint8Array(r+(t.length+(n?0:-1))*e.length);let s=0;for(let r=0;r<t.length;r++)i.set(t[r],s),s+=t[r].length,(r<t.length-1||n)&&(i.set((new TextEncoder).encode(e),s),s+=e.length);return i}function Et(t){return(new TextEncoder).encode(t.toString())}function bt(t){return(new TextEncoder).encode(t.toString())}function It(t){return parseInt((new TextDecoder).decode(t),10)}function Bt(t){return BigInt((new TextDecoder).decode(t))}function vt(t){let e=[];for(let n=0;n<t.length;n++)e.push(t[n]);let n=String.fromCharCode.apply(null,e);return btoa(n)}function kt(t){const e=atob(t),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r}var Nt,At,xt,Rt,St,Ot,Tt,Dt,Ct,zt,Ut,Pt,Mt,Lt,qt,Ft;!function(t){t[t.UNARY=0]="UNARY",t[t.BINARY=1]="BINARY",t[t.TERNARY=2]="TERNARY"}(Nt||