compe
Version:
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
3 lines (2 loc) • 28.2 kB
JavaScript
"use strict";function t(t,r){for(var i=0;i<r.length;i++){var e=r[i];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function r(r,i,e){return i&&t(r.prototype,i),e&&t(r,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function i(t,r){return(i=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function e(t,r){(null==r||r>t.length)&&(r=t.length);for(var i=0,e=new Array(r);i<r;i++)e[i]=t[i];return e}function n(t,r){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,r){if(t){if("string"==typeof t)return e(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?e(t,void 0):void 0}}(t))||r&&t&&"number"==typeof t.length){i&&(t=i);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}Object.defineProperty(exports,"__esModule",{value:!0});var o,s=function(t){global.MOD_=t,global.MOD_CUT=1099511627776%t},a=function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];for(var e=r.length-1;e>=1;e--)r[0]+=r[e],r[0]=r[0]>=global.MOD_?r[0]-global.MOD_:r[0];return r[0]},h=function(t,r){return(t+=global.MOD_-r)>=global.MOD_?t-global.MOD_:t},l=function(){for(var t=arguments.length<=0?void 0:arguments[0],r=1;r<arguments.length;r++)t=((t>>20)*((r<0||arguments.length<=r?void 0:arguments[r])>>20)*global.MOD_CUT+(4293918720&t)*(1048575&(r<0||arguments.length<=r?void 0:arguments[r]))+(1048575&t)*(r<0||arguments.length<=r?void 0:arguments[r]))%global.MOD_;return t},u=function(t,r){for(var i=1;r;)1&r&&(i=l(i,t)),t=l(t,t),r>>>=1;return i},f=function(t){for(var r,i=1,e=0,n=global.MOD_;n;e=(o=[i,e-r*i])[0],i=o[1],o){var o,s;n=(s=[t,n-(r=n/t|0)*t])[0],t=s[1]}return i<0?i+global.MOD_:i},c=function(t,r){return t<r?t:r},p=function(t,r){return t>r?t:r},g=function t(r,i){return 0===i?r:t(i,r%i)},v=function(t){for(var r=t[0],i=0,e=0;e<t.length;e++)t[e]>r&&(r=t[e],i=e);return{res:r,pos:i}},d=function(t){for(var r=t[0],i=0,e=0;e<t.length;e++)t[e]<r&&(r=t[e],i=e);return{res:r,pos:i}},y=function(t,r){void 0===r&&(r=function(t,r){return t<r}),t.sort((function(t,i){return r(t,i)?-1:1}))},m=function t(r){if(null==r||"object"!=typeof r)return r;if(r.constructor!=Object&&r.constructor!=Array)return r;if(r.constructor==Date||r.constructor==RegExp||r.constructor==Function||r.constructor==String||r.constructor==Number||r.constructor==Boolean)return new r.constructor(r);var i=new r.constructor;for(var e in r)i[e]=void 0===i[e]?t(r[e]):i[e];return i},b=function(t){for(var r=arguments.length,i=new Array(r>1?r-1:0),e=1;e<r;e++)i[e-1]=arguments[e];if(0===i.length)throw new Error("Please insert integer dimensional values");var n=function r(e){return e===i.length-1?Array(i[e]).fill(t):Array(i[e]).fill(0).map((function(){return r(e+1)}))},o=function r(e){return e===i.length?m(t):Array(i[e]).fill(0).map((function(){return r(e+1)}))};return"object"!=typeof t?n(0):o(0)},w=function(){global.MOD_=998244353,global.MOD_CUT=444595123,global.min=c,global.max=p,global.gcd=g,global.minElement=d,global.maxElement=v,global.sort=y,global.copy=m,global.sqrt=function(t){return Math.sqrt(t)},global.ceil=function(t){return Math.ceil(t)},global.floor=function(t){return Math.floor(t)},global.round=function(t){return Math.round(t)},global.log=function(t,r){return void 0===r?Math.log(t):Math.log(r)/Math.log(t)},global.abs=function(t){return t<0?-t:t},global.popCount32=function(t){return 16843009*((t=(858993459&(t-=t>>1&1431655765))+(t>>2&858993459))+(t>>4)&252645135)>>24},global.popCount=function(t){for(var r=0;0!==t;)r+=global.popCount32(0|t),t/=4294967296;return r},global.setMod=s,global.add=a,global.sub=h,global.mul=l,global.pow=u,global.inv=f,global.array=b,global.clog=function(){var t;return(t=console).log.apply(t,arguments)},global.INT_MAX=Number.MAX_SAFE_INTEGER,global.INT_MIN=Number.MIN_SAFE_INTEGER,global.PI=Math.PI;var t=Array.prototype.sort;Array.prototype.sort=function(r){void 0===r&&(r=function(t,r){return+t<+r}),t.call(this,(function(t,i){return r(t,i)?-1:1}))}},x=require("fs"),z=function(){function t(t){this.comparator=t||function(t,r){return t<r},this.elem=[]}var i=t.prototype;return i.swap=function(t,r){var i=[this.elem[r],this.elem[t]];this.elem[t]=i[0],this.elem[r]=i[1]},i.push=function(t){for(var r=this.elem.push(t)-1,i=0;r>0&&!this.comparator(this.elem[r],this.elem[i=r>>1]);)this.swap(r,i),r=i},i.pop=function(){var t=this.top,r=this.elem.pop(),i=this.size;if(0==i)return t;this.elem[0]=r;for(var e=0,n=0,o=0,s=0;e<i&&(n=e,s=2+(e<<1),(o=1+(e<<1))<i&&!this.comparator(this.elem[o],this.elem[n])&&(n=o),s<i&&!this.comparator(this.elem[s],this.elem[n])&&(n=s),n!=e);)this.swap(n,e),e=n;return t},r(t,[{key:"size",get:function(){return this.elem.length}},{key:"top",get:function(){if(0==this.elem.length)throw new Error("PriorityQueue is empty");return this.elem[0]}}]),t}(),A=(function(t){var r=function(t){var r=Object.prototype,i=r.hasOwnProperty,e="function"==typeof Symbol?Symbol:{},n=e.iterator||"@@iterator",o=e.asyncIterator||"@@asyncIterator",s=e.toStringTag||"@@toStringTag";function a(t,r,i){return Object.defineProperty(t,r,{value:i,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{a({},"")}catch(t){a=function(t,r,i){return t[r]=i}}function h(t,r,i,e){var n=Object.create((r&&r.prototype instanceof f?r:f).prototype),o=new A(e||[]);return n._invoke=function(t,r,i){var e="suspendedStart";return function(n,o){if("executing"===e)throw new Error("Generator is already running");if("completed"===e){if("throw"===n)throw o;return{value:void 0,done:!0}}for(i.method=n,i.arg=o;;){var s=i.delegate;if(s){var a=w(s,i);if(a){if(a===u)continue;return a}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if("suspendedStart"===e)throw e="completed",i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);e="executing";var h=l(t,r,i);if("normal"===h.type){if(e=i.done?"completed":"suspendedYield",h.arg===u)continue;return{value:h.arg,done:i.done}}"throw"===h.type&&(e="completed",i.method="throw",i.arg=h.arg)}}}(t,i,o),n}function l(t,r,i){try{return{type:"normal",arg:t.call(r,i)}}catch(t){return{type:"throw",arg:t}}}t.wrap=h;var u={};function f(){}function c(){}function p(){}var g={};a(g,n,(function(){return this}));var v=Object.getPrototypeOf,d=v&&v(v(E([])));d&&d!==r&&i.call(d,n)&&(g=d);var y=p.prototype=f.prototype=Object.create(g);function m(t){["next","throw","return"].forEach((function(r){a(t,r,(function(t){return this._invoke(r,t)}))}))}function b(t,r){var e;this._invoke=function(n,o){function s(){return new r((function(e,s){!function e(n,o,s,a){var h=l(t[n],t,o);if("throw"!==h.type){var u=h.arg,f=u.value;return f&&"object"==typeof f&&i.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,s,a)}),(function(t){e("throw",t,s,a)})):r.resolve(f).then((function(t){u.value=t,s(u)}),(function(t){return e("throw",t,s,a)}))}a(h.arg)}(n,o,e,s)}))}return e=e?e.then(s,s):s()}}function w(t,r){var i=t.iterator[r.method];if(void 0===i){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,w(t,r),"throw"===r.method))return u;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var e=l(i,t.iterator,r.arg);if("throw"===e.type)return r.method="throw",r.arg=e.arg,r.delegate=null,u;var n=e.arg;return n?n.done?(r[t.resultName]=n.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,u):n:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,u)}function x(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function z(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function E(t){if(t){var r=t[n];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,o=function r(){for(;++e<t.length;)if(i.call(t,e))return r.value=t[e],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return c.prototype=p,a(y,"constructor",p),a(p,"constructor",c),c.displayName=a(p,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===c||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,a(t,s,"GeneratorFunction")),t.prototype=Object.create(y),t},t.awrap=function(t){return{__await:t}},m(b.prototype),a(b.prototype,o,(function(){return this})),t.AsyncIterator=b,t.async=function(r,i,e,n,o){void 0===o&&(o=Promise);var s=new b(h(r,i,e,n),o);return t.isGeneratorFunction(i)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},m(y),a(y,s,"Generator"),a(y,n,(function(){return this})),a(y,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var i in t)r.push(i);return r.reverse(),function i(){for(;r.length;){var e=r.pop();if(e in t)return i.value=e,i.done=!1,i}return i.done=!0,i}},t.values=E,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(z),!t)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function e(i,e){return s.type="throw",s.arg=t,r.next=i,e&&(r.method="next",r.arg=void 0),!!e}for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],s=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var a=i.call(o,"catchLoc"),h=i.call(o,"finallyLoc");if(a&&h){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!h)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=t,s.arg=r,o?(this.method="next",this.next=o.finallyLoc,u):this.complete(s)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),u},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.finallyLoc===t)return this.complete(i.completion,i.afterLoc),z(i),u}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc===t){var e=i.completion;if("throw"===e.type){var n=e.arg;z(i)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,i){return this.delegate={iterator:E(t),resultName:r,nextLoc:i},"next"===this.method&&(this.arg=void 0),u}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}}(o={exports:{}}),o.exports),E=function(t){function i(t){this.head=0,this.tail=0,this.mask=1,this.list=new Array(2),t&&this.extend(t)}var e=i.prototype;return e.extend=function(t){for(var r,i=n(t);!(r=i()).done;)this.push(r.value);return this},e.extendFront=function(t){for(var r,i=n(t);!(r=i()).done;)this.pushFront(r.value);return this},e._resize=function(t,r){var i=this.head,e=this.mask;if(this.head=0,this.tail=t,this.mask=r-1,0!==i){for(var n=new Array(r),o=0;o<t;o++)n[o]=this.list[i+o&e];this.list=n}else this.list.length=r},e.push=function(t){return this.list[this.tail]=t,this.tail=this.tail+1&this.mask,this.head===this.tail&&this._resize(this.list.length,this.list.length<<1),this},e.pushFront=function(t){return this.head=this.head-1&this.mask,this.list[this.head]=t,this.head===this.tail&&this._resize(this.list.length,this.list.length<<1),this},e.clear=function(){this.head=0,this.tail=0},e.at=function(t){var r=this.head,i=this.size,e=this.tail,n=this.list;if((0|t)!==t||t>=i||t<-i)throw new RangeError("deque index out of range");return n[(t>=0?r:e)+t&this.mask]},e.indexOf=function(t,r){void 0===r&&(r=0);for(var i=this.head,e=this.list,n=this.size,o=this.mask,s=r>=0?r:r<-n?0:n+r;s<n;s++)if(e[i+s&o]===t)return s;return-1},e.has=function(t){for(var r=this.head,i=this.list,e=this.size,n=this.mask,o=0;o<e;o++)if(i[r+o&n]===t)return!0;return!1},e.insert=function(t,r){var i=this.head+t&this.mask,e=this.tail;for(this.tail=this.tail+1&this.mask;e!==i;){var n=e-1&this.mask;this.list[e]=this.list[n],e=n}return this.list[i]=r,this.head===this.tail&&this._resize(this.list.length,this.list.length<<1),this},e.pop=function(){if(this.head===this.tail)throw new RangeError("pop from an empty deque");this.tail=this.tail-1&this.mask;var t=this.list[this.tail];return this.list[this.tail]=void 0,this.size<this.mask>>>1&&this._resize(this.size,this.list.length>>>1),t},e.popFront=function(){if(this.head===this.tail)throw new RangeError("pop from an empty deque");var t=this.list[this.head];return this.list[this.head]=void 0,this.head=this.head+1&this.mask,this.size<this.mask>>>1&&this._resize(this.size,this.list.length>>>1),t},e.delete=function(t){if(t>=this.size||t<0)throw new RangeError("deque index out of range");for(var r=this.head+t&this.mask;r!==this.tail;){var i=r+1&this.mask;this.list[r]=this.list[i],r=i}return this.tail=this.tail-1&this.mask,this.size<this.mask>>>1&&this._resize(this.size,this.list.length>>>1),this},e.reverse=function(){for(var t=this.head,r=this.tail,i=this.size,e=this.mask,n=0;n<~~(i/2);n++){var o=r-n-1&e,s=t+n&e,a=this.list[o];this.list[o]=this.list[s],this.list[s]=a}return this},e.rotate=function(t){void 0===t&&(t=1);var r=this.head,i=this.tail;if(0===t||r===i)return this;if(this.head=r-t&this.mask,this.tail=i-t&this.mask,t>0)for(var e=1;e<=t;e++){var n=i-e&this.mask;this.list[r-e&this.mask]=this.list[n],this.list[n]=void 0}else for(var o=0;o>t;o--){var s=r-o&this.mask;this.list[i-o&this.mask]=this.list[s],this.list[s]=void 0}return this},e.entries=A.mark((function t(){var r,i,e,n,o;return A.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=this.head,i=this.size,e=this.list,n=this.mask,o=0;case 2:if(!(o<i)){t.next=8;break}return t.next=5,e[r+o&n];case 5:o++,t.next=2;break;case 8:case"end":return t.stop()}}),t,this)})),e.keys=function(){return this.entries()},e.values=function(){return this.entries()},e[t]=function(){return this.entries()},r(i,[{key:"front",get:function(){if(this.size)return this.list[this.head];throw new RangeError("deque index out of range")}},{key:"back",get:function(){if(this.size)return this.list[this.tail-1&this.mask];throw new RangeError("deque index out of range")}},{key:"size",get:function(){return this.tail-this.head&this.mask}}]),i}(Symbol.iterator),k=function(t){for(var r=arguments.length,i=new Array(r>1?r-1:0),e=1;e<r;e++)i[e-1]=arguments[e];if(0===i.length)throw new Error("Please insert integer dimensional values");var n=function r(e){return e===i.length-1?Array(i[e]).fill(t):Array(i[e]).fill(0).map((function(){return r(e+1)}))},o=function r(e){return e===i.length?t.slice():Array(i[e]).fill(0).map((function(){return r(e+1)}))},s=function r(e){return e===i.length?Object.assign({},t):Array(i[e]).fill(0).map((function(){return r(e+1)}))};return"object"!=typeof t?n(0):Array.isArray(t)?o(0):s(0)},_=function(){function t(t){this.p=k(-1,t+1)}var r=t.prototype;return r.group=function(t){return this.p[t]<0?t:(this.p[t]=this.group(this.p[t]),this.p[t])},r.join=function(t,r){if((t=this.group(t))==(r=this.group(r)))return!1;if(this.p[t]>this.p[r]){var i=[r,t];t=i[0],r=i[1]}return this.p[t]+=this.p[r],this.p[r]=t,!0},r.size=function(t){return t=this.group(t),-this.p[t]},t}(),L=function(){function t(t,r,i){void 0===r&&(r=0),void 0===i&&(i=function(t,r){return t+r}),this.identityValue=r,this.merger=i,this.elemCount=t,this.cont=Array(t+1).fill(r)}var r=t.prototype;return r.query=function(t){for(var r=this.identityValue;t>=0;t=(t&t+1)-1)r=this.merger(r,this.cont[t]);return r},r.update=function(t,r){for(;t<=this.elemCount;t|=t+1)this.cont[t]=this.merger(this.cont[t],r)},t}(),M=function(){function t(t,r){var i=this;void 0===r&&(r=function(t,r){return t<r?t:r}),this.maxGap=0;var e=t.length;this.logFactor=this.floorLog2(e),this.merger=r,this.cont=Array(e).fill(0).map((function(){return Array(i.logFactor+1)}));for(var n=0;n<e;n++)this.cont[n][0]=t[n];for(var o=1;o<=this.logFactor;o++)for(var s=0;s+(1<<o)-1<e;s++)this.cont[s][o]=r(this.cont[s][o-1],this.cont[s+(1<<o-1)][o-1])}var r=t.prototype;return r.floorLog2=function(t){return 31-Math.clz32(t)},r.query=function(t,r){return this.maxGap=this.floorLog2(r-t+1),this.merger(this.cont[t][this.maxGap],this.cont[r-(1<<this.maxGap)+1][this.maxGap])},t}(),O=function(){function t(t,r,i,e){if(void 0===e&&(e=null),this.identityValue=r,this.merger=i,this.elemCount=t,this.log=Math.ceil(Math.log2(t)),this.size=1<<this.log,this.cont=Array(t<<1).fill(this.identityValue),e){for(var n=0;n<t;n++)this.cont[this.size+n]=e[n];for(var o=this.size-1;o>=1;o--)this.internalUpdate(o)}}var r=t.prototype;return r.internalUpdate=function(t){this.cont[t]=this.merger(this.cont[t<<1],this.cont[t<<1|1])},r.set=function(t,r){this.cont[t+=this.size]=r;for(var i=1;i<=this.log;i++)this.internalUpdate(t>>i)},r.get=function(t){return t?this.cont[t+this.size]:this.cont.slice(this.size,this.size+this.elemCount)},r.query=function(t,r){void 0===t&&(t=0),void 0===r&&(r=this.elemCount-1),r++;var i=this.identityValue,e=this.identityValue;for(t+=this.size,r+=this.size;t<r;)1&t&&(i=this.merger(i,this.cont[t++])),1&r&&(e=this.merger(this.cont[--r],e)),t>>=1,r>>=1;return this.merger(i,e)},r.all=function(){return this.cont[1]},t}(),S=function(){function t(t,r,i,e,n,o,s){if(void 0===s&&(s=null),this.identityValue=r,this.merger=i,this.identityLazy=e,this.pusher=n,this.modifier=o,this.log=Math.ceil(Math.log2(t)),this.size=1<<this.log,this.cont=Array(this.size<<1).fill(this.identityValue),this.lazyCont=Array(this.size).fill(e),s){for(var a=0;a<t;a++)this.cont[this.size+a]=s[a];for(var h=this.size-1;h>=1;h--)this.internalUpdate(h)}}var r=t.prototype;return r.internalUpdate=function(t){this.cont[t]=this.merger(this.cont[t<<1],this.cont[t<<1|1])},r.internalModify=function(t,r){r!==this.identityLazy&&(this.cont[t]=this.modifier(this.cont[t],r),t<this.size&&(this.lazyCont[t]=this.pusher(this.lazyCont[t],r)))},r.internalPush=function(t){this.lazyCont[t]!==this.identityLazy&&(this.internalModify(t<<1,this.lazyCont[t]),this.internalModify(t<<1|1,this.lazyCont[t]),this.lazyCont[t]=this.identityLazy)},r.set=function(t,r){t+=this.size;for(var i=this.log;i>=1;i--)this.internalPush(t>>i);this.cont[t]=r;for(var e=1;e<=this.log;e++)this.internalUpdate(t>>e)},r.get=function(t){t+=this.size;for(var r=this.log;r>=1;r--)this.internalPush(t>>r);return this.cont[t]},r.query=function(t,r){r++,t+=this.size,r+=this.size;for(var i=this.log;i>=1;i--)t>>i<<i!=t&&this.internalPush(t>>i),r>>i<<i!=r&&this.internalPush(r-1>>i);for(var e=this.identityValue,n=this.identityValue;t<r;)1&t&&(e=this.merger(e,this.cont[t++])),1&r&&(n=this.merger(this.cont[--r],n)),t>>=1,r>>=1;return this.merger(e,n)},r.all=function(){return this.cont[1]},r.update=function(t,r,i){r++,t+=this.size,r+=this.size;for(var e=this.log;e>=1;e--)t>>e<<e!=t&&this.internalPush(t>>e),r>>e<<e!=r&&this.internalPush(r-1>>e);for(var n=t,o=r;t<r;)1&t&&this.internalModify(t++,i),1&r&&this.internalModify(--r,i),t>>=1,r>>=1;t=n,r=o;for(var s=1;s<=this.log;s++)t>>s<<s!=t&&this.internalUpdate(t>>s),r>>s<<s!=r&&this.internalUpdate(r-1>>s)},t}(),j=function(t,r){return t<r},F=function(){function t(t){this.g=k([],t),this.vis=k(!1,t),this.par=k(-1,t)}var r=t.prototype;return r.addEdge=function(t,r,i){this.g[t].push({to:r,prop:i})},r.addBiEdge=function(t,r,i){this.addEdge(t,r,i),this.addEdge(r,t,i)},r.reset=function(){this.vis=k(!1,this.g.length),this.par=k(-1,this.g.length)},t}(),C=function(t,r,i,e){var o=new E;for(o.push(r);o.size;){var s=o.back;if(t.vis[s])e(s,t),o.pop();else{t.vis[s]=!0,i(s,t);for(var a,h=n(t.g[s]);!(a=h()).done;){var l=a.value;t.vis[l.to]||(t.par[l.to]=s,o.push(l.to))}}}},I=function(t){var r,e;function o(r,i){var e;return(e=t.call(this,r)||this).root=1,e.root=i,e.childCount=Array(r).fill(1),e.distRoot=Array(r).fill(0),e.distance=Array(r).fill(0),e}e=t,(r=o).prototype=Object.create(e.prototype),r.prototype.constructor=r,i(r,e);var s=o.prototype;return s.setupDist=function(){var t=this;C(this,this.root,(function(r,i){for(var e,o=n(i.g[r]);!(e=o()).done;){var s=e.value;s.to!=i.par[r]&&(s.prop&&(t.distance[s.to]=t.distance[r]+s.prop.weight),t.distRoot[s.to]=t.distRoot[r]+1)}}),(function(r,i){for(var e,o=n(i.g[r]);!(e=o()).done;){var s=e.value;s.to!=i.par[r]&&(t.childCount[r]+=t.childCount[s.to])}}))},s.setupLCA=function(){this.setupDist();var t=31-Math.clz32(this.g.length);this.log=t,this.parentLift=Array(t+1),this.parentLift[0]=this.par;for(var r=1;r<=t;r++){this.parentLift[r]=Array(this.g.length).fill(-1);for(var i=0;i<this.g.length;i++)-1!=this.parentLift[r-1][i]&&(this.parentLift[r][i]=this.parentLift[r-1][this.parentLift[r-1][i]])}this.distRoot=this.distRoot},s.getLCA=function(t,r){if(this.distRoot[t]<this.distRoot[r]){var i=[r,t];t=i[0],r=i[1]}for(var e=this.log;e>=0;e--)this.distRoot[t]-(1<<e)>=this.distRoot[r]&&(t=this.parentLift[e][t]);if(t===r)return t;for(var n=this.log;n>=0;n--)this.parentLift[n][t]!=this.parentLift[n][r]&&(t=this.parentLift[n][t],r=this.parentLift[n][r]);return this.parentLift[0][t]},o}(F);exports.DSU=_,exports.Deque=E,exports.FenwickTree=L,exports.Graph=F,exports.LazySegmentTree=S,exports.PriorityQueue=z,exports.SegmentTree=O,exports.SparseTable=M,exports.Tree=I,exports.bfs=function(t,r,i){var e=new E;if(e.push(r),Array.isArray(r))for(var o,s=n(r);!(o=s()).done;){var a=o.value;t.vis[a]=!0,e.push(a)}else t.vis[r]=!0,e.push(r);for(;e.size;){var h=e.pop();i(h,t);for(var l,u=n(t.g[h]);!(l=u()).done;){var f=l.value;t.vis[f.to]||(t.par[f.to]=h,e.push(f.to),t.vis[f.to]=!0)}}},exports.binarySearch=function(t,r,i){for(var e,n=null;t<=r;)i(e=t+r>>1)?(n=e,r=e-1):t=e+1;return n},exports.binom=function(t,r){return r>t?0:global.fastBinomEnabled?global.fastBinom[t][r]:l(global.factorial[t],global.invFactorial[r],global.invFactorial[t-r])},exports.binomSetup=function(t,r){void 0===t&&(t=1e6),void 0===r&&(r=!1),global.factorial=Array(t+1).fill(1),global.invFactorial=Array(t+1).fill(1);for(var i=1;i<=t;i++)global.factorial[i]=l(global.factorial[i-1],i);global.invFactorial[t]=f(global.factorial[t]);for(var e=t-1;e>=1;e--)global.invFactorial[e]=l(global.invFactorial[e+1],e+1);if(r){if(t>2e3)throw new Error("Fast Binomial is only available for under 2000 range");global.fastBinomEnabled=!0,global.fastBinom=k(0,t+1,t+1);for(var n=0;n<=t;n++){global.fastBinom[n][0]=1;for(var o=1;o<=n;o++)global.fastBinom[n][o]=a(global.fastBinom[n-1][o-1],global.fastBinom[n-1][o])}}},exports.dfs=C,exports.dijkstra=function(t,r){void 0===r&&(r=0),t.reset();var i=new z((function(t,r){return t.dist>r.dist})),e=k(Number.MAX_SAFE_INTEGER,t.g.length);if(Array.isArray(r))for(var o,s=n(r);!(o=s()).done;){var a=o.value;i.push({node:a,dist:0}),e[a]=0}else i.push({node:r,dist:0}),e[r]=0;for(;i.size;){var h=i.pop();if(e[h.node]===h.dist)for(var l,u=n(t.g[h.node]);!(l=u()).done;){var f=l.value;e[f.to]>e[h.node]+f.prop.weight&&(e[f.to]=e[h.node]+f.prop.weight,t.par[f.to]=h.node,i.push({node:f.to,dist:e[f.to]}))}}return{parArray:t.par,distArray:e}},exports.fact=function(t){return global.factorial[t]},exports.integralExtremumSearch=function(t,r,i,e){if(void 0===e&&(e=!1),e){var n,o,s=i(t);for(t++;t<=r;)o=i(n=t+r>>1),i(n-1)<o?(s=o,t=n+1):r=n-1;return s}var a,h,l=i(t);for(t++;t<=r;)h=i(a=t+r>>1),i(a-1)>h?(l=h,t=a+1):r=a-1;return l},exports.lowerBound=function(t,r,i,e,n){var o;for(void 0===i&&(i=0),void 0===e&&(e=0),void 0===n&&(n=j),e||(e=t.length);i<e;)n(t[o=i+(e-i>>>1)],r)?i=o+1:e=o;return i},exports.mst=function(t){for(var r=0,i=[],e=[],o=0;o<t.g.length;o++)for(var s,a=n(t.g[o]);!(s=a()).done;){var h=s.value;o<h.to&&i.push({from:o,to:h.to,weight:h.prop.weight})}var l=new _(t.g.length);i.sort((function(t,r){return t.weight-r.weight}));for(var u=0,f=i;u<f.length;u++){var c=f[u];l.join(c.from,c.to)&&(r+=c.weight,e.push(c))}return{mst:r,mstEdges:e}},exports.proc=function(t,r){if(global.MOD_=998244353,global.MOD_CUT=444595123,w(),x.existsSync("./compe.config.json")){if(r.endsWith(".js")){for(var i=x.readFileSync(r,{encoding:"utf-8"}).split("\n"),e=null,o=null,s=i.length-1;s>=0;s--)if(i[s].startsWith("*/")){o=s;break}if(o)for(var a=o-1;a>=0;a--)if(i[a].startsWith("/*")){e=a;break}if(!e)return void console.log("No input data at the end of file found");for(var h,l=i.slice(e+1,o).join("\n").split(/ |\n|\r/g),u=[],f=0,c=n(l);!(h=c()).done;){var p=h.value;p.length>0&&u.push(p)}global.rnum=function(t){return t?u.slice(f,f+=t).map((function(t){return+t})):+u[f++]},global.rstr=function(t){return t?u.slice(f,f+=t):u[f++]},global.rbig=function(t){return t?u.slice(f,f+=t).map((function(t){return BigInt(t)})):BigInt(u[f++])},global.print=function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];for(var e=0,n=r;e<n.length;e++){var o=n[e];process.stdout.write(String(o))}}}else{if(!x.existsSync(r))return void console.log("Input directory does not exist");var g=x.readFileSync(r,{encoding:"utf-8"}),v=0;g=g.split(/ |\n|\r/g);for(var d,y=[],m=n(g);!(d=m()).done;){var b=d.value;b.length>0&&y.push(b)}global.rnum=function(t){return t?y.slice(v,v+=t).map((function(t){return+t})):+y[v++]},global.rstr=function(t){return t?y.slice(v,v+=t):y[v++]},global.rbig=function(t){return t?y.slice(v,v+=t).map((function(t){return BigInt(t)})):BigInt(y[v++])},global.print=function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];for(var e=0,n=r;e<n.length;e++){var o=n[e];process.stdout.write(String(o))}}}t()}else{var z="";process.stdin.on("data",(function(t){z+=t})),process.stdin.on("end",(function(){var r=0;z=z.split(/ |\n|\r/g);for(var i,e=[],o=n(z);!(i=o()).done;){var s=i.value;s.length>0&&e.push(s)}global.rnum=function(t){return t?e.slice(r,r+=t).map((function(t){return+t})):+e[r++]},global.rstr=function(t){return t?e.slice(r,r+=t):e[r++]},global.rbig=function(t){return t?e.slice(r,r+=t).map((function(t){return BigInt(t)})):BigInt(e[r++])};var a="";global.print=function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];for(var e=0,n=r;e<n.length;e++){var o=n[e];a+=String(o)}},t(),console.log(a)}))}},exports.setGlobalBuiltin=w,exports.spfa=function(t,r){t.reset();var i,e=k(Number.MAX_SAFE_INTEGER,t.g.length),o=k(!1,t.g.length),s=new E;if(Array.isArray(r))for(var a,h=n(r);!(a=h()).done;){var l=a.value;s.push(l),o[l]=!0,e[l]=0}else s.push(r),o[r]=!0,e[r]=0;for(;s.size;){o[i=s.pop()]=!1;for(var u,f=n(t.g[i]);!(u=f()).done;){var c=u.value;e[c.to]>e[i]+c.prop.weight&&(e[c.to]=e[i]+c.prop.weight,t.par[c.to]=i,o[c.to]||(o[c.to]=!0,s.push(c.to)))}}return{parArray:t.par,distArray:e}},exports.ternarySearch=function(t,r,i,e,n){var o,s;if(void 0===e&&(e=!1),void 0===n&&(n=200),e)for(;n--;)s=r-(r-t)/3,i(o=t+(r-t)/3)<i(s)?t=o:r=s;else for(;n--;)o=t+(r-t)/3,i(s=r-(r-t)/3)<i(o)?t=o:r=s;return i(o)},exports.upperBound=function(t,r,i,e,n){var o;for(void 0===i&&(i=0),void 0===e&&(e=0),void 0===n&&(n=j),e||(e=t.length);i<e;)n(r,t[o=i+(e-i>>>1)])?e=o:i=o+1;return i};
//# sourceMappingURL=compe.cjs.production.min.js.map