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