"use strict";functionn(n){returnn>=0?n:-n}functiont(n,t){if("number"==typeofn&&(n=BigInt(n)),"number"==typeoft&&(t=BigInt(t)),n<=0n||t<=0n)thrownewRangeError("a and b MUST be > 0");letr=0n,e=1n,o=1n,i=0n;for(;0n!==n;){constu=t/n,f=t%n,c=r-o*u,p=e-i*u;t=n,n=f,r=o,e=i,o=c,i=p}return{g:t,x:r,y:e}}functionr(n,t){if("number"==typeofn&&(n=BigInt(n)),"number"==typeoft&&(t=BigInt(t)),t<=0n)thrownewRangeError("n must be > 0");constr=n%t;returnr<0n?r+t:r}functione(n,e){consto=t(r(n,e),e);if(1n!==o.g)thrownewRangeError(`${n.toString()} does not have inverse modulo ${e.toString()}`);returnr(o.x,e)}functiono(n,t,o){if(n.length!==t.length)thrownewRangeError("The remainders and modulos arrays should have the same length");consti=o??t.reduce(((n,t)=>n*t),1n);returnt.reduce(((t,o,u)=>{constf=i/o;returnr(t+f*e(f,o)%i*n[u]%i,i)}),0n)}functioni(t,r){lete="number"==typeoft?BigInt(n(t)):n(t),o="number"==typeofr?BigInt(n(r)):n(r);if(0n===e)returno;if(0n===o)returne;leti=0n;for(;0n===(1n&(e|o));)e>>=1n,o>>=1n,i++;for(;0n===(1n&e);)e>>=1n;do{for(;0n===(1n&o);)o>>=1n;if(e>o){constn=e;e=o,o=n}o-=e}while(0n!==o);returne<<i}functionu(n){returnn.map((n=>n[0]**(n[1]-1n)*(n[0]-1n))).reduce(((n,t)=>t*n),1n)}functionf(t,i,c,p){if("number"==typeoft&&(t=BigInt(t)),"number"==typeofi&&(i=BigInt(i)),"number"==typeofc&&(c=BigInt(c)),c<=0n)thrownewRangeError("n must be > 0");if(1n===c)return0n;if(t=r(t,c),i<0n)returne(f(t,n(i),c,p),c);if(void0!==p)returnfunction(n,t,r,e){consti=e.map((n=>n[0]**n[1])),c=e.map((n=>u([n]))),p=c.map(((r,e)=>f(n,t%r,i[e])));returno(p,i,r)}(t,i,c,function(n){constt={};returnn.forEach((n=>{if("bigint"==typeofn||"number"==typeofn){constr=String(n);void0===t[r]?t[r]={p:BigInt(n),k:1n}:t[r].k+=1n}else{constr=String(n[0]);void0===t[r]?t[r]={p:BigInt(n[0]),k:BigInt(n[1])}:t[r].k+=BigInt(n[1])}})),Object.values(t).map((n=>[n.p,n.k]))}(p));lets=1n;for(;i>0;)i%2n===1n&&(s=s*t%c),i/=2n,t=t**2n%c;returns}exports.abs=n,exports.bitLength=function(n){if("number"==typeofn&&(n=BigInt(n)),1n===n)return1;lett=1;do{t++}while((n>>=1n)>1n);returnt},exports.crt=o,exports.eGcd=t,exports.gcd=i,exports.lcm=function(t,r){return"number"==typeoft&&(t=BigInt(t)),"number"==typeofr&&(r=BigInt(r)),0n===t&&0n===r?BigInt(0):n(t/i(t,r)*r)},exports.max=function(n,t){returnn>=t?n:t},exports.min=function(n,t){returnn>=t?t:n},exports.modAdd=function(n,t){conste=BigInt(t);returnr(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n+t%e),0n),e)},exports.modInv=e,exports.modMultiply=function(n,t){conste=BigInt(t);returnr(n.map((n=>BigInt(n)%e)).reduce(((n,t)=>n*t%e),1n),e)},exports.modPow=f,exports.phi=u,exports.toZn=r;