data-structure-typed 2.0.1 → 2.0.2

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/binary-tree.js +8 -9
  3. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  4. package/dist/cjs/types/utils/utils.d.ts +1 -7
  5. package/dist/cjs/utils/utils.d.ts +3 -49
  6. package/dist/cjs/utils/utils.js +13 -82
  7. package/dist/cjs/utils/utils.js.map +1 -1
  8. package/dist/esm/data-structures/binary-tree/binary-tree.js +8 -9
  9. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/esm/types/utils/utils.d.ts +1 -7
  11. package/dist/esm/utils/utils.d.ts +3 -49
  12. package/dist/esm/utils/utils.js +10 -68
  13. package/dist/esm/utils/utils.js.map +1 -1
  14. package/dist/umd/data-structure-typed.js +18 -66
  15. package/dist/umd/data-structure-typed.min.js +2 -2
  16. package/dist/umd/data-structure-typed.min.js.map +1 -1
  17. package/package.json +1 -1
  18. package/src/data-structures/binary-tree/binary-tree.ts +9 -10
  19. package/src/types/utils/utils.ts +1 -6
  20. package/src/utils/utils.ts +11 -83
  21. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  22. package/test/unit/utils/utils.test.ts +35 -2
  23. package/dist/individuals/binary-tree/avl-tree-counter.mjs +0 -4701
  24. package/dist/individuals/binary-tree/avl-tree-multi-map.mjs +0 -4514
  25. package/dist/individuals/binary-tree/avl-tree.mjs +0 -4321
  26. package/dist/individuals/binary-tree/binary-tree.mjs +0 -3097
  27. package/dist/individuals/binary-tree/bst.mjs +0 -3858
  28. package/dist/individuals/binary-tree/red-black-tree.mjs +0 -4391
  29. package/dist/individuals/binary-tree/tree-counter.mjs +0 -4806
  30. package/dist/individuals/binary-tree/tree-multi-map.mjs +0 -4582
  31. package/dist/individuals/graph/directed-graph.mjs +0 -2910
  32. package/dist/individuals/graph/undirected-graph.mjs +0 -2745
  33. package/dist/individuals/hash/hash-map.mjs +0 -1040
  34. package/dist/individuals/heap/heap.mjs +0 -909
  35. package/dist/individuals/heap/max-heap.mjs +0 -671
  36. package/dist/individuals/heap/min-heap.mjs +0 -659
  37. package/dist/individuals/linked-list/doubly-linked-list.mjs +0 -1495
  38. package/dist/individuals/linked-list/singly-linked-list.mjs +0 -1479
  39. package/dist/individuals/priority-queue/max-priority-queue.mjs +0 -768
  40. package/dist/individuals/priority-queue/min-priority-queue.mjs +0 -757
  41. package/dist/individuals/priority-queue/priority-queue.mjs +0 -670
  42. package/dist/individuals/queue/deque.mjs +0 -1262
  43. package/dist/individuals/queue/queue.mjs +0 -1865
  44. package/dist/individuals/stack/stack.mjs +0 -415
  45. package/dist/individuals/trie/trie.mjs +0 -687
