data-structure-typed 1.52.2 → 1.52.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/dist/cjs/data-structures/trie/trie.js +6 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/trie/trie.js +6 -1
- package/dist/umd/data-structure-typed.js +4 -1
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/trie/trie.ts +6 -1
- package/test/unit/data-structures/trie/trie.test.ts +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,11 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v1.52.
|
|
11
|
+
## [v1.52.3](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming)
|
|
12
|
+
|
|
13
|
+
### Changes
|
|
14
|
+
|
|
15
|
+
- fix(trie): trie returns invalid string when only the fist character m… [`#94`](https://github.com/zrwusa/data-structure-typed/pull/94)
|
|
12
16
|
|
|
13
17
|
## [v1.51.5](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...v1.51.5) (18 January 2024)
|
|
14
18
|
|
|
@@ -418,8 +418,13 @@ class Trie extends base_1.IterableElementBase {
|
|
|
418
418
|
if (prefix) {
|
|
419
419
|
for (const c of prefix) {
|
|
420
420
|
const nodeC = startNode.children.get(c);
|
|
421
|
-
if (nodeC)
|
|
421
|
+
if (nodeC) {
|
|
422
422
|
startNode = nodeC;
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
// Early return if the whole prefix is not found
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
423
428
|
}
|
|
424
429
|
}
|
|
425
430
|
if (isAllWhenEmptyPrefix || startNode !== this.root)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../../../src/data-structures/trie/trie.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C;;;GAGG;AACH,MAAa,QAAQ;IACnB,YAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC/C,CAAC;IAID;;;OAGG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,IAAI,GAAG,CAAC,KAAa;QACnB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAID;;;;OAIG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACH,IAAI,QAAQ,CAAC,KAA4B;QACvC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,KAAc;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAlED,4BAkEC;AAED;;;;;;;;;;;;GAYG;AACH,MAAa,IAAc,SAAQ,0BAAuC;IACxE;;;;;OAKG;IACH,YAAY,QAAwC,EAAE,EAAE,OAAwB;QAC9E,KAAK,CAAC,OAAO,CAAC,CAAC;QAgBP,UAAK,GAAW,CAAC,CAAC;QAUlB,mBAAc,GAAY,IAAI,CAAC;QAU/B,UAAK,GAAa,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC;QAnC3C,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,EAAE,aAAa,EAA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I,CAAC;YACb,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAC9C,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;QAED,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY,CAAC,GAAW;QAChC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,+CAA+C;QAC1E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAvfD,oBAufC"}
|
|
@@ -417,8 +417,13 @@ export class Trie extends IterableElementBase {
|
|
|
417
417
|
if (prefix) {
|
|
418
418
|
for (const c of prefix) {
|
|
419
419
|
const nodeC = startNode.children.get(c);
|
|
420
|
-
if (nodeC)
|
|
420
|
+
if (nodeC) {
|
|
421
421
|
startNode = nodeC;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
// Early return if the whole prefix is not found
|
|
425
|
+
return [];
|
|
426
|
+
}
|
|
422
427
|
}
|
|
423
428
|
}
|
|
424
429
|
if (isAllWhenEmptyPrefix || startNode !== this.root)
|
|
@@ -13911,8 +13911,11 @@ var dataStructureTyped = (() => {
|
|
|
13911
13911
|
if (prefix) {
|
|
13912
13912
|
for (const c of prefix) {
|
|
13913
13913
|
const nodeC = startNode.children.get(c);
|
|
13914
|
-
if (nodeC)
|
|
13914
|
+
if (nodeC) {
|
|
13915
13915
|
startNode = nodeC;
|
|
13916
|
+
} else {
|
|
13917
|
+
return [];
|
|
13918
|
+
}
|
|
13916
13919
|
}
|
|
13917
13920
|
}
|
|
13918
13921
|
if (isAllWhenEmptyPrefix || startNode !== this.root)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";var dataStructureTyped=(()=>{var se=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames,je=Object.getOwnPropertySymbols;var Ue=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable;var pe=(h,n)=>{if(n=Symbol[h])return n;throw Error("Symbol."+h+" is not defined")};var Ee=(h,n,e)=>n in h?se(h,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[n]=e,x=(h,n)=>{for(var e in n||(n={}))Ue.call(n,e)&&Ee(h,e,n[e]);if(je)for(var e of je(n))Ye.call(n,e)&&Ee(h,e,n[e]);return h};var Je=(h,n)=>{for(var e in n)se(h,e,{get:n[e],enumerable:!0})},Ze=(h,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Xe(n))!Ue.call(h,r)&&r!==e&&se(h,r,{get:()=>n[r],enumerable:!(t=We(n,r))||t.enumerable});return h};var $e=h=>Ze(se({},"__esModule",{value:!0}),h);var d=(h,n,e)=>(Ee(h,typeof n!="symbol"?n+"":n,e),e);var qe=(h,n,e)=>new Promise((t,r)=>{var i=a=>{try{o(e.next(a))}catch(l){r(l)}},s=a=>{try{o(e.throw(a))}catch(l){r(l)}},o=a=>a.done?t(a.value):Promise.resolve(a.value).then(i,s);o((e=e.apply(h,n)).next())}),et=function(h,n){this[0]=h,this[1]=n};var v=h=>{var n=h[pe("asyncIterator")],e=!1,t,r={};return n==null?(n=h[pe("iterator")](),t=i=>r[i]=s=>n[i](s)):(n=n.call(h),t=i=>r[i]=s=>{if(e){if(e=!1,i==="throw")throw s;return s}return e=!0,{done:!1,value:new et(new Promise(o=>{var a=n[i](s);if(!(a instanceof Object))throw TypeError("Object expected");o(a)}),1)}}),r[pe("iterator")]=()=>r,t("next"),"throw"in n?t("throw"):r.throw=i=>{throw i},"return"in n&&t("return"),r};var st={};Je(st,{AVLTree:()=>te,AVLTreeMultiMap:()=>Le,AVLTreeMultiMapNode:()=>ie,AVLTreeNode:()=>U,AbstractEdge:()=>S,AbstractGraph:()=>H,AbstractVertex:()=>k,BST:()=>j,BSTNode:()=>F,BinaryIndexedTree:()=>ve,BinaryTree:()=>ee,BinaryTreeNode:()=>A,Character:()=>ce,Deque:()=>Ke,DirectedEdge:()=>W,DirectedGraph:()=>$,DirectedVertex:()=>P,DoublyLinkedList:()=>Ve,DoublyLinkedListNode:()=>D,FibonacciHeap:()=>ke,FibonacciHeapNode:()=>le,HashMap:()=>Oe,Heap:()=>B,IterableElementBase:()=>K,IterableEntryBase:()=>w,LinkedHashMap:()=>_e,LinkedListQueue:()=>xe,MapEdge:()=>fe,MapGraph:()=>Be,MapVertex:()=>de,Matrix:()=>Ae,MaxHeap:()=>Me,MaxPriorityQueue:()=>Se,MinHeap:()=>De,MinPriorityQueue:()=>Fe,Navigator:()=>ze,PriorityQueue:()=>Q,Queue:()=>C,RedBlackTree:()=>re,RedBlackTreeNode:()=>q,SegmentTree:()=>we,SegmentTreeNode:()=>X,SinglyLinkedList:()=>J,SinglyLinkedListNode:()=>M,SkipList:()=>Te,SkipListNode:()=>Z,Stack:()=>Re,THUNK_SYMBOL:()=>Ne,TreeMultiMap:()=>Ie,TreeMultiMapNode:()=>ne,TreeNode:()=>Pe,Trie:()=>He,TrieNode:()=>Y,UndirectedEdge:()=>ue,UndirectedGraph:()=>Ce,UndirectedVertex:()=>he,arrayRemove:()=>L,calcMinUnitsRequired:()=>ae,getMSB:()=>be,isComparable:()=>Qe,isThunk:()=>ye,isWeakKey:()=>G,rangeCheck:()=>I,roundFixed:()=>it,throwRangeError:()=>rt,toBinaryString:()=>nt,toThunk:()=>ge,trampoline:()=>oe,trampolineAsync:()=>tt,uuidV4:()=>me});var w=class{*[Symbol.iterator](...n){yield*v(this._getIterator(...n))}*entries(){for(let n of this)yield n}*keys(){for(let n of this)yield n[0]}*values(){for(let n of this)yield n[1]}every(n,e){let t=0;for(let r of this)if(!n.call(e,r[1],r[0],t++,this))return!1;return!0}some(n,e){let t=0;for(let r of this)if(n.call(e,r[1],r[0],t++,this))return!0;return!1}forEach(n,e){let t=0;for(let r of this){let[i,s]=r;n.call(e,s,i,t++,this)}}find(n,e){let t=0;for(let r of this){let[i,s]=r;if(n.call(e,s,i,t++,this))return r}}has(n){for(let e of this){let[t]=e;if(t===n)return!0}return!1}hasValue(n){for(let[,e]of this)if(e===n)return!0;return!1}get(n){for(let e of this){let[t,r]=e;if(t===n)return r}}reduce(n,e){let t=e,r=0;for(let i of this){let[s,o]=i;t=n(t,o,s,r++,this)}return t}print(){console.log([...this])}};var K=class{constructor(n){d(this,"_toElementFn");if(n){let{toElementFn:e}=n;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...n){yield*v(this._getIterator(...n))}*values(){for(let n of this)yield n}every(n,e){let t=0;for(let r of this)if(!n.call(e,r,t++,this))return!1;return!0}some(n,e){let t=0;for(let r of this)if(n.call(e,r,t++,this))return!0;return!1}forEach(n,e){let t=0;for(let r of this)n.call(e,r,t++,this)}find(n,e){let t=0;for(let r of this)if(n.call(e,r,t++,this))return r}has(n){for(let e of this)if(e===n)return!0;return!1}reduce(n,e){let t=e,r=0;for(let i of this)t=n(t,i,r++,this);return t}print(){console.log([...this])}};var me=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(h){let n=Math.random()*16|0;return(h=="x"?n:n&3|8).toString(16)})},L=function(h,n){let e=-1,t=h?h.length:0,r=[];for(;++e<t;){let i=h[e];n(i,e,h)&&(r.push(i),Array.prototype.splice.call(h,e--,1),t--)}return r},Ne=Symbol("thunk"),ye=h=>typeof h=="function"&&h.__THUNK__===Ne,ge=h=>{let n=()=>h();return n.__THUNK__=Ne,n},oe=h=>Object.assign((...e)=>{let t=h(...e);for(;ye(t)&&typeof t=="function";)t=t();return t},{cont:(...e)=>ge(()=>h(...e))}),tt=h=>Object.assign((...e)=>qe(void 0,null,function*(){let t=yield h(...e);for(;ye(t)&&typeof t=="function";)t=yield t();return t}),{cont:(...e)=>ge(()=>h(...e))}),be=h=>h<=0?0:1<<31-Math.clz32(h),I=(h,n,e,t="Index out of bounds.")=>{if(h<n||h>e)throw new RangeError(t)},rt=(h="The value is off-limits.")=>{throw new RangeError(h)},G=h=>{let n=typeof h;return n==="object"&&h!==null||n==="function"},ae=(h,n)=>Math.floor((h+n-1)/n),it=(h,n=10)=>{let e=Math.pow(10,n);return Math.round(h*e)/e};function Qe(h){let n=typeof h;return n==="number"?!isNaN(h):n==="string"||n==="bigint"||n==="boolean"?!0:n==="symbol"||n==="undefined"?!1:n==="function"?Qe(h()):n==="object"?h===null:!1}function nt(h,n=32){let e=(h>>>0).toString(2);return e=e.padStart(n,"0"),e}var Oe=class h extends w{constructor(e=[],t){super();d(this,"_store",{});d(this,"_objMap",new Map);d(this,"_toEntryFn");d(this,"_size",0);d(this,"_hashFn",e=>String(e));if(t){let{hashFn:r,toEntryFn:i}=t;r&&(this._hashFn=r),i&&(this._toEntryFn=i)}e&&this.setMany(e)}get store(){return this._store}get objMap(){return this._objMap}get toEntryFn(){return this._toEntryFn}get size(){return this._size}get hashFn(){return this._hashFn}isEntry(e){return Array.isArray(e)&&e.length===2}isEmpty(){return this.size===0}clear(){this._store={},this._objMap.clear(),this._size=0}set(e,t){if(this._isObjKey(e))this.objMap.has(e)||this._size++,this.objMap.set(e,t);else{let r=this._getNoObjKey(e);this.store[r]===void 0&&this._size++,this._store[r]={key:e,value:t}}return!0}setMany(e){let t=[];for(let r of e){let i,s;if(this.isEntry(r))i=r[0],s=r[1];else if(this.toEntryFn){let o=this.toEntryFn(r);i=o[0],s=o[1]}i!==void 0&&s!==void 0&&t.push(this.set(i,s))}return t}get(e){var t;if(this._isObjKey(e))return this.objMap.get(e);{let r=this._getNoObjKey(e);return(t=this._store[r])==null?void 0:t.value}}has(e){return this._isObjKey(e)?this.objMap.has(e):this._getNoObjKey(e)in this.store}delete(e){if(this._isObjKey(e))return this.objMap.has(e)&&this._size--,this.objMap.delete(e);{let t=this._getNoObjKey(e);return t in this.store?(delete this.store[t],this._size--,!0):!1}}clone(){return new h(this,{hashFn:this.hashFn,toEntryFn:this.toEntryFn})}map(e,t){let r=new h,i=0;for(let[s,o]of this)r.set(s,e.call(t,o,s,i++,this));return r}filter(e,t){let r=new h,i=0;for(let[s,o]of this)e.call(t,o,s,i++,this)&&r.set(s,o);return r}put(e,t){return this.set(e,t)}*_getIterator(){for(let e of Object.values(this.store))yield[e.key,e.value];for(let e of this.objMap)yield e}_isObjKey(e){let t=typeof e;return(t==="object"||t==="function")&&e!==null}_getNoObjKey(e){let t=typeof e,r;return t!=="string"&&t!=="number"&&t!=="symbol"?r=this.hashFn(e):r=e,r}},_e=class h extends w{constructor(e=[],t){super();d(this,"_sentinel");d(this,"_hashFn",e=>String(e));d(this,"_objHashFn",e=>e);d(this,"_noObjMap",{});d(this,"_objMap",new WeakMap);d(this,"_head");d(this,"_tail");d(this,"_toEntryFn",e=>{if(this.isEntry(e))return e;throw new Error("If the provided entryOrRawElements does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.")});d(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:r,objHashFn:i,toEntryFn:s}=t;r&&(this._hashFn=r),i&&(this._objHashFn=i),s&&(this._toEntryFn=s)}if(e)for(let r of e){let[i,s]=this.toEntryFn(r);this.set(i,s)}}get hashFn(){return this._hashFn}get objHashFn(){return this._objHashFn}get noObjMap(){return this._noObjMap}get objMap(){return this._objMap}get head(){return this._head}get tail(){return this._tail}get toEntryFn(){return this._toEntryFn}get size(){return this._size}get first(){if(this._size!==0)return[this.head.key,this.head.value]}get last(){if(this._size!==0)return[this.tail.key,this.tail.value]}*begin(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}*reverseBegin(){let e=this.tail;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.prev}set(e,t){let r,i=!this.has(e);if(G(e)){let s=this.objHashFn(e);r=this.objMap.get(s),!r&&i?(r={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,r)):r&&(r.value=t)}else{let s=this.hashFn(e);r=this.noObjMap[s],!r&&i?this.noObjMap[s]=r={key:e,value:t,prev:this.tail,next:this._sentinel}:r&&(r.value=t)}return r&&i&&(this._size===0?(this._head=r,this._sentinel.next=r):(this.tail.next=r,r.prev=this.tail),this._tail=r,this._sentinel.prev=r,this._size++),!0}setMany(e){let t=[];for(let r of e){let[i,s]=this.toEntryFn(r);t.push(this.set(i,s))}return t}has(e){if(G(e)){let t=this.objHashFn(e);return this.objMap.has(t)}else return this.hashFn(e)in this.noObjMap}get(e){if(G(e)){let t=this.objHashFn(e),r=this.objMap.get(t);return r?r.value:void 0}else{let t=this.hashFn(e),r=this.noObjMap[t];return r?r.value:void 0}}at(e){I(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(G(e)){let r=this.objHashFn(e);if(t=this.objMap.get(r),!t)return!1;this.objMap.delete(r)}else{let r=this.hashFn(e);if(t=this.noObjMap[r],!t)return!1;delete this.noObjMap[r]}return this._deleteNode(t),!0}deleteAt(e){I(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return this._deleteNode(t)}isEmpty(){return this._size===0}isEntry(e){return Array.isArray(e)&&e.length===2}clear(){this._noObjMap={},this._size=0,this._head=this._tail=this._sentinel.prev=this._sentinel.next=this._sentinel}clone(){let e=new h([],{hashFn:this.hashFn,objHashFn:this.objHashFn});for(let t of this){let[r,i]=t;e.set(r,i)}return e}filter(e,t){let r=new h,i=0;for(let[s,o]of this)e.call(t,o,s,i,this)&&r.set(s,o),i++;return r}map(e,t){let r=new h,i=0;for(let[s,o]of this){let a=e.call(t,o,s,i,this);r.set(s,a),i++}return r}put(e,t){return this.set(e,t)}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:r}=e;return t.next=r,r.prev=t,e===this.head&&(this._head=r),e===this.tail&&(this._tail=t),this._size-=1,!0}};var M=class{constructor(n){d(this,"_value");d(this,"_next");this._value=n,this._next=void 0}get value(){return this._value}set value(n){this._value=n}get next(){return this._next}set next(n){this._next=n}},J=class h extends K{constructor(e=[],t){super(t);d(this,"_head");d(this,"_tail");d(this,"_size",0);if(e)for(let r of e)this.toElementFn?this.push(this.toElementFn(r)):this.push(r)}get head(){return this._head}get tail(){return this._tail}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}get size(){return this._size}static fromArray(e){let t=new h;for(let r of e)t.push(r);return t}push(e){let t=new M(e);return this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._size++,!0}pop(){if(!this.head)return;if(this.head===this.tail){let r=this.head.value;return this._head=void 0,this._tail=void 0,this._size--,r}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._size--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._size--,e.value}unshift(e){let t=new M(e);return this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._size++,!0}at(e){if(e<0||e>=this.size)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t.value}getNodeAt(e){let t=this.head;for(let r=0;r<e;r++)t=t.next;return t}deleteAt(e){if(e<0||e>=this.size)return!1;if(e===0)return this.shift(),!0;if(e===this.size-1)return this.pop(),!0;let t=this.getNodeAt(e-1),r=t.next;return t.next=r.next,this._size--,!0}delete(e){if(!e)return!1;let t;e instanceof M?t=e.value:t=e;let r=this.head,i;for(;r;){if(r.value===t)return i===void 0?(this._head=r.next,r===this.tail&&(this._tail=void 0)):(i.next=r.next,r===this.tail&&(this._tail=i)),this._size--,!0;i=r,r=r.next}return!1}addAt(e,t){if(e<0||e>this.size)return!1;if(e===0)return this.unshift(t),!0;if(e===this.size)return this.push(t),!0;let r=new M(t),i=this.getNodeAt(e-1);return r.next=i.next,i.next=r,this._size++,!0}isEmpty(){return this.size===0}clear(){this._head=void 0,this._tail=void 0,this._size=0}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,r;for(;t;)r=t.next,t.next=e,e=t,t=r;return[this._head,this._tail]=[this.tail,this.head],this}indexOf(e){let t=0,r=this.head;for(;r;){if(r.value===e)return t;t++,r=r.next}return-1}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}}addBefore(e,t){if(!this.head)return!1;let r;if(e instanceof M?r=e.value:r=e,this.head.value===r)return this.unshift(t),!0;let i=this.head;for(;i.next;){if(i.next.value===r){let s=new M(t);return s.next=i.next,i.next=s,this._size++,!0}i=i.next}return!1}addAfter(e,t){let r;if(e instanceof M?r=e:r=this.getNode(e),r){let i=new M(t);return i.next=r.next,r.next=i,r===this.tail&&(this._tail=i),this._size++,!0}return!1}countOccurrences(e){let t=0,r=this.head;for(;r;)r.value===e&&t++,r=r.next;return t}clone(){return new h(this,{toElementFn:this.toElementFn})}filter(e,t){let r=new h([],{toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&r.push(s),i++;return r}map(e,t,r){let i=new h([],{toElementFn:t}),s=0;for(let o of this)i.push(e.call(r,o,s,this)),s++;return i}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}};var D=class{constructor(n){d(this,"_value");d(this,"_next");d(this,"_prev");this._value=n,this._next=void 0,this._prev=void 0}get value(){return this._value}set value(n){this._value=n}get next(){return this._next}set next(n){this._next=n}get prev(){return this._prev}set prev(n){this._prev=n}},Ve=class h extends K{constructor(e=[],t){super(t);d(this,"_head");d(this,"_tail");d(this,"_size");if(this._head=void 0,this._tail=void 0,this._size=0,e)for(let r of e)this.toElementFn?this.push(this.toElementFn(r)):this.push(r)}get head(){return this._head}get tail(){return this._tail}get size(){return this._size}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static fromArray(e){return new h(e)}push(e){let t=new D(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._size++,!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._size--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._size--,e.value}unshift(e){let t=new D(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._size++,!0}at(e){if(e<0||e>=this.size)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this.size)return;let t=this.head;for(let r=0;r<e;r++)t=t.next;return t}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}}addAt(e,t){if(e<0||e>this.size)return!1;if(e===0)return this.unshift(t),!0;if(e===this.size)return this.push(t),!0;let r=new D(t),i=this.getNodeAt(e-1),s=i.next;return r.prev=i,r.next=s,i.next=r,s.prev=r,this._size++,!0}addBefore(e,t){let r;if(e instanceof D?r=e:r=this.getNode(e),r){let i=new D(t);return i.prev=r.prev,r.prev&&(r.prev.next=i),i.next=r,r.prev=i,r===this.head&&(this._head=i),this._size++,!0}return!1}addAfter(e,t){let r;if(e instanceof D?r=e:r=this.getNode(e),r){let i=new D(t);return i.next=r.next,r.next&&(r.next.prev=i),i.prev=r,r.next=i,r===this.tail&&(this._tail=i),this._size++,!0}return!1}deleteAt(e){if(e<0||e>=this.size)return!1;if(e===0)return this.shift(),!0;if(e===this.size-1)return this.pop(),!0;let t=this.getNodeAt(e),r=t.prev,i=t.next;return r.next=i,i.prev=r,this._size--,!0}delete(e){let t;if(e instanceof D?t=e:t=this.getNode(e),t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let r=t.prev,i=t.next;r.next=i,i.prev=r,this._size--}return!0}return!1}isEmpty(){return this.size===0}clear(){this._head=void 0,this._tail=void 0,this._size=0}indexOf(e){let t=0,r=this.head;for(;r;){if(r.value===e)return t;t++,r=r.next}return-1}findBackward(e){let t=this.tail;for(;t;){if(e(t.value))return t.value;t=t.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}toReversedArray(){let e=[],t=this.tail;for(;t;)e.push(t.value),t=t.prev;return e}clone(){return new h(this)}filter(e,t){let r=new h([],{toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&r.push(s),i++;return r}map(e,t,r){let i=new h([],{toElementFn:t}),s=0;for(let o of this)i.push(e.call(r,o,s,this)),s++;return i}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}};var Z=class{constructor(n,e,t){d(this,"key");d(this,"value");d(this,"forward");this.key=n,this.value=e,this.forward=new Array(t)}},Te=class{constructor(n=[],e){d(this,"_head",new Z(void 0,void 0,this.maxLevel));d(this,"_level",0);d(this,"_maxLevel",16);d(this,"_probability",.5);if(e){let{maxLevel:t,probability:r}=e;typeof t=="number"&&(this._maxLevel=t),typeof r=="number"&&(this._probability=r)}if(n)for(let[t,r]of n)this.add(t,r)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let n=this.head.forward[0];return n?n.value:void 0}get last(){let n=this.head;for(let e=this.level-1;e>=0;e--)for(;n.forward[e];)n=n.forward[e];return n.value}add(n,e){let t=new Z(n,e,this._randomLevel()),r=new Array(this.maxLevel).fill(this.head),i=this.head;for(let s=this.level-1;s>=0;s--){for(;i.forward[s]&&i.forward[s].key<n;)i=i.forward[s];r[s]=i}for(let s=0;s<t.forward.length;s++)t.forward[s]=r[s].forward[s],r[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(n){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<n;)e=e.forward[t];if(e=e.forward[0],e&&e.key===n)return e.value}has(n){return this.get(n)!==void 0}delete(n){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let r=this.level-1;r>=0;r--){for(;t.forward[r]&&t.forward[r].key<n;)t=t.forward[r];e[r]=t}if(t=t.forward[0],t&&t.key===n){for(let r=0;r<this.level&&e[r].forward[r]===t;r++)e[r].forward[r]=t.forward[r];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(n){let e=this.head;for(let r=this.level-1;r>=0;r--)for(;e.forward[r]&&e.forward[r].key<=n;)e=e.forward[r];let t=e.forward[0];return t?t.value:void 0}lower(n){let e=this.head,t;for(let r=this.level-1;r>=0;r--){for(;e.forward[r]&&e.forward[r].key<n;)e=e.forward[r];e.key<n&&(t=e)}return t?t.value:void 0}_randomLevel(){let n=1;for(;Math.random()<this.probability&&n<this.maxLevel;)n++;return n}};var Re=class h extends K{constructor(e=[],t){super(t);d(this,"_elements",[]);if(e)for(let r of e)this.toElementFn?this.push(this.toElementFn(r)):this.push(r)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e){return new h(e)}isEmpty(){return this.elements.length===0}peek(){if(!this.isEmpty())return this.elements[this.elements.length-1]}push(e){return this.elements.push(e),!0}pop(){if(!this.isEmpty())return this.elements.pop()}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}toArray(){return this.elements.slice()}clear(){this._elements=[]}clone(){return new h(this,{toElementFn:this.toElementFn})}filter(e,t){let r=new h([],{toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&r.push(s),i++;return r}map(e,t,r){let i=new h([],{toElementFn:t}),s=0;for(let o of this)i.push(e.call(r,o,s,this)),s++;return i}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var C=class h extends K{constructor(e=[],t){super(t);d(this,"_elements",[]);d(this,"_offset",0);d(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:r=.5}=t;this._autoCompactRatio=r}if(e)for(let r of e)this.toElementFn?this.push(this.toElementFn(r)):this.push(r)}get elements(){return this._elements}get offset(){return this._offset}get size(){return this.elements.length-this.offset}get first(){return this.size>0?this.elements[this.offset]:void 0}get last(){return this.size>0?this.elements[this.elements.length-1]:void 0}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}static fromArray(e){return new h(e)}push(e){return this.elements.push(e),!0}shift(){if(this.size===0)return;let e=this.first;return this._offset+=1,this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}at(e){return this.elements[e+this._offset]}isEmpty(){return this.size===0}toArray(){return this.elements.slice(this.offset)}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this.offset),this._offset=0,!0}clone(){return new h(this.elements.slice(this.offset),{toElementFn:this.toElementFn})}filter(e,t){let r=new h([],{toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&r.push(s),i++;return r}map(e,t,r){let i=new h([],{toElementFn:t}),s=0;for(let o of this)i.push(e.call(r,o,s,this)),s++;return i}*_getIterator(){for(let e of this.elements.slice(this.offset))yield e}},xe=class h extends J{clone(){return new h(this,{toElementFn:this.toElementFn})}};var Ke=class h extends K{constructor(e=[],t){super(t);d(this,"_bucketSize",4096);d(this,"_maxLen",-1);d(this,"_bucketFirst",0);d(this,"_firstInBucket",0);d(this,"_bucketLast",0);d(this,"_lastInBucket",0);d(this,"_bucketCount",0);d(this,"_buckets",[]);d(this,"_size",0);if(t){let{bucketSize:s,maxLen:o}=t;typeof s=="number"&&(this._bucketSize=s),typeof o=="number"&&o>0&&o%1===0&&(this._maxLen=o)}let r;"length"in e?e.length instanceof Function?r=e.length():r=e.length:e.size instanceof Function?r=e.size():r=e.size,this._bucketCount=ae(r,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let i=ae(r,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(i>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-r%this._bucketSize>>1;for(let s of e)this.toElementFn?this.push(this.toElementFn(s)):this.push(s)}get bucketSize(){return this._bucketSize}get maxLen(){return this._maxLen}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get size(){return this._size}get first(){if(this.size!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this.size!==0)return this._buckets[this._bucketLast][this._lastInBucket]}push(e){return this.size&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._size+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._size>this._maxLen&&this.shift(),!0}pop(){if(this.size===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this.size!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._size-=1,e}unshift(e){return this.size&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._size+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._size>this._maxLen&&this.pop(),!0}shift(){if(this.size===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this.size!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._size-=1,e}isEmpty(){return this.size===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._size=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}*begin(){let e=0;for(;e<this.size;)yield this.at(e),e++}*reverseBegin(){let e=this.size-1;for(;e>=0;)yield this.at(e),e--}at(e){I(e,0,this.size-1);let{bucketIndex:t,indexInBucket:r}=this._getBucketAndPosition(e);return this._buckets[t][r]}setAt(e,t){I(e,0,this.size-1);let{bucketIndex:r,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[r][i]=t,!0}addAt(e,t,r=1){let i=this.size;if(I(e,0,i),e===0)for(;r--;)this.unshift(t);else if(e===this.size)for(;r--;)this.push(t);else{let s=[];for(let o=e;o<this.size;++o)s.push(this.at(o));this.cut(e-1,!0);for(let o=0;o<r;++o)this.push(t);for(let o=0;o<s.length;++o)this.push(s[o])}return!0}cut(e,t=!1){if(t){if(e<0)return this.clear(),this;let{bucketIndex:r,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketLast=r,this._lastInBucket=i,this._size=e+1,this}else{let r=new h([],{bucketSize:this._bucketSize});for(let i=0;i<=e;i++)r.push(this.at(i));return r}}cutRest(e,t=!1){if(t){if(e<0)return this.clear(),this;let{bucketIndex:r,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketFirst=r,this._firstInBucket=i,this._size=this._size-e,this}else{let r=new h([],{bucketSize:this._bucketSize});for(let i=e;i<this.size;i++)r.push(this.at(i));return r}}deleteAt(e){if(I(e,0,this.size-1),e===0)this.shift();else if(e===this.size-1)this.pop();else{let t=this.size-1,{bucketIndex:r,indexInBucket:i}=this._getBucketAndPosition(e);for(let s=e;s<t;++s){let{bucketIndex:o,indexInBucket:a}=this._getBucketAndPosition(e+1);this._buckets[r][i]=this._buckets[o][a],r=o,i=a}this.pop()}return!0}delete(e){let t=this.size;if(t===0)return!1;let r=0,i=0;for(;r<t;){let s=this.at(r);s!==e&&(this.setAt(i,s),i+=1),r+=1}return this.cut(i-1,!0),!0}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:r,_lastInBucket:i}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-i-1,this._lastInBucket=this._bucketSize-r-1,this}unique(){if(this.size<=1)return this;let e=1,t=this.at(0);for(let r=1;r<this.size;++r){let i=this.at(r);i!==t&&(t=i,this.setAt(e++,i))}return this.cut(e-1,!0),this}sort(e){let t=[];for(let r=0;r<this.size;++r)t.push(this.at(r));t.sort(e);for(let r=0;r<this.size;++r)this.setAt(r,t[r]);return this}shrinkToFit(){if(this.size===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}indexOf(e){for(let t=0;t<this.size;++t)if(this.at(t)===e)return t;return-1}toArray(){return[...this]}clone(){return new h(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn})}filter(e,t){let r=new h([],{bucketSize:this._bucketSize,toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&r.push(s),i++;return r}map(e,t,r){let i=new h([],{bucketSize:this._bucketSize,toElementFn:t}),s=0;for(let o of this)i.push(e.call(r,o,s,this)),s++;return i}*_getIterator(){for(let e=0;e<this.size;++e)yield this.at(e)}_reallocate(e){let t=[],r=e||this._bucketCount>>1||1;for(let i=0;i<r;++i)t[i]=new Array(this._bucketSize);for(let i=this._bucketFirst;i<this._bucketCount;++i)t[t.length]=this._buckets[i];for(let i=0;i<this._bucketLast;++i)t[t.length]=this._buckets[i];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=r,this._bucketLast=t.length-1;for(let i=0;i<r;++i)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,r,i=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(i/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),r=(i+1)%this._bucketSize-1,r<0&&(r=this._bucketSize-1),{bucketIndex:t,indexInBucket:r}}};var B=class h extends K{constructor(e=[],t){super(t);d(this,"_elements",[]);d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:r}=t;r&&(this._comparator=r)}if(e)for(let r of e)this.toElementFn?this.add(this.toElementFn(r)):this.add(r)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var e;return(e=this.elements[this.size-1])!=null?e:void 0}static heapify(e,t){return new h(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=e,this.fix()}has(e){return this.elements.includes(e)}delete(e){let t=this.elements.indexOf(e);return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}dfs(e="PRE"){let t=[],r=i=>{let s=2*i+1,o=s+1;i<this.size&&(e==="IN"?(r(s),t.push(this.elements[i]),r(o)):e==="PRE"?(t.push(this.elements[i]),r(s),r(o)):e==="POST"&&(r(s),r(o),t.push(this.elements[i])))};return r(0),t}toArray(){return[...this.elements]}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){let e=[],t=new h(this,{comparator:this.comparator});for(;t.size!==0;){let r=t.poll();r!==void 0&&e.push(r)}return e}fix(){let e=[];for(let t=Math.floor(this.size/2);t>=0;t--)e.push(this._sinkDown(t,this.elements.length>>1));return e}filter(e,t){let r=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let s of this)e.call(t,s,i,this)&&r.add(s),i++;return r}map(e,t,r,i){let s=new h([],{comparator:t,toElementFn:r}),o=0;for(let a of this)s.add(e.call(i,a,o,this)),o++;return s}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let r=e-1>>1,i=this.elements[r];if(this.comparator(i,t)<=0)break;this.elements[e]=i,e=r}return this.elements[e]=t,!0}_sinkDown(e,t){let r=this.elements[e];for(;e<t;){let i=e<<1|1,s=i+1,o=this.elements[i];if(s<this.elements.length&&this.comparator(o,this.elements[s])>0&&(i=s,o=this.elements[s]),this.comparator(o,r)>=0)break;this.elements[e]=o,e=i}return this.elements[e]=r,!0}},le=class{constructor(n,e=0){d(this,"element");d(this,"degree");d(this,"left");d(this,"right");d(this,"child");d(this,"parent");d(this,"marked");this.element=n,this.degree=e,this.marked=!1}},ke=class{constructor(n){d(this,"_root");d(this,"_size",0);d(this,"_min");d(this,"_comparator");if(this.clear(),this._comparator=n||this._defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap constructor: given comparator should be a function.")}get root(){return this._root}get size(){return this._size}get min(){return this._min}get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(n){return this.push(n)}push(n){let e=this.createNode(n);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this._min=e),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(n){let e=[];if(!n)return e;let t=n,r=!1;for(;!(t===n&&r);)t===n&&(r=!0),t&&(e.push(t),t=t.right);return e}mergeWithChild(n,e){n.child?(e.right=n.child.right,e.left=n.child,n.child.right.left=e,n.child.right=e):n.child=e}poll(){return this.pop()}pop(){if(this.size===0)return;let n=this.min;if(n.child){let e=this.consumeLinkedList(n.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(n),n===n.right?(this._min=void 0,this._root=void 0):(this._min=n.right,this._consolidate()),this._size--,n.element}merge(n){if(n.size!==0){if(this.root&&n.root){let e=this.root,t=n.root,r=e.right,i=t.left;e.right=t,t.left=e,r.left=i,i.right=r}(!this.min||n.min&&this.comparator(n.min.element,this.min.element)<0)&&(this._min=n.min),this._size+=n.size,n.clear()}}createNode(n){return new le(n)}_defaultComparator(n,e){return n<e?-1:n>e?1:0}mergeWithRoot(n){this.root?(n.right=this.root.right,n.left=this.root,this.root.right.left=n,this.root.right=n):this._root=n}removeFromRoot(n){this.root===n&&(this._root=n.right),n.left&&(n.left.right=n.right),n.right&&(n.right.left=n.left)}_link(n,e){this.removeFromRoot(n),n.left=n,n.right=n,this.mergeWithChild(e,n),e.degree++,n.parent=e}_consolidate(){let n=new Array(this.size),e=this.consumeLinkedList(this.root),t,r,i,s;for(let o of e){for(t=o,i=t.degree;n[i];)r=n[i],this.comparator(t.element,r.element)>0&&(s=t,t=r,r=s),this._link(r,t),n[i]=void 0,i++;n[i]=t}for(let o=0;o<this.size;o++)n[o]&&this.comparator(n[o].element,this.min.element)<=0&&(this._min=n[o])}};var Me=class h extends B{constructor(n=[],e){super(n,x({comparator:(t,r)=>{if(typeof t=="object"||typeof r=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<r?1:t>r?-1:0}},e))}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var De=class h extends B{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var k=class{constructor(n,e){d(this,"key");d(this,"value");this.key=n,this.value=e}},S=class{constructor(n,e){d(this,"value");d(this,"weight");d(this,"_hashCode");this.weight=n!==void 0?n:1,this.value=e,this._hashCode=me()}get hashCode(){return this._hashCode}},H=class extends w{constructor(){super();d(this,"_vertexMap",new Map)}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof k)return this._addVertex(e);{let r=this.createVertex(e,t);return this._addVertex(r)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let r of e)t.push(this.deleteVertex(r));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,r,i){if(e instanceof S)return this._addEdge(e);if(t instanceof k||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof k&&(e=e.key),t instanceof k&&(t=t.key);let s=this.createEdge(e,t,r,i);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,r){let i=this.getEdge(e,t);return i?(i.weight=r,!0):!1}getAllPathsBetween(e,t,r=1e3){let i=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let a=[];for(a.push({vertex:s,path:[s]});a.length>0;){let{vertex:l,path:u}=a.pop();if(l===o&&(i.push(u),i.length>=r))return i;let f=this.getNeighbors(l);for(let E of f)if(!u.includes(E)){let c=[...u,E];a.push({vertex:E,path:c})}}return i}getPathSumWeight(e){var r;let t=0;for(let i=0;i<e.length;i++)t+=((r=this.getEdge(e[i],e[i+1]))==null?void 0:r.weight)||0;return t}getMinCostBetween(e,t,r){if(r===void 0&&(r=!1),r){let i=this.getAllPathsBetween(e,t),s=1/0;for(let o of i)s=Math.min(this.getPathSumWeight(o),s);return s}else{let i=this._getVertex(t),s=this._getVertex(e);if(!(s&&i))return;let o=new Map,a=new C([s]);o.set(s,!0);let l=0;for(;a.size>0;){for(let u=0;u<a.size;u++){let f=a.shift();if(f===i)return l;if(f!==void 0){let E=this.getNeighbors(f);for(let c of E)o.has(c)||(o.set(c,!0),a.push(c))}}l++}return}}getMinPathBetween(e,t,r,i=!1){var s,o;if(r===void 0&&(r=!1),r)if(i){let a=this.getAllPathsBetween(e,t,1e4),l=1/0,u=-1,f=0;for(let E of a){let c=this.getPathSumWeight(E);c<l&&(l=c,u=f),f++}return a[u]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let a=[],l=this._getVertex(e),u=this._getVertex(t);if(!(l&&u))return[];let f=(E,c,m,y)=>{if(m.add(E),E===c){a=[l,...y];return}let O=this.getNeighbors(E);for(let R of O)m.has(R)||(y.push(R),f(R,c,m,y),y.pop());m.delete(E)};return f(l,u,new Set,[]),a}}dijkstraWithoutHeap(e,t=void 0,r=!1,i=!1){let s=1/0,o,a=[],l=[],u=this._vertexMap,f=new Map,E=new Set,c=new Map,m=this._getVertex(e),y=t?this._getVertex(t):void 0;if(!m)return;for(let N of u){let p=N[1];p instanceof k&&f.set(p,1/0)}f.set(m,0),c.set(m,void 0);let O=()=>{let N=1/0,p;for(let[g,b]of f)E.has(g)||b<N&&(N=b,p=g);return p},R=N=>{for(let p of u){let g=p[1];if(g instanceof k){let b=[g],_=c.get(g);for(;_;)b.push(_),_=c.get(_);let V=b.reverse();p[1]===N&&(a=V),l.push(V)}}};for(let N=1;N<u.size;N++){let p=O();if(p){if(E.add(p),y&&y===p)return r&&(s=f.get(y)||1/0),i&&R(y),{distMap:f,preMap:c,seen:E,paths:l,minDist:s,minPath:a};let g=this.getNeighbors(p);for(let b of g)if(!E.has(b)){let _=this.getEdge(p,b);if(_){let V=f.get(p),T=f.get(b);V!==void 0&&T!==void 0&&_.weight+V<T&&(f.set(b,_.weight+V),c.set(b,p))}}}}return r&&f.forEach((N,p)=>{p!==m&&N<s&&(s=N,i&&(o=p))}),i&&R(o),{distMap:f,preMap:c,seen:E,paths:l,minDist:s,minPath:a}}dijkstra(e,t=void 0,r=!1,i=!1){var N;let s=1/0,o,a=[],l=[],u=this._vertexMap,f=new Map,E=new Set,c=new Map,m=this._getVertex(e),y=t?this._getVertex(t):void 0;if(!m)return;for(let p of u){let g=p[1];g instanceof k&&f.set(g,1/0)}let O=new B([],{comparator:(p,g)=>p.key-g.key});O.add({key:0,value:m}),f.set(m,0),c.set(m,void 0);let R=p=>{for(let g of u){let b=g[1];if(b instanceof k){let _=[b],V=c.get(b);for(;V;)_.push(V),V=c.get(V);let T=_.reverse();g[1]===p&&(a=T),l.push(T)}}};for(;O.size>0;){let p=O.poll(),g=p==null?void 0:p.key,b=p==null?void 0:p.value;if(g!==void 0&&b){if(E.add(b),y&&y===b)return r&&(s=f.get(y)||1/0),i&&R(y),{distMap:f,preMap:c,seen:E,paths:l,minDist:s,minPath:a};let _=this.getNeighbors(b);for(let V of _)if(!E.has(V)){let T=(N=this.getEdge(b,V))==null?void 0:N.weight;if(typeof T=="number"){let z=f.get(V);z&&g+T<z&&(O.add({key:g+T,value:V}),c.set(V,b),f.set(V,g+T))}}}}return r&&f.forEach((p,g)=>{g!==m&&p<s&&(s=p,i&&(o=g))}),i&&R(o),{distMap:f,preMap:c,seen:E,paths:l,minDist:s,minPath:a}}bellmanFord(e,t,r,i){r===void 0&&(r=!1),i===void 0&&(i=!1);let s=this._getVertex(e),o=[],a=new Map,l=new Map,u=1/0,f=[],E;if(t&&(E=!1),!s)return{hasNegativeCycle:E,distMap:a,preMap:l,paths:o,min:u,minPath:f};let c=this._vertexMap,m=c.size,y=this.edgeSet(),O=y.length;this._vertexMap.forEach(N=>{a.set(N,1/0)}),a.set(s,0);for(let N=1;N<m;++N)for(let p=0;p<O;++p){let g=this.getEndsOfEdge(y[p]);if(g){let[b,_]=g,V=y[p].weight,T=a.get(b),z=a.get(_);T!==void 0&&z!==void 0&&a.get(b)!==1/0&&T+V<z&&(a.set(_,T+V),i&&l.set(_,b))}}let R;if(r&&a.forEach((N,p)=>{p!==s&&N<u&&(u=N,i&&(R=p))}),i)for(let N of c){let p=N[1];if(p instanceof k){let g=[p],b=l.get(p);for(;b!==void 0;)g.push(b),b=l.get(b);let _=g.reverse();N[1]===R&&(f=_),o.push(_)}}for(let N=0;N<O;++N){let p=this.getEndsOfEdge(y[N]);if(p){let[g]=p,b=y[N].weight,_=a.get(g);_&&_!==1/0&&_+b<_&&(E=!0)}}return{hasNegativeCycle:E,distMap:a,preMap:l,paths:o,min:u,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,r=[],i=[];for(let o=0;o<t;o++){r[o]=[],i[o]=[];for(let a=0;a<t;a++)i[o][a]=void 0}for(let o=0;o<t;o++)for(let a=0;a<t;a++)r[o][a]=((s=this.getEdge(e[o][1],e[a][1]))==null?void 0:s.weight)||1/0;for(let o=0;o<t;o++)for(let a=0;a<t;a++)for(let l=0;l<t;l++)r[a][l]>r[a][o]+r[o][l]&&(r[a][l]=r[a][o]+r[o][l],i[a][l]=e[o][1]);return{costs:r,predecessor:i}}getCycles(e=!1){let t=[],r=new Set,i=(o,a,l)=>{if(l.has(o)){(!e&&a.length>2||e&&a.length>=2)&&a[0]===o.key&&t.push([...a]);return}l.add(o),a.push(o.key);for(let u of this.getNeighbors(o))u&&i(u,a,l);l.delete(o),a.pop()};for(let o of this.vertexMap.values())i(o,[],r);let s=new Map;for(let o of t){let a=[...o].sort().toString();s.has(a)||s.set(a,o)}return[...s].map(o=>o[1])}filter(e,t){let r=[],i=0;for(let[s,o]of this)e.call(t,o,s,i,this)&&r.push([s,o]),i++;return r}map(e,t){let r=[],i=0;for(let[s,o]of this)r.push(e.call(t,o,s,i,this)),i++;return r}*_getIterator(){for(let e of this._vertexMap.values())yield[e.key,e.value]}_addVertex(e){return this.hasVertex(e)?!1:(this._vertexMap.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertexMap.get(t)||void 0}_getVertexKey(e){return e instanceof k?e.key:e}};var P=class extends k{constructor(n,e){super(n,e)}},W=class extends S{constructor(e,t,r,i){super(r,i);d(this,"src");d(this,"dest");this.src=e,this.dest=t}},$=class h extends H{constructor(){super();d(this,"_outEdgeMap",new Map);d(this,"_inEdgeMap",new Map)}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(e){this._outEdgeMap=e}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(e){this._inEdgeMap=e}createVertex(e,t){return new P(e,t)}createEdge(e,t,r,i){return new W(e,t,r!=null?r:1,i)}getEdge(e,t){let r=[];if(e!==void 0&&t!==void 0){let i=this._getVertex(e),s=this._getVertex(t);if(i&&s){let o=this._outEdgeMap.get(i);o&&(r=o.filter(a=>a.dest===s.key))}}return r[0]||void 0}deleteEdgeSrcToDest(e,t){let r=this._getVertex(e),i=this._getVertex(t),s;if(!r||!i)return;let o=this._outEdgeMap.get(r);o&&L(o,l=>l.dest===i.key);let a=this._inEdgeMap.get(i);return a&&(s=L(a,l=>l.src===r.key)[0]||void 0),s}deleteEdge(e,t){let r,i,s;if(this.isVertexKey(e))if(this.isVertexKey(t))i=this._getVertex(e),s=this._getVertex(t);else return;else i=this._getVertex(e.src),s=this._getVertex(e.dest);if(i&&s){let o=this._outEdgeMap.get(i);o&&o.length>0&&L(o,l=>l.src===i.key&&l.dest===(s==null?void 0:s.key));let a=this._inEdgeMap.get(s);a&&a.length>0&&(r=L(a,l=>l.src===i.key&&l.dest===s.key)[0])}return r}deleteVertex(e){let t,r;if(this.isVertexKey(e)?(r=this.getVertex(e),t=e):(r=e,t=this._getVertexKey(e)),r){let i=this.getNeighbors(r);for(let s of i)this.deleteEdgeSrcToDest(r,s);this._outEdgeMap.delete(r),this._inEdgeMap.delete(r)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let r=[];if(e&&t){let i=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);i&&r.push(i),s&&r.push(s)}return r}incomingEdgesOf(e){let t=this._getVertex(e);return t?this.inEdgeMap.get(t)||[]:[]}outgoingEdgesOf(e){let t=this._getVertex(e);return t?this._outEdgeMap.get(t)||[]:[]}degreeOf(e){return this.outDegreeOf(e)+this.inDegreeOf(e)}inDegreeOf(e){return this.incomingEdgesOf(e).length}outDegreeOf(e){return this.outgoingEdgesOf(e).length}edgesOf(e){return[...this.outgoingEdgesOf(e),...this.incomingEdgesOf(e)]}getEdgeSrc(e){return this._getVertex(e.src)}getEdgeDest(e){return this._getVertex(e.dest)}getDestinations(e){if(e===void 0)return[];let t=[],r=this.outgoingEdgesOf(e);for(let i of r){let s=this.getEdgeDest(i);s&&t.push(s)}return t}topologicalSort(e){e=e!=null?e:"key";let t=new Map;for(let o of this.vertexMap)t.set(o[1],0);let r=[],i=!1,s=o=>{t.set(o,1);let a=this.getDestinations(o);for(let l of a){let u=t.get(l);u===0?s(l):u===1&&(i=!0)}t.set(o,2),r.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!i)return e==="key"&&(r=r.map(o=>o instanceof P?o.key:o)),r.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],r=this._getVertex(e);if(r){let i=this.outgoingEdgesOf(r);for(let s of i){let o=this._getVertex(s.dest);o&&t.push(o)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.src,e.dest))return;let t=this._getVertex(e.src),r=this._getVertex(e.dest);if(t&&r)return[t,r]}isEmpty(){return this.vertexMap.size===0&&this.inEdgeMap.size===0&&this.outEdgeMap.size===0}clear(){this._vertexMap=new Map,this._inEdgeMap=new Map,this._outEdgeMap=new Map}clone(){let e=new h;return e.vertexMap=new Map(this.vertexMap),e.inEdgeMap=new Map(this.inEdgeMap),e.outEdgeMap=new Map(this.outEdgeMap),e}tarjan(){let e=new Map,t=new Map,r=new Map,i=0,s=[],o=new Set,a=l=>{e.set(l,i),t.set(l,i),i++,s.push(l),o.add(l);let u=this.getNeighbors(l);for(let f of u)e.has(f)?o.has(f)&&t.set(l,Math.min(t.get(l),e.get(f))):(a(f),t.set(l,Math.min(t.get(l),t.get(f))));if(e.get(l)===t.get(l)){let f=[],E;do E=s.pop(),o.delete(E),f.push(E);while(E!==l);r.set(r.size,f)}};for(let l of this.vertexMap.values())e.has(l)||a(l);return{dfnMap:e,lowMap:t,SCCs:r}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),r=this._getVertex(e.dest);if(t&&r){let i=this._outEdgeMap.get(t);i?i.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(r);return s?s.push(e):this._inEdgeMap.set(r,[e]),!0}else return!1}};var he=class extends k{constructor(n,e){super(n,e)}},ue=class extends S{constructor(e,t,r,i){super(r,i);d(this,"endpoints");this.endpoints=[e,t]}},Ce=class h extends H{constructor(){super();d(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}createVertex(e,t){return new he(e,t!=null?t:e)}createEdge(e,t,r,i){return new ue(e,t,r!=null?r:1,i)}getEdge(e,t){var i;let r=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(r=(i=this._edgeMap.get(s))==null?void 0:i.filter(a=>a.endpoints.includes(o.key)))}return r&&r[0]||void 0}deleteEdgeBetween(e,t){let r=this._getVertex(e),i=this._getVertex(t);if(!r||!i)return;let s=this._edgeMap.get(r),o;s&&(o=L(s,l=>l.endpoints.includes(i.key))[0]||void 0);let a=this._edgeMap.get(i);return a&&L(a,l=>l.endpoints.includes(r.key)),o}deleteEdge(e,t){let r,i;if(this.isVertexKey(e))if(this.isVertexKey(t))r=this._getVertex(e),i=this._getVertex(t);else return;else r=this._getVertex(e.endpoints[0]),i=this._getVertex(e.endpoints[1]);if(r&&i)return this.deleteEdgeBetween(r,i)}deleteVertex(e){let t,r;this.isVertexKey(e)?(r=this.getVertex(e),t=e):(r=e,t=this._getVertexKey(e));let i=this.getNeighbors(e);return r&&(i.forEach(s=>{let o=this._edgeMap.get(s);if(o){let a=o.filter(l=>!l.endpoints.includes(t));this._edgeMap.set(s,a)}}),this._edgeMap.delete(r)),this._vertexMap.delete(t)}degreeOf(e){var r;let t=this._getVertex(e);return t&&((r=this._edgeMap.get(t))==null?void 0:r.length)||0}edgesOf(e){let t=this._getVertex(e);return t?this._edgeMap.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edgeMap.forEach(t=>{t.forEach(r=>{e.add(r)})}),[...e]}getNeighbors(e){let t=[],r=this._getVertex(e);if(r){let i=this.edgesOf(r);for(let s of i){let o=this._getVertex(s.endpoints.filter(a=>a!==r.key)[0]);o&&t.push(o)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.endpoints[0],e.endpoints[1]))return;let t=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(t&&r)return[t,r]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){let e=new h;return e.vertexMap=new Map(this.vertexMap),e.edgeMap=new Map(this.edgeMap),e}tarjan(){let e=new Map,t=new Map,r=[],i=[],s=0,o=(a,l)=>{e.set(a,s),t.set(a,s),s++;let u=this.getNeighbors(a),f=0;for(let E of u)if(e.has(E))E!==l&&t.set(a,Math.min(t.get(a),e.get(E)));else{if(f++,o(E,a),t.set(a,Math.min(t.get(a),t.get(E))),t.get(E)>e.get(a)){let c=this.getEdge(a,E);c&&r.push(c)}l!==void 0&&t.get(E)>=e.get(a)&&i.push(a)}l===void 0&&f>1&&i.push(a)};for(let a of this.vertexMap.values())e.has(a)||o(a,void 0);return{dfnMap:e,lowMap:t,bridges:r,cutVertices:i}}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(e){for(let t of e.endpoints){let r=this._getVertex(t);if(r===void 0)return!1;if(r){let i=this._edgeMap.get(r);i?i.push(e):this._edgeMap.set(r,[e])}}return!0}};var de=class extends P{constructor(e,t,r,i){super(e,t);d(this,"lat");d(this,"long");this.lat=r,this.long=i}},fe=class extends W{constructor(n,e,t,r){super(n,e,t,r)}},Be=class h extends ${constructor(e,t){super();d(this,"_originCoord",[0,0]);d(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,r=this.originCoord[0],i=this.originCoord[1]){return new de(e,t,r,i)}createEdge(e,t,r,i){return new fe(e,t,r,i)}clone(){let e=new h(this.originCoord,this.bottomRight);return e.vertexMap=new Map(this.vertexMap),e.inEdgeMap=new Map(this.inEdgeMap),e.outEdgeMap=new Map(this.outEdgeMap),e}};var A=class{constructor(n,e){d(this,"key");d(this,"value");d(this,"parent");d(this,"_left");d(this,"_right");this.key=n,this.value=e}get left(){return this._left}set left(n){n&&(n.parent=this),this._left=n}get right(){return this._right}set right(n){n&&(n.parent=this),this._right=n}get familyPosition(){let n=this;return this.parent?this.parent.left===n?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===n?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},ee=class h extends w{constructor(e=[],t){super();d(this,"iterationType","ITERATIVE");d(this,"_root");d(this,"_size",0);d(this,"_NIL",new A(NaN));d(this,"_toEntryFn");d(this,"_DEFAULT_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:r,toEntryFn:i}=t;if(r&&(this.iterationType=r),typeof i=="function")this._toEntryFn=i;else if(i)throw TypeError("toEntryFn must be a function type")}e&&this.addMany(e)}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(e,t){return new A(e,t)}createTree(e){return new h([],x({iterationType:this.iterationType},e))}keyValueOrEntryOrRawElementToNode(e,t){if(e!==void 0){if(e===null)return null;if(this.isNode(e))return e;if(this.toEntryFn){let[r,i]=this.toEntryFn(e);return r?this.createNode(r,i!=null?i:t):void 0}if(this.isEntry(e)){let[r,i]=e;return r===void 0?void 0:r===null?null:this.createNode(r,i)}if(this.isKey(e))return this.createNode(e,t)}}ensureNode(e,t="ITERATIVE"){if(e===null)return null;if(e!==void 0&&e!==this.NIL){if(this.isNode(e))return e;if(this.toEntryFn){let[r]=this.toEntryFn(e);if(r)return this.getNodeByKey(r)}if(this.isEntry(e)){let r=e[0];return r===null?null:r===void 0?void 0:this.getNodeByKey(r,t)}if(this.isKey(e))return this.getNodeByKey(e,t)}}isNode(e){return e instanceof A}isRealNode(e){return e===this.NIL||e===null||e===void 0?!1:this.isNode(e)}isNodeOrNull(e){return this.isRealNode(e)||e===null}isNIL(e){return e===this.NIL}isEntry(e){return Array.isArray(e)&&e.length===2}isKey(e,t=!0){if(e===null)return!0;let r=typeof e;return r==="string"||r==="bigint"||r==="boolean"?!0:r==="number"?!isNaN(e):r==="symbol"||r==="undefined"?!1:r==="function"?this.isKey(e()):r==="object"?typeof e.toString=="function"?!0:(t&&typeof e.valueOf=="function"&&this.isKey(e.valueOf(),!1),!1):!1}add(e,t){let r=this.keyValueOrEntryOrRawElementToNode(e,t);if(r===void 0)return!1;if(!this.root)return this._root=r,this._size=1,!0;let i=new C([this.root]),s;for(;i.size>0;){let o=i.shift();if(o){if(r!==null&&o.key===r.key)return this._replaceNode(o,r),!0;s===void 0&&(o.left===void 0||o.right===void 0)&&(s=o),o.left!==null&&o.left&&i.push(o.left),o.right!==null&&o.right&&i.push(o.right)}}return s?(s.left===void 0?s.left=r:s.right===void 0&&(s.right=r),this._size++,!0):!1}addMany(e,t){let r=[],i;t&&(i=t[Symbol.iterator]());for(let s of e){let o;if(i){let a=i.next();a.done||(o=a.value)}r.push(this.add(s,o))}return r}refill(e,t){this.clear(),this.addMany(e,t)}delete(e,t=this._DEFAULT_CALLBACK){let r=[];if(!this.root)return r;t=this._ensureCallback(e,t);let i=this.getNode(e,t);if(!i)return r;let s=i==null?void 0:i.parent,o,a=i;if(!i.left&&!i.right&&!s)this._setRoot(void 0);else if(i.left){let l=this.getRightMost(i.left);if(l){let u=l.parent;a=this._swapProperties(i,l),u&&(u.right===l?u.right=l.left:u.left=l.left,o=u)}}else if(s){let{familyPosition:l}=i;l==="LEFT"||l==="ROOT_LEFT"?s.left=i.right:(l==="RIGHT"||l==="ROOT_RIGHT")&&(s.right=i.right),o=s}else this._setRoot(i.right),i.right=void 0;return this._size=this.size-1,r.push({deleted:a,needBalanced:o}),r}getNodes(e,t=this._DEFAULT_CALLBACK,r=!1,i=this.root,s=this.iterationType){if(i=this.ensureNode(i),!i)return[];t=this._ensureCallback(e,t);let o=[];if(s==="RECURSIVE"){let a=l=>{t(l)===e&&(o.push(l),r)||!this.isRealNode(l.left)&&!this.isRealNode(l.right)||(this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right))};a(i)}else{let a=[i];for(;a.length>0;){let l=a.pop();if(this.isRealNode(l)){if(t(l)===e&&(o.push(l),r))return o;this.isRealNode(l.left)&&a.push(l.left),this.isRealNode(l.right)&&a.push(l.right)}}}return o}getNode(e,t=this._DEFAULT_CALLBACK,r=this.root,i=this.iterationType){var s;return(s=this.getNodes(e,t,!0,r,i)[0])!=null?s:null}getNodeByKey(e,t="ITERATIVE"){return this.getNode(e,this._DEFAULT_CALLBACK,this.root,t)}get(e,t=this._DEFAULT_CALLBACK,r=this.root,i=this.iterationType){var s;return(s=this.getNode(e,t,r,i))==null?void 0:s.value}has(e,t=this._DEFAULT_CALLBACK,r=this.root,i=this.iterationType){return t=this._ensureCallback(e,t),this.getNodes(e,t,!0,r,i).length>0}clear(){this._setRoot(void 0),this._size=0}isEmpty(){return this.size===0}isPerfectlyBalanced(e=this.root){return this.getMinHeight(e)+1>=this.getHeight(e)}isBST(e=this.root,t=this.iterationType){if(e=this.ensureNode(e),!e)return!0;if(t==="RECURSIVE"){let r=(o,a,l)=>{if(!this.isRealNode(o))return!0;let u=Number(o.key);return u<=a||u>=l?!1:r(o.left,a,u)&&r(o.right,u,l)},i=r(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=r(e,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return i||s}else{let r=(o=!1)=>{let a=[],l=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,u=e;for(;this.isRealNode(u)||a.length>0;){for(;this.isRealNode(u);)a.push(u),u=u.left;u=a.pop();let f=Number(u.key);if(!this.isRealNode(u)||!o&&l>=f||o&&l<=f)return!1;l=f,u=u.right}return!0},i=r(!1),s=r(!0);return i||s}}getDepth(e,t=this.root){let r=this.ensureNode(e),i=this.ensureNode(t),s=0;for(;r!=null&&r.parent;){if(r===i)return s;s++,r=r.parent}return s}getHeight(e=this.root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let r=i=>{if(!this.isRealNode(i))return-1;let s=r(i.left),o=r(i.right);return Math.max(s,o)+1};return r(e)}else{let r=[{node:e,depth:0}],i=0;for(;r.length>0;){let{node:s,depth:o}=r.pop();this.isRealNode(s.left)&&r.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&r.push({node:s.right,depth:o+1}),i=Math.max(i,o)}return i}}getMinHeight(e=this.root,t=this.iterationType){var r,i,s;if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let o=a=>{if(!this.isRealNode(a)||!this.isRealNode(a.left)&&!this.isRealNode(a.right))return 0;let l=o(a.left),u=o(a.right);return Math.min(l,u)+1};return o(e)}else{let o=[],a=e,l=null,u=new Map;for(;o.length>0||a;)if(this.isRealNode(a))o.push(a),a=a.left;else if(a=o[o.length-1],!this.isRealNode(a.right)||l===a.right){if(a=o.pop(),this.isRealNode(a)){let f=this.isRealNode(a.left)&&(r=u.get(a.left))!=null?r:-1,E=this.isRealNode(a.right)&&(i=u.get(a.right))!=null?i:-1;u.set(a,1+Math.min(f,E)),l=a,a=null}}else a=a.right;return(s=u.get(e))!=null?s:-1}}getPathToRoot(e,t=!0){let r=[],i=this.ensureNode(e);if(!i)return r;for(;i.parent;)r.push(i),i=i.parent;return r.push(i),t?r.reverse():r}getLeftMost(e=this.root,t=this.iterationType){if(this.isNIL(e)||(e=this.ensureNode(e),!this.isRealNode(e)))return e;if(t==="RECURSIVE"){let r=i=>this.isRealNode(i.left)?r(i.left):i;return r(e)}else{let r=oe(i=>this.isRealNode(i.left)?r.cont(i.left):i);return r(e)}}getRightMost(e=this.root,t=this.iterationType){if(this.isNIL(e)||(e=this.ensureNode(e),!e))return e;if(t==="RECURSIVE"){let r=i=>this.isRealNode(i.right)?r(i.right):i;return r(e)}else{let r=oe(i=>this.isRealNode(i.right)?r.cont(i.right):i);return r(e)}}getPredecessor(e){if(this.isRealNode(e.left)){let t=e.left;for(;!this.isRealNode(t)||this.isRealNode(t.right)&&t.right!==e;)this.isRealNode(t)&&(t=t.right);return t}else return e}getSuccessor(e){if(e=this.ensureNode(e),!this.isRealNode(e))return;if(this.isRealNode(e.right))return this.getLeftMost(e.right);let t=e.parent;for(;this.isRealNode(t)&&e===t.right;)e=t,t=t.parent;return t}dfs(e=this._DEFAULT_CALLBACK,t="IN",r=this.root,i="ITERATIVE",s=!1){if(r=this.ensureNode(r),!r)return[];let o=[];if(i==="RECURSIVE"){let a=l=>{switch(t){case"IN":s?(this.isRealNode(l)&&this.isNodeOrNull(l.left)&&a(l.left),this.isNodeOrNull(l)&&o.push(e(l)),this.isRealNode(l)&&this.isNodeOrNull(l.right)&&a(l.right)):(this.isRealNode(l)&&this.isRealNode(l.left)&&a(l.left),this.isRealNode(l)&&o.push(e(l)),this.isRealNode(l)&&this.isRealNode(l.right)&&a(l.right));break;case"PRE":s?(this.isNodeOrNull(l)&&o.push(e(l)),this.isRealNode(l)&&this.isNodeOrNull(l.left)&&a(l.left),this.isRealNode(l)&&this.isNodeOrNull(l.right)&&a(l.right)):(this.isRealNode(l)&&o.push(e(l)),this.isRealNode(l)&&this.isRealNode(l.left)&&a(l.left),this.isRealNode(l)&&this.isRealNode(l.right)&&a(l.right));break;case"POST":s?(this.isRealNode(l)&&this.isNodeOrNull(l.left)&&a(l.left),this.isRealNode(l)&&this.isNodeOrNull(l.right)&&a(l.right),this.isNodeOrNull(l)&&o.push(e(l))):(this.isRealNode(l)&&this.isRealNode(l.left)&&a(l.left),this.isRealNode(l)&&this.isRealNode(l.right)&&a(l.right),this.isRealNode(l)&&o.push(e(l)));break}};a(r)}else{let a=[{opt:0,node:r}];for(;a.length>0;){let l=a.pop();if(!(l===void 0||this.isNIL(l.node))){if(s){if(l.node===void 0)continue}else if(l.node===null||l.node===void 0)continue;if(l.opt===1)o.push(e(l.node));else switch(t){case"IN":l.node&&a.push({opt:0,node:l.node.right}),a.push({opt:1,node:l.node}),l.node&&a.push({opt:0,node:l.node.left});break;case"PRE":l.node&&a.push({opt:0,node:l.node.right}),l.node&&a.push({opt:0,node:l.node.left}),a.push({opt:1,node:l.node});break;case"POST":a.push({opt:1,node:l.node}),l.node&&a.push({opt:0,node:l.node.right}),l.node&&a.push({opt:0,node:l.node.left});break;default:l.node&&a.push({opt:0,node:l.node.right}),a.push({opt:1,node:l.node}),l.node&&a.push({opt:0,node:l.node.left});break}}}}return o}bfs(e=this._DEFAULT_CALLBACK,t=this.root,r=this.iterationType,i=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(r==="RECURSIVE"){let o=new C([t]),a=l=>{if(o.size===0)return;let u=o.shift();s.push(e(u)),i?(u&&this.isNodeOrNull(u.left)&&o.push(u.left),u&&this.isNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right)),a(l+1)};a(0)}else{let o=new C([t]);for(;o.size>0;){let a=o.size;for(let l=0;l<a;l++){let u=o.shift();s.push(e(u)),i?(u&&this.isNodeOrNull(u.left)&&o.push(u.left),u&&this.isNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right))}}}return s}listLevels(e=this._DEFAULT_CALLBACK,t=this.root,r=this.iterationType,i=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(r==="RECURSIVE"){let o=(a,l)=>{s[l]||(s[l]=[]),s[l].push(e(a)),i?(a&&this.isNodeOrNull(a.left)&&o(a.left,l+1),a&&this.isNodeOrNull(a.right)&&o(a.right,l+1)):(a&&a.left&&o(a.left,l+1),a&&a.right&&o(a.right,l+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let a=o.pop(),[l,u]=a;s[u]||(s[u]=[]),s[u].push(e(l)),i?(l&&this.isNodeOrNull(l.right)&&o.push([l.right,u+1]),l&&this.isNodeOrNull(l.left)&&o.push([l.left,u+1])):(l&&l.right&&o.push([l.right,u+1]),l&&l.left&&o.push([l.left,u+1]))}}return s}morris(e=this._DEFAULT_CALLBACK,t="IN",r=this.root){if(r=this.ensureNode(r),r===null)return[];let i=[],s=r,o=l=>{let u=null,f=null;for(;l;)f=l.right,l.right=u,u=l,l=f;return u},a=l=>{let u=o(l),f=u;for(;f;)i.push(e(f)),f=f.right;o(u)};switch(t){case"IN":for(;s;){if(s.left){let l=this.getPredecessor(s);if(l.right)l.right=null;else{l.right=s,s=s.left;continue}}i.push(e(s)),s=s.right}break;case"PRE":for(;s;){if(s.left){let l=this.getPredecessor(s);if(l.right)l.right=null;else{l.right=s,i.push(e(s)),s=s.left;continue}}else i.push(e(s));s=s.right}break;case"POST":for(;s;){if(s.left){let l=this.getPredecessor(s);if(l.right===null){l.right=s,s=s.left;continue}else l.right=null,a(s.left)}s=s.right}a(r);break}return i}clone(){let e=this.createTree();return this.bfs(t=>{t===null?e.add(null):e.add([t.key,t.value])},this.root,this.iterationType,!0),e}filter(e,t){let r=this.createTree(),i=0;for(let[s,o]of this)e.call(t,o,s,i++,this)&&r.add([s,o]);return r}map(e,t){let r=this.createTree(),i=0;for(let[s,o]of this)r.add([s,e.call(t,o,s,i++,this)]);return r}print(e=this.root,t){let r=x({isShowUndefined:!1,isShowNull:!1,isShowRedBlackNIL:!1},t);if(e=this.ensureNode(e),!e)return;r.isShowUndefined&&console.log(`U for undefined
|
|
2
2
|
`),r.isShowNull&&console.log(`N for null
|
|
3
3
|
`),r.isShowRedBlackNIL&&console.log(`S for Sentinel Node(NIL)
|
|
4
|
-
`),(s=>{let[o,,,]=this._displayAux(s,r);for(let a of o)console.log(a)})(e)}*_getIterator(e=this.root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],r=e;for(;r||t.length>0;){for(;this.isRealNode(r);)t.push(r),r=r.left;r=t.pop(),this.isRealNode(r)&&(yield[r.key,r.value],r=r.right)}}else e.left&&this.isRealNode(e)&&(yield*v(this[Symbol.iterator](e.left))),yield[e.key,e.value],e.right&&this.isRealNode(e)&&(yield*v(this[Symbol.iterator](e.right)))}_displayAux(e,t){let{isShowNull:r,isShowUndefined:i,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!r)return o;if(e===void 0&&!i)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let l=e.key,u=this.isNIL(e)?"S":String(l),f=u.length;return a(u,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let l=e===void 0?"U":"N",u=l.length;return a(l,u,[[""],1,0,0],[[""],1,0,0])}function a(l,u,f,E){let[c,m,y,O]=f,[R,N,p,g]=E,b=" ".repeat(Math.max(0,O+1))+"_".repeat(Math.max(0,m-O-1))+l+"_".repeat(Math.max(0,g))+" ".repeat(Math.max(0,N-g)),_=(y>0?" ".repeat(O)+"/"+" ".repeat(m-O-1):" ".repeat(m))+" ".repeat(u)+(p>0?" ".repeat(g)+"\\"+" ".repeat(N-g-1):" ".repeat(N)),V=[b,_];for(let T=0;T<Math.max(y,p);T++){let z=T<y?c[T]:" ".repeat(m),Ge=T<p?R[T]:" ".repeat(N);V.push(z+" ".repeat(u)+Ge)}return[V,m+u+N,Math.max(y,p)+2,m+Math.floor(u/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:r,value:i}=t,s=this.createNode(r,i);return s&&(t.key=e.key,t.value=e.value,e.key=s.key,e.value=s.value),t}}_replaceNode(e,t){return e.parent&&(e.parent.left===e?e.parent.left=t:e.parent.right===e&&(e.parent.right=t)),t.left=e.left,t.right=e.right,t.parent=e.parent,this.root===e&&(this._root=t),t}_setRoot(e){e&&(e.parent=void 0),this._root=e}_ensureCallback(e,t=this._DEFAULT_CALLBACK){return(!t||t===this._DEFAULT_CALLBACK)&&this.isNode(e)&&(t=r=>r),t}};var F=class extends A{constructor(e,t){super(e,t);d(this,"parent");d(this,"_left");d(this,"_right");this.parent=void 0,this._left=void 0,this._right=void 0}get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},j=class h extends ee{constructor(e=[],t){super([],t);d(this,"_root");d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:r}=t;r&&(this._comparator=r)}e&&this.addMany(e)}get root(){return this._root}createNode(e,t){return new F(e,t)}createTree(e){return new h([],x({iterationType:this.iterationType,comparator:this.comparator},e))}keyValueOrEntryOrRawElementToNode(e,t){var r;return(r=super.keyValueOrEntryOrRawElementToNode(e,t))!=null?r:void 0}ensureNode(e,t="ITERATIVE"){var r;return(r=super.ensureNode(e,t))!=null?r:void 0}isNode(e){return e instanceof F}add(e,t){let r=this.keyValueOrEntryOrRawElementToNode(e,t);if(r===void 0)return!1;if(this.root===void 0)return this._setRoot(r),this._size++,!0;let i=this.root;for(;i!==void 0;){if(this.comparator(i.key,r.key)===0)return this._replaceNode(i,r),!0;if(this.comparator(i.key,r.key)>0){if(i.left===void 0)return i.left=r,this._size++,!0;i=i.left}else{if(i.right===void 0)return i.right=r,this._size++,!0;i=i.right}}return!1}addMany(e,t,r=!0,i=this.iterationType){let s=[],o;if(t&&(o=t[Symbol.iterator]()),!r){for(let c of e){let m=o==null?void 0:o.next().value,y=this.add(c,m);s.push(y)}return s}let a=[],l=c=>c==null?!1:!(this.isEntry(c)&&(c[0]===void 0||c[0]===null));for(let c of e)l(c)&&a.push(c);let u=[];u=a.sort((c,m)=>{let y,O;return this.isEntry(c)?y=c[0]:this.isRealNode(c)?y=c.key:this.toEntryFn?y=this.toEntryFn(c)[0]:y=c,this.isEntry(m)?O=m[0]:this.isRealNode(m)?O=m.key:this.toEntryFn?O=this.toEntryFn(m)[0]:O=m,y!=null&&O!==void 0&&O!==null?this.comparator(y,O):0});let f=c=>{if(c.length===0)return;let m=Math.floor((c.length-1)/2),y=this.add(c[m]);s.push(y),f(c.slice(0,m)),f(c.slice(m+1))};return i==="RECURSIVE"?f(u):(()=>{let m=[[0,u.length-1]];for(;m.length>0;){let y=m.pop();if(y){let[O,R]=y;if(O<=R){let N=O+Math.floor((R-O)/2),p=this.add(u[N]);s.push(p),m.push([N+1,R]),m.push([O,N-1])}}}})(),s}getNodes(e,t=this._DEFAULT_CALLBACK,r=!1,i=this.root,s=this.iterationType){if(i=this.ensureNode(i),!i)return[];t=this._ensureCallback(e,t);let o=[];if(s==="RECURSIVE"){let a=l=>{t(l)===e&&(o.push(l),r)||!this.isRealNode(l.left)&&!this.isRealNode(l.right)||(t===this._DEFAULT_CALLBACK?(this.isRealNode(l.left)&&this.comparator(l.key,e)>0&&a(l.left),this.isRealNode(l.right)&&this.comparator(l.key,e)<0&&a(l.right)):(this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right)))};a(i)}else{let a=[i];for(;a.length>0;){let l=a.pop();if(t(l)===e&&(o.push(l),r))return o;t===this._DEFAULT_CALLBACK?(this.isRealNode(l.right)&&this.comparator(l.key,e)<0&&a.push(l.right),this.isRealNode(l.left)&&this.comparator(l.key,e)>0&&a.push(l.left)):(this.isRealNode(l.right)&&a.push(l.right),this.isRealNode(l.left)&&a.push(l.left))}}return o}getNode(e,t=this._DEFAULT_CALLBACK,r=this.root,i=this.iterationType){var s;return(s=this.getNodes(e,t,!0,r,i)[0])!=null?s:void 0}getNodeByKey(e,t="ITERATIVE"){return this.getNode(e,this._DEFAULT_CALLBACK,this.root,t)}dfs(e=this._DEFAULT_CALLBACK,t="IN",r=this.root,i="ITERATIVE"){return super.dfs(e,t,r,i,!1)}bfs(e=this._DEFAULT_CALLBACK,t=this.root,r=this.iterationType){return super.bfs(e,t,r,!1)}listLevels(e=this._DEFAULT_CALLBACK,t=this.root,r=this.iterationType){return super.listLevels(e,t,r,!1)}lesserOrGreaterTraverse(e=this._DEFAULT_CALLBACK,t=-1,r=this.root,i=this.iterationType){let s=this.ensureNode(r),o=[];if(!s||!this.root)return o;let a=s.key;if(i==="RECURSIVE"){let l=u=>{let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&l(u.left),this.isRealNode(u.right)&&l(u.right)};return l(this.root),o}else{let l=new C([this.root]);for(;l.size>0;){let u=l.shift();if(this.isRealNode(u)){let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&l.push(u.left),this.isRealNode(u.right)&&l.push(u.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),r=t.length;if(this.clear(),t.length<1)return!1;if(e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this.add([l.key,l.value]),i(s,a-1),i(a+1,o)};return i(0,r-1),!0}else{let i=[[0,r-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this.add([u.key,u.value]),i.push([l+1,a]),i.push([o,l-1])}}}return!0}}isAVLBalanced(e=this.iterationType){var r,i;if(!this.root)return!0;let t=!0;if(e==="RECURSIVE"){let s=o=>{if(!o)return 0;let a=s(o.left),l=s(o.right);return Math.abs(a-l)>1&&(t=!1),Math.max(a,l)+1};s(this.root)}else{let s=[],o=this.root,a,l=new Map;for(;s.length>0||o;)if(o)s.push(o),o=o.left;else if(o=s[s.length-1],!o.right||a===o.right){if(o=s.pop(),o){let u=o.left&&(r=l.get(o.left))!=null?r:-1,f=o.right&&(i=l.get(o.right))!=null?i:-1;if(Math.abs(u-f)>1)return!1;l.set(o,1+Math.max(u,f)),a=o,o=void 0}}else o=o.right}return t}get comparator(){return this._comparator}_setRoot(e){e&&(e.parent=void 0),this._root=e}};var ve=class{constructor({frequency:n=0,max:e}){d(this,"_freq");d(this,"_max");d(this,"_freqMap");d(this,"_msb");d(this,"_negativeCount");this._freq=n,this._max=e,this._freqMap={0:0},this._msb=be(e),this._negativeCount=n<0?e:0}get freqMap(){return this._freqMap}get msb(){return this._msb}get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(n){return this._checkIndex(n),this._readSingle(n)}update(n,e){this._checkIndex(n);let t=this._readSingle(n);this._update(n,e),this._updateNegativeCount(t,t+e)}writeSingle(n,e){this._checkIndex(n),this._writeSingle(n,e)}read(n){if(!Number.isInteger(n))throw new Error("Invalid count");return this._read(Math.max(Math.min(n,this.max),0))}lowerBound(n){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(n,(e,t)=>e<t)}upperBound(n){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(n,(e,t)=>e<=t)}getPrefixSum(n){this._checkIndex(n),n++;let e=0;for(;n>0;)e+=this._getFrequency(n),n-=n&-n;return e}_getFrequency(n){return n in this.freqMap?this.freqMap[n]:this.freq*(n&-n)}_updateFrequency(n,e){this.freqMap[n]=this._getFrequency(n)+e}_checkIndex(n){if(!Number.isInteger(n))throw new Error("Invalid index: Index must be an integer.");if(n<0||n>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(n){n=n+1;let e=this._getFrequency(n),t=n-(n&-n);for(n--;n!==t;)e-=this._getFrequency(n),n-=n&-n;return e}_updateNegativeCount(n,e){n<0&&e>=0?this._negativeCount--:n>=0&&e<0&&this._negativeCount++}_update(n,e){for(n=n+1;n<=this.max;)this._updateFrequency(n,e),n+=n&-n}_writeSingle(n,e){let t=this._readSingle(n);this._update(n,e-t),this._updateNegativeCount(t,e)}_read(n){let e=n,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(n,e){let t=0,r=this.msb<<1,i=n;for(;r>t+1;){let s=t+r>>1,o=this._getFrequency(s);s<=this.max&&e(o,i)?(i-=o,t=s):r=s}return t}};var X=class{constructor(n,e,t,r){d(this,"_start",0);d(this,"_end",0);d(this,"_value");d(this,"_sum",0);d(this,"_left");d(this,"_right");this._start=n,this._end=e,this._sum=t,this._value=r||void 0}get start(){return this._start}set start(n){this._start=n}get end(){return this._end}set end(n){this._end=n}get value(){return this._value}set value(n){this._value=n}get sum(){return this._sum}set sum(n){this._sum=n}get left(){return this._left}set left(n){this._left=n}get right(){return this._right}set right(n){this._right=n}},we=class{constructor(n,e,t){d(this,"_values",[]);d(this,"_start",0);d(this,"_end");d(this,"_root");e=e||0,t=t||n.length-1,this._values=n,this._start=e,this._end=t,n.length>0?this._root=this.build(e,t):(this._root=void 0,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(n,e){if(n>e)return new X(n,e,0);if(n===e)return new X(n,e,this._values[n]);let t=n+Math.floor((e-n)/2),r=this.build(n,t),i=this.build(t+1,e),s=new X(n,e,r.sum+i.sum);return s.left=r,s.right=i,s}updateNode(n,e,t){let r=this.root||void 0;if(!r)return;let i=(s,o,a,l)=>{if(s.start===s.end&&s.start===o){s.sum=a,l!==void 0&&(s.value=l);return}let u=s.start+Math.floor((s.end-s.start)/2);o<=u?s.left&&i(s.left,o,a,l):s.right&&i(s.right,o,a,l),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};i(r,n,e,t)}querySumByRange(n,e){let t=this.root||void 0;if(!t)return 0;if(n<0||e>=this.values.length||n>e)return NaN;let r=(i,s,o)=>{if(s<=i.start&&o>=i.end)return i.sum;let a=i.start+Math.floor((i.end-i.start)/2);if(o<=a)return i.left?r(i.left,s,o):NaN;if(s>a)return i.right?r(i.right,s,o):NaN;{let l=0,u=0;return i.left&&(l=r(i.left,s,a)),i.right&&(u=r(i.right,a+1,o)),l+u}};return r(t,n,e)}};var U=class extends F{constructor(e,t){super(e,t);d(this,"_height");this._height=0}get height(){return this._height}set height(e){this._height=e}},te=class h extends j{constructor(n=[],e){super([],e),n&&super.addMany(n)}createNode(n,e){return new U(n,e)}createTree(n){return new h([],x({iterationType:this.iterationType,comparator:this.comparator},n))}isNode(n){return n instanceof U}add(n,e){if(n===null)return!1;let t=super.add(n,e);return t&&this._balancePath(n),t}delete(n,e=this._DEFAULT_CALLBACK){let t=super.delete(n,e);for(let{needBalanced:r}of t)r&&this._balancePath(r);return t}_swapProperties(n,e){let t=this.ensureNode(n),r=this.ensureNode(e);if(t&&r){let{key:i,value:s,height:o}=r,a=this.createNode(i,s);return a&&(a.height=o,r.key=t.key,r.value=t.value,r.height=t.height,t.key=a.key,t.value=a.value,t.height=a.height),r}}_balanceFactor(n){return n.right?n.left?n.right.height-n.left.height:+n.height:-n.height}_updateHeight(n){if(!n.left&&!n.right)n.height=0;else if(n.left)n.right?n.height=1+Math.max(n.right.height,n.left.height):n.height=1+n.left.height;else{let e=n.right?n.right.height:0;n.height=1+e}}_balanceLL(n){let e=n.parent,t=n.left;n.parent=t,t&&t.right&&(t.right.parent=n),t&&(t.parent=e),n===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===n?e.left=t:e&&(e.right=t),t&&(n.left=t.right,t.right=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceLR(n){let e=n.parent,t=n.left,r;t&&(r=t.right),n&&(n.parent=r),t&&(t.parent=r),r&&(r.left&&(r.left.parent=t),r.right&&(r.right.parent=n),r.parent=e),n===this.root?r&&this._setRoot(r):e&&(e.left===n?e.left=r:e.right=r),r&&(n.left=r.right,t&&(t.right=r.left),r.left=t,r.right=n),this._updateHeight(n),t&&this._updateHeight(t),r&&this._updateHeight(r)}_balanceRR(n){let e=n.parent,t=n.right;n.parent=t,t&&(t.left&&(t.left.parent=n),t.parent=e),n===this.root?t&&this._setRoot(t):e&&(e.left===n?e.left=t:e.right=t),t&&(n.right=t.left,t.left=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceRL(n){let e=n.parent,t=n.right,r;t&&(r=t.left),n.parent=r,t&&(t.parent=r),r&&(r.left&&(r.left.parent=n),r.right&&(r.right.parent=t),r.parent=e),n===this.root?r&&this._setRoot(r):e&&(e.left===n?e.left=r:e.right=r),r&&(n.right=r.left),t&&r&&(t.left=r.right),r&&(r.left=n),r&&(r.right=t),this._updateHeight(n),t&&this._updateHeight(t),r&&this._updateHeight(r)}_balancePath(n){n=this.ensureNode(n);let e=this.getPathToRoot(n,!1);for(let t=0;t<e.length;t++){let r=e[t];switch(this._updateHeight(r),this._balanceFactor(r)){case-2:r&&r.left&&(this._balanceFactor(r.left)<=0?this._balanceLL(r):this._balanceLR(r));break;case 2:r&&r.right&&(this._balanceFactor(r.right)>=0?this._balanceRR(r):this._balanceRL(r))}}}_replaceNode(n,e){return e.height=n.height,super._replaceNode(n,e)}};var q=class extends F{constructor(e,t,r="BLACK"){super(e,t);d(this,"_color");this._color=r}get color(){return this._color}set color(e){this._color=e}},re=class h extends j{constructor(e=[],t){super([],t);d(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,r="BLACK"){return new q(e,t,r)}createTree(e){return new h([],x({iterationType:this.iterationType},e))}isNode(e){return e instanceof q}clear(){super.clear(),this._root=this.NIL}add(e,t){let r=this.keyValueOrEntryOrRawElementToNode(e,t);if(!this.isRealNode(r))return!1;let i=this._insert(r);if(i==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._size++,!0}else return i==="UPDATED"}delete(e,t=this._DEFAULT_CALLBACK){if(e===null)return[];let r=[];t=this._ensureCallback(e,t);let i=this.isRealNode(e)?e:this.getNode(e,t);if(!i)return r;let s=i.color,o;if(!this.isRealNode(i.left))o=i.right,this._transplant(i,i.right);else if(!this.isRealNode(i.right))o=i.left,this._transplant(i,i.left);else{let a=this.getLeftMost(i.right);a&&(s=a.color,o=a.right,a.parent===i?this.isRealNode(o)&&(o.parent=a):(this._transplant(a,a.right),a.right=i.right,this.isRealNode(a.right)&&(a.right.parent=a)),this._transplant(i,a),a.left=i.left,this.isRealNode(a.left)&&(a.left.parent=a),a.color=i.color)}return this._size--,s==="BLACK"&&this._deleteFixup(o),r.push({deleted:i,needBalanced:void 0}),r}_setRoot(e){e&&(e.parent=void 0),this._root=e}_replaceNode(e,t){return t.color=e.color,super._replaceNode(e,t)}_insert(e){var i,s;let t=this.root,r;for(;this.isRealNode(t);){r=t;let o=this.comparator(e.key,t.key);if(o<0)t=(i=t.left)!=null?i:this.NIL;else if(o>0)t=(s=t.right)!=null?s:this.NIL;else return this._replaceNode(t,e),"UPDATED"}return e.parent=r,r?e.key<r.key?r.left=e:r.right=e:this._setRoot(e),e.left=this.NIL,e.right=this.NIL,e.color="RED",this._insertFixup(e),"CREATED"}_transplant(e,t){e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t&&(t.parent=e.parent)}_insertFixup(e){var t,r,i,s;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((r=e.parent.parent)==null?void 0:r.left)){let o=e.parent.parent.right;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._rightRotate(e.parent.parent)))}else{let o=(s=(i=e==null?void 0:e.parent)==null?void 0:i.parent)==null?void 0:s.left;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._leftRotate(e.parent.parent)))}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,r,i,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let o=e.parent;if(!o)break;if(e===o.left){let a=o.right;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o.color="RED",this._leftRotate(o),a=o.right),((r=(t=a==null?void 0:a.left)==null?void 0:t.color)!=null?r:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.left&&(a.left.color="BLACK"),a&&(a.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let a=o.left;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(a=o.left)),((s=(i=a==null?void 0:a.right)==null?void 0:i.color)!=null?s:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.right&&(a.right.color="BLACK"),a&&(a.color=o.color),o&&(o.color="BLACK"),this._leftRotate(o),e=this.root)}}e&&(e.color="BLACK")}_leftRotate(e){if(!e||!e.right)return;let t=e.right;e.right=t.left,this.isRealNode(t.left)&&(t.left.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.left=e,e.parent=t}_rightRotate(e){if(!e||!e.left)return;let t=e.left;e.left=t.right,this.isRealNode(t.right)&&(t.right.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.right=e,e.parent=t}};var ie=class extends U{constructor(e,t,r=1){super(e,t);d(this,"_count",1);this.count=r}get count(){return this._count}set count(e){this._count=e}},Le=class h extends te{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,r){return new ie(e,t,r)}createTree(e){return new h([],x({iterationType:this.iterationType,comparator:this.comparator},e))}isNode(e){return e instanceof ie}keyValueOrEntryOrRawElementToNode(e,t,r=1){if(e!=null){if(this.isNode(e))return e;if(this.toEntryFn){let[i,s]=this.toEntryFn(e);if(i)return this.createNode(i,s!=null?s:t,r)}if(this.isEntry(e)){let[i,s]=e;return i==null?void 0:this.createNode(i,s,r)}if(this.isKey(e))return this.createNode(e,t,r)}}add(e,t,r=1){let i=this.keyValueOrEntryOrRawElementToNode(e,t,r);if(i===void 0)return!1;let s=(i==null?void 0:i.count)||0;return super.add(i)&&(this._count+=s),!0}delete(e,t=this._DEFAULT_CALLBACK,r=!1){var u;let i=[];if(!this.root)return i;t=this._ensureCallback(e,t);let s=(u=this.getNode(e,t))!=null?u:void 0;if(!s)return i;let o=s!=null&&s.parent?s.parent:void 0,a,l=s;if(s.count>1&&!r)s.count--,this._count--;else{if(s.left){let f=s.left?this.getRightMost(s.left):void 0;if(f){let E=f.parent;l=this._swapProperties(s,f),E&&(E.right===f?E.right=f.left:E.left=f.left,a=E)}}else if(!o)s.right!==void 0&&this._setRoot(s.right);else{let{familyPosition:f}=s;f==="LEFT"||f==="ROOT_LEFT"?o.left=s.right:(f==="RIGHT"||f==="ROOT_RIGHT")&&(o.right=s.right),a=o}this._size=this.size-1,l&&(this._count-=l.count)}return i.push({deleted:l,needBalanced:a}),a&&this._balancePath(a),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),r=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this.add(l.key,l.value,l.count),i(s,a-1),i(a+1,o)};return i(0,r-1),!0}else{let i=[[0,r-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this.add(u.key,u.value,u.count),i.push([l+1,a]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t.key,t.value,t.count)),e}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:r,value:i,count:s,height:o}=t,a=this.createNode(r,i,s);return a&&(a.height=o,t.key=e.key,t.value=e.value,t.count=e.count,t.height=e.height,e.key=a.key,e.value=a.value,e.count=a.count,e.height=a.height),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var ne=class extends q{constructor(e,t,r=1,i="BLACK"){super(e,t,i);d(this,"_count",1);this.count=r}get count(){return this._count}set count(e){this._count=e}},Ie=class h extends re{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,r="BLACK",i){return new ne(e,t,i,r)}createTree(e){return new h([],x({iterationType:this.iterationType},e))}keyValueOrEntryOrRawElementToNode(e,t,r=1){if(e!=null){if(this.isNode(e))return e;if(this.toEntryFn){let[i]=this.toEntryFn(e);if(i)return this.getNodeByKey(i)}if(this.isEntry(e)){let[i,s]=e;return i==null?void 0:this.createNode(i,s,"BLACK",r)}if(this.isKey(e))return this.createNode(e,t,"BLACK",r)}}isNode(e){return e instanceof ne}add(e,t,r=1){let i=this.keyValueOrEntryOrRawElementToNode(e,t,r),s=(i==null?void 0:i.count)||0;return super.add(i)?(this._count+=s,!0):!1}delete(e,t=this._DEFAULT_CALLBACK,r=!1){if(e===null)return[];let i=[];t=this._ensureCallback(e,t);let s=this.isRealNode(e)?e:this.getNode(e,t);if(!s)return i;let o=s.color,a;if(this.isRealNode(s.left))if(this.isRealNode(s.right)){let l=this.getLeftMost(s.right);if(l){if(o=l.color,a=l.right,l.parent===s)this.isRealNode(a)&&(a.parent=l);else{if(r||s.count<=1)this._transplant(l,l.right),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;l.right=s.right,this.isRealNode(l.right)&&(l.right.parent=l)}if(r||s.count<=1)this._transplant(s,l),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;l.left=s.left,this.isRealNode(l.left)&&(l.left.parent=l),l.color=s.color}}else if(a=s.left,r||s.count<=1)this._transplant(s,s.left),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;else if(a=s.right,r||s.count<=1)this._transplant(s,s.right),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;return this._size--,o==="BLACK"&&this._deleteFixup(a),i.push({deleted:s,needBalanced:void 0}),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),r=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this.add(l.key,l.value,l.count),i(s,a-1),i(a+1,o)};return i(0,r-1),!0}else{let i=[[0,r-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this.add(u.key,u.value,u.count),i.push([l+1,a]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t.key,t.value,t.count)),e}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:r,value:i,count:s,color:o}=t,a=this.createNode(r,i,o,s);return a&&(a.color=o,t.key=e.key,t.value=e.value,t.count=e.count,t.color=e.color,e.key=a.key,e.value=a.value,e.count=a.count,e.color=a.color),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var Q=class h extends B{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var Fe=class h extends Q{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var Se=class h extends Q{constructor(n=[],e){super(n,x({comparator:(t,r)=>{if(typeof t=="object"||typeof r=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<r?1:t>r?-1:0}},e))}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var Ae=class h{constructor(n,e){d(this,"_rows",0);d(this,"_cols",0);d(this,"_data");var t,r,i;if(e){let{rows:s,cols:o,addFn:a,subtractFn:l,multiplyFn:u}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=n.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=n[0])==null?void 0:t.length)||0,a&&(this._addFn=a),l&&(this._subtractFn=l),u&&(this._multiplyFn=u)}else this._rows=n.length,this._cols=(i=(r=n[0])==null?void 0:r.length)!=null?i:0;if(n.length>0)this._data=n;else{this._data=[];for(let s=0;s<this.rows;s++)this._data[s]=new Array(this.cols).fill(0)}}get rows(){return this._rows}get cols(){return this._cols}get data(){return this._data}get addFn(){return this._addFn}get subtractFn(){return this._subtractFn}get multiplyFn(){return this._multiplyFn}get(n,e){if(this.isValidIndex(n,e))return this.data[n][e]}set(n,e,t){return this.isValidIndex(n,e)?(this.data[n][e]=t,!0):!1}isMatchForCalculate(n){return this.rows===n.rows&&this.cols===n.cols}add(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<this.cols;r++){let i=this.get(t,r),s=n.get(t,r);if(i!==void 0&&s!==void 0){let o=this._addFn(i,s);o&&(e[t][r]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<this.cols;r++){let i=this.get(t,r),s=n.get(t,r);if(i!==void 0&&s!==void 0){let o=this._subtractFn(i,s);o&&(e[t][r]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(n){if(this.cols!==n.rows)throw new Error("Matrix dimensions must be compatible for multiplication (A.cols = B.rows).");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<n.cols;r++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,r);if(o!==void 0&&a!==void 0){let l=this.multiplyFn(o,a);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][r]=i)}}return new h(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){if(this.data.some(e=>e.length!==this.rows))throw new Error("Matrix must be rectangular for transposition.");let n=[];for(let e=0;e<this.cols;e++){n[e]=[];for(let t=0;t<this.rows;t++){let r=this.get(t,e);r!==void 0&&(n[e][t]=r)}}return new h(n,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var r;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let n=[];for(let i=0;i<this.rows;i++){n[i]=this.data[i].slice();for(let s=0;s<this.cols;s++)n[i][this.cols+s]=i===s?1:0}let e=new h(n,{rows:this.rows,cols:this.cols*2,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn});for(let i=0;i<this.rows;i++){let s=i;for(;s<this.rows&&e.get(s,i)===0;)s++;if(s===this.rows)throw new Error("Matrix is singular, and its inverse does not exist.");e._swapRows(i,s);let o=(r=e.get(i,i))!=null?r:1;if(o===0)throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");e._scaleRow(i,1/o);for(let a=0;a<this.rows;a++)if(a!==i){let l=e.get(a,i);l===void 0&&(l=0),e._addScaledRow(a,i,-l)}}let t=[];for(let i=0;i<this.rows;i++)t[i]=e.data[i].slice(this.cols);return new h(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(n){if(this.cols!==n.rows)throw new Error("Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<n.cols;r++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,r);if(o!==void 0&&a!==void 0){let l=this.multiplyFn(o,a);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][r]=i)}}return new h(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(n,e){return n>=0&&n<this.rows&&e>=0&&e<this.cols}clone(){return new h(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(n,e){return n===void 0?e:n+e}_subtractFn(n,e){return n-e}_multiplyFn(n,e){return n*e}_swapRows(n,e){let t=this.data[n];this.data[n]=this.data[e],this.data[e]=t}_scaleRow(n,e){for(let t=0;t<this.cols;t++){let r=this.multiplyFn(this.data[n][t],e);r===void 0&&(r=0),this.data[n][t]=r}}_addScaledRow(n,e,t){for(let r=0;r<this.cols;r++){let i=this.multiplyFn(this.data[e][r],t);i===void 0&&(i=0);let s=i,o=this.addFn(this.data[n][r],s);o===void 0&&(o=0),this.data[n][r]=o}}};var ce=class h{constructor(n,e){d(this,"direction");d(this,"turn");this.direction=n,this.turn=()=>new h(e[n],e)}},ze=class{constructor({matrix:n,turning:e,onMove:t,init:{cur:r,charDir:i,VISITED:s}}){d(this,"onMove");d(this,"_matrix");d(this,"_cur");d(this,"_character");d(this,"_VISITED");this._matrix=n,this._cur=r,this._character=new ce(i,e),this.onMove=t,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:n}=this._character;this.check(n)?this.move(n):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(n){let e,t,r=this._matrix,[i,s]=this._cur;switch(n){case"up":if(t=r[i-1],!t)return!1;e=t[s];break;case"right":e=r[i][s+1];break;case"down":if(t=r[i+1],!t)return!1;e=t[s];break;case"left":e=r[i][s-1];break}return e!==void 0&&e!==this._VISITED}move(n){switch(n){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[e,t]=this._cur;this._matrix[e][t]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var Y=class{constructor(n){d(this,"_key");d(this,"_children");d(this,"_isEnd");this._key=n,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(n){this._key=n}get children(){return this._children}set children(n){this._children=n}get isEnd(){return this._isEnd}set isEnd(n){this._isEnd=n}},He=class h extends K{constructor(e=[],t){super(t);d(this,"_size",0);d(this,"_caseSensitive",!0);d(this,"_root",new Y(""));if(t){let{caseSensitive:r}=t;r!==void 0&&(this._caseSensitive=r)}if(e)for(let r of e)this.toElementFn?this.add(this.toElementFn(r)):this.add(r)}get size(){return this._size}get caseSensitive(){return this._caseSensitive}get root(){return this._root}add(e){e=this._caseProcess(e);let t=this.root,r=!1;for(let i of e){let s=t.children.get(i);s||(s=new Y(i),t.children.set(i,s)),t=s}return t.isEnd||(r=!0,t.isEnd=!0,this._size++),r}has(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let i=t.children.get(r);if(!i)return!1;t=i}return t.isEnd}isEmpty(){return this.size===0}clear(){this._size=0,this._root=new Y("")}delete(e){e=this._caseProcess(e);let t=!1,r=(i,s)=>{let o=e[s],a=i.children.get(o);return a?s===e.length-1?a.isEnd?(a.children.size>0?a.isEnd=!1:i.children.delete(o),t=!0,!0):!1:r(a,s+1)&&!i.isEnd&&a.children.size===0?(i.children.delete(o),!0):!1:!1};return r(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let r=(i,s)=>{s>t&&(t=s);let{children:o}=i;if(o)for(let a of o.entries())r(a[1],s+1)};r(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let i=t.children.get(r);if(!i)return!1;t=i}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let i=t.children.get(r);if(!i)return!1;t=i}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",r=i=>{if(t+=i.key,t!==e&&!i.isEnd)if(i&&i.children&&i.children.size===1)r(Array.from(i.children.values())[0]);else return};return r(this.root),t===e}getLongestCommonPrefix(){let e="",t=r=>{if(e+=r.key,!r.isEnd)if(r&&r.children&&r.children.size===1)t(Array.from(r.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,r=!1){e=this._caseProcess(e);let i=[],s=0;function o(l,u){for(let f of l.children.keys()){let E=l.children.get(f);E!==void 0&&o(E,u.concat(f))}if(l.isEnd){if(s>t-1)return;i.push(u),s++}}let a=this.root;if(e)for(let l of e){let u=a.children.get(l);u&&(a=u)}return(r||a!==this.root)&&o(a,e),i}clone(){return new h(this,{caseSensitive:this.caseSensitive,toElementFn:this.toElementFn})}filter(e,t){let r=new h([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive}),i=0;for(let s of this)e.call(t,s,i,this)&&r.add(s),i++;return r}map(e,t,r){let i=new h([],{toElementFn:t,caseSensitive:this.caseSensitive}),s=0;for(let o of this)i.add(e.call(r,o,s,this)),s++;return i}*_getIterator(){function*e(t,r){t.isEnd&&(yield r);for(let[i,s]of t.children)yield*v(e(s,r+i))}yield*v(e(this.root,""))}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var Pe=class h{constructor(n,e,t){d(this,"_key");d(this,"_value");d(this,"_children");this._key=n,this._value=e||void 0,this._children=t||[]}get key(){return this._key}set key(n){this._key=n}get value(){return this._value}set value(n){this._value=n}get children(){return this._children}set children(n){this._children=n}addChildren(n){this._children||(this._children=[]),n instanceof h?this._children.push(n):this._children=this._children.concat(n)}getHeight(){let n=0;if(this){let e=(t,r)=>{r>n&&(n=r);let{_children:i}=t;if(i)for(let s=0,o=i.length;s<o;s++)e(i[s],r+1)};e(this,0)}return n}};return $e(st);})();
|
|
4
|
+
`),(s=>{let[o,,,]=this._displayAux(s,r);for(let a of o)console.log(a)})(e)}*_getIterator(e=this.root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],r=e;for(;r||t.length>0;){for(;this.isRealNode(r);)t.push(r),r=r.left;r=t.pop(),this.isRealNode(r)&&(yield[r.key,r.value],r=r.right)}}else e.left&&this.isRealNode(e)&&(yield*v(this[Symbol.iterator](e.left))),yield[e.key,e.value],e.right&&this.isRealNode(e)&&(yield*v(this[Symbol.iterator](e.right)))}_displayAux(e,t){let{isShowNull:r,isShowUndefined:i,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!r)return o;if(e===void 0&&!i)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let l=e.key,u=this.isNIL(e)?"S":String(l),f=u.length;return a(u,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let l=e===void 0?"U":"N",u=l.length;return a(l,u,[[""],1,0,0],[[""],1,0,0])}function a(l,u,f,E){let[c,m,y,O]=f,[R,N,p,g]=E,b=" ".repeat(Math.max(0,O+1))+"_".repeat(Math.max(0,m-O-1))+l+"_".repeat(Math.max(0,g))+" ".repeat(Math.max(0,N-g)),_=(y>0?" ".repeat(O)+"/"+" ".repeat(m-O-1):" ".repeat(m))+" ".repeat(u)+(p>0?" ".repeat(g)+"\\"+" ".repeat(N-g-1):" ".repeat(N)),V=[b,_];for(let T=0;T<Math.max(y,p);T++){let z=T<y?c[T]:" ".repeat(m),Ge=T<p?R[T]:" ".repeat(N);V.push(z+" ".repeat(u)+Ge)}return[V,m+u+N,Math.max(y,p)+2,m+Math.floor(u/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:r,value:i}=t,s=this.createNode(r,i);return s&&(t.key=e.key,t.value=e.value,e.key=s.key,e.value=s.value),t}}_replaceNode(e,t){return e.parent&&(e.parent.left===e?e.parent.left=t:e.parent.right===e&&(e.parent.right=t)),t.left=e.left,t.right=e.right,t.parent=e.parent,this.root===e&&(this._root=t),t}_setRoot(e){e&&(e.parent=void 0),this._root=e}_ensureCallback(e,t=this._DEFAULT_CALLBACK){return(!t||t===this._DEFAULT_CALLBACK)&&this.isNode(e)&&(t=r=>r),t}};var F=class extends A{constructor(e,t){super(e,t);d(this,"parent");d(this,"_left");d(this,"_right");this.parent=void 0,this._left=void 0,this._right=void 0}get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},j=class h extends ee{constructor(e=[],t){super([],t);d(this,"_root");d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:r}=t;r&&(this._comparator=r)}e&&this.addMany(e)}get root(){return this._root}createNode(e,t){return new F(e,t)}createTree(e){return new h([],x({iterationType:this.iterationType,comparator:this.comparator},e))}keyValueOrEntryOrRawElementToNode(e,t){var r;return(r=super.keyValueOrEntryOrRawElementToNode(e,t))!=null?r:void 0}ensureNode(e,t="ITERATIVE"){var r;return(r=super.ensureNode(e,t))!=null?r:void 0}isNode(e){return e instanceof F}add(e,t){let r=this.keyValueOrEntryOrRawElementToNode(e,t);if(r===void 0)return!1;if(this.root===void 0)return this._setRoot(r),this._size++,!0;let i=this.root;for(;i!==void 0;){if(this.comparator(i.key,r.key)===0)return this._replaceNode(i,r),!0;if(this.comparator(i.key,r.key)>0){if(i.left===void 0)return i.left=r,this._size++,!0;i=i.left}else{if(i.right===void 0)return i.right=r,this._size++,!0;i=i.right}}return!1}addMany(e,t,r=!0,i=this.iterationType){let s=[],o;if(t&&(o=t[Symbol.iterator]()),!r){for(let c of e){let m=o==null?void 0:o.next().value,y=this.add(c,m);s.push(y)}return s}let a=[],l=c=>c==null?!1:!(this.isEntry(c)&&(c[0]===void 0||c[0]===null));for(let c of e)l(c)&&a.push(c);let u=[];u=a.sort((c,m)=>{let y,O;return this.isEntry(c)?y=c[0]:this.isRealNode(c)?y=c.key:this.toEntryFn?y=this.toEntryFn(c)[0]:y=c,this.isEntry(m)?O=m[0]:this.isRealNode(m)?O=m.key:this.toEntryFn?O=this.toEntryFn(m)[0]:O=m,y!=null&&O!==void 0&&O!==null?this.comparator(y,O):0});let f=c=>{if(c.length===0)return;let m=Math.floor((c.length-1)/2),y=this.add(c[m]);s.push(y),f(c.slice(0,m)),f(c.slice(m+1))};return i==="RECURSIVE"?f(u):(()=>{let m=[[0,u.length-1]];for(;m.length>0;){let y=m.pop();if(y){let[O,R]=y;if(O<=R){let N=O+Math.floor((R-O)/2),p=this.add(u[N]);s.push(p),m.push([N+1,R]),m.push([O,N-1])}}}})(),s}getNodes(e,t=this._DEFAULT_CALLBACK,r=!1,i=this.root,s=this.iterationType){if(i=this.ensureNode(i),!i)return[];t=this._ensureCallback(e,t);let o=[];if(s==="RECURSIVE"){let a=l=>{t(l)===e&&(o.push(l),r)||!this.isRealNode(l.left)&&!this.isRealNode(l.right)||(t===this._DEFAULT_CALLBACK?(this.isRealNode(l.left)&&this.comparator(l.key,e)>0&&a(l.left),this.isRealNode(l.right)&&this.comparator(l.key,e)<0&&a(l.right)):(this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right)))};a(i)}else{let a=[i];for(;a.length>0;){let l=a.pop();if(t(l)===e&&(o.push(l),r))return o;t===this._DEFAULT_CALLBACK?(this.isRealNode(l.right)&&this.comparator(l.key,e)<0&&a.push(l.right),this.isRealNode(l.left)&&this.comparator(l.key,e)>0&&a.push(l.left)):(this.isRealNode(l.right)&&a.push(l.right),this.isRealNode(l.left)&&a.push(l.left))}}return o}getNode(e,t=this._DEFAULT_CALLBACK,r=this.root,i=this.iterationType){var s;return(s=this.getNodes(e,t,!0,r,i)[0])!=null?s:void 0}getNodeByKey(e,t="ITERATIVE"){return this.getNode(e,this._DEFAULT_CALLBACK,this.root,t)}dfs(e=this._DEFAULT_CALLBACK,t="IN",r=this.root,i="ITERATIVE"){return super.dfs(e,t,r,i,!1)}bfs(e=this._DEFAULT_CALLBACK,t=this.root,r=this.iterationType){return super.bfs(e,t,r,!1)}listLevels(e=this._DEFAULT_CALLBACK,t=this.root,r=this.iterationType){return super.listLevels(e,t,r,!1)}lesserOrGreaterTraverse(e=this._DEFAULT_CALLBACK,t=-1,r=this.root,i=this.iterationType){let s=this.ensureNode(r),o=[];if(!s||!this.root)return o;let a=s.key;if(i==="RECURSIVE"){let l=u=>{let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&l(u.left),this.isRealNode(u.right)&&l(u.right)};return l(this.root),o}else{let l=new C([this.root]);for(;l.size>0;){let u=l.shift();if(this.isRealNode(u)){let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&l.push(u.left),this.isRealNode(u.right)&&l.push(u.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),r=t.length;if(this.clear(),t.length<1)return!1;if(e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this.add([l.key,l.value]),i(s,a-1),i(a+1,o)};return i(0,r-1),!0}else{let i=[[0,r-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this.add([u.key,u.value]),i.push([l+1,a]),i.push([o,l-1])}}}return!0}}isAVLBalanced(e=this.iterationType){var r,i;if(!this.root)return!0;let t=!0;if(e==="RECURSIVE"){let s=o=>{if(!o)return 0;let a=s(o.left),l=s(o.right);return Math.abs(a-l)>1&&(t=!1),Math.max(a,l)+1};s(this.root)}else{let s=[],o=this.root,a,l=new Map;for(;s.length>0||o;)if(o)s.push(o),o=o.left;else if(o=s[s.length-1],!o.right||a===o.right){if(o=s.pop(),o){let u=o.left&&(r=l.get(o.left))!=null?r:-1,f=o.right&&(i=l.get(o.right))!=null?i:-1;if(Math.abs(u-f)>1)return!1;l.set(o,1+Math.max(u,f)),a=o,o=void 0}}else o=o.right}return t}get comparator(){return this._comparator}_setRoot(e){e&&(e.parent=void 0),this._root=e}};var ve=class{constructor({frequency:n=0,max:e}){d(this,"_freq");d(this,"_max");d(this,"_freqMap");d(this,"_msb");d(this,"_negativeCount");this._freq=n,this._max=e,this._freqMap={0:0},this._msb=be(e),this._negativeCount=n<0?e:0}get freqMap(){return this._freqMap}get msb(){return this._msb}get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(n){return this._checkIndex(n),this._readSingle(n)}update(n,e){this._checkIndex(n);let t=this._readSingle(n);this._update(n,e),this._updateNegativeCount(t,t+e)}writeSingle(n,e){this._checkIndex(n),this._writeSingle(n,e)}read(n){if(!Number.isInteger(n))throw new Error("Invalid count");return this._read(Math.max(Math.min(n,this.max),0))}lowerBound(n){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(n,(e,t)=>e<t)}upperBound(n){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(n,(e,t)=>e<=t)}getPrefixSum(n){this._checkIndex(n),n++;let e=0;for(;n>0;)e+=this._getFrequency(n),n-=n&-n;return e}_getFrequency(n){return n in this.freqMap?this.freqMap[n]:this.freq*(n&-n)}_updateFrequency(n,e){this.freqMap[n]=this._getFrequency(n)+e}_checkIndex(n){if(!Number.isInteger(n))throw new Error("Invalid index: Index must be an integer.");if(n<0||n>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(n){n=n+1;let e=this._getFrequency(n),t=n-(n&-n);for(n--;n!==t;)e-=this._getFrequency(n),n-=n&-n;return e}_updateNegativeCount(n,e){n<0&&e>=0?this._negativeCount--:n>=0&&e<0&&this._negativeCount++}_update(n,e){for(n=n+1;n<=this.max;)this._updateFrequency(n,e),n+=n&-n}_writeSingle(n,e){let t=this._readSingle(n);this._update(n,e-t),this._updateNegativeCount(t,e)}_read(n){let e=n,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(n,e){let t=0,r=this.msb<<1,i=n;for(;r>t+1;){let s=t+r>>1,o=this._getFrequency(s);s<=this.max&&e(o,i)?(i-=o,t=s):r=s}return t}};var X=class{constructor(n,e,t,r){d(this,"_start",0);d(this,"_end",0);d(this,"_value");d(this,"_sum",0);d(this,"_left");d(this,"_right");this._start=n,this._end=e,this._sum=t,this._value=r||void 0}get start(){return this._start}set start(n){this._start=n}get end(){return this._end}set end(n){this._end=n}get value(){return this._value}set value(n){this._value=n}get sum(){return this._sum}set sum(n){this._sum=n}get left(){return this._left}set left(n){this._left=n}get right(){return this._right}set right(n){this._right=n}},we=class{constructor(n,e,t){d(this,"_values",[]);d(this,"_start",0);d(this,"_end");d(this,"_root");e=e||0,t=t||n.length-1,this._values=n,this._start=e,this._end=t,n.length>0?this._root=this.build(e,t):(this._root=void 0,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(n,e){if(n>e)return new X(n,e,0);if(n===e)return new X(n,e,this._values[n]);let t=n+Math.floor((e-n)/2),r=this.build(n,t),i=this.build(t+1,e),s=new X(n,e,r.sum+i.sum);return s.left=r,s.right=i,s}updateNode(n,e,t){let r=this.root||void 0;if(!r)return;let i=(s,o,a,l)=>{if(s.start===s.end&&s.start===o){s.sum=a,l!==void 0&&(s.value=l);return}let u=s.start+Math.floor((s.end-s.start)/2);o<=u?s.left&&i(s.left,o,a,l):s.right&&i(s.right,o,a,l),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};i(r,n,e,t)}querySumByRange(n,e){let t=this.root||void 0;if(!t)return 0;if(n<0||e>=this.values.length||n>e)return NaN;let r=(i,s,o)=>{if(s<=i.start&&o>=i.end)return i.sum;let a=i.start+Math.floor((i.end-i.start)/2);if(o<=a)return i.left?r(i.left,s,o):NaN;if(s>a)return i.right?r(i.right,s,o):NaN;{let l=0,u=0;return i.left&&(l=r(i.left,s,a)),i.right&&(u=r(i.right,a+1,o)),l+u}};return r(t,n,e)}};var U=class extends F{constructor(e,t){super(e,t);d(this,"_height");this._height=0}get height(){return this._height}set height(e){this._height=e}},te=class h extends j{constructor(n=[],e){super([],e),n&&super.addMany(n)}createNode(n,e){return new U(n,e)}createTree(n){return new h([],x({iterationType:this.iterationType,comparator:this.comparator},n))}isNode(n){return n instanceof U}add(n,e){if(n===null)return!1;let t=super.add(n,e);return t&&this._balancePath(n),t}delete(n,e=this._DEFAULT_CALLBACK){let t=super.delete(n,e);for(let{needBalanced:r}of t)r&&this._balancePath(r);return t}_swapProperties(n,e){let t=this.ensureNode(n),r=this.ensureNode(e);if(t&&r){let{key:i,value:s,height:o}=r,a=this.createNode(i,s);return a&&(a.height=o,r.key=t.key,r.value=t.value,r.height=t.height,t.key=a.key,t.value=a.value,t.height=a.height),r}}_balanceFactor(n){return n.right?n.left?n.right.height-n.left.height:+n.height:-n.height}_updateHeight(n){if(!n.left&&!n.right)n.height=0;else if(n.left)n.right?n.height=1+Math.max(n.right.height,n.left.height):n.height=1+n.left.height;else{let e=n.right?n.right.height:0;n.height=1+e}}_balanceLL(n){let e=n.parent,t=n.left;n.parent=t,t&&t.right&&(t.right.parent=n),t&&(t.parent=e),n===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===n?e.left=t:e&&(e.right=t),t&&(n.left=t.right,t.right=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceLR(n){let e=n.parent,t=n.left,r;t&&(r=t.right),n&&(n.parent=r),t&&(t.parent=r),r&&(r.left&&(r.left.parent=t),r.right&&(r.right.parent=n),r.parent=e),n===this.root?r&&this._setRoot(r):e&&(e.left===n?e.left=r:e.right=r),r&&(n.left=r.right,t&&(t.right=r.left),r.left=t,r.right=n),this._updateHeight(n),t&&this._updateHeight(t),r&&this._updateHeight(r)}_balanceRR(n){let e=n.parent,t=n.right;n.parent=t,t&&(t.left&&(t.left.parent=n),t.parent=e),n===this.root?t&&this._setRoot(t):e&&(e.left===n?e.left=t:e.right=t),t&&(n.right=t.left,t.left=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceRL(n){let e=n.parent,t=n.right,r;t&&(r=t.left),n.parent=r,t&&(t.parent=r),r&&(r.left&&(r.left.parent=n),r.right&&(r.right.parent=t),r.parent=e),n===this.root?r&&this._setRoot(r):e&&(e.left===n?e.left=r:e.right=r),r&&(n.right=r.left),t&&r&&(t.left=r.right),r&&(r.left=n),r&&(r.right=t),this._updateHeight(n),t&&this._updateHeight(t),r&&this._updateHeight(r)}_balancePath(n){n=this.ensureNode(n);let e=this.getPathToRoot(n,!1);for(let t=0;t<e.length;t++){let r=e[t];switch(this._updateHeight(r),this._balanceFactor(r)){case-2:r&&r.left&&(this._balanceFactor(r.left)<=0?this._balanceLL(r):this._balanceLR(r));break;case 2:r&&r.right&&(this._balanceFactor(r.right)>=0?this._balanceRR(r):this._balanceRL(r))}}}_replaceNode(n,e){return e.height=n.height,super._replaceNode(n,e)}};var q=class extends F{constructor(e,t,r="BLACK"){super(e,t);d(this,"_color");this._color=r}get color(){return this._color}set color(e){this._color=e}},re=class h extends j{constructor(e=[],t){super([],t);d(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,r="BLACK"){return new q(e,t,r)}createTree(e){return new h([],x({iterationType:this.iterationType},e))}isNode(e){return e instanceof q}clear(){super.clear(),this._root=this.NIL}add(e,t){let r=this.keyValueOrEntryOrRawElementToNode(e,t);if(!this.isRealNode(r))return!1;let i=this._insert(r);if(i==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._size++,!0}else return i==="UPDATED"}delete(e,t=this._DEFAULT_CALLBACK){if(e===null)return[];let r=[];t=this._ensureCallback(e,t);let i=this.isRealNode(e)?e:this.getNode(e,t);if(!i)return r;let s=i.color,o;if(!this.isRealNode(i.left))o=i.right,this._transplant(i,i.right);else if(!this.isRealNode(i.right))o=i.left,this._transplant(i,i.left);else{let a=this.getLeftMost(i.right);a&&(s=a.color,o=a.right,a.parent===i?this.isRealNode(o)&&(o.parent=a):(this._transplant(a,a.right),a.right=i.right,this.isRealNode(a.right)&&(a.right.parent=a)),this._transplant(i,a),a.left=i.left,this.isRealNode(a.left)&&(a.left.parent=a),a.color=i.color)}return this._size--,s==="BLACK"&&this._deleteFixup(o),r.push({deleted:i,needBalanced:void 0}),r}_setRoot(e){e&&(e.parent=void 0),this._root=e}_replaceNode(e,t){return t.color=e.color,super._replaceNode(e,t)}_insert(e){var i,s;let t=this.root,r;for(;this.isRealNode(t);){r=t;let o=this.comparator(e.key,t.key);if(o<0)t=(i=t.left)!=null?i:this.NIL;else if(o>0)t=(s=t.right)!=null?s:this.NIL;else return this._replaceNode(t,e),"UPDATED"}return e.parent=r,r?e.key<r.key?r.left=e:r.right=e:this._setRoot(e),e.left=this.NIL,e.right=this.NIL,e.color="RED",this._insertFixup(e),"CREATED"}_transplant(e,t){e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t&&(t.parent=e.parent)}_insertFixup(e){var t,r,i,s;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((r=e.parent.parent)==null?void 0:r.left)){let o=e.parent.parent.right;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._rightRotate(e.parent.parent)))}else{let o=(s=(i=e==null?void 0:e.parent)==null?void 0:i.parent)==null?void 0:s.left;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._leftRotate(e.parent.parent)))}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,r,i,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let o=e.parent;if(!o)break;if(e===o.left){let a=o.right;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o.color="RED",this._leftRotate(o),a=o.right),((r=(t=a==null?void 0:a.left)==null?void 0:t.color)!=null?r:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.left&&(a.left.color="BLACK"),a&&(a.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let a=o.left;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(a=o.left)),((s=(i=a==null?void 0:a.right)==null?void 0:i.color)!=null?s:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.right&&(a.right.color="BLACK"),a&&(a.color=o.color),o&&(o.color="BLACK"),this._leftRotate(o),e=this.root)}}e&&(e.color="BLACK")}_leftRotate(e){if(!e||!e.right)return;let t=e.right;e.right=t.left,this.isRealNode(t.left)&&(t.left.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.left=e,e.parent=t}_rightRotate(e){if(!e||!e.left)return;let t=e.left;e.left=t.right,this.isRealNode(t.right)&&(t.right.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.right=e,e.parent=t}};var ie=class extends U{constructor(e,t,r=1){super(e,t);d(this,"_count",1);this.count=r}get count(){return this._count}set count(e){this._count=e}},Le=class h extends te{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,r){return new ie(e,t,r)}createTree(e){return new h([],x({iterationType:this.iterationType,comparator:this.comparator},e))}isNode(e){return e instanceof ie}keyValueOrEntryOrRawElementToNode(e,t,r=1){if(e!=null){if(this.isNode(e))return e;if(this.toEntryFn){let[i,s]=this.toEntryFn(e);if(i)return this.createNode(i,s!=null?s:t,r)}if(this.isEntry(e)){let[i,s]=e;return i==null?void 0:this.createNode(i,s,r)}if(this.isKey(e))return this.createNode(e,t,r)}}add(e,t,r=1){let i=this.keyValueOrEntryOrRawElementToNode(e,t,r);if(i===void 0)return!1;let s=(i==null?void 0:i.count)||0;return super.add(i)&&(this._count+=s),!0}delete(e,t=this._DEFAULT_CALLBACK,r=!1){var u;let i=[];if(!this.root)return i;t=this._ensureCallback(e,t);let s=(u=this.getNode(e,t))!=null?u:void 0;if(!s)return i;let o=s!=null&&s.parent?s.parent:void 0,a,l=s;if(s.count>1&&!r)s.count--,this._count--;else{if(s.left){let f=s.left?this.getRightMost(s.left):void 0;if(f){let E=f.parent;l=this._swapProperties(s,f),E&&(E.right===f?E.right=f.left:E.left=f.left,a=E)}}else if(!o)s.right!==void 0&&this._setRoot(s.right);else{let{familyPosition:f}=s;f==="LEFT"||f==="ROOT_LEFT"?o.left=s.right:(f==="RIGHT"||f==="ROOT_RIGHT")&&(o.right=s.right),a=o}this._size=this.size-1,l&&(this._count-=l.count)}return i.push({deleted:l,needBalanced:a}),a&&this._balancePath(a),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),r=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this.add(l.key,l.value,l.count),i(s,a-1),i(a+1,o)};return i(0,r-1),!0}else{let i=[[0,r-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this.add(u.key,u.value,u.count),i.push([l+1,a]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t.key,t.value,t.count)),e}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:r,value:i,count:s,height:o}=t,a=this.createNode(r,i,s);return a&&(a.height=o,t.key=e.key,t.value=e.value,t.count=e.count,t.height=e.height,e.key=a.key,e.value=a.value,e.count=a.count,e.height=a.height),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var ne=class extends q{constructor(e,t,r=1,i="BLACK"){super(e,t,i);d(this,"_count",1);this.count=r}get count(){return this._count}set count(e){this._count=e}},Ie=class h extends re{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,r="BLACK",i){return new ne(e,t,i,r)}createTree(e){return new h([],x({iterationType:this.iterationType},e))}keyValueOrEntryOrRawElementToNode(e,t,r=1){if(e!=null){if(this.isNode(e))return e;if(this.toEntryFn){let[i]=this.toEntryFn(e);if(i)return this.getNodeByKey(i)}if(this.isEntry(e)){let[i,s]=e;return i==null?void 0:this.createNode(i,s,"BLACK",r)}if(this.isKey(e))return this.createNode(e,t,"BLACK",r)}}isNode(e){return e instanceof ne}add(e,t,r=1){let i=this.keyValueOrEntryOrRawElementToNode(e,t,r),s=(i==null?void 0:i.count)||0;return super.add(i)?(this._count+=s,!0):!1}delete(e,t=this._DEFAULT_CALLBACK,r=!1){if(e===null)return[];let i=[];t=this._ensureCallback(e,t);let s=this.isRealNode(e)?e:this.getNode(e,t);if(!s)return i;let o=s.color,a;if(this.isRealNode(s.left))if(this.isRealNode(s.right)){let l=this.getLeftMost(s.right);if(l){if(o=l.color,a=l.right,l.parent===s)this.isRealNode(a)&&(a.parent=l);else{if(r||s.count<=1)this._transplant(l,l.right),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;l.right=s.right,this.isRealNode(l.right)&&(l.right.parent=l)}if(r||s.count<=1)this._transplant(s,l),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;l.left=s.left,this.isRealNode(l.left)&&(l.left.parent=l),l.color=s.color}}else if(a=s.left,r||s.count<=1)this._transplant(s,s.left),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;else if(a=s.right,r||s.count<=1)this._transplant(s,s.right),this._count-=s.count;else return s.count--,this._count--,i.push({deleted:s,needBalanced:void 0}),i;return this._size--,o==="BLACK"&&this._deleteFixup(a),i.push({deleted:s,needBalanced:void 0}),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),r=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this.add(l.key,l.value,l.count),i(s,a-1),i(a+1,o)};return i(0,r-1),!0}else{let i=[[0,r-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this.add(u.key,u.value,u.count),i.push([l+1,a]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t.key,t.value,t.count)),e}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:r,value:i,count:s,color:o}=t,a=this.createNode(r,i,o,s);return a&&(a.color=o,t.key=e.key,t.value=e.value,t.count=e.count,t.color=e.color,e.key=a.key,e.value=a.value,e.count=a.count,e.color=a.color),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var Q=class h extends B{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var Fe=class h extends Q{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var Se=class h extends Q{constructor(n=[],e){super(n,x({comparator:(t,r)=>{if(typeof t=="object"||typeof r=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<r?1:t>r?-1:0}},e))}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let i of this)n.call(e,i,r,this)&&t.add(i),r++;return t}map(n,e,t,r){let i=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(n.call(r,o,s,this)),s++;return i}};var Ae=class h{constructor(n,e){d(this,"_rows",0);d(this,"_cols",0);d(this,"_data");var t,r,i;if(e){let{rows:s,cols:o,addFn:a,subtractFn:l,multiplyFn:u}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=n.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=n[0])==null?void 0:t.length)||0,a&&(this._addFn=a),l&&(this._subtractFn=l),u&&(this._multiplyFn=u)}else this._rows=n.length,this._cols=(i=(r=n[0])==null?void 0:r.length)!=null?i:0;if(n.length>0)this._data=n;else{this._data=[];for(let s=0;s<this.rows;s++)this._data[s]=new Array(this.cols).fill(0)}}get rows(){return this._rows}get cols(){return this._cols}get data(){return this._data}get addFn(){return this._addFn}get subtractFn(){return this._subtractFn}get multiplyFn(){return this._multiplyFn}get(n,e){if(this.isValidIndex(n,e))return this.data[n][e]}set(n,e,t){return this.isValidIndex(n,e)?(this.data[n][e]=t,!0):!1}isMatchForCalculate(n){return this.rows===n.rows&&this.cols===n.cols}add(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<this.cols;r++){let i=this.get(t,r),s=n.get(t,r);if(i!==void 0&&s!==void 0){let o=this._addFn(i,s);o&&(e[t][r]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<this.cols;r++){let i=this.get(t,r),s=n.get(t,r);if(i!==void 0&&s!==void 0){let o=this._subtractFn(i,s);o&&(e[t][r]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(n){if(this.cols!==n.rows)throw new Error("Matrix dimensions must be compatible for multiplication (A.cols = B.rows).");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<n.cols;r++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,r);if(o!==void 0&&a!==void 0){let l=this.multiplyFn(o,a);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][r]=i)}}return new h(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){if(this.data.some(e=>e.length!==this.rows))throw new Error("Matrix must be rectangular for transposition.");let n=[];for(let e=0;e<this.cols;e++){n[e]=[];for(let t=0;t<this.rows;t++){let r=this.get(t,e);r!==void 0&&(n[e][t]=r)}}return new h(n,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var r;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let n=[];for(let i=0;i<this.rows;i++){n[i]=this.data[i].slice();for(let s=0;s<this.cols;s++)n[i][this.cols+s]=i===s?1:0}let e=new h(n,{rows:this.rows,cols:this.cols*2,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn});for(let i=0;i<this.rows;i++){let s=i;for(;s<this.rows&&e.get(s,i)===0;)s++;if(s===this.rows)throw new Error("Matrix is singular, and its inverse does not exist.");e._swapRows(i,s);let o=(r=e.get(i,i))!=null?r:1;if(o===0)throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");e._scaleRow(i,1/o);for(let a=0;a<this.rows;a++)if(a!==i){let l=e.get(a,i);l===void 0&&(l=0),e._addScaledRow(a,i,-l)}}let t=[];for(let i=0;i<this.rows;i++)t[i]=e.data[i].slice(this.cols);return new h(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(n){if(this.cols!==n.rows)throw new Error("Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let r=0;r<n.cols;r++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,r);if(o!==void 0&&a!==void 0){let l=this.multiplyFn(o,a);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][r]=i)}}return new h(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(n,e){return n>=0&&n<this.rows&&e>=0&&e<this.cols}clone(){return new h(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(n,e){return n===void 0?e:n+e}_subtractFn(n,e){return n-e}_multiplyFn(n,e){return n*e}_swapRows(n,e){let t=this.data[n];this.data[n]=this.data[e],this.data[e]=t}_scaleRow(n,e){for(let t=0;t<this.cols;t++){let r=this.multiplyFn(this.data[n][t],e);r===void 0&&(r=0),this.data[n][t]=r}}_addScaledRow(n,e,t){for(let r=0;r<this.cols;r++){let i=this.multiplyFn(this.data[e][r],t);i===void 0&&(i=0);let s=i,o=this.addFn(this.data[n][r],s);o===void 0&&(o=0),this.data[n][r]=o}}};var ce=class h{constructor(n,e){d(this,"direction");d(this,"turn");this.direction=n,this.turn=()=>new h(e[n],e)}},ze=class{constructor({matrix:n,turning:e,onMove:t,init:{cur:r,charDir:i,VISITED:s}}){d(this,"onMove");d(this,"_matrix");d(this,"_cur");d(this,"_character");d(this,"_VISITED");this._matrix=n,this._cur=r,this._character=new ce(i,e),this.onMove=t,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:n}=this._character;this.check(n)?this.move(n):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(n){let e,t,r=this._matrix,[i,s]=this._cur;switch(n){case"up":if(t=r[i-1],!t)return!1;e=t[s];break;case"right":e=r[i][s+1];break;case"down":if(t=r[i+1],!t)return!1;e=t[s];break;case"left":e=r[i][s-1];break}return e!==void 0&&e!==this._VISITED}move(n){switch(n){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[e,t]=this._cur;this._matrix[e][t]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var Y=class{constructor(n){d(this,"_key");d(this,"_children");d(this,"_isEnd");this._key=n,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(n){this._key=n}get children(){return this._children}set children(n){this._children=n}get isEnd(){return this._isEnd}set isEnd(n){this._isEnd=n}},He=class h extends K{constructor(e=[],t){super(t);d(this,"_size",0);d(this,"_caseSensitive",!0);d(this,"_root",new Y(""));if(t){let{caseSensitive:r}=t;r!==void 0&&(this._caseSensitive=r)}if(e)for(let r of e)this.toElementFn?this.add(this.toElementFn(r)):this.add(r)}get size(){return this._size}get caseSensitive(){return this._caseSensitive}get root(){return this._root}add(e){e=this._caseProcess(e);let t=this.root,r=!1;for(let i of e){let s=t.children.get(i);s||(s=new Y(i),t.children.set(i,s)),t=s}return t.isEnd||(r=!0,t.isEnd=!0,this._size++),r}has(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let i=t.children.get(r);if(!i)return!1;t=i}return t.isEnd}isEmpty(){return this.size===0}clear(){this._size=0,this._root=new Y("")}delete(e){e=this._caseProcess(e);let t=!1,r=(i,s)=>{let o=e[s],a=i.children.get(o);return a?s===e.length-1?a.isEnd?(a.children.size>0?a.isEnd=!1:i.children.delete(o),t=!0,!0):!1:r(a,s+1)&&!i.isEnd&&a.children.size===0?(i.children.delete(o),!0):!1:!1};return r(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let r=(i,s)=>{s>t&&(t=s);let{children:o}=i;if(o)for(let a of o.entries())r(a[1],s+1)};r(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let i=t.children.get(r);if(!i)return!1;t=i}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let r of e){let i=t.children.get(r);if(!i)return!1;t=i}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",r=i=>{if(t+=i.key,t!==e&&!i.isEnd)if(i&&i.children&&i.children.size===1)r(Array.from(i.children.values())[0]);else return};return r(this.root),t===e}getLongestCommonPrefix(){let e="",t=r=>{if(e+=r.key,!r.isEnd)if(r&&r.children&&r.children.size===1)t(Array.from(r.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,r=!1){e=this._caseProcess(e);let i=[],s=0;function o(l,u){for(let f of l.children.keys()){let E=l.children.get(f);E!==void 0&&o(E,u.concat(f))}if(l.isEnd){if(s>t-1)return;i.push(u),s++}}let a=this.root;if(e)for(let l of e){let u=a.children.get(l);if(u)a=u;else return[]}return(r||a!==this.root)&&o(a,e),i}clone(){return new h(this,{caseSensitive:this.caseSensitive,toElementFn:this.toElementFn})}filter(e,t){let r=new h([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive}),i=0;for(let s of this)e.call(t,s,i,this)&&r.add(s),i++;return r}map(e,t,r){let i=new h([],{toElementFn:t,caseSensitive:this.caseSensitive}),s=0;for(let o of this)i.add(e.call(r,o,s,this)),s++;return i}*_getIterator(){function*e(t,r){t.isEnd&&(yield r);for(let[i,s]of t.children)yield*v(e(s,r+i))}yield*v(e(this.root,""))}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var Pe=class h{constructor(n,e,t){d(this,"_key");d(this,"_value");d(this,"_children");this._key=n,this._value=e||void 0,this._children=t||[]}get key(){return this._key}set key(n){this._key=n}get value(){return this._value}set value(n){this._value=n}get children(){return this._children}set children(n){this._children=n}addChildren(n){this._children||(this._children=[]),n instanceof h?this._children.push(n):this._children=this._children.concat(n)}getHeight(){let n=0;if(this){let e=(t,r)=>{r>n&&(n=r);let{_children:i}=t;if(i)for(let s=0,o=i.length;s<o;s++)e(i[s],r+1)};e(this,0)}return n}};return $e(st);})();
|
|
5
5
|
/**
|
|
6
6
|
* data-structure-typed
|
|
7
7
|
*
|