@@ -1,8 +1,8 @@
1
- "use strict";var dataStructureTyped=(()=>{var ae=Object.defineProperty,ot=Object.defineProperties,dt=Object.getOwnPropertyDescriptor,lt=Object.getOwnPropertyDescriptors,ut=Object.getOwnPropertyNames,et=Object.getOwnPropertySymbols;var tt=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable;var Ee=(u,r)=>(r=Symbol[u])?r:Symbol.for("Symbol."+u),ht=u=>{throw TypeError(u)};var Ke=(u,r,e)=>r in u?ae(u,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[r]=e,T=(u,r)=>{for(var e in r||(r={}))tt.call(r,e)&&Ke(u,e,r[e]);if(et)for(var e of et(r))at.call(r,e)&&Ke(u,e,r[e]);return u},nt=(u,r)=>ot(u,lt(r));var ft=(u,r)=>{for(var e in r)ae(u,e,{get:r[e],enumerable:!0})},ct=(u,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of ut(r))!tt.call(u,n)&&n!==e&&ae(u,n,{get:()=>r[n],enumerable:!(t=dt(r,n))||t.enumerable});return u};var pt=u=>ct(ae({},"__esModule",{value:!0}),u);var h=(u,r,e)=>Ke(u,typeof r!="symbol"?r+"":r,e);var it=(u,r,e)=>new Promise((t,n)=>{var i=d=>{try{o(e.next(d))}catch(l){n(l)}},s=d=>{try{o(e.throw(d))}catch(l){n(l)}},o=d=>d.done?t(d.value):Promise.resolve(d.value).then(i,s);o((e=e.apply(u,r)).next())}),gt=function(u,r){this[0]=u,this[1]=r};var B=u=>{var r=u[Ee("asyncIterator")],e=!1,t,n={};return r==null?(r=u[Ee("iterator")](),t=i=>n[i]=s=>r[i](s)):(r=r.call(u),t=i=>n[i]=s=>{if(e){if(e=!1,i==="throw")throw s;return s}return e=!0,{done:!1,value:new gt(new Promise(o=>{var d=r[i](s);d instanceof Object||ht("Object expected"),o(d)}),1)}}),n[Ee("iterator")]=()=>n,t("next"),"throw"in r?t("throw"):n.throw=i=>{throw i},"return"in r&&t("return"),n};var yt={};ft(yt,{AVLTree:()=>Q,AVLTreeCounter:()=>Qe,AVLTreeCounterNode:()=>ue,AVLTreeMultiMap:()=>Ue,AVLTreeMultiMapNode:()=>Ve,AVLTreeNode:()=>F,AbstractEdge:()=>P,AbstractGraph:()=>U,AbstractVertex:()=>R,BST:()=>G,BSTNode:()=>S,BinaryIndexedTree:()=>je,BinaryTree:()=>de,BinaryTreeNode:()=>j,Character:()=>ye,DFSOperation:()=>He,Deque:()=>Ie,DirectedEdge:()=>$,DirectedGraph:()=>oe,DirectedVertex:()=>q,DoublyLinkedList:()=>Be,DoublyLinkedListNode:()=>re,FibonacciHeap:()=>Se,FibonacciHeapNode:()=>ce,HashMap:()=>Le,Heap:()=>v,IterableElementBase:()=>L,IterableEntryBase:()=>C,LinkedHashMap:()=>ve,LinkedListQueue:()=>we,MapEdge:()=>_e,MapGraph:()=>Pe,MapVertex:()=>me,Matrix:()=>Ye,MaxHeap:()=>Fe,MaxPriorityQueue:()=>Xe,MinHeap:()=>Ae,MinPriorityQueue:()=>We,Navigator:()=>Je,PriorityQueue:()=>X,Queue:()=>k,Range:()=>H,RedBlackTree:()=>W,RedBlackTreeNode:()=>A,SegmentTree:()=>ze,SegmentTreeNode:()=>ee,SinglyLinkedList:()=>ie,SinglyLinkedListNode:()=>ne,SkipList:()=>Ce,SkipListNode:()=>se,Stack:()=>Oe,THUNK_SYMBOL:()=>Te,TreeCounter:()=>Ge,TreeCounterNode:()=>le,TreeMultiMap:()=>qe,TreeMultiMapNode:()=>be,TreeNode:()=>$e,Trie:()=>Ze,TrieNode:()=>te,UndirectedEdge:()=>ge,UndirectedGraph:()=>De,UndirectedVertex:()=>pe,arrayRemove:()=>I,calcMinUnitsRequired:()=>fe,getMSB:()=>ke,isComparable:()=>w,isThunk:()=>xe,isWeakKey:()=>Y,rangeCheck:()=>O,roundFixed:()=>Vt,throwRangeError:()=>_t,toBinaryString:()=>bt,toThunk:()=>Re,trampoline:()=>he,trampolineAsync:()=>mt,uuidV4:()=>Me});var C=class{*[Symbol.iterator](...r){yield*B(this._getIterator(...r))}*entries(){for(let r of this)yield r}*keys(){for(let r of this)yield r[0]}*values(){for(let r of this)yield r[1]}every(r,e){let t=0;for(let n of this)if(!r.call(e,n[0],n[1],t++,this))return!1;return!0}some(r,e){let t=0;for(let n of this)if(r.call(e,n[0],n[1],t++,this))return!0;return!1}forEach(r,e){let t=0;for(let n of this){let[i,s]=n;r.call(e,i,s,t++,this)}}find(r,e){let t=0;for(let n of this){let[i,s]=n;if(r.call(e,i,s,t++,this))return n}}has(r){for(let e of this){let[t]=e;if(t===r)return!0}return!1}hasValue(r){for(let[,e]of this)if(e===r)return!0;return!1}get(r){for(let e of this){let[t,n]=e;if(t===r)return n}}reduce(r,e){let t=e,n=0;for(let i of this){let[s,o]=i;t=r(t,o,s,n++,this)}return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var L=class{constructor(r){h(this,"_toElementFn");if(r){let{toElementFn:e}=r;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](...r){yield*B(this._getIterator(...r))}*values(){for(let r of this)yield r}every(r,e){let t=0;for(let n of this)if(!r.call(e,n,t++,this))return!1;return!0}some(r,e){let t=0;for(let n of this)if(r.call(e,n,t++,this))return!0;return!1}forEach(r,e){let t=0;for(let n of this)r.call(e,n,t++,this)}find(r,e){let t=0;for(let n of this)if(r.call(e,n,t++,this))return n}has(r){for(let e of this)if(e===r)return!0;return!1}reduce(r,e){let t=e!=null?e:0,n=0;for(let i of this)t=r(t,i,n++,this);return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var Me=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(u){let r=Math.random()*16|0;return(u=="x"?r:r&3|8).toString(16)})},I=function(u,r){let e=-1,t=u?u.length:0,n=[];for(;++e<t;){let i=u[e];r(i,e,u)&&(n.push(i),Array.prototype.splice.call(u,e--,1),t--)}return n},Te=Symbol("thunk"),xe=u=>typeof u=="function"&&u.__THUNK__===Te,Re=u=>{let r=()=>u();return r.__THUNK__=Te,r},he=u=>Object.assign((...e)=>{let t=u(...e);for(;xe(t)&&typeof t=="function";)t=t();return t},{cont:(...e)=>Re(()=>u(...e))}),mt=u=>Object.assign((...e)=>it(void 0,null,function*(){let t=yield u(...e);for(;xe(t)&&typeof t=="function";)t=yield t();return t}),{cont:(...e)=>Re(()=>u(...e))}),ke=u=>u<=0?0:1<<31-Math.clz32(u),O=(u,r,e,t="Index out of bounds.")=>{if(u<r||u>e)throw new RangeError(t)},_t=(u="The value is off-limits.")=>{throw new RangeError(u)},Y=u=>{let r=typeof u;return r==="object"&&u!==null||r==="function"},fe=(u,r)=>Math.floor((u+r-1)/r),Vt=(u,r=10)=>{let e=Math.pow(10,r);return Math.round(u*e)/e};function Ne(u){let r=typeof u;return r==="number"?!0:r==="bigint"||r==="string"||r==="boolean"}function rt(u){if(typeof u.valueOf=="function"){let r=u.valueOf();if(r!==u){if(Ne(r))return r;if(typeof r=="object"&&r!==null)return rt(r)}}if(typeof u.toString=="function"){let r=u.toString();if(r!=="[object Object]")return r}return null}function w(u,r=!1){if(u==null)return!1;if(Ne(u))return!0;if(typeof u!="object")return!1;if(u instanceof Date||r)return!0;let e=rt(u);return e==null?!1:Ne(e)}function bt(u,r=32){let e=(u>>>0).toString(2);return e=e.padStart(r,"0"),e}var Le=class u extends C{constructor(e=[],t){super();h(this,"_store",{});h(this,"_objMap",new Map);h(this,"_toEntryFn");h(this,"_size",0);h(this,"_hashFn",e=>String(e));if(t){let{hashFn:n,toEntryFn:i}=t;n&&(this._hashFn=n),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 n=this._getNoObjKey(e);this.store[n]===void 0&&this._size++,this._store[n]={key:e,value:t}}return!0}setMany(e){let t=[];for(let n of e){let i,s;if(this.isEntry(n))i=n[0],s=n[1];else if(this._toEntryFn){let o=this._toEntryFn(n);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 n=this._getNoObjKey(e);return(t=this._store[n])==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 u(this,{hashFn:this._hashFn,toEntryFn:this._toEntryFn})}map(e,t){let n=new u,i=0;for(let[s,o]of this)n.set(s,e.call(t,s,o,i++,this));return n}filter(e,t){let n=new u,i=0;for(let[s,o]of this)e.call(t,s,o,i++,this)&&n.set(s,o);return n}*_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,n;return t!=="string"&&t!=="number"&&t!=="symbol"?n=this._hashFn(e):n=e,n}},ve=class u extends C{constructor(e=[],t){super();h(this,"_sentinel");h(this,"_hashFn",e=>String(e));h(this,"_objHashFn",e=>e);h(this,"_noObjMap",{});h(this,"_objMap",new WeakMap);h(this,"_head");h(this,"_tail");h(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.")});h(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:n,objHashFn:i,toEntryFn:s}=t;n&&(this._hashFn=n),i&&(this._objHashFn=i),s&&(this._toEntryFn=s)}e&&this.setMany(e)}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 n,i=!this.has(e);if(Y(e)){let s=this._objHashFn(e);n=this.objMap.get(s),!n&&i?(n={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,n)):n&&(n.value=t)}else{let s=this._hashFn(e);n=this.noObjMap[s],!n&&i?this.noObjMap[s]=n={key:e,value:t,prev:this.tail,next:this._sentinel}:n&&(n.value=t)}return n&&i&&(this._size===0?(this._head=n,this._sentinel.next=n):(this.tail.next=n,n.prev=this.tail),this._tail=n,this._sentinel.prev=n,this._size++),!0}setMany(e){let t=[];for(let n of e){let i,s;if(this.isEntry(n))i=n[0],s=n[1];else if(this._toEntryFn){let o=this._toEntryFn(n);i=o[0],s=o[1]}i!==void 0&&s!==void 0&&t.push(this.set(i,s))}return t}has(e){if(Y(e)){let t=this._objHashFn(e);return this.objMap.has(t)}else return this._hashFn(e)in this.noObjMap}get(e){if(Y(e)){let t=this._objHashFn(e),n=this.objMap.get(t);return n?n.value:void 0}else{let t=this._hashFn(e),n=this.noObjMap[t];return n?n.value:void 0}}at(e){O(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(Y(e)){let n=this._objHashFn(e);if(t=this.objMap.get(n),!t)return!1;this.objMap.delete(n)}else{let n=this._hashFn(e);if(t=this.noObjMap[n],!t)return!1;delete this.noObjMap[n]}return this._deleteNode(t),!0}deleteAt(e){O(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 u([],{hashFn:this._hashFn,objHashFn:this._objHashFn});for(let t of this){let[n,i]=t;e.set(n,i)}return e}filter(e,t){let n=new u,i=0;for(let[s,o]of this)e.call(t,s,o,i,this)&&n.set(s,o),i++;return n}map(e,t){let n=new u,i=0;for(let[s,o]of this){let[d,l]=e.call(t,s,o,i,this);n.set(d,l),i++}return n}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:n}=e;return t.next=n,n.prev=t,e===this.head&&(this._head=n),e===this.tail&&(this._tail=t),this._size-=1,!0}};var J=class{constructor(r){h(this,"_value");h(this,"_next");this._value=r,this._next=void 0}get value(){return this._value}set value(r){this._value=r}get next(){return this._next}set next(r){this._next=r}},D=class u extends L{constructor(e){super(e);h(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let i=this.at(n);if(i!==void 0&&e.call(t,i,n,this))return n}return-1}concat(...e){let t=this.clone();for(let n of e)n instanceof u?t.pushMany(n):t.push(n);return t}sort(e){let t=this.toArray();t.sort(e),this.clear();for(let n of t)this.push(n);return this}splice(e,t=0,...n){let i=this._createInstance();e=e<0?this.length+e:e,e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));for(let s=0;s<t;s++){let o=this.deleteAt(e);o!==void 0&&i.push(o)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);return i}join(e=","){return this.toArray().join(e)}toReversedArray(){let e=[];for(let t=this.length-1;t>=0;t--)e.push(this.at(t));return e}reduceRight(e,t){let n=t!=null?t:0;for(let i=this.length-1;i>=0;i--)n=e(n,this.at(i),i,this);return n}slice(e=0,t=this.length){e=e<0?this.length+e:e,t=t<0?this.length+t:t;let n=this._createInstance();for(let i=e;i<t;i++)n.push(this.at(i));return n}fill(e,t=0,n=this.length){if(t=t<0?this.length+t:t,n=n<0?this.length+n:n,t<0&&(t=0),n>this.length&&(n=this.length),t>=n)return this;for(let i=t;i<n;i++)this.setAt(i,e);return this}},Z=class extends D{constructor(r){if(super(r),r){let{maxLen:e}=r;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(r,e=0){let t=this._getIterator(),n=t.next(),i=0;for(;i<e;)n=t.next(),i++;for(;!n.done;){if(n.value===r)return i;n=t.next(),i++}return-1}lastIndexOf(r,e=this.length-1){let t=this._getReverseIterator(),n=t.next(),i=this.length-1;for(;i>e;)n=t.next(),i--;for(;!n.done;){if(n.value===r)return i;n=t.next(),i--}return-1}concat(...r){let e=this.clone();for(let t of r)t instanceof D?e.pushMany(t):e.push(t);return e}slice(r=0,e=this.length){r=r<0?this.length+r:r,e=e<0?this.length+e:e;let t=this._createInstance(),n=this._getIterator(),i=n.next(),s=0;for(;s<r;)i=n.next(),s++;for(let o=r;o<e;o++)t.push(i.value),i=n.next();return t}splice(r,e=0,...t){let n=this._createInstance();r=r<0?this.length+r:r,r=Math.max(0,Math.min(r,this.length)),e=Math.max(0,e);let i=0,s,o,d=this._getNodeIterator();for(let l of d){if(i===r){s=l;break}o=l,i++}for(let l=0;l<e&&s;l++){n.push(s.value);let a=s.next;this.delete(s),s=a}for(let l=0;l<t.length;l++)o?(this.addAfter(o,t[l]),o=o.next):(this.addAt(0,t[l]),o=this._getNodeIterator().next().value);return n}reduceRight(r,e){let t=e!=null?e:0,n=this.length-1;for(let i of this._getReverseIterator())t=r(t,i,n--,this);return t}};var ne=class extends J{constructor(e){super(e);h(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},ie=class u extends Z{constructor(e=[],t){super(t);h(this,"_head");h(this,"_tail");h(this,"_length",0);this.pushMany(e)}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 length(){return this._length}static fromArray(e){let t=new u;for(let n of e)t.push(n);return t}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.head)return;if(this.head===this.tail){let n=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,n}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._length--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._length++,!0}pushMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.push(this.toElementFn(n)));continue}t.push(this.push(n))}return t}unshiftMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.unshift(this.toElementFn(n)));continue}t.push(this.unshift(n))}return t}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}isNode(e){return e instanceof ne}getNodeAt(e){let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._length)return;let t;if(e===0)return t=this.first,this.shift(),t;let n=this.getNodeAt(e),i=this._getPrevNode(n);if(i&&n)return t=n.value,i.next=n.next,n===this.tail&&(this._tail=i),this._length--,t}delete(e){if(e===void 0||!this.head)return!1;let t=this.isNode(e)?e:this.getNode(e);if(!t)return!1;let n=this._getPrevNode(t);return n?(n.next=t.next,t===this.tail&&(this._tail=n)):(this._head=t.next,t===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t),!0;if(e===this._length)return this.push(t),!0;let n=this._ensureNode(t),i=this.getNodeAt(e-1);return n.next=i.next,i.next=n,this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,n;for(;t;)n=t.next,t.next=e,e=t,t=n;return[this._head,this._tail]=[this.tail,this.head],this}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addBefore(e,t){let n=this.getNode(e);if(!n)return!1;let i=this._getPrevNode(n),s=this._ensureNode(t);return i?(i.next=s,s.next=n,this._length++):this.unshift(s),!0}addAfter(e,t){let n=this.getNode(e);if(n){let i=this._ensureNode(t);return i.next=n.next,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}return!1}splice(e,t=0,...n){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,t);let s=e===0?void 0:this.getNodeAt(e-1),d=s?s.next:this.head;for(let f=0;f<t&&d;f++)i.push(d.value),d=d.next;let l=d,a;for(let f of n){let c=this._ensureNode(f);a?a.next=c:s?s.next=c:this._head=c,a=c}return a?a.next=l:s&&(s.next=l),l||(this._tail=a||s),this._length+=n.length-i.length,i}countOccurrences(e){let t=this._ensurePredicate(e),n=0,i=this.head;for(;i;)t(i)&&n++,i=i.next;return n}clone(){return new u(this,{toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}_createInstance(e){return new u([],e)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=[...this].reverse();for(let t of e)yield t}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new ne(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}_getPrevNode(e){if(!this.head||this.head===e)return;let t=this.head;for(;t.next&&t.next!==e;)t=t.next;return t.next===e?t:void 0}};var re=class extends J{constructor(e){super(e);h(this,"_next");h(this,"_prev");this._value=e,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(e){this._next=e}get prev(){return this._prev}set prev(e){this._prev=e}},Be=class u extends Z{constructor(e=[],t){super(t);h(this,"_head");h(this,"_tail");h(this,"_length");if(this._head=void 0,this._tail=void 0,this._length=0,t){let{maxLen:n}=t;typeof n=="number"&&n>0&&n%1===0&&(this._maxLen=n)}this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}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 u(e)}isNode(e){return e instanceof re}push(e){let t=this._ensureNode(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!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._length--,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._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.push(this.toElementFn(n)));continue}t.push(this.push(n))}return t}unshiftMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.unshift(this.toElementFn(n)));continue}t.push(this.unshift(n))}return t}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t),!0;if(e===this._length)return this.push(t),!0;let n=this._ensureNode(t),i=this.getNodeAt(e-1),s=i.next;return n.prev=i,n.next=s,i.next=n,s.prev=n,this._length++,!0}addBefore(e,t){let n=this.isNode(e)?e:this.getNode(e);if(n){let i=this._ensureNode(t);return i.prev=n.prev,n.prev&&(n.prev.next=i),i.next=n,n.prev=i,n===this.head&&(this._head=i),this._length++,!0}return!1}addAfter(e,t){let n=this.isNode(e)?e:this.getNode(e);if(n){let i=this._ensureNode(t);return i.next=n.next,n.next&&(n.next.prev=i),i.prev=n,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}return!1}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}deleteAt(e){if(e<0||e>=this._length)return;let t;if(e===0)return t=this.first,this.shift(),t;if(e===this._length-1)return t=this.last,this.pop(),t;let n=this.getNodeAt(e),i=n.prev,s=n.next;return i.next=s,s.prev=i,this._length--,n==null?void 0:n.value}delete(e){let t=this.getNode(e);if(t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let n=t.prev,i=t.next;n&&(n.next=i),i&&(i.prev=n),this._length--}return!0}return!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}getBackward(e){let t=this._ensurePredicate(e),n=this.tail;for(;n;){if(t(n))return n.value;n=n.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}clone(){return new u(this,{toElementFn:this._toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}countOccurrences(e){let t=this._ensurePredicate(e),n=0,i=this.head;for(;i;)t(i)&&n++,i=i.next;return n}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=this.tail;for(;e;)yield e.value,e=e.prev}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new re(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}_createInstance(e){return new u([],e)}_getPrevNode(e){return e.prev}};var se=class{constructor(r,e,t){h(this,"key");h(this,"value");h(this,"forward");this.key=r,this.value=e,this.forward=new Array(t)}},Ce=class{constructor(r=[],e){h(this,"_head",new se(void 0,void 0,this.maxLevel));h(this,"_level",0);h(this,"_maxLevel",16);h(this,"_probability",.5);if(e){let{maxLevel:t,probability:n}=e;typeof t=="number"&&(this._maxLevel=t),typeof n=="number"&&(this._probability=n)}if(r)for(let[t,n]of r)this.add(t,n)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let r=this.head.forward[0];return r?r.value:void 0}get last(){let r=this.head;for(let e=this.level-1;e>=0;e--)for(;r.forward[e];)r=r.forward[e];return r.value}add(r,e){let t=new se(r,e,this._randomLevel()),n=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<r;)i=i.forward[s];n[s]=i}for(let s=0;s<t.forward.length;s++)t.forward[s]=n[s].forward[s],n[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(r){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<r;)e=e.forward[t];if(e=e.forward[0],e&&e.key===r)return e.value}has(r){return this.get(r)!==void 0}delete(r){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<r;)t=t.forward[n];e[n]=t}if(t=t.forward[0],t&&t.key===r){for(let n=0;n<this.level&&e[n].forward[n]===t;n++)e[n].forward[n]=t.forward[n];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(r){let e=this.head;for(let n=this.level-1;n>=0;n--)for(;e.forward[n]&&e.forward[n].key<=r;)e=e.forward[n];let t=e.forward[0];return t?t.value:void 0}lower(r){let e=this.head,t;for(let n=this.level-1;n>=0;n--){for(;e.forward[n]&&e.forward[n].key<r;)e=e.forward[n];e.key<r&&(t=e)}return t?t.value:void 0}_randomLevel(){let r=1;for(;Math.random()<this.probability&&r<this.maxLevel;)r++;return r}};var Oe=class u extends L{constructor(e=[],t){super(t);h(this,"_elements",[]);this.pushMany(e)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e){return new u(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()}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}clear(){this._elements=[]}clone(){return new u(this,{toElementFn:this.toElementFn})}filter(e,t){let n=new u([],{toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var k=class u extends D{constructor(e=[],t){super(t);h(this,"_elements",[]);h(this,"_offset",0);h(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get length(){return this.elements.length-this.offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get first(){return this.length>0?this.elements[this.offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new u(e)}push(e){return this.elements.push(e),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}shift(){if(this.length===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){let t=this.elements[e];return this.elements.splice(e,1),t}at(e){return this.elements[e+this._offset]}reverse(){return this._elements=this.elements.slice(this.offset).reverse(),this._offset=0,this}addAt(e,t){return e<0||e>this.length?!1:(this._elements.splice(this.offset+e,0,t),!0)}setAt(e,t){return e<0||e>this.length?!1:(this._elements[this.offset+e]=t,!0)}isEmpty(){return this.length===0}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this.offset),this._offset=0,!0}splice(e,t=0,...n){let i=this._createInstance();e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));let s=this.offset+e,o=this._elements.splice(s,t,...n);return i.pushMany(o),this.compact(),i}clone(){return new u(this.elements.slice(this.offset),{toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this._toElementFn,autoCompactRatio:this._autoCompactRatio,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,autoCompactRatio:this._autoCompactRatio,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}*_getIterator(){for(let e of this.elements.slice(this.offset))yield e}_createInstance(e){return new u([],e)}*_getReverseIterator(){for(let e=this.length-1;e>=0;e--){let t=this.at(e);t!==void 0&&(yield t)}}},we=class u extends ie{clone(){return new u(this,{toElementFn:this.toElementFn,maxLen:this._maxLen})}};var Ie=class u extends D{constructor(e=[],t){super(t);h(this,"_bucketSize",4096);h(this,"_bucketFirst",0);h(this,"_firstInBucket",0);h(this,"_bucketLast",0);h(this,"_lastInBucket",0);h(this,"_bucketCount",0);h(this,"_buckets",[]);h(this,"_length",0);if(t){let{bucketSize:s}=t;typeof s=="number"&&(this._bucketSize=s)}let n;"length"in e?e.length instanceof Function?n=e.length():n=e.length:e.size instanceof Function?n=e.size():n=e.size,this._bucketCount=fe(n,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let i=fe(n,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(i>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-n%this._bucketSize>>1,this.pushMany(e)}get bucketSize(){return this._bucketSize}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 length(){return this._length}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}push(e){return this._length&&(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._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==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._length-=1,e}shift(){if(this._length===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==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._length-=1,e}unshift(e){return this._length&&(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._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e=[]){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(e){O(e,0,this._length-1);let{bucketIndex:t,indexInBucket:n}=this._getBucketAndPosition(e);return this._buckets[t][n]}setAt(e,t){O(e,0,this._length-1);let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[n][i]=t,!0}addAt(e,t,n=1){let i=this._length;if(O(e,0,i),e===0)for(;n--;)this.unshift(t);else if(e===this._length)for(;n--;)this.push(t);else{let s=[];for(let o=e;o<this._length;++o)s.push(this.at(o));this.cut(e-1,!0);for(let o=0;o<n;++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:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketLast=n,this._lastInBucket=i,this._length=e+1,this}else{let n=this._createInstance({bucketSize:this._bucketSize,toElementFn:this._toElementFn,maxLen:this._maxLen});for(let i=0;i<=e;i++)n.push(this.at(i));return n}}splice(e,t=this._length-e,...n){O(e,0,this._length),t<0&&(t=0),e+t>this._length&&(t=this._length-e);let i=this._createInstance();for(let o=0;o<t;o++)i.push(this.at(e+o));let s=[];for(let o=e+t;o<this._length;o++)s.push(this.at(o));this.cut(e-1,!0);for(let o of n)this.push(o);for(let o of s)this.push(o);return i}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketFirst=n,this._firstInBucket=i,this._length=this._length-e,this}else{let n=this._createInstance({bucketSize:this._bucketSize,toElementFn:this._toElementFn,maxLen:this._maxLen});e<0&&(e=0);for(let i=e;i<this._length;i++)n.push(this.at(i));return n}}deleteAt(e){O(e,0,this._length-1);let t;if(e===0)return this.shift();if(e===this._length-1)return t=this.last,this.pop(),t;{let n=this._length-1,{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(e);t=this._buckets[i][s];for(let o=e;o<n;o++){let{bucketIndex:d,indexInBucket:l}=this._getBucketAndPosition(o),{bucketIndex:a,indexInBucket:f}=this._getBucketAndPosition(o+1);this._buckets[d][l]=this._buckets[a][f]}return this.pop(),t}}delete(e){let t=this._length;if(t===0)return!1;let n=0,i=0;for(;n<t;){let s=this.at(n);s!==e&&(this.setAt(i,s),i+=1),n+=1}return this.cut(i-1,!0),!0}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:n,_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-n-1,this}unique(){if(this._length<=1)return this;let e=1,t=this.at(0);for(let n=1;n<this._length;++n){let i=this.at(n);i!==t&&(t=i,this.setAt(e++,i))}return this.cut(e-1,!0),this}shrinkToFit(){if(this._length===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}}clone(){return new u(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({bucketSize:this._bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{bucketSize:this._bucketSize,toElementFn:t,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}*_getIterator(){for(let e=0;e<this._length;++e)yield this.at(e)}_reallocate(e){let t=[],n=e||this._bucketCount>>1||1;for(let i=0;i<n;++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=n,this._bucketLast=t.length-1;for(let i=0;i<n;++i)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,n,i=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(i/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),n=(i+1)%this._bucketSize-1,n<0&&(n=this._bucketSize-1),{bucketIndex:t,indexInBucket:n}}_createInstance(e){return new u([],e)}*_getReverseIterator(){for(let e=this._length-1;e>-1;e--)yield this.at(e)}};var v=class u extends L{constructor(e=[],t){super(t);h(this,"_elements",[]);h(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});h(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:n}=t;n&&(this._comparator=n)}this.addMany(e)}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 u(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}addMany(e){let t=[];for(let n of e){if(this._toElementFn){t.push(this.add(this._toElementFn(n)));continue}t.push(this.add(n))}return t}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=[],n=i=>{let s=2*i+1,o=s+1;i<this.size&&(e==="IN"?(n(s),t.push(this.elements[i]),n(o)):e==="PRE"?(t.push(this.elements[i]),n(s),n(o)):e==="POST"&&(n(s),n(o),t.push(this.elements[i])))};return n(0),t}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){let e=[],t=new u(this,{comparator:this.comparator});for(;t.size!==0;){let n=t.poll();n!==void 0&&e.push(n)}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 n=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let s of this)e.call(t,s,i,this)&&n.add(s),i++;return n}map(e,t,n,i){let s=new u([],{comparator:t,toElementFn:n}),o=0;for(let d of this)s.add(e.call(i,d,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 n=e-1>>1,i=this.elements[n];if(this.comparator(i,t)<=0)break;this.elements[e]=i,e=n}return this.elements[e]=t,!0}_sinkDown(e,t){let n=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,n)>=0)break;this.elements[e]=o,e=i}return this.elements[e]=n,!0}},ce=class{constructor(r,e=0){h(this,"element");h(this,"degree");h(this,"left");h(this,"right");h(this,"child");h(this,"parent");h(this,"marked");this.element=r,this.degree=e,this.marked=!1}},Se=class{constructor(r){h(this,"_root");h(this,"_size",0);h(this,"_min");h(this,"_comparator");if(this.clear(),this._comparator=r||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(r){return this.push(r)}push(r){let e=this.createNode(r);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(r){let e=[];if(!r)return e;let t=r,n=!1;for(;!(t===r&&n);)t===r&&(n=!0),t&&(e.push(t),t=t.right);return e}mergeWithChild(r,e){r.child?(e.right=r.child.right,e.left=r.child,r.child.right.left=e,r.child.right=e):r.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let r=this.min;if(r.child){let e=this.consumeLinkedList(r.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(r),r===r.right?(this._min=void 0,this._root=void 0):(this._min=r.right,this._consolidate()),this._size--,r.element}merge(r){if(r.size!==0){if(this.root&&r.root){let e=this.root,t=r.root,n=e.right,i=t.left;e.right=t,t.left=e,n.left=i,i.right=n}(!this.min||r.min&&this.comparator(r.min.element,this.min.element)<0)&&(this._min=r.min),this._size+=r.size,r.clear()}}createNode(r){return new ce(r)}_defaultComparator(r,e){return r<e?-1:r>e?1:0}mergeWithRoot(r){this.root?(r.right=this.root.right,r.left=this.root,this.root.right.left=r,this.root.right=r):this._root=r}removeFromRoot(r){this.root===r&&(this._root=r.right),r.left&&(r.left.right=r.right),r.right&&(r.right.left=r.left)}_link(r,e){this.removeFromRoot(r),r.left=r,r.right=r,this.mergeWithChild(e,r),e.degree++,r.parent=e}_consolidate(){let r=new Array(this._size),e=this.consumeLinkedList(this.root),t,n,i,s;for(let o of e){for(t=o,i=t.degree;r[i];)n=r[i],this.comparator(t.element,n.element)>0&&(s=t,t=n,n=s),this._link(n,t),r[i]=void 0,i++;r[i]=t}for(let o=0;o<this._size;o++)r[o]&&this.comparator(r[o].element,this.min.element)<=0&&(this._min=r[o])}};var Fe=class u extends v{constructor(r=[],e){super(r,T({comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0}},e))}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var Ae=class u extends v{constructor(r=[],e){super(r,e)}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var R=class{constructor(r,e){h(this,"key");h(this,"value");this.key=r,this.value=e}},P=class{constructor(r,e){h(this,"value");h(this,"weight");h(this,"_hashCode");this.weight=r!==void 0?r:1,this.value=e,this._hashCode=Me()}get hashCode(){return this._hashCode}},U=class extends C{constructor(){super();h(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 R)return this._addVertex(e);{let n=this.createVertex(e,t);return this._addVertex(n)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let n of e)t.push(this.deleteVertex(n));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,n,i){if(e instanceof P)return this._addEdge(e);if(t instanceof R||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof R&&(e=e.key),t instanceof R&&(t=t.key);let s=this.createEdge(e,t,n,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,n){let i=this.getEdge(e,t);return i?(i.weight=n,!0):!1}getAllPathsBetween(e,t,n=1e3){let i=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let d=[];for(d.push({vertex:s,path:[s]});d.length>0;){let{vertex:l,path:a}=d.pop();if(l===o&&(i.push(a),i.length>=n))return i;let f=this.getNeighbors(l);for(let c of f)if(!a.includes(c)){let g=[...a,c];d.push({vertex:c,path:g})}}return i}getPathSumWeight(e){var n;let t=0;for(let i=0;i<e.length;i++)t+=((n=this.getEdge(e[i],e[i+1]))==null?void 0:n.weight)||0;return t}getMinCostBetween(e,t,n){if(n===void 0&&(n=!1),n){let i=this.getAllPathsBetween(e,t),s=Number.MAX_SAFE_INTEGER;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,d=new k([s]);o.set(s,!0);let l=0;for(;d.length>0;){for(let a=0;a<d.length;a++){let f=d.shift();if(f===i)return l;if(f!==void 0){let c=this.getNeighbors(f);for(let g of c)o.has(g)||(o.set(g,!0),d.push(g))}}l++}return}}getMinPathBetween(e,t,n,i=!1){var s,o;if(n===void 0&&(n=!1),n)if(i){let d=this.getAllPathsBetween(e,t,1e4),l=Number.MAX_SAFE_INTEGER,a=-1,f=0;for(let c of d){let g=this.getPathSumWeight(c);g<l&&(l=g,a=f),f++}return d[a]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let d=[],l=this._getVertex(e),a=this._getVertex(t);if(!(l&&a))return[];let f=(c,g,p,V)=>{if(p.add(c),c===g){d=[l,...V];return}let y=this.getNeighbors(c);for(let b of y)p.has(b)||(V.push(b),f(b,g,p,V),V.pop());p.delete(c)};return f(l,a,new Set,[]),d}}dijkstraWithoutHeap(e,t=void 0,n=!1,i=!1){let s=Number.MAX_SAFE_INTEGER,o,d=[],l=[],a=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),V=t?this._getVertex(t):void 0;if(!p)return;for(let _ of a){let m=_[1];m instanceof R&&f.set(m,Number.MAX_SAFE_INTEGER)}f.set(p,0),g.set(p,void 0);let y=()=>{let _=Number.MAX_SAFE_INTEGER,m;for(let[E,K]of f)c.has(E)||K<_&&(_=K,m=E);return m},b=_=>{for(let m of a){let E=m[1];if(E instanceof R){let K=[E],N=g.get(E);for(;N;)K.push(N),N=g.get(N);let M=K.reverse();m[1]===_&&(d=M),l.push(M)}}};for(let _=1;_<a.size;_++){let m=y();if(m){if(c.add(m),V&&V===m)return n&&(s=f.get(V)||Number.MAX_SAFE_INTEGER),i&&b(V),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d};let E=this.getNeighbors(m);for(let K of E)if(!c.has(K)){let N=this.getEdge(m,K);if(N){let M=f.get(m),x=f.get(K);M!==void 0&&x!==void 0&&N.weight+M<x&&(f.set(K,N.weight+M),g.set(K,m))}}}}return n&&f.forEach((_,m)=>{m!==p&&_<s&&(s=_,i&&(o=m))}),i&&b(o),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d}}dijkstra(e,t=void 0,n=!1,i=!1){var _;let s=Number.MAX_SAFE_INTEGER,o,d=[],l=[],a=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),V=t?this._getVertex(t):void 0;if(!p)return;for(let m of a){let E=m[1];E instanceof R&&f.set(E,Number.MAX_SAFE_INTEGER)}let y=new v([],{comparator:(m,E)=>m.key-E.key});y.add({key:0,value:p}),f.set(p,0),g.set(p,void 0);let b=m=>{for(let E of a){let K=E[1];if(K instanceof R){let N=[K],M=g.get(K);for(;M;)N.push(M),M=g.get(M);let x=N.reverse();E[1]===m&&(d=x),l.push(x)}}};for(;y.size>0;){let m=y.poll(),E=m==null?void 0:m.key,K=m==null?void 0:m.value;if(E!==void 0&&K){if(c.add(K),V&&V===K)return n&&(s=f.get(V)||Number.MAX_SAFE_INTEGER),i&&b(V),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d};let N=this.getNeighbors(K);for(let M of N)if(!c.has(M)){let x=(_=this.getEdge(K,M))==null?void 0:_.weight;if(typeof x=="number"){let z=f.get(M);z&&E+x<z&&(y.add({key:E+x,value:M}),g.set(M,K),f.set(M,E+x))}}}}return n&&f.forEach((m,E)=>{E!==p&&m<s&&(s=m,i&&(o=E))}),i&&b(o),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d}}bellmanFord(e,t,n,i){n===void 0&&(n=!1),i===void 0&&(i=!1);let s=this._getVertex(e),o=[],d=new Map,l=new Map,a=Number.MAX_SAFE_INTEGER,f=[],c;if(t&&(c=!1),!s)return{hasNegativeCycle:c,distMap:d,preMap:l,paths:o,min:a,minPath:f};let g=this._vertexMap,p=g.size,V=this.edgeSet(),y=V.length;this._vertexMap.forEach(_=>{d.set(_,Number.MAX_SAFE_INTEGER)}),d.set(s,0);for(let _=1;_<p;++_)for(let m=0;m<y;++m){let E=this.getEndsOfEdge(V[m]);if(E){let[K,N]=E,M=V[m].weight,x=d.get(K),z=d.get(N);x!==void 0&&z!==void 0&&d.get(K)!==Number.MAX_SAFE_INTEGER&&x+M<z&&(d.set(N,x+M),i&&l.set(N,K))}}let b;if(n&&d.forEach((_,m)=>{m!==s&&_<a&&(a=_,i&&(b=m))}),i)for(let _ of g){let m=_[1];if(m instanceof R){let E=[m],K=l.get(m);for(;K!==void 0;)E.push(K),K=l.get(K);let N=E.reverse();_[1]===b&&(f=N),o.push(N)}}for(let _=0;_<y;++_){let m=this.getEndsOfEdge(V[_]);if(m){let[E]=m,K=V[_].weight,N=d.get(E);N&&N!==Number.MAX_SAFE_INTEGER&&N+K<N&&(c=!0)}}return{hasNegativeCycle:c,distMap:d,preMap:l,paths:o,min:a,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],i=[];for(let o=0;o<t;o++){n[o]=[],i[o]=[];for(let d=0;d<t;d++)i[o][d]=void 0}for(let o=0;o<t;o++)for(let d=0;d<t;d++)n[o][d]=((s=this.getEdge(e[o][1],e[d][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let o=0;o<t;o++)for(let d=0;d<t;d++)for(let l=0;l<t;l++)n[d][l]>n[d][o]+n[o][l]&&(n[d][l]=n[d][o]+n[o][l],i[d][l]=e[o][1]);return{costs:n,predecessor:i}}getCycles(e=!1){let t=[],n=new Set,i=(o,d,l)=>{if(l.has(o)){(!e&&d.length>2||e&&d.length>=2)&&d[0]===o.key&&t.push([...d]);return}l.add(o),d.push(o.key);for(let a of this.getNeighbors(o))a&&i(a,d,l);l.delete(o),d.pop()};for(let o of this.vertexMap.values())i(o,[],n);let s=new Map;for(let o of t){let d=[...o].sort().toString();s.has(d)||s.set(d,o)}return[...s].map(o=>o[1])}filter(e,t){let n=[],i=0;for(let[s,o]of this)e.call(t,s,o,i,this)&&n.push([s,o]),i++;return n}map(e,t){let n=[],i=0;for(let[s,o]of this)n.push(e.call(t,s,o,i,this)),i++;return n}*_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 R?e.key:e}};var q=class extends R{constructor(r,e){super(r,e)}},$=class extends P{constructor(e,t,n,i){super(n,i);h(this,"src");h(this,"dest");this.src=e,this.dest=t}},oe=class u extends U{constructor(){super();h(this,"_outEdgeMap",new Map);h(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 q(e,t)}createEdge(e,t,n,i){return new $(e,t,n!=null?n:1,i)}getEdge(e,t){let n=[];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&&(n=o.filter(d=>d.dest===s.key))}}return n[0]||void 0}deleteEdgeSrcToDest(e,t){let n=this._getVertex(e),i=this._getVertex(t),s;if(!n||!i)return;let o=this._outEdgeMap.get(n);o&&I(o,l=>l.dest===i.key);let d=this._inEdgeMap.get(i);return d&&(s=I(d,l=>l.src===n.key)[0]||void 0),s}deleteEdge(e,t){let n,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&&I(o,l=>l.src===i.key&&l.dest===(s==null?void 0:s.key));let d=this._inEdgeMap.get(s);d&&d.length>0&&(n=I(d,l=>l.src===i.key&&l.dest===s.key)[0])}return n}deleteVertex(e){let t,n;if(this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e)),n){let i=this.getNeighbors(n);for(let s of i)this.deleteEdgeSrcToDest(n,s);this._outEdgeMap.delete(n),this._inEdgeMap.delete(n)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let n=[];if(e&&t){let i=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);i&&n.push(i),s&&n.push(s)}return n}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=[],n=this.outgoingEdgesOf(e);for(let i of n){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 n=[],i=!1,s=o=>{t.set(o,1);let d=this.getDestinations(o);for(let l of d){let a=t.get(l);a===0?s(l):a===1&&(i=!0)}t.set(o,2),n.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!i)return e==="key"&&(n=n.map(o=>o instanceof q?o.key:o)),n.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let i=this.outgoingEdgesOf(n);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),n=this._getVertex(e.dest);if(t&&n)return[t,n]}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 u;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,n=new Map,i=0,s=[],o=new Set,d=l=>{e.set(l,i),t.set(l,i),i++,s.push(l),o.add(l);let a=this.getNeighbors(l);for(let f of a)e.has(f)?o.has(f)&&t.set(l,Math.min(t.get(l),e.get(f))):(d(f),t.set(l,Math.min(t.get(l),t.get(f))));if(e.get(l)===t.get(l)){let f=[],c;do c=s.pop(),o.delete(c),f.push(c);while(c!==l);n.set(n.size,f)}};for(let l of this.vertexMap.values())e.has(l)||d(l);return{dfnMap:e,lowMap:t,SCCs:n}}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),n=this._getVertex(e.dest);if(t&&n){let i=this._outEdgeMap.get(t);i?i.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(n);return s?s.push(e):this._inEdgeMap.set(n,[e]),!0}else return!1}};var pe=class extends R{constructor(r,e){super(r,e)}},ge=class extends P{constructor(e,t,n,i){super(n,i);h(this,"endpoints");this.endpoints=[e,t]}},De=class u extends U{constructor(){super();h(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}createVertex(e,t){return new pe(e,t!=null?t:e)}createEdge(e,t,n,i){return new ge(e,t,n!=null?n:1,i)}getEdge(e,t){var i;let n=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(n=(i=this._edgeMap.get(s))==null?void 0:i.filter(d=>d.endpoints.includes(o.key)))}return n&&n[0]||void 0}deleteEdgeBetween(e,t){let n=this._getVertex(e),i=this._getVertex(t);if(!n||!i)return;let s=this._edgeMap.get(n),o;s&&(o=I(s,l=>l.endpoints.includes(i.key))[0]||void 0);let d=this._edgeMap.get(i);return d&&I(d,l=>l.endpoints.includes(n.key)),o}deleteEdge(e,t){let n,i;if(this.isVertexKey(e))if(this.isVertexKey(t))n=this._getVertex(e),i=this._getVertex(t);else return;else n=this._getVertex(e.endpoints[0]),i=this._getVertex(e.endpoints[1]);if(n&&i)return this.deleteEdgeBetween(n,i)}deleteVertex(e){let t,n;this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e));let i=this.getNeighbors(e);return n&&(i.forEach(s=>{let o=this._edgeMap.get(s);if(o){let d=o.filter(l=>!l.endpoints.includes(t));this._edgeMap.set(s,d)}}),this._edgeMap.delete(n)),this._vertexMap.delete(t)}degreeOf(e){var n;let t=this._getVertex(e);return t&&((n=this._edgeMap.get(t))==null?void 0:n.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(n=>{e.add(n)})}),[...e]}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let i=this.edgesOf(n);for(let s of i){let o=this._getVertex(s.endpoints.filter(d=>d!==n.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]),n=this._getVertex(e.endpoints[1]);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){let e=new u;return e.vertexMap=new Map(this.vertexMap),e.edgeMap=new Map(this.edgeMap),e}tarjan(){let e=new Map,t=new Map,n=[],i=[],s=0,o=(d,l)=>{e.set(d,s),t.set(d,s),s++;let a=this.getNeighbors(d),f=0;for(let c of a)if(e.has(c))c!==l&&t.set(d,Math.min(t.get(d),e.get(c)));else{if(f++,o(c,d),t.set(d,Math.min(t.get(d),t.get(c))),t.get(c)>e.get(d)){let g=this.getEdge(d,c);g&&n.push(g)}l!==void 0&&t.get(c)>=e.get(d)&&i.push(d)}l===void 0&&f>1&&i.push(d)};for(let d of this.vertexMap.values())e.has(d)||o(d,void 0);return{dfnMap:e,lowMap:t,bridges:n,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 n=this._getVertex(t);if(n===void 0)return!1;if(n){let i=this._edgeMap.get(n);i?i.push(e):this._edgeMap.set(n,[e])}}return!0}};var me=class extends q{constructor(e,t,n,i){super(e,t);h(this,"lat");h(this,"long");this.lat=n,this.long=i}},_e=class extends ${constructor(r,e,t,n){super(r,e,t,n)}},Pe=class u extends oe{constructor(e,t){super();h(this,"_originCoord",[0,0]);h(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,n=this.originCoord[0],i=this.originCoord[1]){return new me(e,t,n,i)}createEdge(e,t,n,i){return new _e(e,t,n,i)}clone(){let e=new u(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 He=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(He||{}),H=class{constructor(r,e,t=!0,n=!0){this.low=r;this.high=e;this.includeLow=t;this.includeHigh=n;if(!(w(r)&&w(e)))throw new RangeError("low or high is not comparable");if(r>e)throw new RangeError("low must be less than or equal to high")}isInRange(r,e){let t=this.includeLow?e(r,this.low)>=0:e(r,this.low)>0,n=this.includeHigh?e(r,this.high)<=0:e(r,this.high)<0;return t&&n}};var j=class{constructor(r,e){h(this,"key");h(this,"value");h(this,"parent");h(this,"_left");h(this,"_right");h(this,"_height",0);h(this,"_color","BLACK");h(this,"_count",1);this.key=r,this.value=e}get left(){return this._left}set left(r){r&&(r.parent=this),this._left=r}get right(){return this._right}set right(r){r&&(r.parent=this),this._right=r}get height(){return this._height}set height(r){this._height=r}get color(){return this._color}set color(r){this._color=r}get count(){return this._count}set count(r){this._count=r}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},de=class u extends C{constructor(e=[],t){super();h(this,"iterationType","ITERATIVE");h(this,"_isMapMode",!0);h(this,"_isDuplicate",!1);h(this,"_store",new Map);h(this,"_root");h(this,"_size",0);h(this,"_NIL",new j(NaN));h(this,"_toEntryFn");h(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:i,isMapMode:s,isDuplicate:o}=t;if(n&&(this.iterationType=n),s!==void 0&&(this._isMapMode=s),o!==void 0&&(this._isDuplicate=o),typeof i=="function")this._toEntryFn=i;else if(i)throw TypeError("toEntryFn must be a function type")}e&&this.addMany(e)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}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 j(e,this._isMapMode?void 0:t)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,toEntryFn:this._toEntryFn},e))}ensureNode(e,t=this.iterationType){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e;if(this.isEntry(e)){let n=e[0];return n===null?null:n===void 0?void 0:this.getNode(n,this._root,t)}return this.getNode(e,this._root,t)}}isNode(e){return e instanceof j}isRaw(e){return this._toEntryFn!==void 0&&typeof e=="object"}isRealNode(e){return e===this._NIL||e===null||e===void 0?!1:this.isNode(e)}isRealNodeOrNull(e){return e===null||this.isRealNode(e)}isNIL(e){return e===this._NIL}isRange(e){return e instanceof H}isLeaf(e){return e=this.ensureNode(e),e===void 0?!1:e===null?!0:!this.isRealNode(e.left)&&!this.isRealNode(e.right)}isEntry(e){return Array.isArray(e)&&e.length===2}isValidKey(e){return e===null?!0:w(e)}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size=1,!0;let s=new k([this._root]),o;for(;s.length>0;){let d=s.shift();if(d){if(!this._isDuplicate&&n!==null&&d.key===n.key)return this._replaceNode(d,n),this._isMapMode&&this._setValue(d.key,i),!0;o===void 0&&(d.left===void 0||d.right===void 0)&&(o=d),d.left!==null&&d.left&&s.push(d.left),d.right!==null&&d.right&&s.push(d.right)}}return o?(o.left===void 0?o.left=n:o.right===void 0&&(o.right=n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0):!1}addMany(e,t){let n=[],i;t&&(i=t[Symbol.iterator]());for(let s of e){let o;if(i){let d=i.next();d.done||(o=d.value)}this.isRaw(s)&&(s=this._toEntryFn(s)),n.push(this.add(s,o))}return n}merge(e){this.addMany(e,[])}refill(e,t){this.clear(),this.addMany(e,t)}delete(e){let t=[];if(!this._root)return t;let n=this.getNode(e);if(!n)return t;let i=n==null?void 0:n.parent,s,o=n;if(!n.left&&!n.right&&!i)this._setRoot(void 0);else if(n.left){let d=this.getRightMost(l=>l,n.left);if(d){let l=d.parent;o=this._swapProperties(n,d),l&&(l.right===d?l.right=d.left:l.left=d.left,s=l)}}else if(i){let{familyPosition:d}=n;d==="LEFT"||d==="ROOT_LEFT"?i.left=n.right:(d==="RIGHT"||d==="ROOT_RIGHT")&&(i.right=n.right),s=i}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:o,needBalanced:s}),this._isMapMode&&o&&this._store.delete(o.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let o=this._ensurePredicate(e),d=[];if(s==="RECURSIVE"){let l=a=>{o(a)&&(d.push(n(a)),t)||!this.isRealNode(a.left)&&!this.isRealNode(a.right)||(this.isRealNode(a.left)&&l(a.left),this.isRealNode(a.right)&&l(a.right))};l(i)}else{let l=[i];for(;l.length>0;){let a=l.pop();if(this.isRealNode(a)){if(o(a)&&(d.push(n(a)),t))return d;this.isRealNode(a.left)&&l.push(a.left),this.isRealNode(a.right)&&l.push(a.right)}}}return d}getNodes(e,t=!1,n=this._root,i=this.iterationType){return this.search(e,t,s=>s,n,i)}getNode(e,t=this._root,n=this.iterationType){return this.search(e,!0,i=>i,t,n)[0]}get(e,t=this._root,n=this.iterationType){var i;if(this._isMapMode){let s=this._extractKey(e);return s==null?void 0:this._store.get(s)}return(i=this.getNode(e,t,n))==null?void 0:i.value}has(e,t=this._root,n=this.iterationType){return this.search(e,!0,i=>i,t,n).length>0}clear(){this._clearNodes(),this._isMapMode&&this._clearValues()}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 n=(o,d,l)=>{if(!this.isRealNode(o))return!0;let a=Number(o.key);return a<=d||a>=l?!1:n(o.left,d,a)&&n(o.right,a,l)},i=n(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=n(e,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return i||s}else{let n=(o=!1)=>{let d=[],l=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,a=e;for(;this.isRealNode(a)||d.length>0;){for(;this.isRealNode(a);)d.push(a),a=a.left;a=d.pop();let f=Number(a.key);if(!this.isRealNode(a)||!o&&l>=f||o&&l<=f)return!1;l=f,a=a.right}return!0},i=n(!1),s=n(!0);return i||s}}getDepth(e,t=this._root){let n=this.ensureNode(e),i=this.ensureNode(t),s=0;for(;n!=null&&n.parent;){if(n===i)return s;s++,n=n.parent}return s}getHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i))return-1;let s=n(i.left),o=n(i.right);return Math.max(s,o)+1};return n(e)}else{let n=[{node:e,depth:0}],i=0;for(;n.length>0;){let{node:s,depth:o}=n.pop();this.isRealNode(s.left)&&n.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&n.push({node:s.right,depth:o+1}),i=Math.max(i,o)}return i}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i)||!this.isRealNode(i.left)&&!this.isRealNode(i.right))return 0;let s=n(i.left),o=n(i.right);return Math.min(s,o)+1};return n(e)}else{let n=[],i=e,s=null,o=new Map;for(;n.length>0||i;)if(this.isRealNode(i))n.push(i),i=i.left;else if(i=n[n.length-1],!this.isRealNode(i.right)||s===i.right){if(i=n.pop(),this.isRealNode(i)){let d=this.isRealNode(i.left)?o.get(i.left):-1,l=this.isRealNode(i.right)?o.get(i.right):-1;o.set(i,1+Math.min(d,l)),s=i,i=null}}else i=i.right;return o.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let i=[],s=this.ensureNode(e);if(!s)return i;for(;s.parent;)i.push(t(s)),s=s.parent;return i.push(t(s)),n?i.reverse():i}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!this.isRealNode(t))return e(t);if(n==="RECURSIVE"){let i=s=>this.isRealNode(s.left)?i(s.left):s;return e(i(t))}else{let i=he(s=>this.isRealNode(s.left)?i.cont(s.left):s);return e(i(t))}}getRightMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!t)return e(t);if(n==="RECURSIVE"){let i=s=>this.isRealNode(s.right)?i(s.right):s;return e(i(t))}else{let i=he(s=>this.isRealNode(s.right)?i.cont(s.right):s);return e(i(t))}}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(n=>n,e.right);let t=e.parent;for(;this.isRealNode(t)&&e===t.right;)e=t,t=t.parent;return t}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType,o=!1){return i=this.ensureNode(i),i?this._dfs(e,t,n,i,s,o):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(n==="RECURSIVE"){let o=new k([t]),d=l=>{if(o.length===0)return;let a=o.shift();s.push(e(a)),i?(a&&this.isRealNodeOrNull(a.left)&&o.push(a.left),a&&this.isRealNodeOrNull(a.right)&&o.push(a.right)):(this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right)),d(l+1)};d(0)}else{let o=new k([t]);for(;o.length>0;){let d=o.length;for(let l=0;l<d;l++){let a=o.shift();s.push(e(a)),i?(a&&this.isRealNodeOrNull(a.left)&&o.push(a.left),a&&this.isRealNodeOrNull(a.right)&&o.push(a.right)):(this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right))}}}return s}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){t=this.ensureNode(t);let i=[];if(!this.isRealNode(t))return[];if(n==="RECURSIVE"){let s=o=>{this.isLeaf(o)&&i.push(e(o)),!(!this.isRealNode(o.left)&&!this.isRealNode(o.right))&&(this.isRealNode(o.left)&&s(o.left),this.isRealNode(o.right)&&s(o.right))};s(t)}else{let s=new k([t]);for(;s.length>0;){let o=s.shift();this.isRealNode(o)&&(this.isLeaf(o)&&i.push(e(o)),this.isRealNode(o.left)&&s.push(o.left),this.isRealNode(o.right)&&s.push(o.right))}}return i}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(n==="RECURSIVE"){let o=(d,l)=>{s[l]||(s[l]=[]),s[l].push(e(d)),i?(d&&this.isRealNodeOrNull(d.left)&&o(d.left,l+1),d&&this.isRealNodeOrNull(d.right)&&o(d.right,l+1)):(d&&d.left&&o(d.left,l+1),d&&d.right&&o(d.right,l+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let d=o.pop(),[l,a]=d;s[a]||(s[a]=[]),s[a].push(e(l)),i?(l&&this.isRealNodeOrNull(l.right)&&o.push([l.right,a+1]),l&&this.isRealNodeOrNull(l.left)&&o.push([l.left,a+1])):(l&&l.right&&o.push([l.right,a+1]),l&&l.left&&o.push([l.left,a+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let i=[],s=n,o=l=>{let a=null,f=null;for(;l;)f=l.right,l.right=a,a=l,l=f;return a},d=l=>{let a=o(l),f=a;for(;f;)i.push(e(f)),f=f.right;o(a)};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,d(s.left)}s=s.right}d(n);break}return i}clone(){let e=this.createTree();return this._clone(e),e}filter(e,t){let n=this.createTree(),i=0;for(let[s,o]of this)e.call(t,s,o,i++,this)&&n.add([s,o]);return n}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}toVisual(e=this._root,t){let n=T({isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1},t);e=this.ensureNode(e);let i="";return e&&(n.isShowUndefined&&(i+=`U for undefined
1
+ "use strict";var dataStructureTyped=(()=>{var ae=Object.defineProperty,it=Object.defineProperties,rt=Object.getOwnPropertyDescriptor,st=Object.getOwnPropertyDescriptors,ot=Object.getOwnPropertyNames,Ye=Object.getOwnPropertySymbols;var Ze=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var Ee=(u,r)=>(r=Symbol[u])?r:Symbol.for("Symbol."+u),lt=u=>{throw TypeError(u)};var Ke=(u,r,e)=>r in u?ae(u,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[r]=e,T=(u,r)=>{for(var e in r||(r={}))Ze.call(r,e)&&Ke(u,e,r[e]);if(Ye)for(var e of Ye(r))dt.call(r,e)&&Ke(u,e,r[e]);return u},$e=(u,r)=>it(u,st(r));var ut=(u,r)=>{for(var e in r)ae(u,e,{get:r[e],enumerable:!0})},at=(u,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of ot(r))!Ze.call(u,n)&&n!==e&&ae(u,n,{get:()=>r[n],enumerable:!(t=rt(r,n))||t.enumerable});return u};var ht=u=>at(ae({},"__esModule",{value:!0}),u);var h=(u,r,e)=>Ke(u,typeof r!="symbol"?r+"":r,e);var ft=function(u,r){this[0]=u,this[1]=r};var B=u=>{var r=u[Ee("asyncIterator")],e=!1,t,n={};return r==null?(r=u[Ee("iterator")](),t=i=>n[i]=s=>r[i](s)):(r=r.call(u),t=i=>n[i]=s=>{if(e){if(e=!1,i==="throw")throw s;return s}return e=!0,{done:!1,value:new ft(new Promise(o=>{var d=r[i](s);d instanceof Object||lt("Object expected"),o(d)}),1)}}),n[Ee("iterator")]=()=>n,t("next"),"throw"in r?t("throw"):n.throw=i=>{throw i},"return"in r&&t("return"),n};var mt={};ut(mt,{AVLTree:()=>Q,AVLTreeCounter:()=>Ue,AVLTreeCounterNode:()=>ue,AVLTreeMultiMap:()=>He,AVLTreeMultiMapNode:()=>Ve,AVLTreeNode:()=>F,AbstractEdge:()=>P,AbstractGraph:()=>U,AbstractVertex:()=>R,BST:()=>G,BSTNode:()=>S,BinaryIndexedTree:()=>De,BinaryTree:()=>de,BinaryTreeNode:()=>j,Character:()=>ye,DFSOperation:()=>Ae,Deque:()=>Ce,DirectedEdge:()=>$,DirectedGraph:()=>oe,DirectedVertex:()=>q,DoublyLinkedList:()=>ke,DoublyLinkedListNode:()=>re,FibonacciHeap:()=>Oe,FibonacciHeapNode:()=>ce,HashMap:()=>xe,Heap:()=>v,IterableElementBase:()=>L,IterableEntryBase:()=>C,LinkedHashMap:()=>Re,LinkedListQueue:()=>Be,MapEdge:()=>_e,MapGraph:()=>Fe,MapVertex:()=>me,Matrix:()=>Qe,MaxHeap:()=>we,MaxPriorityQueue:()=>Ge,MinHeap:()=>Ie,MinPriorityQueue:()=>qe,Navigator:()=>We,PriorityQueue:()=>X,Queue:()=>k,Range:()=>H,RedBlackTree:()=>W,RedBlackTreeNode:()=>A,SegmentTree:()=>Pe,SegmentTreeNode:()=>ee,SinglyLinkedList:()=>ie,SinglyLinkedListNode:()=>ne,SkipList:()=>Le,SkipListNode:()=>se,Stack:()=>ve,TreeCounter:()=>ze,TreeCounterNode:()=>le,TreeMultiMap:()=>je,TreeMultiMapNode:()=>be,TreeNode:()=>Je,Trie:()=>Xe,TrieNode:()=>te,UndirectedEdge:()=>ge,UndirectedGraph:()=>Se,UndirectedVertex:()=>pe,arrayRemove:()=>I,calcMinUnitsRequired:()=>fe,getMSB:()=>Te,isComparable:()=>w,isThunk:()=>et,isWeakKey:()=>J,rangeCheck:()=>O,roundFixed:()=>pt,throwRangeError:()=>ct,toBinaryString:()=>gt,trampoline:()=>he,uuidV4:()=>Me});var C=class{*[Symbol.iterator](...r){yield*B(this._getIterator(...r))}*entries(){for(let r of this)yield r}*keys(){for(let r of this)yield r[0]}*values(){for(let r of this)yield r[1]}every(r,e){let t=0;for(let n of this)if(!r.call(e,n[0],n[1],t++,this))return!1;return!0}some(r,e){let t=0;for(let n of this)if(r.call(e,n[0],n[1],t++,this))return!0;return!1}forEach(r,e){let t=0;for(let n of this){let[i,s]=n;r.call(e,i,s,t++,this)}}find(r,e){let t=0;for(let n of this){let[i,s]=n;if(r.call(e,i,s,t++,this))return n}}has(r){for(let e of this){let[t]=e;if(t===r)return!0}return!1}hasValue(r){for(let[,e]of this)if(e===r)return!0;return!1}get(r){for(let e of this){let[t,n]=e;if(t===r)return n}}reduce(r,e){let t=e,n=0;for(let i of this){let[s,o]=i;t=r(t,o,s,n++,this)}return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var L=class{constructor(r){h(this,"_toElementFn");if(r){let{toElementFn:e}=r;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](...r){yield*B(this._getIterator(...r))}*values(){for(let r of this)yield r}every(r,e){let t=0;for(let n of this)if(!r.call(e,n,t++,this))return!1;return!0}some(r,e){let t=0;for(let n of this)if(r.call(e,n,t++,this))return!0;return!1}forEach(r,e){let t=0;for(let n of this)r.call(e,n,t++,this)}find(r,e){let t=0;for(let n of this)if(r.call(e,n,t++,this))return n}has(r){for(let e of this)if(e===r)return!0;return!1}reduce(r,e){let t=e!=null?e:0,n=0;for(let i of this)t=r(t,i,n++,this);return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var Me=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(u){let r=Math.random()*16|0;return(u=="x"?r:r&3|8).toString(16)})},I=function(u,r){let e=-1,t=u?u.length:0,n=[];for(;++e<t;){let i=u[e];r(i,e,u)&&(n.push(i),Array.prototype.splice.call(u,e--,1),t--)}return n};function et(u){return typeof u=="function"}function he(u){let r=u;for(;et(r);)r=r();return r}var Te=u=>u<=0?0:1<<31-Math.clz32(u),O=(u,r,e,t="Index out of bounds.")=>{if(u<r||u>e)throw new RangeError(t)},ct=(u="The value is off-limits.")=>{throw new RangeError(u)},J=u=>{let r=typeof u;return r==="object"&&u!==null||r==="function"},fe=(u,r)=>Math.floor((u+r-1)/r),pt=(u,r=10)=>{let e=Math.pow(10,r);return Math.round(u*e)/e};function Ne(u){let r=typeof u;return r==="number"?!0:r==="bigint"||r==="string"||r==="boolean"}function tt(u){if(typeof u.valueOf=="function"){let r=u.valueOf();if(r!==u){if(Ne(r))return r;if(typeof r=="object"&&r!==null)return tt(r)}}if(typeof u.toString=="function"){let r=u.toString();if(r!=="[object Object]")return r}return null}function w(u,r=!1){if(u==null)return!1;if(Ne(u))return!0;if(typeof u!="object")return!1;if(u instanceof Date||r)return!0;let e=tt(u);return e==null?!1:Ne(e)}function gt(u,r=32){let e=(u>>>0).toString(2);return e=e.padStart(r,"0"),e}var xe=class u extends C{constructor(e=[],t){super();h(this,"_store",{});h(this,"_objMap",new Map);h(this,"_toEntryFn");h(this,"_size",0);h(this,"_hashFn",e=>String(e));if(t){let{hashFn:n,toEntryFn:i}=t;n&&(this._hashFn=n),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 n=this._getNoObjKey(e);this.store[n]===void 0&&this._size++,this._store[n]={key:e,value:t}}return!0}setMany(e){let t=[];for(let n of e){let i,s;if(this.isEntry(n))i=n[0],s=n[1];else if(this._toEntryFn){let o=this._toEntryFn(n);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 n=this._getNoObjKey(e);return(t=this._store[n])==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 u(this,{hashFn:this._hashFn,toEntryFn:this._toEntryFn})}map(e,t){let n=new u,i=0;for(let[s,o]of this)n.set(s,e.call(t,s,o,i++,this));return n}filter(e,t){let n=new u,i=0;for(let[s,o]of this)e.call(t,s,o,i++,this)&&n.set(s,o);return n}*_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,n;return t!=="string"&&t!=="number"&&t!=="symbol"?n=this._hashFn(e):n=e,n}},Re=class u extends C{constructor(e=[],t){super();h(this,"_sentinel");h(this,"_hashFn",e=>String(e));h(this,"_objHashFn",e=>e);h(this,"_noObjMap",{});h(this,"_objMap",new WeakMap);h(this,"_head");h(this,"_tail");h(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.")});h(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:n,objHashFn:i,toEntryFn:s}=t;n&&(this._hashFn=n),i&&(this._objHashFn=i),s&&(this._toEntryFn=s)}e&&this.setMany(e)}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 n,i=!this.has(e);if(J(e)){let s=this._objHashFn(e);n=this.objMap.get(s),!n&&i?(n={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,n)):n&&(n.value=t)}else{let s=this._hashFn(e);n=this.noObjMap[s],!n&&i?this.noObjMap[s]=n={key:e,value:t,prev:this.tail,next:this._sentinel}:n&&(n.value=t)}return n&&i&&(this._size===0?(this._head=n,this._sentinel.next=n):(this.tail.next=n,n.prev=this.tail),this._tail=n,this._sentinel.prev=n,this._size++),!0}setMany(e){let t=[];for(let n of e){let i,s;if(this.isEntry(n))i=n[0],s=n[1];else if(this._toEntryFn){let o=this._toEntryFn(n);i=o[0],s=o[1]}i!==void 0&&s!==void 0&&t.push(this.set(i,s))}return t}has(e){if(J(e)){let t=this._objHashFn(e);return this.objMap.has(t)}else return this._hashFn(e)in this.noObjMap}get(e){if(J(e)){let t=this._objHashFn(e),n=this.objMap.get(t);return n?n.value:void 0}else{let t=this._hashFn(e),n=this.noObjMap[t];return n?n.value:void 0}}at(e){O(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(J(e)){let n=this._objHashFn(e);if(t=this.objMap.get(n),!t)return!1;this.objMap.delete(n)}else{let n=this._hashFn(e);if(t=this.noObjMap[n],!t)return!1;delete this.noObjMap[n]}return this._deleteNode(t),!0}deleteAt(e){O(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 u([],{hashFn:this._hashFn,objHashFn:this._objHashFn});for(let t of this){let[n,i]=t;e.set(n,i)}return e}filter(e,t){let n=new u,i=0;for(let[s,o]of this)e.call(t,s,o,i,this)&&n.set(s,o),i++;return n}map(e,t){let n=new u,i=0;for(let[s,o]of this){let[d,l]=e.call(t,s,o,i,this);n.set(d,l),i++}return n}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:n}=e;return t.next=n,n.prev=t,e===this.head&&(this._head=n),e===this.tail&&(this._tail=t),this._size-=1,!0}};var Y=class{constructor(r){h(this,"_value");h(this,"_next");this._value=r,this._next=void 0}get value(){return this._value}set value(r){this._value=r}get next(){return this._next}set next(r){this._next=r}},D=class u extends L{constructor(e){super(e);h(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let i=this.at(n);if(i!==void 0&&e.call(t,i,n,this))return n}return-1}concat(...e){let t=this.clone();for(let n of e)n instanceof u?t.pushMany(n):t.push(n);return t}sort(e){let t=this.toArray();t.sort(e),this.clear();for(let n of t)this.push(n);return this}splice(e,t=0,...n){let i=this._createInstance();e=e<0?this.length+e:e,e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));for(let s=0;s<t;s++){let o=this.deleteAt(e);o!==void 0&&i.push(o)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);return i}join(e=","){return this.toArray().join(e)}toReversedArray(){let e=[];for(let t=this.length-1;t>=0;t--)e.push(this.at(t));return e}reduceRight(e,t){let n=t!=null?t:0;for(let i=this.length-1;i>=0;i--)n=e(n,this.at(i),i,this);return n}slice(e=0,t=this.length){e=e<0?this.length+e:e,t=t<0?this.length+t:t;let n=this._createInstance();for(let i=e;i<t;i++)n.push(this.at(i));return n}fill(e,t=0,n=this.length){if(t=t<0?this.length+t:t,n=n<0?this.length+n:n,t<0&&(t=0),n>this.length&&(n=this.length),t>=n)return this;for(let i=t;i<n;i++)this.setAt(i,e);return this}},Z=class extends D{constructor(r){if(super(r),r){let{maxLen:e}=r;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(r,e=0){let t=this._getIterator(),n=t.next(),i=0;for(;i<e;)n=t.next(),i++;for(;!n.done;){if(n.value===r)return i;n=t.next(),i++}return-1}lastIndexOf(r,e=this.length-1){let t=this._getReverseIterator(),n=t.next(),i=this.length-1;for(;i>e;)n=t.next(),i--;for(;!n.done;){if(n.value===r)return i;n=t.next(),i--}return-1}concat(...r){let e=this.clone();for(let t of r)t instanceof D?e.pushMany(t):e.push(t);return e}slice(r=0,e=this.length){r=r<0?this.length+r:r,e=e<0?this.length+e:e;let t=this._createInstance(),n=this._getIterator(),i=n.next(),s=0;for(;s<r;)i=n.next(),s++;for(let o=r;o<e;o++)t.push(i.value),i=n.next();return t}splice(r,e=0,...t){let n=this._createInstance();r=r<0?this.length+r:r,r=Math.max(0,Math.min(r,this.length)),e=Math.max(0,e);let i=0,s,o,d=this._getNodeIterator();for(let l of d){if(i===r){s=l;break}o=l,i++}for(let l=0;l<e&&s;l++){n.push(s.value);let a=s.next;this.delete(s),s=a}for(let l=0;l<t.length;l++)o?(this.addAfter(o,t[l]),o=o.next):(this.addAt(0,t[l]),o=this._getNodeIterator().next().value);return n}reduceRight(r,e){let t=e!=null?e:0,n=this.length-1;for(let i of this._getReverseIterator())t=r(t,i,n--,this);return t}};var ne=class extends Y{constructor(e){super(e);h(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},ie=class u extends Z{constructor(e=[],t){super(t);h(this,"_head");h(this,"_tail");h(this,"_length",0);this.pushMany(e)}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 length(){return this._length}static fromArray(e){let t=new u;for(let n of e)t.push(n);return t}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.head)return;if(this.head===this.tail){let n=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,n}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._length--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._length++,!0}pushMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.push(this.toElementFn(n)));continue}t.push(this.push(n))}return t}unshiftMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.unshift(this.toElementFn(n)));continue}t.push(this.unshift(n))}return t}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}isNode(e){return e instanceof ne}getNodeAt(e){let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._length)return;let t;if(e===0)return t=this.first,this.shift(),t;let n=this.getNodeAt(e),i=this._getPrevNode(n);if(i&&n)return t=n.value,i.next=n.next,n===this.tail&&(this._tail=i),this._length--,t}delete(e){if(e===void 0||!this.head)return!1;let t=this.isNode(e)?e:this.getNode(e);if(!t)return!1;let n=this._getPrevNode(t);return n?(n.next=t.next,t===this.tail&&(this._tail=n)):(this._head=t.next,t===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t),!0;if(e===this._length)return this.push(t),!0;let n=this._ensureNode(t),i=this.getNodeAt(e-1);return n.next=i.next,i.next=n,this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,n;for(;t;)n=t.next,t.next=e,e=t,t=n;return[this._head,this._tail]=[this.tail,this.head],this}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addBefore(e,t){let n=this.getNode(e);if(!n)return!1;let i=this._getPrevNode(n),s=this._ensureNode(t);return i?(i.next=s,s.next=n,this._length++):this.unshift(s),!0}addAfter(e,t){let n=this.getNode(e);if(n){let i=this._ensureNode(t);return i.next=n.next,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}return!1}splice(e,t=0,...n){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,t);let s=e===0?void 0:this.getNodeAt(e-1),d=s?s.next:this.head;for(let f=0;f<t&&d;f++)i.push(d.value),d=d.next;let l=d,a;for(let f of n){let c=this._ensureNode(f);a?a.next=c:s?s.next=c:this._head=c,a=c}return a?a.next=l:s&&(s.next=l),l||(this._tail=a||s),this._length+=n.length-i.length,i}countOccurrences(e){let t=this._ensurePredicate(e),n=0,i=this.head;for(;i;)t(i)&&n++,i=i.next;return n}clone(){return new u(this,{toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}_createInstance(e){return new u([],e)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=[...this].reverse();for(let t of e)yield t}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new ne(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}_getPrevNode(e){if(!this.head||this.head===e)return;let t=this.head;for(;t.next&&t.next!==e;)t=t.next;return t.next===e?t:void 0}};var re=class extends Y{constructor(e){super(e);h(this,"_next");h(this,"_prev");this._value=e,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(e){this._next=e}get prev(){return this._prev}set prev(e){this._prev=e}},ke=class u extends Z{constructor(e=[],t){super(t);h(this,"_head");h(this,"_tail");h(this,"_length");if(this._head=void 0,this._tail=void 0,this._length=0,t){let{maxLen:n}=t;typeof n=="number"&&n>0&&n%1===0&&(this._maxLen=n)}this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}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 u(e)}isNode(e){return e instanceof re}push(e){let t=this._ensureNode(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!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._length--,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._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.push(this.toElementFn(n)));continue}t.push(this.push(n))}return t}unshiftMany(e){let t=[];for(let n of e){if(this.toElementFn){t.push(this.unshift(this.toElementFn(n)));continue}t.push(this.unshift(n))}return t}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t),!0;if(e===this._length)return this.push(t),!0;let n=this._ensureNode(t),i=this.getNodeAt(e-1),s=i.next;return n.prev=i,n.next=s,i.next=n,s.prev=n,this._length++,!0}addBefore(e,t){let n=this.isNode(e)?e:this.getNode(e);if(n){let i=this._ensureNode(t);return i.prev=n.prev,n.prev&&(n.prev.next=i),i.next=n,n.prev=i,n===this.head&&(this._head=i),this._length++,!0}return!1}addAfter(e,t){let n=this.isNode(e)?e:this.getNode(e);if(n){let i=this._ensureNode(t);return i.next=n.next,n.next&&(n.next.prev=i),i.prev=n,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}return!1}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}deleteAt(e){if(e<0||e>=this._length)return;let t;if(e===0)return t=this.first,this.shift(),t;if(e===this._length-1)return t=this.last,this.pop(),t;let n=this.getNodeAt(e),i=n.prev,s=n.next;return i.next=s,s.prev=i,this._length--,n==null?void 0:n.value}delete(e){let t=this.getNode(e);if(t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let n=t.prev,i=t.next;n&&(n.next=i),i&&(i.prev=n),this._length--}return!0}return!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}getBackward(e){let t=this._ensurePredicate(e),n=this.tail;for(;n;){if(t(n))return n.value;n=n.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}clone(){return new u(this,{toElementFn:this._toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}countOccurrences(e){let t=this._ensurePredicate(e),n=0,i=this.head;for(;i;)t(i)&&n++,i=i.next;return n}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=this.tail;for(;e;)yield e.value,e=e.prev}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new re(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}_createInstance(e){return new u([],e)}_getPrevNode(e){return e.prev}};var se=class{constructor(r,e,t){h(this,"key");h(this,"value");h(this,"forward");this.key=r,this.value=e,this.forward=new Array(t)}},Le=class{constructor(r=[],e){h(this,"_head",new se(void 0,void 0,this.maxLevel));h(this,"_level",0);h(this,"_maxLevel",16);h(this,"_probability",.5);if(e){let{maxLevel:t,probability:n}=e;typeof t=="number"&&(this._maxLevel=t),typeof n=="number"&&(this._probability=n)}if(r)for(let[t,n]of r)this.add(t,n)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let r=this.head.forward[0];return r?r.value:void 0}get last(){let r=this.head;for(let e=this.level-1;e>=0;e--)for(;r.forward[e];)r=r.forward[e];return r.value}add(r,e){let t=new se(r,e,this._randomLevel()),n=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<r;)i=i.forward[s];n[s]=i}for(let s=0;s<t.forward.length;s++)t.forward[s]=n[s].forward[s],n[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(r){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<r;)e=e.forward[t];if(e=e.forward[0],e&&e.key===r)return e.value}has(r){return this.get(r)!==void 0}delete(r){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<r;)t=t.forward[n];e[n]=t}if(t=t.forward[0],t&&t.key===r){for(let n=0;n<this.level&&e[n].forward[n]===t;n++)e[n].forward[n]=t.forward[n];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(r){let e=this.head;for(let n=this.level-1;n>=0;n--)for(;e.forward[n]&&e.forward[n].key<=r;)e=e.forward[n];let t=e.forward[0];return t?t.value:void 0}lower(r){let e=this.head,t;for(let n=this.level-1;n>=0;n--){for(;e.forward[n]&&e.forward[n].key<r;)e=e.forward[n];e.key<r&&(t=e)}return t?t.value:void 0}_randomLevel(){let r=1;for(;Math.random()<this.probability&&r<this.maxLevel;)r++;return r}};var ve=class u extends L{constructor(e=[],t){super(t);h(this,"_elements",[]);this.pushMany(e)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e){return new u(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()}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}clear(){this._elements=[]}clone(){return new u(this,{toElementFn:this.toElementFn})}filter(e,t){let n=new u([],{toElementFn:this.toElementFn}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var k=class u extends D{constructor(e=[],t){super(t);h(this,"_elements",[]);h(this,"_offset",0);h(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get length(){return this.elements.length-this.offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get first(){return this.length>0?this.elements[this.offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new u(e)}push(e){return this.elements.push(e),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}shift(){if(this.length===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){let t=this.elements[e];return this.elements.splice(e,1),t}at(e){return this.elements[e+this._offset]}reverse(){return this._elements=this.elements.slice(this.offset).reverse(),this._offset=0,this}addAt(e,t){return e<0||e>this.length?!1:(this._elements.splice(this.offset+e,0,t),!0)}setAt(e,t){return e<0||e>this.length?!1:(this._elements[this.offset+e]=t,!0)}isEmpty(){return this.length===0}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this.offset),this._offset=0,!0}splice(e,t=0,...n){let i=this._createInstance();e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));let s=this.offset+e,o=this._elements.splice(s,t,...n);return i.pushMany(o),this.compact(),i}clone(){return new u(this.elements.slice(this.offset),{toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this._toElementFn,autoCompactRatio:this._autoCompactRatio,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,autoCompactRatio:this._autoCompactRatio,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}*_getIterator(){for(let e of this.elements.slice(this.offset))yield e}_createInstance(e){return new u([],e)}*_getReverseIterator(){for(let e=this.length-1;e>=0;e--){let t=this.at(e);t!==void 0&&(yield t)}}},Be=class u extends ie{clone(){return new u(this,{toElementFn:this.toElementFn,maxLen:this._maxLen})}};var Ce=class u extends D{constructor(e=[],t){super(t);h(this,"_bucketSize",4096);h(this,"_bucketFirst",0);h(this,"_firstInBucket",0);h(this,"_bucketLast",0);h(this,"_lastInBucket",0);h(this,"_bucketCount",0);h(this,"_buckets",[]);h(this,"_length",0);if(t){let{bucketSize:s}=t;typeof s=="number"&&(this._bucketSize=s)}let n;"length"in e?e.length instanceof Function?n=e.length():n=e.length:e.size instanceof Function?n=e.size():n=e.size,this._bucketCount=fe(n,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let i=fe(n,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(i>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-n%this._bucketSize>>1,this.pushMany(e)}get bucketSize(){return this._bucketSize}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 length(){return this._length}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}push(e){return this._length&&(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._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==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._length-=1,e}shift(){if(this._length===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==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._length-=1,e}unshift(e){return this._length&&(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._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e=[]){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(e){O(e,0,this._length-1);let{bucketIndex:t,indexInBucket:n}=this._getBucketAndPosition(e);return this._buckets[t][n]}setAt(e,t){O(e,0,this._length-1);let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[n][i]=t,!0}addAt(e,t,n=1){let i=this._length;if(O(e,0,i),e===0)for(;n--;)this.unshift(t);else if(e===this._length)for(;n--;)this.push(t);else{let s=[];for(let o=e;o<this._length;++o)s.push(this.at(o));this.cut(e-1,!0);for(let o=0;o<n;++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:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketLast=n,this._lastInBucket=i,this._length=e+1,this}else{let n=this._createInstance({bucketSize:this._bucketSize,toElementFn:this._toElementFn,maxLen:this._maxLen});for(let i=0;i<=e;i++)n.push(this.at(i));return n}}splice(e,t=this._length-e,...n){O(e,0,this._length),t<0&&(t=0),e+t>this._length&&(t=this._length-e);let i=this._createInstance();for(let o=0;o<t;o++)i.push(this.at(e+o));let s=[];for(let o=e+t;o<this._length;o++)s.push(this.at(o));this.cut(e-1,!0);for(let o of n)this.push(o);for(let o of s)this.push(o);return i}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketFirst=n,this._firstInBucket=i,this._length=this._length-e,this}else{let n=this._createInstance({bucketSize:this._bucketSize,toElementFn:this._toElementFn,maxLen:this._maxLen});e<0&&(e=0);for(let i=e;i<this._length;i++)n.push(this.at(i));return n}}deleteAt(e){O(e,0,this._length-1);let t;if(e===0)return this.shift();if(e===this._length-1)return t=this.last,this.pop(),t;{let n=this._length-1,{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(e);t=this._buckets[i][s];for(let o=e;o<n;o++){let{bucketIndex:d,indexInBucket:l}=this._getBucketAndPosition(o),{bucketIndex:a,indexInBucket:f}=this._getBucketAndPosition(o+1);this._buckets[d][l]=this._buckets[a][f]}return this.pop(),t}}delete(e){let t=this._length;if(t===0)return!1;let n=0,i=0;for(;n<t;){let s=this.at(n);s!==e&&(this.setAt(i,s),i+=1),n+=1}return this.cut(i-1,!0),!0}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:n,_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-n-1,this}unique(){if(this._length<=1)return this;let e=1,t=this.at(0);for(let n=1;n<this._length;++n){let i=this.at(n);i!==t&&(t=i,this.setAt(e++,i))}return this.cut(e-1,!0),this}shrinkToFit(){if(this._length===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}}clone(){return new u(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({bucketSize:this._bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen}),i=0;for(let s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){let i=new u([],{bucketSize:this._bucketSize,toElementFn:t,maxLen:this._maxLen}),s=0;for(let o of this)i.push(e.call(n,o,s,this)),s++;return i}*_getIterator(){for(let e=0;e<this._length;++e)yield this.at(e)}_reallocate(e){let t=[],n=e||this._bucketCount>>1||1;for(let i=0;i<n;++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=n,this._bucketLast=t.length-1;for(let i=0;i<n;++i)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,n,i=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(i/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),n=(i+1)%this._bucketSize-1,n<0&&(n=this._bucketSize-1),{bucketIndex:t,indexInBucket:n}}_createInstance(e){return new u([],e)}*_getReverseIterator(){for(let e=this._length-1;e>-1;e--)yield this.at(e)}};var v=class u extends L{constructor(e=[],t){super(t);h(this,"_elements",[]);h(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});h(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:n}=t;n&&(this._comparator=n)}this.addMany(e)}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 u(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}addMany(e){let t=[];for(let n of e){if(this._toElementFn){t.push(this.add(this._toElementFn(n)));continue}t.push(this.add(n))}return t}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=[],n=i=>{let s=2*i+1,o=s+1;i<this.size&&(e==="IN"?(n(s),t.push(this.elements[i]),n(o)):e==="PRE"?(t.push(this.elements[i]),n(s),n(o)):e==="POST"&&(n(s),n(o),t.push(this.elements[i])))};return n(0),t}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){let e=[],t=new u(this,{comparator:this.comparator});for(;t.size!==0;){let n=t.poll();n!==void 0&&e.push(n)}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 n=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let s of this)e.call(t,s,i,this)&&n.add(s),i++;return n}map(e,t,n,i){let s=new u([],{comparator:t,toElementFn:n}),o=0;for(let d of this)s.add(e.call(i,d,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 n=e-1>>1,i=this.elements[n];if(this.comparator(i,t)<=0)break;this.elements[e]=i,e=n}return this.elements[e]=t,!0}_sinkDown(e,t){let n=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,n)>=0)break;this.elements[e]=o,e=i}return this.elements[e]=n,!0}},ce=class{constructor(r,e=0){h(this,"element");h(this,"degree");h(this,"left");h(this,"right");h(this,"child");h(this,"parent");h(this,"marked");this.element=r,this.degree=e,this.marked=!1}},Oe=class{constructor(r){h(this,"_root");h(this,"_size",0);h(this,"_min");h(this,"_comparator");if(this.clear(),this._comparator=r||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(r){return this.push(r)}push(r){let e=this.createNode(r);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(r){let e=[];if(!r)return e;let t=r,n=!1;for(;!(t===r&&n);)t===r&&(n=!0),t&&(e.push(t),t=t.right);return e}mergeWithChild(r,e){r.child?(e.right=r.child.right,e.left=r.child,r.child.right.left=e,r.child.right=e):r.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let r=this.min;if(r.child){let e=this.consumeLinkedList(r.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(r),r===r.right?(this._min=void 0,this._root=void 0):(this._min=r.right,this._consolidate()),this._size--,r.element}merge(r){if(r.size!==0){if(this.root&&r.root){let e=this.root,t=r.root,n=e.right,i=t.left;e.right=t,t.left=e,n.left=i,i.right=n}(!this.min||r.min&&this.comparator(r.min.element,this.min.element)<0)&&(this._min=r.min),this._size+=r.size,r.clear()}}createNode(r){return new ce(r)}_defaultComparator(r,e){return r<e?-1:r>e?1:0}mergeWithRoot(r){this.root?(r.right=this.root.right,r.left=this.root,this.root.right.left=r,this.root.right=r):this._root=r}removeFromRoot(r){this.root===r&&(this._root=r.right),r.left&&(r.left.right=r.right),r.right&&(r.right.left=r.left)}_link(r,e){this.removeFromRoot(r),r.left=r,r.right=r,this.mergeWithChild(e,r),e.degree++,r.parent=e}_consolidate(){let r=new Array(this._size),e=this.consumeLinkedList(this.root),t,n,i,s;for(let o of e){for(t=o,i=t.degree;r[i];)n=r[i],this.comparator(t.element,n.element)>0&&(s=t,t=n,n=s),this._link(n,t),r[i]=void 0,i++;r[i]=t}for(let o=0;o<this._size;o++)r[o]&&this.comparator(r[o].element,this.min.element)<=0&&(this._min=r[o])}};var we=class u extends v{constructor(r=[],e){super(r,T({comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0}},e))}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var Ie=class u extends v{constructor(r=[],e){super(r,e)}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var R=class{constructor(r,e){h(this,"key");h(this,"value");this.key=r,this.value=e}},P=class{constructor(r,e){h(this,"value");h(this,"weight");h(this,"_hashCode");this.weight=r!==void 0?r:1,this.value=e,this._hashCode=Me()}get hashCode(){return this._hashCode}},U=class extends C{constructor(){super();h(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 R)return this._addVertex(e);{let n=this.createVertex(e,t);return this._addVertex(n)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let n of e)t.push(this.deleteVertex(n));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,n,i){if(e instanceof P)return this._addEdge(e);if(t instanceof R||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof R&&(e=e.key),t instanceof R&&(t=t.key);let s=this.createEdge(e,t,n,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,n){let i=this.getEdge(e,t);return i?(i.weight=n,!0):!1}getAllPathsBetween(e,t,n=1e3){let i=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let d=[];for(d.push({vertex:s,path:[s]});d.length>0;){let{vertex:l,path:a}=d.pop();if(l===o&&(i.push(a),i.length>=n))return i;let f=this.getNeighbors(l);for(let c of f)if(!a.includes(c)){let g=[...a,c];d.push({vertex:c,path:g})}}return i}getPathSumWeight(e){var n;let t=0;for(let i=0;i<e.length;i++)t+=((n=this.getEdge(e[i],e[i+1]))==null?void 0:n.weight)||0;return t}getMinCostBetween(e,t,n){if(n===void 0&&(n=!1),n){let i=this.getAllPathsBetween(e,t),s=Number.MAX_SAFE_INTEGER;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,d=new k([s]);o.set(s,!0);let l=0;for(;d.length>0;){for(let a=0;a<d.length;a++){let f=d.shift();if(f===i)return l;if(f!==void 0){let c=this.getNeighbors(f);for(let g of c)o.has(g)||(o.set(g,!0),d.push(g))}}l++}return}}getMinPathBetween(e,t,n,i=!1){var s,o;if(n===void 0&&(n=!1),n)if(i){let d=this.getAllPathsBetween(e,t,1e4),l=Number.MAX_SAFE_INTEGER,a=-1,f=0;for(let c of d){let g=this.getPathSumWeight(c);g<l&&(l=g,a=f),f++}return d[a]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let d=[],l=this._getVertex(e),a=this._getVertex(t);if(!(l&&a))return[];let f=(c,g,p,V)=>{if(p.add(c),c===g){d=[l,...V];return}let y=this.getNeighbors(c);for(let b of y)p.has(b)||(V.push(b),f(b,g,p,V),V.pop());p.delete(c)};return f(l,a,new Set,[]),d}}dijkstraWithoutHeap(e,t=void 0,n=!1,i=!1){let s=Number.MAX_SAFE_INTEGER,o,d=[],l=[],a=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),V=t?this._getVertex(t):void 0;if(!p)return;for(let _ of a){let m=_[1];m instanceof R&&f.set(m,Number.MAX_SAFE_INTEGER)}f.set(p,0),g.set(p,void 0);let y=()=>{let _=Number.MAX_SAFE_INTEGER,m;for(let[E,K]of f)c.has(E)||K<_&&(_=K,m=E);return m},b=_=>{for(let m of a){let E=m[1];if(E instanceof R){let K=[E],N=g.get(E);for(;N;)K.push(N),N=g.get(N);let M=K.reverse();m[1]===_&&(d=M),l.push(M)}}};for(let _=1;_<a.size;_++){let m=y();if(m){if(c.add(m),V&&V===m)return n&&(s=f.get(V)||Number.MAX_SAFE_INTEGER),i&&b(V),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d};let E=this.getNeighbors(m);for(let K of E)if(!c.has(K)){let N=this.getEdge(m,K);if(N){let M=f.get(m),x=f.get(K);M!==void 0&&x!==void 0&&N.weight+M<x&&(f.set(K,N.weight+M),g.set(K,m))}}}}return n&&f.forEach((_,m)=>{m!==p&&_<s&&(s=_,i&&(o=m))}),i&&b(o),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d}}dijkstra(e,t=void 0,n=!1,i=!1){var _;let s=Number.MAX_SAFE_INTEGER,o,d=[],l=[],a=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),V=t?this._getVertex(t):void 0;if(!p)return;for(let m of a){let E=m[1];E instanceof R&&f.set(E,Number.MAX_SAFE_INTEGER)}let y=new v([],{comparator:(m,E)=>m.key-E.key});y.add({key:0,value:p}),f.set(p,0),g.set(p,void 0);let b=m=>{for(let E of a){let K=E[1];if(K instanceof R){let N=[K],M=g.get(K);for(;M;)N.push(M),M=g.get(M);let x=N.reverse();E[1]===m&&(d=x),l.push(x)}}};for(;y.size>0;){let m=y.poll(),E=m==null?void 0:m.key,K=m==null?void 0:m.value;if(E!==void 0&&K){if(c.add(K),V&&V===K)return n&&(s=f.get(V)||Number.MAX_SAFE_INTEGER),i&&b(V),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d};let N=this.getNeighbors(K);for(let M of N)if(!c.has(M)){let x=(_=this.getEdge(K,M))==null?void 0:_.weight;if(typeof x=="number"){let z=f.get(M);z&&E+x<z&&(y.add({key:E+x,value:M}),g.set(M,K),f.set(M,E+x))}}}}return n&&f.forEach((m,E)=>{E!==p&&m<s&&(s=m,i&&(o=E))}),i&&b(o),{distMap:f,preMap:g,seen:c,paths:l,minDist:s,minPath:d}}bellmanFord(e,t,n,i){n===void 0&&(n=!1),i===void 0&&(i=!1);let s=this._getVertex(e),o=[],d=new Map,l=new Map,a=Number.MAX_SAFE_INTEGER,f=[],c;if(t&&(c=!1),!s)return{hasNegativeCycle:c,distMap:d,preMap:l,paths:o,min:a,minPath:f};let g=this._vertexMap,p=g.size,V=this.edgeSet(),y=V.length;this._vertexMap.forEach(_=>{d.set(_,Number.MAX_SAFE_INTEGER)}),d.set(s,0);for(let _=1;_<p;++_)for(let m=0;m<y;++m){let E=this.getEndsOfEdge(V[m]);if(E){let[K,N]=E,M=V[m].weight,x=d.get(K),z=d.get(N);x!==void 0&&z!==void 0&&d.get(K)!==Number.MAX_SAFE_INTEGER&&x+M<z&&(d.set(N,x+M),i&&l.set(N,K))}}let b;if(n&&d.forEach((_,m)=>{m!==s&&_<a&&(a=_,i&&(b=m))}),i)for(let _ of g){let m=_[1];if(m instanceof R){let E=[m],K=l.get(m);for(;K!==void 0;)E.push(K),K=l.get(K);let N=E.reverse();_[1]===b&&(f=N),o.push(N)}}for(let _=0;_<y;++_){let m=this.getEndsOfEdge(V[_]);if(m){let[E]=m,K=V[_].weight,N=d.get(E);N&&N!==Number.MAX_SAFE_INTEGER&&N+K<N&&(c=!0)}}return{hasNegativeCycle:c,distMap:d,preMap:l,paths:o,min:a,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],i=[];for(let o=0;o<t;o++){n[o]=[],i[o]=[];for(let d=0;d<t;d++)i[o][d]=void 0}for(let o=0;o<t;o++)for(let d=0;d<t;d++)n[o][d]=((s=this.getEdge(e[o][1],e[d][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let o=0;o<t;o++)for(let d=0;d<t;d++)for(let l=0;l<t;l++)n[d][l]>n[d][o]+n[o][l]&&(n[d][l]=n[d][o]+n[o][l],i[d][l]=e[o][1]);return{costs:n,predecessor:i}}getCycles(e=!1){let t=[],n=new Set,i=(o,d,l)=>{if(l.has(o)){(!e&&d.length>2||e&&d.length>=2)&&d[0]===o.key&&t.push([...d]);return}l.add(o),d.push(o.key);for(let a of this.getNeighbors(o))a&&i(a,d,l);l.delete(o),d.pop()};for(let o of this.vertexMap.values())i(o,[],n);let s=new Map;for(let o of t){let d=[...o].sort().toString();s.has(d)||s.set(d,o)}return[...s].map(o=>o[1])}filter(e,t){let n=[],i=0;for(let[s,o]of this)e.call(t,s,o,i,this)&&n.push([s,o]),i++;return n}map(e,t){let n=[],i=0;for(let[s,o]of this)n.push(e.call(t,s,o,i,this)),i++;return n}*_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 R?e.key:e}};var q=class extends R{constructor(r,e){super(r,e)}},$=class extends P{constructor(e,t,n,i){super(n,i);h(this,"src");h(this,"dest");this.src=e,this.dest=t}},oe=class u extends U{constructor(){super();h(this,"_outEdgeMap",new Map);h(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 q(e,t)}createEdge(e,t,n,i){return new $(e,t,n!=null?n:1,i)}getEdge(e,t){let n=[];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&&(n=o.filter(d=>d.dest===s.key))}}return n[0]||void 0}deleteEdgeSrcToDest(e,t){let n=this._getVertex(e),i=this._getVertex(t),s;if(!n||!i)return;let o=this._outEdgeMap.get(n);o&&I(o,l=>l.dest===i.key);let d=this._inEdgeMap.get(i);return d&&(s=I(d,l=>l.src===n.key)[0]||void 0),s}deleteEdge(e,t){let n,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&&I(o,l=>l.src===i.key&&l.dest===(s==null?void 0:s.key));let d=this._inEdgeMap.get(s);d&&d.length>0&&(n=I(d,l=>l.src===i.key&&l.dest===s.key)[0])}return n}deleteVertex(e){let t,n;if(this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e)),n){let i=this.getNeighbors(n);for(let s of i)this.deleteEdgeSrcToDest(n,s);this._outEdgeMap.delete(n),this._inEdgeMap.delete(n)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let n=[];if(e&&t){let i=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);i&&n.push(i),s&&n.push(s)}return n}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=[],n=this.outgoingEdgesOf(e);for(let i of n){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 n=[],i=!1,s=o=>{t.set(o,1);let d=this.getDestinations(o);for(let l of d){let a=t.get(l);a===0?s(l):a===1&&(i=!0)}t.set(o,2),n.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!i)return e==="key"&&(n=n.map(o=>o instanceof q?o.key:o)),n.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let i=this.outgoingEdgesOf(n);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),n=this._getVertex(e.dest);if(t&&n)return[t,n]}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 u;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,n=new Map,i=0,s=[],o=new Set,d=l=>{e.set(l,i),t.set(l,i),i++,s.push(l),o.add(l);let a=this.getNeighbors(l);for(let f of a)e.has(f)?o.has(f)&&t.set(l,Math.min(t.get(l),e.get(f))):(d(f),t.set(l,Math.min(t.get(l),t.get(f))));if(e.get(l)===t.get(l)){let f=[],c;do c=s.pop(),o.delete(c),f.push(c);while(c!==l);n.set(n.size,f)}};for(let l of this.vertexMap.values())e.has(l)||d(l);return{dfnMap:e,lowMap:t,SCCs:n}}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),n=this._getVertex(e.dest);if(t&&n){let i=this._outEdgeMap.get(t);i?i.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(n);return s?s.push(e):this._inEdgeMap.set(n,[e]),!0}else return!1}};var pe=class extends R{constructor(r,e){super(r,e)}},ge=class extends P{constructor(e,t,n,i){super(n,i);h(this,"endpoints");this.endpoints=[e,t]}},Se=class u extends U{constructor(){super();h(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}createVertex(e,t){return new pe(e,t!=null?t:e)}createEdge(e,t,n,i){return new ge(e,t,n!=null?n:1,i)}getEdge(e,t){var i;let n=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(n=(i=this._edgeMap.get(s))==null?void 0:i.filter(d=>d.endpoints.includes(o.key)))}return n&&n[0]||void 0}deleteEdgeBetween(e,t){let n=this._getVertex(e),i=this._getVertex(t);if(!n||!i)return;let s=this._edgeMap.get(n),o;s&&(o=I(s,l=>l.endpoints.includes(i.key))[0]||void 0);let d=this._edgeMap.get(i);return d&&I(d,l=>l.endpoints.includes(n.key)),o}deleteEdge(e,t){let n,i;if(this.isVertexKey(e))if(this.isVertexKey(t))n=this._getVertex(e),i=this._getVertex(t);else return;else n=this._getVertex(e.endpoints[0]),i=this._getVertex(e.endpoints[1]);if(n&&i)return this.deleteEdgeBetween(n,i)}deleteVertex(e){let t,n;this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e));let i=this.getNeighbors(e);return n&&(i.forEach(s=>{let o=this._edgeMap.get(s);if(o){let d=o.filter(l=>!l.endpoints.includes(t));this._edgeMap.set(s,d)}}),this._edgeMap.delete(n)),this._vertexMap.delete(t)}degreeOf(e){var n;let t=this._getVertex(e);return t&&((n=this._edgeMap.get(t))==null?void 0:n.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(n=>{e.add(n)})}),[...e]}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let i=this.edgesOf(n);for(let s of i){let o=this._getVertex(s.endpoints.filter(d=>d!==n.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]),n=this._getVertex(e.endpoints[1]);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){let e=new u;return e.vertexMap=new Map(this.vertexMap),e.edgeMap=new Map(this.edgeMap),e}tarjan(){let e=new Map,t=new Map,n=[],i=[],s=0,o=(d,l)=>{e.set(d,s),t.set(d,s),s++;let a=this.getNeighbors(d),f=0;for(let c of a)if(e.has(c))c!==l&&t.set(d,Math.min(t.get(d),e.get(c)));else{if(f++,o(c,d),t.set(d,Math.min(t.get(d),t.get(c))),t.get(c)>e.get(d)){let g=this.getEdge(d,c);g&&n.push(g)}l!==void 0&&t.get(c)>=e.get(d)&&i.push(d)}l===void 0&&f>1&&i.push(d)};for(let d of this.vertexMap.values())e.has(d)||o(d,void 0);return{dfnMap:e,lowMap:t,bridges:n,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 n=this._getVertex(t);if(n===void 0)return!1;if(n){let i=this._edgeMap.get(n);i?i.push(e):this._edgeMap.set(n,[e])}}return!0}};var me=class extends q{constructor(e,t,n,i){super(e,t);h(this,"lat");h(this,"long");this.lat=n,this.long=i}},_e=class extends ${constructor(r,e,t,n){super(r,e,t,n)}},Fe=class u extends oe{constructor(e,t){super();h(this,"_originCoord",[0,0]);h(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,n=this.originCoord[0],i=this.originCoord[1]){return new me(e,t,n,i)}createEdge(e,t,n,i){return new _e(e,t,n,i)}clone(){let e=new u(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 Ae=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(Ae||{}),H=class{constructor(r,e,t=!0,n=!0){this.low=r;this.high=e;this.includeLow=t;this.includeHigh=n;if(!(w(r)&&w(e)))throw new RangeError("low or high is not comparable");if(r>e)throw new RangeError("low must be less than or equal to high")}isInRange(r,e){let t=this.includeLow?e(r,this.low)>=0:e(r,this.low)>0,n=this.includeHigh?e(r,this.high)<=0:e(r,this.high)<0;return t&&n}};var j=class{constructor(r,e){h(this,"key");h(this,"value");h(this,"parent");h(this,"_left");h(this,"_right");h(this,"_height",0);h(this,"_color","BLACK");h(this,"_count",1);this.key=r,this.value=e}get left(){return this._left}set left(r){r&&(r.parent=this),this._left=r}get right(){return this._right}set right(r){r&&(r.parent=this),this._right=r}get height(){return this._height}set height(r){this._height=r}get color(){return this._color}set color(r){this._color=r}get count(){return this._count}set count(r){this._count=r}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},de=class u extends C{constructor(e=[],t){super();h(this,"iterationType","ITERATIVE");h(this,"_isMapMode",!0);h(this,"_isDuplicate",!1);h(this,"_store",new Map);h(this,"_root");h(this,"_size",0);h(this,"_NIL",new j(NaN));h(this,"_toEntryFn");h(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:i,isMapMode:s,isDuplicate:o}=t;if(n&&(this.iterationType=n),s!==void 0&&(this._isMapMode=s),o!==void 0&&(this._isDuplicate=o),typeof i=="function")this._toEntryFn=i;else if(i)throw TypeError("toEntryFn must be a function type")}e&&this.addMany(e)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}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 j(e,this._isMapMode?void 0:t)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,toEntryFn:this._toEntryFn},e))}ensureNode(e,t=this.iterationType){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e;if(this.isEntry(e)){let n=e[0];return n===null?null:n===void 0?void 0:this.getNode(n,this._root,t)}return this.getNode(e,this._root,t)}}isNode(e){return e instanceof j}isRaw(e){return this._toEntryFn!==void 0&&typeof e=="object"}isRealNode(e){return e===this._NIL||e===null||e===void 0?!1:this.isNode(e)}isRealNodeOrNull(e){return e===null||this.isRealNode(e)}isNIL(e){return e===this._NIL}isRange(e){return e instanceof H}isLeaf(e){return e=this.ensureNode(e),e===void 0?!1:e===null?!0:!this.isRealNode(e.left)&&!this.isRealNode(e.right)}isEntry(e){return Array.isArray(e)&&e.length===2}isValidKey(e){return e===null?!0:w(e)}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size=1,!0;let s=new k([this._root]),o;for(;s.length>0;){let d=s.shift();if(d){if(!this._isDuplicate&&n!==null&&d.key===n.key)return this._replaceNode(d,n),this._isMapMode&&this._setValue(d.key,i),!0;o===void 0&&(d.left===void 0||d.right===void 0)&&(o=d),d.left!==null&&d.left&&s.push(d.left),d.right!==null&&d.right&&s.push(d.right)}}return o?(o.left===void 0?o.left=n:o.right===void 0&&(o.right=n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0):!1}addMany(e,t){let n=[],i;t&&(i=t[Symbol.iterator]());for(let s of e){let o;if(i){let d=i.next();d.done||(o=d.value)}this.isRaw(s)&&(s=this._toEntryFn(s)),n.push(this.add(s,o))}return n}merge(e){this.addMany(e,[])}refill(e,t){this.clear(),this.addMany(e,t)}delete(e){let t=[];if(!this._root)return t;let n=this.getNode(e);if(!n)return t;let i=n==null?void 0:n.parent,s,o=n;if(!n.left&&!n.right&&!i)this._setRoot(void 0);else if(n.left){let d=this.getRightMost(l=>l,n.left);if(d){let l=d.parent;o=this._swapProperties(n,d),l&&(l.right===d?l.right=d.left:l.left=d.left,s=l)}}else if(i){let{familyPosition:d}=n;d==="LEFT"||d==="ROOT_LEFT"?i.left=n.right:(d==="RIGHT"||d==="ROOT_RIGHT")&&(i.right=n.right),s=i}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:o,needBalanced:s}),this._isMapMode&&o&&this._store.delete(o.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let o=this._ensurePredicate(e),d=[];if(s==="RECURSIVE"){let l=a=>{o(a)&&(d.push(n(a)),t)||!this.isRealNode(a.left)&&!this.isRealNode(a.right)||(this.isRealNode(a.left)&&l(a.left),this.isRealNode(a.right)&&l(a.right))};l(i)}else{let l=[i];for(;l.length>0;){let a=l.pop();if(this.isRealNode(a)){if(o(a)&&(d.push(n(a)),t))return d;this.isRealNode(a.left)&&l.push(a.left),this.isRealNode(a.right)&&l.push(a.right)}}}return d}getNodes(e,t=!1,n=this._root,i=this.iterationType){return this.search(e,t,s=>s,n,i)}getNode(e,t=this._root,n=this.iterationType){return this.search(e,!0,i=>i,t,n)[0]}get(e,t=this._root,n=this.iterationType){var i;if(this._isMapMode){let s=this._extractKey(e);return s==null?void 0:this._store.get(s)}return(i=this.getNode(e,t,n))==null?void 0:i.value}has(e,t=this._root,n=this.iterationType){return this.search(e,!0,i=>i,t,n).length>0}clear(){this._clearNodes(),this._isMapMode&&this._clearValues()}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 n=(o,d,l)=>{if(!this.isRealNode(o))return!0;let a=Number(o.key);return a<=d||a>=l?!1:n(o.left,d,a)&&n(o.right,a,l)},i=n(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=n(e,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return i||s}else{let n=(o=!1)=>{let d=[],l=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,a=e;for(;this.isRealNode(a)||d.length>0;){for(;this.isRealNode(a);)d.push(a),a=a.left;a=d.pop();let f=Number(a.key);if(!this.isRealNode(a)||!o&&l>=f||o&&l<=f)return!1;l=f,a=a.right}return!0},i=n(!1),s=n(!0);return i||s}}getDepth(e,t=this._root){let n=this.ensureNode(e),i=this.ensureNode(t),s=0;for(;n!=null&&n.parent;){if(n===i)return s;s++,n=n.parent}return s}getHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i))return-1;let s=n(i.left),o=n(i.right);return Math.max(s,o)+1};return n(e)}else{let n=[{node:e,depth:0}],i=0;for(;n.length>0;){let{node:s,depth:o}=n.pop();this.isRealNode(s.left)&&n.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&n.push({node:s.right,depth:o+1}),i=Math.max(i,o)}return i}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i)||!this.isRealNode(i.left)&&!this.isRealNode(i.right))return 0;let s=n(i.left),o=n(i.right);return Math.min(s,o)+1};return n(e)}else{let n=[],i=e,s=null,o=new Map;for(;n.length>0||i;)if(this.isRealNode(i))n.push(i),i=i.left;else if(i=n[n.length-1],!this.isRealNode(i.right)||s===i.right){if(i=n.pop(),this.isRealNode(i)){let d=this.isRealNode(i.left)?o.get(i.left):-1,l=this.isRealNode(i.right)?o.get(i.right):-1;o.set(i,1+Math.min(d,l)),s=i,i=null}}else i=i.right;return o.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let i=[],s=this.ensureNode(e);if(!s)return i;for(;s.parent;)i.push(t(s)),s=s.parent;return i.push(t(s)),n?i.reverse():i}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!this.isRealNode(t))return e(t);if(n==="RECURSIVE"){let i=s=>this.isRealNode(s.left)?i(s.left):s;return e(i(t))}else{let i=s=>this.isRealNode(s.left)?()=>i(s.left):s;return e(he(()=>i(t)))}}getRightMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!t)return e(t);if(n==="RECURSIVE"){let i=s=>this.isRealNode(s.right)?i(s.right):s;return e(i(t))}else{let i=s=>this.isRealNode(s.right)?()=>i(s.right):s;return e(he(()=>i(t)))}}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(n=>n,e.right);let t=e.parent;for(;this.isRealNode(t)&&e===t.right;)e=t,t=t.parent;return t}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType,o=!1){return i=this.ensureNode(i),i?this._dfs(e,t,n,i,s,o):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(n==="RECURSIVE"){let o=new k([t]),d=l=>{if(o.length===0)return;let a=o.shift();s.push(e(a)),i?(a&&this.isRealNodeOrNull(a.left)&&o.push(a.left),a&&this.isRealNodeOrNull(a.right)&&o.push(a.right)):(this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right)),d(l+1)};d(0)}else{let o=new k([t]);for(;o.length>0;){let d=o.length;for(let l=0;l<d;l++){let a=o.shift();s.push(e(a)),i?(a&&this.isRealNodeOrNull(a.left)&&o.push(a.left),a&&this.isRealNodeOrNull(a.right)&&o.push(a.right)):(this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right))}}}return s}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){t=this.ensureNode(t);let i=[];if(!this.isRealNode(t))return[];if(n==="RECURSIVE"){let s=o=>{this.isLeaf(o)&&i.push(e(o)),!(!this.isRealNode(o.left)&&!this.isRealNode(o.right))&&(this.isRealNode(o.left)&&s(o.left),this.isRealNode(o.right)&&s(o.right))};s(t)}else{let s=new k([t]);for(;s.length>0;){let o=s.shift();this.isRealNode(o)&&(this.isLeaf(o)&&i.push(e(o)),this.isRealNode(o.left)&&s.push(o.left),this.isRealNode(o.right)&&s.push(o.right))}}return i}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(n==="RECURSIVE"){let o=(d,l)=>{s[l]||(s[l]=[]),s[l].push(e(d)),i?(d&&this.isRealNodeOrNull(d.left)&&o(d.left,l+1),d&&this.isRealNodeOrNull(d.right)&&o(d.right,l+1)):(d&&d.left&&o(d.left,l+1),d&&d.right&&o(d.right,l+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let d=o.pop(),[l,a]=d;s[a]||(s[a]=[]),s[a].push(e(l)),i?(l&&this.isRealNodeOrNull(l.right)&&o.push([l.right,a+1]),l&&this.isRealNodeOrNull(l.left)&&o.push([l.left,a+1])):(l&&l.right&&o.push([l.right,a+1]),l&&l.left&&o.push([l.left,a+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let i=[],s=n,o=l=>{let a=null,f=null;for(;l;)f=l.right,l.right=a,a=l,l=f;return a},d=l=>{let a=o(l),f=a;for(;f;)i.push(e(f)),f=f.right;o(a)};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,d(s.left)}s=s.right}d(n);break}return i}clone(){let e=this.createTree();return this._clone(e),e}filter(e,t){let n=this.createTree(),i=0;for(let[s,o]of this)e.call(t,s,o,i++,this)&&n.add([s,o]);return n}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}toVisual(e=this._root,t){let n=T({isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1},t);e=this.ensureNode(e);let i="";return e&&(n.isShowUndefined&&(i+=`U for undefined
2
2
  `),n.isShowNull&&(i+=`N for null
3
3
  `),n.isShowRedBlackNIL&&(i+=`S for Sentinel Node(NIL)
4
4
  `),(o=>{let[d]=this._displayAux(o,n),l="";for(let a of d)l+=a+`
5
- `;i+=l})(e)),i}print(e,t=this._root){console.log(this.toVisual(t,e))}_clone(e){this.bfs(t=>{t===null?e.add(null):this._isMapMode?e.add([t.key,this._store.get(t.key)]):e.add([t.key,t.value])},this._root,this.iterationType,!0),this._isMapMode&&(e._store=this._store)}_keyValueNodeOrEntryToNodeAndValue(e,t){if(e===void 0)return[void 0,void 0];if(e===null)return[null,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[n,i]=e;if(n===void 0)return[void 0,void 0];if(n===null)return[null,void 0];let s=t!=null?t:i;return[this.createNode(n,s),s]}return[this.createNode(e,t),t]}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType,o=!1,d=c=>!!c,l=c=>!!c,a=c=>o?this.isRealNodeOrNull(c):this.isRealNode(c),f=c=>this.isRealNodeOrNull(c)){if(i=this.ensureNode(i),!i)return[];let c=[];if(s==="RECURSIVE"){let g=p=>{if(!a(p))return;let V=()=>{d(p)&&(p==null?void 0:p.left)!==void 0&&g(p==null?void 0:p.left)},y=()=>{l(p)&&(p==null?void 0:p.right)!==void 0&&g(p==null?void 0:p.right)};switch(t){case"IN":if(V(),f(p)&&(c.push(e(p)),n))return;y();break;case"PRE":if(f(p)&&(c.push(e(p)),n))return;V(),y();break;case"POST":if(V(),y(),f(p)&&(c.push(e(p)),n))return;break}};g(i)}else{let g=[{opt:0,node:i}],p=b=>{var _;d(b.node)&&g.push({opt:0,node:(_=b.node)==null?void 0:_.left})},V=b=>{var _;l(b.node)&&g.push({opt:0,node:(_=b.node)==null?void 0:_.right})},y=b=>{a(b.node)&&g.push({opt:1,node:b.node})};for(;g.length>0;){let b=g.pop();if(b!==void 0&&a(b.node))if(b.opt===1){if(f(b.node)&&b.node!==void 0&&(c.push(e(b.node)),n))return c}else switch(t){case"IN":V(b),y(b),p(b);break;case"PRE":V(b),p(b),y(b);break;case"POST":y(b),V(b),p(b);break}}}return c}*_getIterator(e=this._root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],n=e;for(;n||t.length>0;){for(;this.isRealNode(n);)t.push(n),n=n.left;n=t.pop(),this.isRealNode(n)&&(this._isMapMode?yield[n.key,this._store.get(n.key)]:yield[n.key,n.value],n=n.right)}}else e.left&&this.isRealNode(e)&&(yield*B(this[Symbol.iterator](e.left))),this._isMapMode?yield[e.key,this._store.get(e.key)]:yield[e.key,e.value],e.right&&this.isRealNode(e)&&(yield*B(this[Symbol.iterator](e.right)))}_displayAux(e,t){let{isShowNull:n,isShowUndefined:i,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!n)return o;if(e===void 0&&!i)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let l=e.key,a=this.isNIL(e)?"S":String(l),f=a.length;return d(a,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let l=e===void 0?"U":"N",a=l.length;return d(l,a,[[""],1,0,0],[[""],1,0,0])}function d(l,a,f,c){let[g,p,V,y]=f,[b,_,m,E]=c,K=" ".repeat(Math.max(0,y+1))+"_".repeat(Math.max(0,p-y-1))+l+"_".repeat(Math.max(0,E))+" ".repeat(Math.max(0,_-E)),N=(V>0?" ".repeat(y)+"/"+" ".repeat(p-y-1):" ".repeat(p))+" ".repeat(a)+(m>0?" ".repeat(E)+"\\"+" ".repeat(_-E-1):" ".repeat(_)),M=[K,N];for(let x=0;x<Math.max(V,m);x++){let z=x<V?g[x]:" ".repeat(p),st=x<m?b[x]:" ".repeat(_);M.push(z+" ".repeat(a)+st)}return[M,p+a+_,Math.max(V,m)+2,p+Math.floor(a/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i}=t,s=this.createNode(n,i);return s&&(t.key=e.key,this._isMapMode||(t.value=e.value),e.key=s.key,this._isMapMode||(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._setRoot(t),t}_setRoot(e){e&&(e.parent=void 0),this._root=e}_ensurePredicate(e){if(e==null)return t=>!1;if(this._isPredicate(e))return e;if(this.isRealNode(e))return t=>t===e;if(this.isEntry(e)){let[t]=e;return n=>n?n.key===t:!1}return t=>t?t.key===e:!1}_isPredicate(e){return typeof e=="function"}_extractKey(e){if(e===null)return null;if(e!==void 0&&e!==this._NIL)return this.isNode(e)?e.key:this.isEntry(e)?e[0]:e}_setValue(e,t){return e==null||t===void 0?!1:this._store.set(e,t)}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};var S=class extends j{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},G=class u extends de{constructor(e=[],t){super([],t);h(this,"_root");h(this,"_isReverse",!1);h(this,"_comparator",(e,t)=>{if(w(e)&&w(t))return e>t?1:e<t?-1:0;if(this._specifyComparable)return this._specifyComparable(e)>this._specifyComparable(t)?1:this._specifyComparable(e)<this._specifyComparable(t)?-1:0;if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.");return 0});h(this,"_specifyComparable");if(t){let{specifyComparable:n,isReverse:i}=t;typeof n=="function"&&(this._specifyComparable=n),i!==void 0&&(this._isReverse=i)}e&&this.addMany(e)}get root(){return this._root}get isReverse(){return this._isReverse}get comparator(){return this._comparator}get specifyComparable(){return this._specifyComparable}createNode(e,t){return new S(e,this._isMapMode?void 0:t)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse},e))}ensureNode(e,t=this.iterationType){var n;return(n=super.ensureNode(e,t))!=null?n:void 0}isNode(e){return e instanceof S}isValidKey(e){return w(e,this._specifyComparable!==void 0)}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(this._root===void 0)return this._setRoot(n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;let s=this._root;for(;s!==void 0;){if(this._compare(s.key,n.key)===0)return this._replaceNode(s,n),this._isMapMode&&this._setValue(s.key,i),!0;if(this._compare(s.key,n.key)>0){if(s.left===void 0)return s.left=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;s.left!==null&&(s=s.left)}else{if(s.right===void 0)return s.right=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;s.right!==null&&(s=s.right)}}return!1}addMany(e,t,n=!0,i=this.iterationType){let s=[],o;if(t&&(o=t[Symbol.iterator]()),!n){for(let g of e){let p=o==null?void 0:o.next().value;this.isRaw(g)&&(g=this._toEntryFn(g)),s.push(this.add(g,p))}return s}let d=[],l=0;for(let g of e)d.push({key:g,value:o==null?void 0:o.next().value,orgIndex:l}),l++;let a=[];a=d.sort(({key:g},{key:p})=>{let V,y;return this.isRaw(g)?V=this._toEntryFn(g)[0]:this.isEntry(g)?V=g[0]:this.isRealNode(g)?V=g.key:V=g,this.isRaw(p)?y=this._toEntryFn(p)[0]:this.isEntry(p)?y=p[0]:this.isRealNode(p)?y=p.key:y=p,V!=null&&y!==void 0&&y!==null?this._compare(V,y):0});let f=g=>{if(g.length===0)return;let p=Math.floor((g.length-1)/2),{key:V,value:y}=g[p],{orgIndex:b}=g[p];if(this.isRaw(V)){let _=this._toEntryFn(V);s[b]=this.add(_)}else s[b]=this.add(V,y);f(g.slice(0,p)),f(g.slice(p+1))};return i==="RECURSIVE"?f(a):(()=>{let p=[[0,a.length-1]];for(;p.length>0;){let V=p.pop();if(V){let[y,b]=V;if(y<=b){let _=y+Math.floor((b-y)/2),{key:m,value:E}=a[_],{orgIndex:K}=a[_];if(this.isRaw(m)){let N=this._toEntryFn(m);s[K]=this.add(N)}else s[K]=this.add(m,E);p.push([_+1,b]),p.push([y,_-1])}}}})(),s}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let o,d=this.isRange(e);d?o=f=>f?e.isInRange(f.key,this._comparator):!1:o=this._ensurePredicate(e);let l=f=>{if(!f||!this.isRealNode(f.left))return!1;if(d){let c=e,g=this.isReverse?c.high:c.low,p=this.isReverse?c.includeHigh:c.includeLow;return p&&this._compare(f.key,g)>=0||!p&&this._compare(f.key,g)>0}if(!d&&!this._isPredicate(e)){let c=this._extractKey(e);return c!=null&&this._compare(f.key,c)>0}return!0},a=f=>{if(!f||!this.isRealNode(f.right))return!1;if(d){let c=e,g=this.isReverse?c.low:c.high,p=(this.isReverse,c.includeLow);return p&&this._compare(f.key,g)<=0||!p&&this._compare(f.key,g)<0}if(!d&&!this._isPredicate(e)){let c=this._extractKey(e);return c!=null&&this._compare(f.key,c)<0}return!0};return super._dfs(n,"IN",t,i,s,!1,l,a,()=>!0,f=>f?o(f):!1)}rangeSearch(e,t=this._DEFAULT_NODE_CALLBACK,n=this._root,i=this.iterationType){let s=e instanceof H?e:new H(e[0],e[1]);return this.search(s,!1,t,n,i)}getNode(e,t=this._root,n=this.iterationType){var i;return(i=this.getNodes(e,!0,t,n)[0])!=null?i:void 0}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType){return super.dfs(e,t,n,i,s)}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){return super.bfs(e,t,n,!1)}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){return super.listLevels(e,t,n,!1)}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,n=this._root,i=this.iterationType){let s=this.ensureNode(n),o=[];if(!this._root||!s)return o;let d=s.key;if(i==="RECURSIVE"){let l=a=>{let f=this._compare(a.key,d);Math.sign(f)===t&&o.push(e(a)),this.isRealNode(a.left)&&l(a.left),this.isRealNode(a.right)&&l(a.right)};return l(this._root),o}else{let l=new k([this._root]);for(;l.length>0;){let a=l.shift();if(this.isRealNode(a)){let f=this._compare(a.key,d);Math.sign(f)===t&&o.push(e(a)),this.isRealNode(a.left)&&l.push(a.left),this.isRealNode(a.right)&&l.push(a.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),n=t.length;if(this._clearNodes(),t.length<1)return!1;if(e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let d=s+Math.floor((o-s)/2),l=t[d];this._isMapMode&&l!==null?this.add(l.key):l!==null&&this.add([l.key,l.value]),i(s,d-1),i(d+1,o)};return i(0,n-1),!0}else{let i=[[0,n-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,d]=s;if(o<=d){let l=o+Math.floor((d-o)/2),a=t[l];this._isMapMode&&a!==null?this.add(a.key):a!==null&&this.add([a.key,a.value]),i.push([l+1,d]),i.push([o,l-1])}}}return!0}}isAVLBalanced(e=this.iterationType){if(!this._root)return!0;let t=!0;if(e==="RECURSIVE"){let n=i=>{if(!i)return 0;let s=n(i.left),o=n(i.right);return Math.abs(s-o)>1&&(t=!1),Math.max(s,o)+1};n(this._root)}else{let n=[],i=this._root,s,o=new Map;for(;n.length>0||i;)if(i)n.push(i),i.left!==null&&(i=i.left);else if(i=n[n.length-1],!i.right||s===i.right){if(i=n.pop(),i){let d=i.left?o.get(i.left):-1,l=i.right?o.get(i.right):-1;if(Math.abs(d-l)>1)return!1;o.set(i,1+Math.max(d,l)),s=i,i=void 0}}else i=i.right}return t}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}clone(){let e=this.createTree();return this._clone(e),e}_keyValueNodeOrEntryToNodeAndValue(e,t){let[n,i]=super._keyValueNodeOrEntryToNodeAndValue(e,t);return n===null?[void 0,void 0]:[n,t!=null?t:i]}_setRoot(e){e&&(e.parent=void 0),this._root=e}_compare(e,t){return this._isReverse?-this._comparator(e,t):this._comparator(e,t)}};var je=class{constructor({frequency:r=0,max:e}){h(this,"_freq");h(this,"_max");h(this,"_freqMap");h(this,"_msb");h(this,"_negativeCount");this._freq=r,this._max=e,this._freqMap={0:0},this._msb=ke(e),this._negativeCount=r<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(r){return this._checkIndex(r),this._readSingle(r)}update(r,e){this._checkIndex(r);let t=this._readSingle(r);this._update(r,e),this._updateNegativeCount(t,t+e)}writeSingle(r,e){this._checkIndex(r),this._writeSingle(r,e)}read(r){if(!Number.isInteger(r))throw new Error("Invalid count");return this._read(Math.max(Math.min(r,this.max),0))}lowerBound(r){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(r,(e,t)=>e<t)}upperBound(r){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(r,(e,t)=>e<=t)}getPrefixSum(r){this._checkIndex(r),r++;let e=0;for(;r>0;)e+=this._getFrequency(r),r-=r&-r;return e}_getFrequency(r){return r in this.freqMap?this.freqMap[r]:this.freq*(r&-r)}_updateFrequency(r,e){this.freqMap[r]=this._getFrequency(r)+e}_checkIndex(r){if(!Number.isInteger(r))throw new Error("Invalid index: Index must be an integer.");if(r<0||r>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(r){r=r+1;let e=this._getFrequency(r),t=r-(r&-r);for(r--;r!==t;)e-=this._getFrequency(r),r-=r&-r;return e}_updateNegativeCount(r,e){r<0&&e>=0?this._negativeCount--:r>=0&&e<0&&this._negativeCount++}_update(r,e){for(r=r+1;r<=this.max;)this._updateFrequency(r,e),r+=r&-r}_writeSingle(r,e){let t=this._readSingle(r);this._update(r,e-t),this._updateNegativeCount(t,e)}_read(r){let e=r,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(r,e){let t=0,n=this.msb<<1,i=r;for(;n>t+1;){let s=t+n>>1,o=this._getFrequency(s);s<=this.max&&e(o,i)?(i-=o,t=s):n=s}return t}};var ee=class{constructor(r,e,t,n){h(this,"_start",0);h(this,"_end",0);h(this,"_value");h(this,"_sum",0);h(this,"_left");h(this,"_right");this._start=r,this._end=e,this._sum=t,this._value=n||void 0}get start(){return this._start}set start(r){this._start=r}get end(){return this._end}set end(r){this._end=r}get value(){return this._value}set value(r){this._value=r}get sum(){return this._sum}set sum(r){this._sum=r}get left(){return this._left}set left(r){this._left=r}get right(){return this._right}set right(r){this._right=r}},ze=class{constructor(r,e,t){h(this,"_values",[]);h(this,"_start",0);h(this,"_end");h(this,"_root");e=e||0,t=t||r.length-1,this._values=r,this._start=e,this._end=t,r.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(r,e){if(r>e)return new ee(r,e,0);if(r===e)return new ee(r,e,this._values[r]);let t=r+Math.floor((e-r)/2),n=this.build(r,t),i=this.build(t+1,e),s=new ee(r,e,n.sum+i.sum);return s.left=n,s.right=i,s}updateNode(r,e,t){let n=this.root||void 0;if(!n)return;let i=(s,o,d,l)=>{if(s.start===s.end&&s.start===o){s.sum=d,l!==void 0&&(s.value=l);return}let a=s.start+Math.floor((s.end-s.start)/2);o<=a?s.left&&i(s.left,o,d,l):s.right&&i(s.right,o,d,l),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};i(n,r,e,t)}querySumByRange(r,e){let t=this.root||void 0;if(!t)return 0;if(r<0||e>=this.values.length||r>e)return NaN;let n=(i,s,o)=>{if(s<=i.start&&o>=i.end)return i.sum;let d=i.start+Math.floor((i.end-i.start)/2);if(o<=d)return i.left?n(i.left,s,o):NaN;if(s>d)return i.right?n(i.right,s,o):NaN;{let l=0,a=0;return i.left&&(l=n(i.left,s,d)),i.right&&(a=n(i.right,d+1,o)),l+a}};return n(t,r,e)}};var F=class extends S{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},Q=class u extends G{constructor(r=[],e){super([],e),r&&super.addMany(r)}createNode(r,e){return new F(r,this._isMapMode?void 0:e)}createTree(r){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse},r))}isNode(r){return r instanceof F}add(r,e){if(r===null)return!1;let t=super.add(r,e);return t&&this._balancePath(r),t}delete(r){let e=super.delete(r);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}map(r,e,t){let n=new u([],e),i=0;for(let[s,o]of this)n.add(r.call(t,s,o,i++,this));return n}clone(){let r=this.createTree();return this._clone(r),r}_swapProperties(r,e){let t=this.ensureNode(r),n=this.ensureNode(e);if(t&&n){let{key:i,value:s,height:o}=n,d=this.createNode(i,s);return d&&(d.height=o,n.key=t.key,this._isMapMode||(n.value=t.value),n.height=t.height,t.key=d.key,this._isMapMode||(t.value=d.value),t.height=d.height),n}}_balanceFactor(r){return r.right?r.left?r.right.height-r.left.height:+r.height:-r.height}_updateHeight(r){if(!r.left&&!r.right)r.height=0;else if(r.left)r.right?r.height=1+Math.max(r.right.height,r.left.height):r.height=1+r.left.height;else{let e=r.right?r.right.height:0;r.height=1+e}}_balanceLL(r){let e=r.parent,t=r.left;t!==null&&(r.parent=t),t&&t.right&&(t.right.parent=r),t&&(t.parent=e),r===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===r?e.left=t:e&&(e.right=t),t&&(r.left=t.right,t.right=r),this._updateHeight(r),t&&this._updateHeight(t)}_balanceLR(r){let e=r.parent,t=r.left,n;t&&(n=t.right),r&&n!==null&&(r.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&t!==null&&(n.left.parent=t),n.right&&(n.right.parent=r),n.parent=e),r===this.root?n&&this._setRoot(n):e&&(e.left===r?e.left=n:e.right=n),n&&(r.left=n.right,t&&(t.right=n.left),n.left=t,n.right=r),this._updateHeight(r),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balanceRR(r){let e=r.parent,t=r.right;t!==null&&(r.parent=t),t&&(t.left&&(t.left.parent=r),t.parent=e),r===this.root?t&&this._setRoot(t):e&&(e.left===r?e.left=t:e.right=t),t&&(r.right=t.left,t.left=r),this._updateHeight(r),t&&this._updateHeight(t)}_balanceRL(r){let e=r.parent,t=r.right,n;t&&(n=t.left),n!==null&&(r.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&(n.left.parent=r),n.right&&t!==null&&(n.right.parent=t),n.parent=e),r===this.root?n&&this._setRoot(n):e&&(e.left===r?e.left=n:e.right=n),n&&(r.right=n.left),t&&n&&(t.left=n.right),n&&(n.left=r),n&&(n.right=t),this._updateHeight(r),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balancePath(r){r=this.ensureNode(r);let e=this.getPathToRoot(r,t=>t,!1);for(let t=0;t<e.length;t++){let n=e[t];if(n)switch(this._updateHeight(n),this._balanceFactor(n)){case-2:n&&n.left&&(this._balanceFactor(n.left)<=0?this._balanceLL(n):this._balanceLR(n));break;case 2:n&&n.right&&(this._balanceFactor(n.right)>=0?this._balanceRR(n):this._balanceRL(n))}}}_replaceNode(r,e){return e.height=r.height,super._replaceNode(r,e)}};var A=class extends S{constructor(e,t,n="BLACK"){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right");this._color=n}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}},W=class u extends G{constructor(e=[],t){super([],t);h(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,n="BLACK"){return new A(e,this._isMapMode?void 0:t,n)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof A}clear(){super.clear(),this._root=this.NIL}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(!this.isRealNode(n))return!1;let s=this._insert(n);if(s==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._isMapMode&&this._setValue(n.key,i),this._size++,!0}return s==="UPDATED"?(this._isMapMode&&this._setValue(n.key,i),!0):!1}delete(e){if(e===null)return[];let t=[],n;if(this._isPredicate(e)?n=this.getNode(e):n=this.isRealNode(e)?e:this.getNode(e),!n)return t;let i=n.color,s;if(!this.isRealNode(n.left))n.right!==null&&(s=n.right,this._transplant(n,n.right));else if(!this.isRealNode(n.right))s=n.left,this._transplant(n,n.left);else{let o=this.getLeftMost(d=>d,n.right);o&&(i=o.color,o.right!==null&&(s=o.right),o.parent===n?this.isRealNode(s)&&(s.parent=o):(o.right!==null&&(this._transplant(o,o.right),o.right=n.right),this.isRealNode(o.right)&&(o.right.parent=o)),this._transplant(n,o),o.left=n.left,this.isRealNode(o.left)&&(o.left.parent=o),o.color=n.color)}return this._isMapMode&&this._store.delete(n.key),this._size--,i==="BLACK"&&this._deleteFixup(s),t.push({deleted:n,needBalanced:void 0}),t}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}clone(){let e=this.createTree();return this._clone(e),e}_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,n;for(;this.isRealNode(t);){n=t;let o=this._compare(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=n,n?this._compare(e.key,n.key)<0?n.left=e:n.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,n,i,s,o;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((n=e.parent.parent)==null?void 0:n.left)){let d=e.parent.parent.right;(d==null?void 0:d.color)==="RED"?(e.parent.color="BLACK",d.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 d=(o=(s=(i=e==null?void 0:e.parent)==null?void 0:i.parent)==null?void 0:s.left)!=null?o:void 0;(d==null?void 0:d.color)==="RED"?(e.parent.color="BLACK",d.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,n,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 d=o.right;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o.color="RED",this._leftRotate(o),d=o.right),((n=(t=d==null?void 0:d.left)==null?void 0:t.color)!=null?n:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.left&&(d.left.color="BLACK"),d&&(d.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let d=o.left;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(d=o.left)),((s=(i=d==null?void 0:d.right)==null?void 0:i.color)!=null?s:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.right&&(d.right.color="BLACK"),d&&(d.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 Ve=class extends F{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},Ue=class u extends Q{constructor(r=[],e){super([],nt(T({},e),{isMapMode:!0})),r&&this.addMany(r)}createTree(r){return new u([],T({iterationType:this.iterationType,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse,isMapMode:this._isMapMode},r))}createNode(r,e=[]){return new Ve(r,this._isMapMode?[]:e)}add(r,e){if(this.isRealNode(r))return super.add(r);let t=(n,i)=>{if(n==null)return!1;let s=()=>{let d=this.get(n);if(d!==void 0&&i!==void 0){for(let l of i)d.push(l);return!0}return!1},o=()=>{let d=this.getNode(n);if(this.isRealNode(d)){let l=this.get(d);if(l===void 0)return super.add(n,i),!0;if(i!==void 0){for(let a of i)l.push(a);return!0}else return!1}else return super.add(n,i)};return this._isMapMode?o()||s():s()||o()};if(this.isEntry(r)){let[n,i]=r;return t(n,e!==void 0?[e]:i)}return t(r,e!==void 0?[e]:void 0)}deleteValue(r,e){let t=this.get(r);if(Array.isArray(t)){let n=t.indexOf(e);return n===-1?!1:(t.splice(n,1),t.length===0&&this.delete(r),!0)}return!1}clone(){let r=this.createTree();return this._clone(r),r}};var be=class extends A{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},qe=class u extends W{constructor(r=[],e){super([],T({},e)),r&&this.addMany(r)}createTree(r){return new u([],T({iterationType:this.iterationType,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse,isMapMode:this._isMapMode},r))}createNode(r,e=[]){return new be(r,this._isMapMode?[]:e)}add(r,e){if(this.isRealNode(r))return super.add(r);let t=(n,i)=>{if(n==null)return!1;let s=()=>{let d=this.get(n);if(d!==void 0&&i!==void 0){for(let l of i)d.push(l);return!0}return!1},o=()=>{let d=this.getNode(n);if(this.isRealNode(d)){let l=this.get(d);if(l===void 0)return super.add(n,i),!0;if(i!==void 0){for(let a of i)l.push(a);return!0}else return!1}else return super.add(n,i)};return this._isMapMode?o()||s():s()||o()};if(this.isEntry(r)){let[n,i]=r;return t(n,e!==void 0?[e]:i)}return t(r,e!==void 0?[e]:void 0)}deleteValue(r,e){let t=this.get(r);if(Array.isArray(t)){let n=t.indexOf(e);return n===-1?!1:(t.splice(n,1),t.length===0&&this.delete(r),!0)}return!1}clone(){let r=this.createTree();return this._clone(r),r}};var le=class extends A{constructor(e,t,n=1,i="BLACK"){super(e,t,i);h(this,"parent");h(this,"_left");h(this,"_right");this.count=n}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}},Ge=class u extends W{constructor(e=[],t){super([],t);h(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t?t.count:0),e}createNode(e,t,n="BLACK",i){return new le(e,this._isMapMode?void 0:t,i,n)}createTree(e){return new u([],T({iterationType:this.iterationType,specifyComparable:this._specifyComparable,isMapMode:this._isMapMode,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof le}add(e,t,n=1){let[i,s]=this._keyValueNodeOrEntryToNodeAndValue(e,t,n),o=(i==null?void 0:i.count)||0;return super.add(i,s)?(this._count+=o,!0):!1}delete(e,t=!1){if(e===null)return[];let n=[],i;if(this._isPredicate(e)?i=this.getNode(e):i=this.isRealNode(e)?e:this.getNode(e),!i)return n;let s=i.color,o;if(this.isRealNode(i.left))if(this.isRealNode(i.right)){let d=this.getLeftMost(l=>l,i.right);if(d){if(s=d.color,d.right!==null&&(o=d.right),d.parent===i)this.isRealNode(o)&&(o.parent=d);else{if(t||i.count<=1)d.right!==null&&(this._transplant(d,d.right),this._count-=i.count);else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;d.right=i.right,this.isRealNode(d.right)&&(d.right.parent=d)}if(t||i.count<=1)this._transplant(i,d),this._count-=i.count;else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;d.left=i.left,this.isRealNode(d.left)&&(d.left.parent=d),d.color=i.color}}else if(o=i.left,t||i.count<=1)this._transplant(i,i.left),this._count-=i.count;else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;else if(i.right!==null&&(o=i.right),t||i.count<=1)i.right!==null&&(this._transplant(i,i.right),this._count-=i.count);else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;return this._size--,s==="BLACK"&&this._deleteFixup(o),n.push({deleted:i,needBalanced:void 0}),n}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),n=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let d=s+Math.floor((o-s)/2),l=t[d];this._isMapMode&&l!==null?this.add(l.key,void 0,l.count):l!==null&&this.add(l.key,l.value,l.count),i(s,d-1),i(d+1,o)};return i(0,n-1),!0}else{let i=[[0,n-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,d]=s;if(o<=d){let l=o+Math.floor((d-o)/2),a=t[l];this._isMapMode&&a!==null?this.add(a.key,void 0,a.count):a!==null&&this.add(a.key,a.value,a.count),i.push([l+1,d]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t===null?null:t.key,void 0,t===null?0:t.count)),this._isMapMode&&(e._store=this._store),e}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}_keyValueNodeOrEntryToNodeAndValue(e,t,n=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[i,s]=e;if(i==null)return[void 0,void 0];let o=t!=null?t:s;return[this.createNode(i,o,"BLACK",n),o]}return[this.createNode(e,t,"BLACK",n),t]}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i,count:s,color:o}=t,d=this.createNode(n,i,o,s);return d&&(d.color=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.color=e.color,e.key=d.key,this._isMapMode||(e.value=d.value),e.count=d.count,e.color=d.color),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var ue=class extends F{constructor(e,t,n=1){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right");this.count=n}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}},Qe=class u extends Q{constructor(e=[],t){super([],t);h(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,n){return new ue(e,this._isMapMode?void 0:t,n)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse},e))}isNode(e){return e instanceof ue}add(e,t,n=1){let[i,s]=this._keyValueNodeOrEntryToNodeAndValue(e,t,n);if(i===void 0)return!1;let o=(i==null?void 0:i.count)||0;return super.add(i,s)&&(this._count+=o),!0}delete(e,t=!1){var l;let n=[];if(!this.root)return n;let i=(l=this.getNode(e))!=null?l:void 0;if(!i)return n;let s=i!=null&&i.parent?i.parent:void 0,o,d=i;if(i.count>1&&!t)i.count--,this._count--;else{if(i.left){let a=i.left?this.getRightMost(f=>f,i.left):void 0;if(a){let f=a.parent;d=this._swapProperties(i,a),f&&(f.right===a?f.right=a.left:f.left=a.left,o=f)}}else if(!s)i.right!==void 0&&i.right!==null&&this._setRoot(i.right);else{let{familyPosition:a}=i;a==="LEFT"||a==="ROOT_LEFT"?s.left=i.right:(a==="RIGHT"||a==="ROOT_RIGHT")&&(s.right=i.right),o=s}this._size=this._size-1,d&&(this._count-=d.count)}return n.push({deleted:d,needBalanced:o}),o&&this._balancePath(o),n}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),n=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let d=s+Math.floor((o-s)/2),l=t[d];this._isMapMode?this.add(l.key,void 0,l.count):this.add(l.key,l.value,l.count),i(s,d-1),i(d+1,o)};return i(0,n-1),!0}else{let i=[[0,n-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,d]=s;if(o<=d){let l=o+Math.floor((d-o)/2),a=t[l];this._isMapMode?this.add(a.key,void 0,a.count):this.add(a.key,a.value,a.count),i.push([l+1,d]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this._isMapMode?this.bfs(t=>e.add(t.key,void 0,t.count)):this.bfs(t=>e.add(t.key,t.value,t.count)),this._isMapMode&&(e._store=this._store),e}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}_keyValueNodeOrEntryToNodeAndValue(e,t,n=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[i,s]=e;if(i==null)return[void 0,void 0];let o=t!=null?t:s;return[this.createNode(i,o,n),o]}return[this.createNode(e,t,n),t]}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i,count:s,height:o}=t,d=this.createNode(n,i,s);return d&&(d.height=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.height=e.height,e.key=d.key,this._isMapMode||(e.value=d.value),e.count=d.count,e.height=d.height),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var X=class u extends v{constructor(r=[],e){super(r,e)}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var We=class u extends X{constructor(r=[],e){super(r,e)}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var Xe=class u extends X{constructor(r=[],e){super(r,T({comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0}},e))}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var Ye=class u{constructor(r,e){h(this,"_rows",0);h(this,"_cols",0);h(this,"_data");var t,n,i;if(e){let{rows:s,cols:o,addFn:d,subtractFn:l,multiplyFn:a}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=r.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=r[0])==null?void 0:t.length)||0,d&&(this._addFn=d),l&&(this._subtractFn=l),a&&(this._multiplyFn=a)}else this._rows=r.length,this._cols=(i=(n=r[0])==null?void 0:n.length)!=null?i:0;if(r.length>0)this._data=r;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(r,e){if(this.isValidIndex(r,e))return this.data[r][e]}set(r,e,t){return this.isValidIndex(r,e)?(this.data[r][e]=t,!0):!1}isMatchForCalculate(r){return this.rows===r.rows&&this.cols===r.cols}add(r){if(!this.isMatchForCalculate(r))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let i=this.get(t,n),s=r.get(t,n);if(i!==void 0&&s!==void 0){let o=this._addFn(i,s);o&&(e[t][n]=o)}}}return new u(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(r){if(!this.isMatchForCalculate(r))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let i=this.get(t,n),s=r.get(t,n);if(i!==void 0&&s!==void 0){let o=this._subtractFn(i,s);o&&(e[t][n]=o)}}}return new u(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(r){if(this.cols!==r.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 n=0;n<r.cols;n++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=r.get(s,n);if(o!==void 0&&d!==void 0){let l=this.multiplyFn(o,d);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][n]=i)}}return new u(e,{rows:this.rows,cols:r.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 r=[];for(let e=0;e<this.cols;e++){r[e]=[];for(let t=0;t<this.rows;t++){let n=this.get(t,e);n!==void 0&&(r[e][t]=n)}}return new u(r,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var n;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let r=[];for(let i=0;i<this.rows;i++){r[i]=this.data[i].slice();for(let s=0;s<this.cols;s++)r[i][this.cols+s]=i===s?1:0}let e=new u(r,{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=(n=e.get(i,i))!=null?n: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 d=0;d<this.rows;d++)if(d!==i){let l=e.get(d,i);l===void 0&&(l=0),e._addScaledRow(d,i,-l)}}let t=[];for(let i=0;i<this.rows;i++)t[i]=e.data[i].slice(this.cols);return new u(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(r){if(this.cols!==r.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 n=0;n<r.cols;n++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=r.get(s,n);if(o!==void 0&&d!==void 0){let l=this.multiplyFn(o,d);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][n]=i)}}return new u(e,{rows:this.rows,cols:r.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(r,e){return r>=0&&r<this.rows&&e>=0&&e<this.cols}clone(){return new u(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(r,e){return r===void 0?e:r+e}_subtractFn(r,e){return r-e}_multiplyFn(r,e){return r*e}_swapRows(r,e){let t=this.data[r];this.data[r]=this.data[e],this.data[e]=t}_scaleRow(r,e){for(let t=0;t<this.cols;t++){let n=this.multiplyFn(this.data[r][t],e);n===void 0&&(n=0),this.data[r][t]=n}}_addScaledRow(r,e,t){for(let n=0;n<this.cols;n++){let i=this.multiplyFn(this.data[e][n],t);i===void 0&&(i=0);let s=i,o=this.addFn(this.data[r][n],s);o===void 0&&(o=0),this.data[r][n]=o}}};var ye=class u{constructor(r,e){h(this,"direction");h(this,"turn");this.direction=r,this.turn=()=>new u(e[r],e)}},Je=class{constructor({matrix:r,turning:e,onMove:t,init:{cur:n,charDir:i,VISITED:s}}){h(this,"onMove");h(this,"_matrix");h(this,"_cur");h(this,"_character");h(this,"_VISITED");this._matrix=r,this._cur=n,this._character=new ye(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:r}=this._character;this.check(r)?this.move(r):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(r){let e,t,n=this._matrix,[i,s]=this._cur;switch(r){case"up":if(t=n[i-1],!t)return!1;e=t[s];break;case"right":e=n[i][s+1];break;case"down":if(t=n[i+1],!t)return!1;e=t[s];break;case"left":e=n[i][s-1];break}return e!==void 0&&e!==this._VISITED}move(r){switch(r){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 te=class{constructor(r){h(this,"_key");h(this,"_children");h(this,"_isEnd");this._key=r,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(r){this._key=r}get children(){return this._children}set children(r){this._children=r}get isEnd(){return this._isEnd}set isEnd(r){this._isEnd=r}},Ze=class u extends L{constructor(e=[],t){super(t);h(this,"_size",0);h(this,"_caseSensitive",!0);h(this,"_root",new te(""));if(t){let{caseSensitive:n}=t;n!==void 0&&(this._caseSensitive=n)}e&&this.addMany(e)}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,n=!1;for(let i of e){let s=t.children.get(i);s||(s=new te(i),t.children.set(i,s)),t=s}return t.isEnd||(n=!0,t.isEnd=!0,this._size++),n}addMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.add(this.toElementFn(n))):t.push(this.add(n));return t}has(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return t.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new te("")}delete(e){e=this._caseProcess(e);let t=!1,n=(i,s)=>{let o=e[s],d=i.children.get(o);return d?s===e.length-1?d.isEnd?(d.children.size>0?d.isEnd=!1:i.children.delete(o),t=!0,!0):!1:n(d,s+1)&&!i.isEnd&&d.children.size===0?(i.children.delete(o),!0):!1:!1};return n(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let n=(i,s)=>{s>t&&(t=s);let{children:o}=i;if(o)for(let d of o.entries())n(d[1],s+1)};n(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",n=i=>{if(t+=i.key,t!==e&&!i.isEnd)if(i&&i.children&&i.children.size===1)n(Array.from(i.children.values())[0]);else return};return n(this.root),t===e}getLongestCommonPrefix(){let e="",t=n=>{if(e+=n.key,!n.isEnd)if(n&&n.children&&n.children.size===1)t(Array.from(n.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,n=!1){e=this._caseProcess(e);let i=[],s=0;function o(l,a){for(let f of l.children.keys()){let c=l.children.get(f);c!==void 0&&o(c,a.concat(f))}if(l.isEnd){if(s>t-1)return;i.push(a),s++}}let d=this.root;if(e)for(let l of e){let a=d.children.get(l);if(a)d=a;else return[]}return(n||d!==this.root)&&o(d,e),i}clone(){return new u(this,{caseSensitive:this.caseSensitive,toElementFn:this.toElementFn})}filter(e,t){let n=new u([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive}),i=0;for(let s of this)e.call(t,s,i,this)&&n.add(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,caseSensitive:this.caseSensitive}),s=0;for(let o of this)i.add(e.call(n,o,s,this)),s++;return i}*_getIterator(){function*e(t,n){t.isEnd&&(yield n);for(let[i,s]of t.children)yield*B(e(s,n+i))}yield*B(e(this.root,""))}get _total(){return this._size}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var $e=class u{constructor(r,e,t){h(this,"_key");h(this,"_value");h(this,"_children");this._key=r,this._value=e||void 0,t&&(this._children=t)}get key(){return this._key}set key(r){this._key=r}get value(){return this._value}set value(r){this._value=r}get children(){return this._children}set children(r){this._children=r}addChildren(r){this._children||(this._children=[]),r instanceof u?this._children.push(r):this._children=this._children.concat(r)}getHeight(){let r=0;if(this){let e=(t,n)=>{n>r&&(r=n);let{_children:i}=t;if(i)for(let s=0,o=i.length;s<o;s++)e(i[s],n+1)};e(this,0)}return r}};return pt(yt);})();
5
+ `;i+=l})(e)),i}print(e,t=this._root){console.log(this.toVisual(t,e))}_clone(e){this.bfs(t=>{t===null?e.add(null):this._isMapMode?e.add([t.key,this._store.get(t.key)]):e.add([t.key,t.value])},this._root,this.iterationType,!0),this._isMapMode&&(e._store=this._store)}_keyValueNodeOrEntryToNodeAndValue(e,t){if(e===void 0)return[void 0,void 0];if(e===null)return[null,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[n,i]=e;if(n===void 0)return[void 0,void 0];if(n===null)return[null,void 0];let s=t!=null?t:i;return[this.createNode(n,s),s]}return[this.createNode(e,t),t]}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType,o=!1,d=c=>!!c,l=c=>!!c,a=c=>o?this.isRealNodeOrNull(c):this.isRealNode(c),f=c=>this.isRealNodeOrNull(c)){if(i=this.ensureNode(i),!i)return[];let c=[];if(s==="RECURSIVE"){let g=p=>{if(!a(p))return;let V=()=>{d(p)&&(p==null?void 0:p.left)!==void 0&&g(p==null?void 0:p.left)},y=()=>{l(p)&&(p==null?void 0:p.right)!==void 0&&g(p==null?void 0:p.right)};switch(t){case"IN":if(V(),f(p)&&(c.push(e(p)),n))return;y();break;case"PRE":if(f(p)&&(c.push(e(p)),n))return;V(),y();break;case"POST":if(V(),y(),f(p)&&(c.push(e(p)),n))return;break}};g(i)}else{let g=[{opt:0,node:i}],p=b=>{var _;d(b.node)&&g.push({opt:0,node:(_=b.node)==null?void 0:_.left})},V=b=>{var _;l(b.node)&&g.push({opt:0,node:(_=b.node)==null?void 0:_.right})},y=b=>{a(b.node)&&g.push({opt:1,node:b.node})};for(;g.length>0;){let b=g.pop();if(b!==void 0&&a(b.node))if(b.opt===1){if(f(b.node)&&b.node!==void 0&&(c.push(e(b.node)),n))return c}else switch(t){case"IN":V(b),y(b),p(b);break;case"PRE":V(b),p(b),y(b);break;case"POST":y(b),V(b),p(b);break}}}return c}*_getIterator(e=this._root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],n=e;for(;n||t.length>0;){for(;this.isRealNode(n);)t.push(n),n=n.left;n=t.pop(),this.isRealNode(n)&&(this._isMapMode?yield[n.key,this._store.get(n.key)]:yield[n.key,n.value],n=n.right)}}else e.left&&this.isRealNode(e)&&(yield*B(this[Symbol.iterator](e.left))),this._isMapMode?yield[e.key,this._store.get(e.key)]:yield[e.key,e.value],e.right&&this.isRealNode(e)&&(yield*B(this[Symbol.iterator](e.right)))}_displayAux(e,t){let{isShowNull:n,isShowUndefined:i,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!n)return o;if(e===void 0&&!i)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let l=e.key,a=this.isNIL(e)?"S":String(l),f=a.length;return d(a,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let l=e===void 0?"U":"N",a=l.length;return d(l,a,[[""],1,0,0],[[""],1,0,0])}function d(l,a,f,c){let[g,p,V,y]=f,[b,_,m,E]=c,K=" ".repeat(Math.max(0,y+1))+"_".repeat(Math.max(0,p-y-1))+l+"_".repeat(Math.max(0,E))+" ".repeat(Math.max(0,_-E)),N=(V>0?" ".repeat(y)+"/"+" ".repeat(p-y-1):" ".repeat(p))+" ".repeat(a)+(m>0?" ".repeat(E)+"\\"+" ".repeat(_-E-1):" ".repeat(_)),M=[K,N];for(let x=0;x<Math.max(V,m);x++){let z=x<V?g[x]:" ".repeat(p),nt=x<m?b[x]:" ".repeat(_);M.push(z+" ".repeat(a)+nt)}return[M,p+a+_,Math.max(V,m)+2,p+Math.floor(a/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i}=t,s=this.createNode(n,i);return s&&(t.key=e.key,this._isMapMode||(t.value=e.value),e.key=s.key,this._isMapMode||(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._setRoot(t),t}_setRoot(e){e&&(e.parent=void 0),this._root=e}_ensurePredicate(e){if(e==null)return t=>!1;if(this._isPredicate(e))return e;if(this.isRealNode(e))return t=>t===e;if(this.isEntry(e)){let[t]=e;return n=>n?n.key===t:!1}return t=>t?t.key===e:!1}_isPredicate(e){return typeof e=="function"}_extractKey(e){if(e===null)return null;if(e!==void 0&&e!==this._NIL)return this.isNode(e)?e.key:this.isEntry(e)?e[0]:e}_setValue(e,t){return e==null||t===void 0?!1:this._store.set(e,t)}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};var S=class extends j{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},G=class u extends de{constructor(e=[],t){super([],t);h(this,"_root");h(this,"_isReverse",!1);h(this,"_comparator",(e,t)=>{if(w(e)&&w(t))return e>t?1:e<t?-1:0;if(this._specifyComparable)return this._specifyComparable(e)>this._specifyComparable(t)?1:this._specifyComparable(e)<this._specifyComparable(t)?-1:0;if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.");return 0});h(this,"_specifyComparable");if(t){let{specifyComparable:n,isReverse:i}=t;typeof n=="function"&&(this._specifyComparable=n),i!==void 0&&(this._isReverse=i)}e&&this.addMany(e)}get root(){return this._root}get isReverse(){return this._isReverse}get comparator(){return this._comparator}get specifyComparable(){return this._specifyComparable}createNode(e,t){return new S(e,this._isMapMode?void 0:t)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse},e))}ensureNode(e,t=this.iterationType){var n;return(n=super.ensureNode(e,t))!=null?n:void 0}isNode(e){return e instanceof S}isValidKey(e){return w(e,this._specifyComparable!==void 0)}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(this._root===void 0)return this._setRoot(n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;let s=this._root;for(;s!==void 0;){if(this._compare(s.key,n.key)===0)return this._replaceNode(s,n),this._isMapMode&&this._setValue(s.key,i),!0;if(this._compare(s.key,n.key)>0){if(s.left===void 0)return s.left=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;s.left!==null&&(s=s.left)}else{if(s.right===void 0)return s.right=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;s.right!==null&&(s=s.right)}}return!1}addMany(e,t,n=!0,i=this.iterationType){let s=[],o;if(t&&(o=t[Symbol.iterator]()),!n){for(let g of e){let p=o==null?void 0:o.next().value;this.isRaw(g)&&(g=this._toEntryFn(g)),s.push(this.add(g,p))}return s}let d=[],l=0;for(let g of e)d.push({key:g,value:o==null?void 0:o.next().value,orgIndex:l}),l++;let a=[];a=d.sort(({key:g},{key:p})=>{let V,y;return this.isRaw(g)?V=this._toEntryFn(g)[0]:this.isEntry(g)?V=g[0]:this.isRealNode(g)?V=g.key:V=g,this.isRaw(p)?y=this._toEntryFn(p)[0]:this.isEntry(p)?y=p[0]:this.isRealNode(p)?y=p.key:y=p,V!=null&&y!==void 0&&y!==null?this._compare(V,y):0});let f=g=>{if(g.length===0)return;let p=Math.floor((g.length-1)/2),{key:V,value:y}=g[p],{orgIndex:b}=g[p];if(this.isRaw(V)){let _=this._toEntryFn(V);s[b]=this.add(_)}else s[b]=this.add(V,y);f(g.slice(0,p)),f(g.slice(p+1))};return i==="RECURSIVE"?f(a):(()=>{let p=[[0,a.length-1]];for(;p.length>0;){let V=p.pop();if(V){let[y,b]=V;if(y<=b){let _=y+Math.floor((b-y)/2),{key:m,value:E}=a[_],{orgIndex:K}=a[_];if(this.isRaw(m)){let N=this._toEntryFn(m);s[K]=this.add(N)}else s[K]=this.add(m,E);p.push([_+1,b]),p.push([y,_-1])}}}})(),s}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let o,d=this.isRange(e);d?o=f=>f?e.isInRange(f.key,this._comparator):!1:o=this._ensurePredicate(e);let l=f=>{if(!f||!this.isRealNode(f.left))return!1;if(d){let c=e,g=this.isReverse?c.high:c.low,p=this.isReverse?c.includeHigh:c.includeLow;return p&&this._compare(f.key,g)>=0||!p&&this._compare(f.key,g)>0}if(!d&&!this._isPredicate(e)){let c=this._extractKey(e);return c!=null&&this._compare(f.key,c)>0}return!0},a=f=>{if(!f||!this.isRealNode(f.right))return!1;if(d){let c=e,g=this.isReverse?c.low:c.high,p=(this.isReverse,c.includeLow);return p&&this._compare(f.key,g)<=0||!p&&this._compare(f.key,g)<0}if(!d&&!this._isPredicate(e)){let c=this._extractKey(e);return c!=null&&this._compare(f.key,c)<0}return!0};return super._dfs(n,"IN",t,i,s,!1,l,a,()=>!0,f=>f?o(f):!1)}rangeSearch(e,t=this._DEFAULT_NODE_CALLBACK,n=this._root,i=this.iterationType){let s=e instanceof H?e:new H(e[0],e[1]);return this.search(s,!1,t,n,i)}getNode(e,t=this._root,n=this.iterationType){var i;return(i=this.getNodes(e,!0,t,n)[0])!=null?i:void 0}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType){return super.dfs(e,t,n,i,s)}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){return super.bfs(e,t,n,!1)}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){return super.listLevels(e,t,n,!1)}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,n=this._root,i=this.iterationType){let s=this.ensureNode(n),o=[];if(!this._root||!s)return o;let d=s.key;if(i==="RECURSIVE"){let l=a=>{let f=this._compare(a.key,d);Math.sign(f)===t&&o.push(e(a)),this.isRealNode(a.left)&&l(a.left),this.isRealNode(a.right)&&l(a.right)};return l(this._root),o}else{let l=new k([this._root]);for(;l.length>0;){let a=l.shift();if(this.isRealNode(a)){let f=this._compare(a.key,d);Math.sign(f)===t&&o.push(e(a)),this.isRealNode(a.left)&&l.push(a.left),this.isRealNode(a.right)&&l.push(a.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),n=t.length;if(this._clearNodes(),t.length<1)return!1;if(e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let d=s+Math.floor((o-s)/2),l=t[d];this._isMapMode&&l!==null?this.add(l.key):l!==null&&this.add([l.key,l.value]),i(s,d-1),i(d+1,o)};return i(0,n-1),!0}else{let i=[[0,n-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,d]=s;if(o<=d){let l=o+Math.floor((d-o)/2),a=t[l];this._isMapMode&&a!==null?this.add(a.key):a!==null&&this.add([a.key,a.value]),i.push([l+1,d]),i.push([o,l-1])}}}return!0}}isAVLBalanced(e=this.iterationType){if(!this._root)return!0;let t=!0;if(e==="RECURSIVE"){let n=i=>{if(!i)return 0;let s=n(i.left),o=n(i.right);return Math.abs(s-o)>1&&(t=!1),Math.max(s,o)+1};n(this._root)}else{let n=[],i=this._root,s,o=new Map;for(;n.length>0||i;)if(i)n.push(i),i.left!==null&&(i=i.left);else if(i=n[n.length-1],!i.right||s===i.right){if(i=n.pop(),i){let d=i.left?o.get(i.left):-1,l=i.right?o.get(i.right):-1;if(Math.abs(d-l)>1)return!1;o.set(i,1+Math.max(d,l)),s=i,i=void 0}}else i=i.right}return t}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}clone(){let e=this.createTree();return this._clone(e),e}_keyValueNodeOrEntryToNodeAndValue(e,t){let[n,i]=super._keyValueNodeOrEntryToNodeAndValue(e,t);return n===null?[void 0,void 0]:[n,t!=null?t:i]}_setRoot(e){e&&(e.parent=void 0),this._root=e}_compare(e,t){return this._isReverse?-this._comparator(e,t):this._comparator(e,t)}};var De=class{constructor({frequency:r=0,max:e}){h(this,"_freq");h(this,"_max");h(this,"_freqMap");h(this,"_msb");h(this,"_negativeCount");this._freq=r,this._max=e,this._freqMap={0:0},this._msb=Te(e),this._negativeCount=r<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(r){return this._checkIndex(r),this._readSingle(r)}update(r,e){this._checkIndex(r);let t=this._readSingle(r);this._update(r,e),this._updateNegativeCount(t,t+e)}writeSingle(r,e){this._checkIndex(r),this._writeSingle(r,e)}read(r){if(!Number.isInteger(r))throw new Error("Invalid count");return this._read(Math.max(Math.min(r,this.max),0))}lowerBound(r){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(r,(e,t)=>e<t)}upperBound(r){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(r,(e,t)=>e<=t)}getPrefixSum(r){this._checkIndex(r),r++;let e=0;for(;r>0;)e+=this._getFrequency(r),r-=r&-r;return e}_getFrequency(r){return r in this.freqMap?this.freqMap[r]:this.freq*(r&-r)}_updateFrequency(r,e){this.freqMap[r]=this._getFrequency(r)+e}_checkIndex(r){if(!Number.isInteger(r))throw new Error("Invalid index: Index must be an integer.");if(r<0||r>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(r){r=r+1;let e=this._getFrequency(r),t=r-(r&-r);for(r--;r!==t;)e-=this._getFrequency(r),r-=r&-r;return e}_updateNegativeCount(r,e){r<0&&e>=0?this._negativeCount--:r>=0&&e<0&&this._negativeCount++}_update(r,e){for(r=r+1;r<=this.max;)this._updateFrequency(r,e),r+=r&-r}_writeSingle(r,e){let t=this._readSingle(r);this._update(r,e-t),this._updateNegativeCount(t,e)}_read(r){let e=r,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(r,e){let t=0,n=this.msb<<1,i=r;for(;n>t+1;){let s=t+n>>1,o=this._getFrequency(s);s<=this.max&&e(o,i)?(i-=o,t=s):n=s}return t}};var ee=class{constructor(r,e,t,n){h(this,"_start",0);h(this,"_end",0);h(this,"_value");h(this,"_sum",0);h(this,"_left");h(this,"_right");this._start=r,this._end=e,this._sum=t,this._value=n||void 0}get start(){return this._start}set start(r){this._start=r}get end(){return this._end}set end(r){this._end=r}get value(){return this._value}set value(r){this._value=r}get sum(){return this._sum}set sum(r){this._sum=r}get left(){return this._left}set left(r){this._left=r}get right(){return this._right}set right(r){this._right=r}},Pe=class{constructor(r,e,t){h(this,"_values",[]);h(this,"_start",0);h(this,"_end");h(this,"_root");e=e||0,t=t||r.length-1,this._values=r,this._start=e,this._end=t,r.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(r,e){if(r>e)return new ee(r,e,0);if(r===e)return new ee(r,e,this._values[r]);let t=r+Math.floor((e-r)/2),n=this.build(r,t),i=this.build(t+1,e),s=new ee(r,e,n.sum+i.sum);return s.left=n,s.right=i,s}updateNode(r,e,t){let n=this.root||void 0;if(!n)return;let i=(s,o,d,l)=>{if(s.start===s.end&&s.start===o){s.sum=d,l!==void 0&&(s.value=l);return}let a=s.start+Math.floor((s.end-s.start)/2);o<=a?s.left&&i(s.left,o,d,l):s.right&&i(s.right,o,d,l),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};i(n,r,e,t)}querySumByRange(r,e){let t=this.root||void 0;if(!t)return 0;if(r<0||e>=this.values.length||r>e)return NaN;let n=(i,s,o)=>{if(s<=i.start&&o>=i.end)return i.sum;let d=i.start+Math.floor((i.end-i.start)/2);if(o<=d)return i.left?n(i.left,s,o):NaN;if(s>d)return i.right?n(i.right,s,o):NaN;{let l=0,a=0;return i.left&&(l=n(i.left,s,d)),i.right&&(a=n(i.right,d+1,o)),l+a}};return n(t,r,e)}};var F=class extends S{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},Q=class u extends G{constructor(r=[],e){super([],e),r&&super.addMany(r)}createNode(r,e){return new F(r,this._isMapMode?void 0:e)}createTree(r){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse},r))}isNode(r){return r instanceof F}add(r,e){if(r===null)return!1;let t=super.add(r,e);return t&&this._balancePath(r),t}delete(r){let e=super.delete(r);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}map(r,e,t){let n=new u([],e),i=0;for(let[s,o]of this)n.add(r.call(t,s,o,i++,this));return n}clone(){let r=this.createTree();return this._clone(r),r}_swapProperties(r,e){let t=this.ensureNode(r),n=this.ensureNode(e);if(t&&n){let{key:i,value:s,height:o}=n,d=this.createNode(i,s);return d&&(d.height=o,n.key=t.key,this._isMapMode||(n.value=t.value),n.height=t.height,t.key=d.key,this._isMapMode||(t.value=d.value),t.height=d.height),n}}_balanceFactor(r){return r.right?r.left?r.right.height-r.left.height:+r.height:-r.height}_updateHeight(r){if(!r.left&&!r.right)r.height=0;else if(r.left)r.right?r.height=1+Math.max(r.right.height,r.left.height):r.height=1+r.left.height;else{let e=r.right?r.right.height:0;r.height=1+e}}_balanceLL(r){let e=r.parent,t=r.left;t!==null&&(r.parent=t),t&&t.right&&(t.right.parent=r),t&&(t.parent=e),r===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===r?e.left=t:e&&(e.right=t),t&&(r.left=t.right,t.right=r),this._updateHeight(r),t&&this._updateHeight(t)}_balanceLR(r){let e=r.parent,t=r.left,n;t&&(n=t.right),r&&n!==null&&(r.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&t!==null&&(n.left.parent=t),n.right&&(n.right.parent=r),n.parent=e),r===this.root?n&&this._setRoot(n):e&&(e.left===r?e.left=n:e.right=n),n&&(r.left=n.right,t&&(t.right=n.left),n.left=t,n.right=r),this._updateHeight(r),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balanceRR(r){let e=r.parent,t=r.right;t!==null&&(r.parent=t),t&&(t.left&&(t.left.parent=r),t.parent=e),r===this.root?t&&this._setRoot(t):e&&(e.left===r?e.left=t:e.right=t),t&&(r.right=t.left,t.left=r),this._updateHeight(r),t&&this._updateHeight(t)}_balanceRL(r){let e=r.parent,t=r.right,n;t&&(n=t.left),n!==null&&(r.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&(n.left.parent=r),n.right&&t!==null&&(n.right.parent=t),n.parent=e),r===this.root?n&&this._setRoot(n):e&&(e.left===r?e.left=n:e.right=n),n&&(r.right=n.left),t&&n&&(t.left=n.right),n&&(n.left=r),n&&(n.right=t),this._updateHeight(r),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balancePath(r){r=this.ensureNode(r);let e=this.getPathToRoot(r,t=>t,!1);for(let t=0;t<e.length;t++){let n=e[t];if(n)switch(this._updateHeight(n),this._balanceFactor(n)){case-2:n&&n.left&&(this._balanceFactor(n.left)<=0?this._balanceLL(n):this._balanceLR(n));break;case 2:n&&n.right&&(this._balanceFactor(n.right)>=0?this._balanceRR(n):this._balanceRL(n))}}}_replaceNode(r,e){return e.height=r.height,super._replaceNode(r,e)}};var A=class extends S{constructor(e,t,n="BLACK"){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right");this._color=n}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}},W=class u extends G{constructor(e=[],t){super([],t);h(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,n="BLACK"){return new A(e,this._isMapMode?void 0:t,n)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof A}clear(){super.clear(),this._root=this.NIL}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(!this.isRealNode(n))return!1;let s=this._insert(n);if(s==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._isMapMode&&this._setValue(n.key,i),this._size++,!0}return s==="UPDATED"?(this._isMapMode&&this._setValue(n.key,i),!0):!1}delete(e){if(e===null)return[];let t=[],n;if(this._isPredicate(e)?n=this.getNode(e):n=this.isRealNode(e)?e:this.getNode(e),!n)return t;let i=n.color,s;if(!this.isRealNode(n.left))n.right!==null&&(s=n.right,this._transplant(n,n.right));else if(!this.isRealNode(n.right))s=n.left,this._transplant(n,n.left);else{let o=this.getLeftMost(d=>d,n.right);o&&(i=o.color,o.right!==null&&(s=o.right),o.parent===n?this.isRealNode(s)&&(s.parent=o):(o.right!==null&&(this._transplant(o,o.right),o.right=n.right),this.isRealNode(o.right)&&(o.right.parent=o)),this._transplant(n,o),o.left=n.left,this.isRealNode(o.left)&&(o.left.parent=o),o.color=n.color)}return this._isMapMode&&this._store.delete(n.key),this._size--,i==="BLACK"&&this._deleteFixup(s),t.push({deleted:n,needBalanced:void 0}),t}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}clone(){let e=this.createTree();return this._clone(e),e}_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,n;for(;this.isRealNode(t);){n=t;let o=this._compare(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=n,n?this._compare(e.key,n.key)<0?n.left=e:n.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,n,i,s,o;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((n=e.parent.parent)==null?void 0:n.left)){let d=e.parent.parent.right;(d==null?void 0:d.color)==="RED"?(e.parent.color="BLACK",d.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 d=(o=(s=(i=e==null?void 0:e.parent)==null?void 0:i.parent)==null?void 0:s.left)!=null?o:void 0;(d==null?void 0:d.color)==="RED"?(e.parent.color="BLACK",d.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,n,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 d=o.right;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o.color="RED",this._leftRotate(o),d=o.right),((n=(t=d==null?void 0:d.left)==null?void 0:t.color)!=null?n:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.left&&(d.left.color="BLACK"),d&&(d.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let d=o.left;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(d=o.left)),((s=(i=d==null?void 0:d.right)==null?void 0:i.color)!=null?s:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.right&&(d.right.color="BLACK"),d&&(d.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 Ve=class extends F{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},He=class u extends Q{constructor(r=[],e){super([],$e(T({},e),{isMapMode:!0})),r&&this.addMany(r)}createTree(r){return new u([],T({iterationType:this.iterationType,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse,isMapMode:this._isMapMode},r))}createNode(r,e=[]){return new Ve(r,this._isMapMode?[]:e)}add(r,e){if(this.isRealNode(r))return super.add(r);let t=(n,i)=>{if(n==null)return!1;let s=()=>{let d=this.get(n);if(d!==void 0&&i!==void 0){for(let l of i)d.push(l);return!0}return!1},o=()=>{let d=this.getNode(n);if(this.isRealNode(d)){let l=this.get(d);if(l===void 0)return super.add(n,i),!0;if(i!==void 0){for(let a of i)l.push(a);return!0}else return!1}else return super.add(n,i)};return this._isMapMode?o()||s():s()||o()};if(this.isEntry(r)){let[n,i]=r;return t(n,e!==void 0?[e]:i)}return t(r,e!==void 0?[e]:void 0)}deleteValue(r,e){let t=this.get(r);if(Array.isArray(t)){let n=t.indexOf(e);return n===-1?!1:(t.splice(n,1),t.length===0&&this.delete(r),!0)}return!1}clone(){let r=this.createTree();return this._clone(r),r}};var be=class extends A{constructor(e,t){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right")}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}},je=class u extends W{constructor(r=[],e){super([],T({},e)),r&&this.addMany(r)}createTree(r){return new u([],T({iterationType:this.iterationType,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse,isMapMode:this._isMapMode},r))}createNode(r,e=[]){return new be(r,this._isMapMode?[]:e)}add(r,e){if(this.isRealNode(r))return super.add(r);let t=(n,i)=>{if(n==null)return!1;let s=()=>{let d=this.get(n);if(d!==void 0&&i!==void 0){for(let l of i)d.push(l);return!0}return!1},o=()=>{let d=this.getNode(n);if(this.isRealNode(d)){let l=this.get(d);if(l===void 0)return super.add(n,i),!0;if(i!==void 0){for(let a of i)l.push(a);return!0}else return!1}else return super.add(n,i)};return this._isMapMode?o()||s():s()||o()};if(this.isEntry(r)){let[n,i]=r;return t(n,e!==void 0?[e]:i)}return t(r,e!==void 0?[e]:void 0)}deleteValue(r,e){let t=this.get(r);if(Array.isArray(t)){let n=t.indexOf(e);return n===-1?!1:(t.splice(n,1),t.length===0&&this.delete(r),!0)}return!1}clone(){let r=this.createTree();return this._clone(r),r}};var le=class extends A{constructor(e,t,n=1,i="BLACK"){super(e,t,i);h(this,"parent");h(this,"_left");h(this,"_right");this.count=n}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}},ze=class u extends W{constructor(e=[],t){super([],t);h(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t?t.count:0),e}createNode(e,t,n="BLACK",i){return new le(e,this._isMapMode?void 0:t,i,n)}createTree(e){return new u([],T({iterationType:this.iterationType,specifyComparable:this._specifyComparable,isMapMode:this._isMapMode,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof le}add(e,t,n=1){let[i,s]=this._keyValueNodeOrEntryToNodeAndValue(e,t,n),o=(i==null?void 0:i.count)||0;return super.add(i,s)?(this._count+=o,!0):!1}delete(e,t=!1){if(e===null)return[];let n=[],i;if(this._isPredicate(e)?i=this.getNode(e):i=this.isRealNode(e)?e:this.getNode(e),!i)return n;let s=i.color,o;if(this.isRealNode(i.left))if(this.isRealNode(i.right)){let d=this.getLeftMost(l=>l,i.right);if(d){if(s=d.color,d.right!==null&&(o=d.right),d.parent===i)this.isRealNode(o)&&(o.parent=d);else{if(t||i.count<=1)d.right!==null&&(this._transplant(d,d.right),this._count-=i.count);else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;d.right=i.right,this.isRealNode(d.right)&&(d.right.parent=d)}if(t||i.count<=1)this._transplant(i,d),this._count-=i.count;else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;d.left=i.left,this.isRealNode(d.left)&&(d.left.parent=d),d.color=i.color}}else if(o=i.left,t||i.count<=1)this._transplant(i,i.left),this._count-=i.count;else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;else if(i.right!==null&&(o=i.right),t||i.count<=1)i.right!==null&&(this._transplant(i,i.right),this._count-=i.count);else return i.count--,this._count--,n.push({deleted:i,needBalanced:void 0}),n;return this._size--,s==="BLACK"&&this._deleteFixup(o),n.push({deleted:i,needBalanced:void 0}),n}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),n=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let d=s+Math.floor((o-s)/2),l=t[d];this._isMapMode&&l!==null?this.add(l.key,void 0,l.count):l!==null&&this.add(l.key,l.value,l.count),i(s,d-1),i(d+1,o)};return i(0,n-1),!0}else{let i=[[0,n-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,d]=s;if(o<=d){let l=o+Math.floor((d-o)/2),a=t[l];this._isMapMode&&a!==null?this.add(a.key,void 0,a.count):a!==null&&this.add(a.key,a.value,a.count),i.push([l+1,d]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t===null?null:t.key,void 0,t===null?0:t.count)),this._isMapMode&&(e._store=this._store),e}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}_keyValueNodeOrEntryToNodeAndValue(e,t,n=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[i,s]=e;if(i==null)return[void 0,void 0];let o=t!=null?t:s;return[this.createNode(i,o,"BLACK",n),o]}return[this.createNode(e,t,"BLACK",n),t]}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i,count:s,color:o}=t,d=this.createNode(n,i,o,s);return d&&(d.color=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.color=e.color,e.key=d.key,this._isMapMode||(e.value=d.value),e.count=d.count,e.color=d.color),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var ue=class extends F{constructor(e,t,n=1){super(e,t);h(this,"parent");h(this,"_left");h(this,"_right");this.count=n}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}},Ue=class u extends Q{constructor(e=[],t){super([],t);h(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,n){return new ue(e,this._isMapMode?void 0:t,n)}createTree(e){return new u([],T({iterationType:this.iterationType,isMapMode:this._isMapMode,specifyComparable:this._specifyComparable,toEntryFn:this._toEntryFn,isReverse:this._isReverse},e))}isNode(e){return e instanceof ue}add(e,t,n=1){let[i,s]=this._keyValueNodeOrEntryToNodeAndValue(e,t,n);if(i===void 0)return!1;let o=(i==null?void 0:i.count)||0;return super.add(i,s)&&(this._count+=o),!0}delete(e,t=!1){var l;let n=[];if(!this.root)return n;let i=(l=this.getNode(e))!=null?l:void 0;if(!i)return n;let s=i!=null&&i.parent?i.parent:void 0,o,d=i;if(i.count>1&&!t)i.count--,this._count--;else{if(i.left){let a=i.left?this.getRightMost(f=>f,i.left):void 0;if(a){let f=a.parent;d=this._swapProperties(i,a),f&&(f.right===a?f.right=a.left:f.left=a.left,o=f)}}else if(!s)i.right!==void 0&&i.right!==null&&this._setRoot(i.right);else{let{familyPosition:a}=i;a==="LEFT"||a==="ROOT_LEFT"?s.left=i.right:(a==="RIGHT"||a==="ROOT_RIGHT")&&(s.right=i.right),o=s}this._size=this._size-1,d&&(this._count-=d.count)}return n.push({deleted:d,needBalanced:o}),o&&this._balancePath(o),n}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(i=>i,"IN"),n=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let i=(s,o)=>{if(s>o)return;let d=s+Math.floor((o-s)/2),l=t[d];this._isMapMode?this.add(l.key,void 0,l.count):this.add(l.key,l.value,l.count),i(s,d-1),i(d+1,o)};return i(0,n-1),!0}else{let i=[[0,n-1]];for(;i.length>0;){let s=i.pop();if(s){let[o,d]=s;if(o<=d){let l=o+Math.floor((d-o)/2),a=t[l];this._isMapMode?this.add(a.key,void 0,a.count):this.add(a.key,a.value,a.count),i.push([l+1,d]),i.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this._isMapMode?this.bfs(t=>e.add(t.key,void 0,t.count)):this.bfs(t=>e.add(t.key,t.value,t.count)),this._isMapMode&&(e._store=this._store),e}map(e,t,n){let i=new u([],t),s=0;for(let[o,d]of this)i.add(e.call(n,o,d,s++,this));return i}_keyValueNodeOrEntryToNodeAndValue(e,t,n=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[i,s]=e;if(i==null)return[void 0,void 0];let o=t!=null?t:s;return[this.createNode(i,o,n),o]}return[this.createNode(e,t,n),t]}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i,count:s,height:o}=t,d=this.createNode(n,i,s);return d&&(d.height=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.height=e.height,e.key=d.key,this._isMapMode||(e.value=d.value),e.count=d.count,e.height=d.height),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var X=class u extends v{constructor(r=[],e){super(r,e)}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var qe=class u extends X{constructor(r=[],e){super(r,e)}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var Ge=class u extends X{constructor(r=[],e){super(r,T({comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0}},e))}clone(){return new u(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(r,e){let t=new u([],{toElementFn:this.toElementFn,comparator:this.comparator}),n=0;for(let i of this)r.call(e,i,n,this)&&t.add(i),n++;return t}map(r,e,t,n){let i=new u([],{comparator:e,toElementFn:t}),s=0;for(let o of this)i.add(r.call(n,o,s,this)),s++;return i}};var Qe=class u{constructor(r,e){h(this,"_rows",0);h(this,"_cols",0);h(this,"_data");var t,n,i;if(e){let{rows:s,cols:o,addFn:d,subtractFn:l,multiplyFn:a}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=r.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=r[0])==null?void 0:t.length)||0,d&&(this._addFn=d),l&&(this._subtractFn=l),a&&(this._multiplyFn=a)}else this._rows=r.length,this._cols=(i=(n=r[0])==null?void 0:n.length)!=null?i:0;if(r.length>0)this._data=r;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(r,e){if(this.isValidIndex(r,e))return this.data[r][e]}set(r,e,t){return this.isValidIndex(r,e)?(this.data[r][e]=t,!0):!1}isMatchForCalculate(r){return this.rows===r.rows&&this.cols===r.cols}add(r){if(!this.isMatchForCalculate(r))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let i=this.get(t,n),s=r.get(t,n);if(i!==void 0&&s!==void 0){let o=this._addFn(i,s);o&&(e[t][n]=o)}}}return new u(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(r){if(!this.isMatchForCalculate(r))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let i=this.get(t,n),s=r.get(t,n);if(i!==void 0&&s!==void 0){let o=this._subtractFn(i,s);o&&(e[t][n]=o)}}}return new u(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(r){if(this.cols!==r.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 n=0;n<r.cols;n++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=r.get(s,n);if(o!==void 0&&d!==void 0){let l=this.multiplyFn(o,d);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][n]=i)}}return new u(e,{rows:this.rows,cols:r.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 r=[];for(let e=0;e<this.cols;e++){r[e]=[];for(let t=0;t<this.rows;t++){let n=this.get(t,e);n!==void 0&&(r[e][t]=n)}}return new u(r,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var n;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let r=[];for(let i=0;i<this.rows;i++){r[i]=this.data[i].slice();for(let s=0;s<this.cols;s++)r[i][this.cols+s]=i===s?1:0}let e=new u(r,{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=(n=e.get(i,i))!=null?n: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 d=0;d<this.rows;d++)if(d!==i){let l=e.get(d,i);l===void 0&&(l=0),e._addScaledRow(d,i,-l)}}let t=[];for(let i=0;i<this.rows;i++)t[i]=e.data[i].slice(this.cols);return new u(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(r){if(this.cols!==r.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 n=0;n<r.cols;n++){let i;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=r.get(s,n);if(o!==void 0&&d!==void 0){let l=this.multiplyFn(o,d);l!==void 0&&(i=this.addFn(i,l))}}i!==void 0&&(e[t][n]=i)}}return new u(e,{rows:this.rows,cols:r.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(r,e){return r>=0&&r<this.rows&&e>=0&&e<this.cols}clone(){return new u(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(r,e){return r===void 0?e:r+e}_subtractFn(r,e){return r-e}_multiplyFn(r,e){return r*e}_swapRows(r,e){let t=this.data[r];this.data[r]=this.data[e],this.data[e]=t}_scaleRow(r,e){for(let t=0;t<this.cols;t++){let n=this.multiplyFn(this.data[r][t],e);n===void 0&&(n=0),this.data[r][t]=n}}_addScaledRow(r,e,t){for(let n=0;n<this.cols;n++){let i=this.multiplyFn(this.data[e][n],t);i===void 0&&(i=0);let s=i,o=this.addFn(this.data[r][n],s);o===void 0&&(o=0),this.data[r][n]=o}}};var ye=class u{constructor(r,e){h(this,"direction");h(this,"turn");this.direction=r,this.turn=()=>new u(e[r],e)}},We=class{constructor({matrix:r,turning:e,onMove:t,init:{cur:n,charDir:i,VISITED:s}}){h(this,"onMove");h(this,"_matrix");h(this,"_cur");h(this,"_character");h(this,"_VISITED");this._matrix=r,this._cur=n,this._character=new ye(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:r}=this._character;this.check(r)?this.move(r):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(r){let e,t,n=this._matrix,[i,s]=this._cur;switch(r){case"up":if(t=n[i-1],!t)return!1;e=t[s];break;case"right":e=n[i][s+1];break;case"down":if(t=n[i+1],!t)return!1;e=t[s];break;case"left":e=n[i][s-1];break}return e!==void 0&&e!==this._VISITED}move(r){switch(r){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 te=class{constructor(r){h(this,"_key");h(this,"_children");h(this,"_isEnd");this._key=r,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(r){this._key=r}get children(){return this._children}set children(r){this._children=r}get isEnd(){return this._isEnd}set isEnd(r){this._isEnd=r}},Xe=class u extends L{constructor(e=[],t){super(t);h(this,"_size",0);h(this,"_caseSensitive",!0);h(this,"_root",new te(""));if(t){let{caseSensitive:n}=t;n!==void 0&&(this._caseSensitive=n)}e&&this.addMany(e)}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,n=!1;for(let i of e){let s=t.children.get(i);s||(s=new te(i),t.children.set(i,s)),t=s}return t.isEnd||(n=!0,t.isEnd=!0,this._size++),n}addMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.add(this.toElementFn(n))):t.push(this.add(n));return t}has(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return t.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new te("")}delete(e){e=this._caseProcess(e);let t=!1,n=(i,s)=>{let o=e[s],d=i.children.get(o);return d?s===e.length-1?d.isEnd?(d.children.size>0?d.isEnd=!1:i.children.delete(o),t=!0,!0):!1:n(d,s+1)&&!i.isEnd&&d.children.size===0?(i.children.delete(o),!0):!1:!1};return n(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let n=(i,s)=>{s>t&&(t=s);let{children:o}=i;if(o)for(let d of o.entries())n(d[1],s+1)};n(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",n=i=>{if(t+=i.key,t!==e&&!i.isEnd)if(i&&i.children&&i.children.size===1)n(Array.from(i.children.values())[0]);else return};return n(this.root),t===e}getLongestCommonPrefix(){let e="",t=n=>{if(e+=n.key,!n.isEnd)if(n&&n.children&&n.children.size===1)t(Array.from(n.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,n=!1){e=this._caseProcess(e);let i=[],s=0;function o(l,a){for(let f of l.children.keys()){let c=l.children.get(f);c!==void 0&&o(c,a.concat(f))}if(l.isEnd){if(s>t-1)return;i.push(a),s++}}let d=this.root;if(e)for(let l of e){let a=d.children.get(l);if(a)d=a;else return[]}return(n||d!==this.root)&&o(d,e),i}clone(){return new u(this,{caseSensitive:this.caseSensitive,toElementFn:this.toElementFn})}filter(e,t){let n=new u([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive}),i=0;for(let s of this)e.call(t,s,i,this)&&n.add(s),i++;return n}map(e,t,n){let i=new u([],{toElementFn:t,caseSensitive:this.caseSensitive}),s=0;for(let o of this)i.add(e.call(n,o,s,this)),s++;return i}*_getIterator(){function*e(t,n){t.isEnd&&(yield n);for(let[i,s]of t.children)yield*B(e(s,n+i))}yield*B(e(this.root,""))}get _total(){return this._size}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var Je=class u{constructor(r,e,t){h(this,"_key");h(this,"_value");h(this,"_children");this._key=r,this._value=e||void 0,t&&(this._children=t)}get key(){return this._key}set key(r){this._key=r}get value(){return this._value}set value(r){this._value=r}get children(){return this._children}set children(r){this._children=r}addChildren(r){this._children||(this._children=[]),r instanceof u?this._children.push(r):this._children=this._children.concat(r)}getHeight(){let r=0;if(this){let e=(t,n)=>{n>r&&(r=n);let{_children:i}=t;if(i)for(let s=0,o=i.length;s<o;s++)e(i[s],n+1)};e(this,0)}return r}};return ht(mt);})();
6
6
  /**
7
7
  * data-structure-typed
8
8
  *