data-structure-typed 1.53.5 → 1.53.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +13 -11
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +27 -26
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +144 -62
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +201 -97
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +13 -11
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +27 -26
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +144 -62
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +201 -97
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/umd/data-structure-typed.js +216 -113
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +7 -7
- package/src/data-structures/linked-list/doubly-linked-list.ts +30 -26
- package/src/data-structures/linked-list/singly-linked-list.ts +219 -98
- package/testToExample.ts +0 -215
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var dataStructureTyped=(()=>{var oe=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames,Qe=Object.getOwnPropertySymbols;var Ge=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var Ee=(l,n)=>(n=Symbol[l])?n:Symbol.for("Symbol."+l),et=l=>{throw TypeError(l)};var me=(l,n,e)=>n in l?oe(l,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[n]=e,M=(l,n)=>{for(var e in n||(n={}))Ge.call(n,e)&&me(l,e,n[e]);if(Qe)for(var e of Qe(n))$e.call(n,e)&&me(l,e,n[e]);return l};var tt=(l,n)=>{for(var e in n)oe(l,e,{get:n[e],enumerable:!0})},it=(l,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Ze(n))!Ge.call(l,i)&&i!==e&&oe(l,i,{get:()=>n[i],enumerable:!(t=Je(n,i))||t.enumerable});return l};var rt=l=>it(oe({},"__esModule",{value:!0}),l);var d=(l,n,e)=>me(l,typeof n!="symbol"?n+"":n,e);var We=(l,n,e)=>new Promise((t,i)=>{var r=a=>{try{o(e.next(a))}catch(h){i(h)}},s=a=>{try{o(e.throw(a))}catch(h){i(h)}},o=a=>a.done?t(a.value):Promise.resolve(a.value).then(r,s);o((e=e.apply(l,n)).next())}),nt=function(l,n){this[0]=l,this[1]=n};var L=l=>{var n=l[Ee("asyncIterator")],e=!1,t,i={};return n==null?(n=l[Ee("iterator")](),t=r=>i[r]=s=>n[r](s)):(n=n.call(l),t=r=>i[r]=s=>{if(e){if(e=!1,r==="throw")throw s;return s}return e=!0,{done:!1,value:new nt(new Promise(o=>{var a=n[r](s);a instanceof Object||et("Object expected"),o(a)}),1)}}),i[Ee("iterator")]=()=>i,t("next"),"throw"in n?t("throw"):i.throw=r=>{throw r},"return"in n&&t("return"),i};var lt={};tt(lt,{AVLTree:()=>ie,AVLTreeMultiMap:()=>Se,AVLTreeMultiMapNode:()=>ne,AVLTreeNode:()=>U,AbstractEdge:()=>B,AbstractGraph:()=>H,AbstractVertex:()=>T,BST:()=>j,BSTNode:()=>I,BinaryIndexedTree:()=>Ie,BinaryTree:()=>te,BinaryTreeNode:()=>S,Character:()=>pe,DFSOperation:()=>Fe,Deque:()=>De,DirectedEdge:()=>W,DirectedGraph:()=>ee,DirectedVertex:()=>P,DoublyLinkedList:()=>xe,DoublyLinkedListNode:()=>z,FibonacciHeap:()=>Ke,FibonacciHeapNode:()=>le,HashMap:()=>Oe,Heap:()=>v,IterableElementBase:()=>k,IterableEntryBase:()=>C,LinkedHashMap:()=>Re,LinkedListQueue:()=>Te,MapEdge:()=>ce,MapGraph:()=>we,MapVertex:()=>fe,Matrix:()=>Pe,MaxHeap:()=>ve,MaxPriorityQueue:()=>He,MinHeap:()=>Le,MinPriorityQueue:()=>ze,Navigator:()=>je,PriorityQueue:()=>Q,Queue:()=>D,RedBlackTree:()=>re,RedBlackTreeNode:()=>q,SegmentTree:()=>Be,SegmentTreeNode:()=>X,SinglyLinkedList:()=>Z,SinglyLinkedListNode:()=>K,SkipList:()=>Me,SkipListNode:()=>$,Stack:()=>ke,THUNK_SYMBOL:()=>be,TreeMultiMap:()=>Ae,TreeMultiMapNode:()=>se,TreeNode:()=>qe,Trie:()=>Ue,TrieNode:()=>Y,UndirectedEdge:()=>de,UndirectedGraph:()=>Ce,UndirectedVertex:()=>ue,arrayRemove:()=>w,calcMinUnitsRequired:()=>he,getMSB:()=>Ve,isComparable:()=>J,isThunk:()=>Ne,isWeakKey:()=>G,rangeCheck:()=>F,roundFixed:()=>at,throwRangeError:()=>ot,toBinaryString:()=>ht,toThunk:()=>ye,trampoline:()=>ae,trampolineAsync:()=>st,uuidV4:()=>_e});var C=class{*[Symbol.iterator](...n){yield*L(this._getIterator(...n))}*entries(){for(let n of this)yield n}*keys(){for(let n of this)yield n[0]}*values(){for(let n of this)yield n[1]}every(n,e){let t=0;for(let i of this)if(!n.call(e,i[1],i[0],t++,this))return!1;return!0}some(n,e){let t=0;for(let i of this)if(n.call(e,i[1],i[0],t++,this))return!0;return!1}forEach(n,e){let t=0;for(let i of this){let[r,s]=i;n.call(e,s,r,t++,this)}}find(n,e){let t=0;for(let i of this){let[r,s]=i;if(n.call(e,s,r,t++,this))return i}}has(n){for(let e of this){let[t]=e;if(t===n)return!0}return!1}hasValue(n){for(let[,e]of this)if(e===n)return!0;return!1}get(n){for(let e of this){let[t,i]=e;if(t===n)return i}}reduce(n,e){let t=e,i=0;for(let r of this){let[s,o]=r;t=n(t,o,s,i++,this)}return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var k=class{constructor(n){d(this,"_toElementFn");if(n){let{toElementFn:e}=n;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...n){yield*L(this._getIterator(...n))}*values(){for(let n of this)yield n}every(n,e){let t=0;for(let i of this)if(!n.call(e,i,t++,this))return!1;return!0}some(n,e){let t=0;for(let i of this)if(n.call(e,i,t++,this))return!0;return!1}forEach(n,e){let t=0;for(let i of this)n.call(e,i,t++,this)}find(n,e){let t=0;for(let i of this)if(n.call(e,i,t++,this))return i}has(n){for(let e of this)if(e===n)return!0;return!1}reduce(n,e){let t=e,i=0;for(let r of this)t=n(t,r,i++,this);return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var _e=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(l){let n=Math.random()*16|0;return(l=="x"?n:n&3|8).toString(16)})},w=function(l,n){let e=-1,t=l?l.length:0,i=[];for(;++e<t;){let r=l[e];n(r,e,l)&&(i.push(r),Array.prototype.splice.call(l,e--,1),t--)}return i},be=Symbol("thunk"),Ne=l=>typeof l=="function"&&l.__THUNK__===be,ye=l=>{let n=()=>l();return n.__THUNK__=be,n},ae=l=>Object.assign((...e)=>{let t=l(...e);for(;Ne(t)&&typeof t=="function";)t=t();return t},{cont:(...e)=>ye(()=>l(...e))}),st=l=>Object.assign((...e)=>We(void 0,null,function*(){let t=yield l(...e);for(;Ne(t)&&typeof t=="function";)t=yield t();return t}),{cont:(...e)=>ye(()=>l(...e))}),Ve=l=>l<=0?0:1<<31-Math.clz32(l),F=(l,n,e,t="Index out of bounds.")=>{if(l<n||l>e)throw new RangeError(t)},ot=(l="The value is off-limits.")=>{throw new RangeError(l)},G=l=>{let n=typeof l;return n==="object"&&l!==null||n==="function"},he=(l,n)=>Math.floor((l+n-1)/n),at=(l,n=10)=>{let e=Math.pow(10,n);return Math.round(l*e)/e};function ge(l){let n=typeof l;return n==="number"?!Number.isNaN(l):n==="bigint"||n==="string"||n==="boolean"}function Xe(l){if(typeof l.valueOf=="function"){let n=l.valueOf();if(n!==l){if(ge(n))return n;if(typeof n=="object"&&n!==null)return Xe(n)}}if(typeof l.toString=="function"){let n=l.toString();if(n!=="[object Object]")return n}return null}function J(l,n=!1){if(l==null)return!1;if(ge(l))return!0;if(typeof l!="object")return!1;if(l instanceof Date)return!Number.isNaN(l.getTime());if(n)return!0;let e=Xe(l);return e==null?!1:ge(e)}function ht(l,n=32){let e=(l>>>0).toString(2);return e=e.padStart(n,"0"),e}var Oe=class l extends C{constructor(e=[],t){super();d(this,"_store",{});d(this,"_objMap",new Map);d(this,"_toEntryFn");d(this,"_size",0);d(this,"_hashFn",e=>String(e));if(t){let{hashFn:i,toEntryFn:r}=t;i&&(this._hashFn=i),r&&(this._toEntryFn=r)}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 i=this._getNoObjKey(e);this.store[i]===void 0&&this._size++,this._store[i]={key:e,value:t}}return!0}setMany(e){let t=[];for(let i of e){let r,s;if(this.isEntry(i))r=i[0],s=i[1];else if(this._toEntryFn){let o=this._toEntryFn(i);r=o[0],s=o[1]}r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}get(e){var t;if(this._isObjKey(e))return this.objMap.get(e);{let i=this._getNoObjKey(e);return(t=this._store[i])==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 l(this,{hashFn:this._hashFn,toEntryFn:this._toEntryFn})}map(e,t){let i=new l,r=0;for(let[s,o]of this)i.set(s,e.call(t,o,s,r++,this));return i}filter(e,t){let i=new l,r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&i.set(s,o);return i}*_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,i;return t!=="string"&&t!=="number"&&t!=="symbol"?i=this._hashFn(e):i=e,i}},Re=class l extends C{constructor(e=[],t){super();d(this,"_sentinel");d(this,"_hashFn",e=>String(e));d(this,"_objHashFn",e=>e);d(this,"_noObjMap",{});d(this,"_objMap",new WeakMap);d(this,"_head");d(this,"_tail");d(this,"_toEntryFn",e=>{if(this.isEntry(e))return e;throw new Error("If the provided entryOrRawElements does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.")});d(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:i,objHashFn:r,toEntryFn:s}=t;i&&(this._hashFn=i),r&&(this._objHashFn=r),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 i,r=!this.has(e);if(G(e)){let s=this._objHashFn(e);i=this.objMap.get(s),!i&&r?(i={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,i)):i&&(i.value=t)}else{let s=this._hashFn(e);i=this.noObjMap[s],!i&&r?this.noObjMap[s]=i={key:e,value:t,prev:this.tail,next:this._sentinel}:i&&(i.value=t)}return i&&r&&(this._size===0?(this._head=i,this._sentinel.next=i):(this.tail.next=i,i.prev=this.tail),this._tail=i,this._sentinel.prev=i,this._size++),!0}setMany(e){let t=[];for(let i of e){let r,s;if(this.isEntry(i))r=i[0],s=i[1];else if(this._toEntryFn){let o=this._toEntryFn(i);r=o[0],s=o[1]}r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}has(e){if(G(e)){let t=this._objHashFn(e);return this.objMap.has(t)}else return this._hashFn(e)in this.noObjMap}get(e){if(G(e)){let t=this._objHashFn(e),i=this.objMap.get(t);return i?i.value:void 0}else{let t=this._hashFn(e),i=this.noObjMap[t];return i?i.value:void 0}}at(e){F(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(G(e)){let i=this._objHashFn(e);if(t=this.objMap.get(i),!t)return!1;this.objMap.delete(i)}else{let i=this._hashFn(e);if(t=this.noObjMap[i],!t)return!1;delete this.noObjMap[i]}return this._deleteNode(t),!0}deleteAt(e){F(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 l([],{hashFn:this._hashFn,objHashFn:this._objHashFn});for(let t of this){let[i,r]=t;e.set(i,r)}return e}filter(e,t){let i=new l,r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&i.set(s,o),r++;return i}map(e,t){let i=new l,r=0;for(let[s,o]of this){let a=e.call(t,o,s,r,this);i.set(s,a),r++}return i}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:i}=e;return t.next=i,i.prev=t,e===this.head&&(this._head=i),e===this.tail&&(this._tail=t),this._size-=1,!0}};var K=class{constructor(n){d(this,"_value");d(this,"_next");this._value=n,this._next=void 0}get value(){return this._value}set value(n){this._value=n}get next(){return this._next}set next(n){this._next=n}},Z=class l extends k{constructor(e=[],t){super(t);d(this,"_head");d(this,"_tail");d(this,"_size",0);if(e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get head(){return this._head}get tail(){return this._tail}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}get size(){return this._size}static fromArray(e){let t=new l;for(let i of e)t.push(i);return t}push(e){let t=new K(e);return this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._size++,!0}pop(){if(!this.head)return;if(this.head===this.tail){let i=this.head.value;return this._head=void 0,this._tail=void 0,this._size--,i}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._size--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._size--,e.value}unshift(e){let t=new K(e);return this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._size++,!0}at(e){if(e<0||e>=this._size)return;let t=this.head;for(let i=0;i<e;i++)t=t.next;return t.value}getNodeAt(e){let t=this.head;for(let i=0;i<e;i++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._size)return!1;if(e===0)return this.shift(),!0;if(e===this._size-1)return this.pop(),!0;let t=this.getNodeAt(e-1),i=t.next;return t.next=i.next,this._size--,!0}delete(e){if(e===void 0)return!1;let t;e instanceof K?t=e.value:t=e;let i=this.head,r;for(;i;){if(i.value===t)return r===void 0?(this._head=i.next,i===this.tail&&(this._tail=void 0)):(r.next=i.next,i===this.tail&&(this._tail=r)),this._size--,!0;r=i,i=i.next}return!1}addAt(e,t){if(e<0||e>this._size)return!1;if(e===0)return this.unshift(t),!0;if(e===this._size)return this.push(t),!0;let i=new K(t),r=this.getNodeAt(e-1);return i.next=r.next,r.next=i,this._size++,!0}isEmpty(){return this._size===0}clear(){this._head=void 0,this._tail=void 0,this._size=0}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,i;for(;t;)i=t.next,t.next=e,e=t,t=i;return[this._head,this._tail]=[this.tail,this.head],this}indexOf(e){let t=0,i=this.head;for(;i;){if(i.value===e)return t;t++,i=i.next}return-1}getNode(e){let t=this.head;for(;t;){if(t.value===e)return t;t=t.next}}addBefore(e,t){if(!this.head)return!1;let i;if(e instanceof K?i=e.value:i=e,this.head.value===i)return this.unshift(t),!0;let r=this.head;for(;r.next;){if(r.next.value===i){let s=new K(t);return s.next=r.next,r.next=s,this._size++,!0}r=r.next}return!1}addAfter(e,t){let i;if(e instanceof K?i=e:i=this.getNode(e),i){let r=new K(t);return r.next=i.next,i.next=r,i===this.tail&&(this._tail=r),this._size++,!0}return!1}countOccurrences(e){let t=0,i=this.head;for(;i;)i.value===e&&t++,i=i.next;return t}clone(){return new l(this,{toElementFn:this.toElementFn})}filter(e,t){let i=new l([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new l([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}};var z=class{constructor(n){d(this,"_value");d(this,"_next");d(this,"_prev");this._value=n,this._next=void 0,this._prev=void 0}get value(){return this._value}set value(n){this._value=n}get next(){return this._next}set next(n){this._next=n}get prev(){return this._prev}set prev(n){this._prev=n}},xe=class l extends k{constructor(e=[],t){super(t);d(this,"_head");d(this,"_tail");d(this,"_size");if(this._head=void 0,this._tail=void 0,this._size=0,e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get head(){return this._head}get tail(){return this._tail}get size(){return this._size}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}isNode(e){return e instanceof z}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._size++,!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._size--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._size--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._size++,!0}at(e){if(e<0||e>=this._size)return;let t=this.head;for(let i=0;i<e;i++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this._size)return;let t=this.head;for(let i=0;i<e;i++)t=t.next;return t}getNode(e){if(e===void 0)return;let t=this._ensurePredicate(e),i=this.head;for(;i;){if(t(i))return i;i=i.next}}addAt(e,t){if(e<0||e>this._size)return!1;if(e===0)return this.unshift(t),!0;if(e===this._size)return this.push(t),!0;let i=this._ensureNode(t),r=this.getNodeAt(e-1),s=r.next;return i.prev=r,i.next=s,r.next=i,s.prev=i,this._size++,!0}addBefore(e,t){let i;if(e instanceof z?i=e:i=this.getNode(e),i){let r=this._ensureNode(t);return r.prev=i.prev,i.prev&&(i.prev.next=r),r.next=i,i.prev=r,i===this.head&&(this._head=r),this._size++,!0}return!1}addAfter(e,t){let i;if(e instanceof z?i=e:i=this.getNode(e),i){let r=this._ensureNode(t);return r.next=i.next,i.next&&(i.next.prev=r),r.prev=i,i.next=r,i===this.tail&&(this._tail=r),this._size++,!0}return!1}deleteAt(e){if(e<0||e>=this._size)return!1;if(e===0)return this.shift(),!0;if(e===this._size-1)return this.pop(),!0;let t=this.getNodeAt(e),i=t.prev,r=t.next;return i.next=r,r.prev=i,this._size--,!0}delete(e){let t=this.getNode(e);if(t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let i=t.prev,r=t.next;i&&(i.next=r),r&&(r.prev=i),this._size--}return!0}return!1}isEmpty(){return this._size===0}clear(){this._head=void 0,this._tail=void 0,this._size=0}indexOf(e){let t=this._ensurePredicate(e),i=0,r=this.head;for(;r;){if(t(r))return i;i++,r=r.next}return-1}get(e){let t=this._ensurePredicate(e),i=this.head;for(;i;){if(t(i))return i.value;i=i.next}}getBackward(e){let t=this._ensurePredicate(e),i=this.tail;for(;i;){if(t(i))return i.value;i=i.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}toReversedArray(){let e=[],t=this.tail;for(;t;)e.push(t.value),t=t.prev;return e}clone(){return new l(this)}filter(e,t){let i=new l([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new l([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}static fromArray(e){return new l(e)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new z(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}};var $=class{constructor(n,e,t){d(this,"key");d(this,"value");d(this,"forward");this.key=n,this.value=e,this.forward=new Array(t)}},Me=class{constructor(n=[],e){d(this,"_head",new $(void 0,void 0,this.maxLevel));d(this,"_level",0);d(this,"_maxLevel",16);d(this,"_probability",.5);if(e){let{maxLevel:t,probability:i}=e;typeof t=="number"&&(this._maxLevel=t),typeof i=="number"&&(this._probability=i)}if(n)for(let[t,i]of n)this.add(t,i)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let n=this.head.forward[0];return n?n.value:void 0}get last(){let n=this.head;for(let e=this.level-1;e>=0;e--)for(;n.forward[e];)n=n.forward[e];return n.value}add(n,e){let t=new $(n,e,this._randomLevel()),i=new Array(this.maxLevel).fill(this.head),r=this.head;for(let s=this.level-1;s>=0;s--){for(;r.forward[s]&&r.forward[s].key<n;)r=r.forward[s];i[s]=r}for(let s=0;s<t.forward.length;s++)t.forward[s]=i[s].forward[s],i[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(n){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<n;)e=e.forward[t];if(e=e.forward[0],e&&e.key===n)return e.value}has(n){return this.get(n)!==void 0}delete(n){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let i=this.level-1;i>=0;i--){for(;t.forward[i]&&t.forward[i].key<n;)t=t.forward[i];e[i]=t}if(t=t.forward[0],t&&t.key===n){for(let i=0;i<this.level&&e[i].forward[i]===t;i++)e[i].forward[i]=t.forward[i];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(n){let e=this.head;for(let i=this.level-1;i>=0;i--)for(;e.forward[i]&&e.forward[i].key<=n;)e=e.forward[i];let t=e.forward[0];return t?t.value:void 0}lower(n){let e=this.head,t;for(let i=this.level-1;i>=0;i--){for(;e.forward[i]&&e.forward[i].key<n;)e=e.forward[i];e.key<n&&(t=e)}return t?t.value:void 0}_randomLevel(){let n=1;for(;Math.random()<this.probability&&n<this.maxLevel;)n++;return n}};var ke=class l extends k{constructor(e=[],t){super(t);d(this,"_elements",[]);if(e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e){return new l(e)}isEmpty(){return this.elements.length===0}peek(){if(!this.isEmpty())return this.elements[this.elements.length-1]}push(e){return this.elements.push(e),!0}pop(){if(!this.isEmpty())return this.elements.pop()}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}toArray(){return this.elements.slice()}clear(){this._elements=[]}clone(){return new l(this,{toElementFn:this.toElementFn})}filter(e,t){let i=new l([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new l([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var D=class l extends k{constructor(e=[],t){super(t);d(this,"_elements",[]);d(this,"_offset",0);d(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:i=.5}=t;this._autoCompactRatio=i}if(e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get elements(){return this._elements}get offset(){return this._offset}get size(){return this.elements.length-this.offset}get first(){return this.size>0?this.elements[this.offset]:void 0}get last(){return this.size>0?this.elements[this.elements.length-1]:void 0}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}static fromArray(e){return new l(e)}push(e){return this.elements.push(e),!0}shift(){if(this.size===0)return;let e=this.first;return this._offset+=1,this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}at(e){return this.elements[e+this._offset]}isEmpty(){return this.size===0}toArray(){return this.elements.slice(this.offset)}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this.offset),this._offset=0,!0}clone(){return new l(this.elements.slice(this.offset),{toElementFn:this.toElementFn})}filter(e,t){let i=new l([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new l([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){for(let e of this.elements.slice(this.offset))yield e}},Te=class l extends Z{clone(){return new l(this,{toElementFn:this.toElementFn})}};var De=class l extends k{constructor(e=[],t){super(t);d(this,"_bucketSize",4096);d(this,"_maxLen",-1);d(this,"_bucketFirst",0);d(this,"_firstInBucket",0);d(this,"_bucketLast",0);d(this,"_lastInBucket",0);d(this,"_bucketCount",0);d(this,"_buckets",[]);d(this,"_size",0);if(t){let{bucketSize:s,maxLen:o}=t;typeof s=="number"&&(this._bucketSize=s),typeof o=="number"&&o>0&&o%1===0&&(this._maxLen=o)}let i;"length"in e?e.length instanceof Function?i=e.length():i=e.length:e.size instanceof Function?i=e.size():i=e.size,this._bucketCount=he(i,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let r=he(i,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(r>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-i%this._bucketSize>>1;for(let s of e)this.toElementFn?this.push(this.toElementFn(s)):this.push(s)}get bucketSize(){return this._bucketSize}get maxLen(){return this._maxLen}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get size(){return this._size}get first(){if(this._size!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._size!==0)return this._buckets[this._bucketLast][this._lastInBucket]}push(e){return this._size&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._size+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._size>this._maxLen&&this.shift(),!0}pop(){if(this._size===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._size!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._size-=1,e}unshift(e){return this._size&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._size+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._size>this._maxLen&&this.pop(),!0}shift(){if(this._size===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._size!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._size-=1,e}isEmpty(){return this._size===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._size=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}*begin(){let e=0;for(;e<this._size;)yield this.at(e),e++}*reverseBegin(){let e=this._size-1;for(;e>=0;)yield this.at(e),e--}at(e){F(e,0,this._size-1);let{bucketIndex:t,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[t][i]}setAt(e,t){F(e,0,this._size-1);let{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);return this._buckets[i][r]=t,!0}addAt(e,t,i=1){let r=this._size;if(F(e,0,r),e===0)for(;i--;)this.unshift(t);else if(e===this._size)for(;i--;)this.push(t);else{let s=[];for(let o=e;o<this._size;++o)s.push(this.at(o));this.cut(e-1,!0);for(let o=0;o<i;++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:i,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketLast=i,this._lastInBucket=r,this._size=e+1,this}else{let i=new l([],{bucketSize:this._bucketSize});for(let r=0;r<=e;r++)i.push(this.at(r));return i}}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketFirst=i,this._firstInBucket=r,this._size=this._size-e,this}else{let i=new l([],{bucketSize:this._bucketSize});e<0&&(e=0);for(let r=e;r<this._size;r++)i.push(this.at(r));return i}}deleteAt(e){if(F(e,0,this._size-1),e===0)this.shift();else if(e===this._size-1)this.pop();else{let t=this._size-1,{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);for(let s=e;s<t;++s){let{bucketIndex:o,indexInBucket:a}=this._getBucketAndPosition(e+1);this._buckets[i][r]=this._buckets[o][a],i=o,r=a}this.pop()}return!0}delete(e){let t=this._size;if(t===0)return!1;let i=0,r=0;for(;i<t;){let s=this.at(i);s!==e&&(this.setAt(r,s),r+=1),i+=1}return this.cut(r-1,!0),!0}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:i,_lastInBucket:r}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-r-1,this._lastInBucket=this._bucketSize-i-1,this}unique(){if(this._size<=1)return this;let e=1,t=this.at(0);for(let i=1;i<this._size;++i){let r=this.at(i);r!==t&&(t=r,this.setAt(e++,r))}return this.cut(e-1,!0),this}sort(e){let t=[];for(let i=0;i<this._size;++i)t.push(this.at(i));t.sort(e);for(let i=0;i<this._size;++i)this.setAt(i,t[i]);return this}shrinkToFit(){if(this._size===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}indexOf(e){for(let t=0;t<this._size;++t)if(this.at(t)===e)return t;return-1}toArray(){return[...this]}clone(){return new l(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn})}filter(e,t){let i=new l([],{bucketSize:this._bucketSize,toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new l([],{bucketSize:this._bucketSize,toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){for(let e=0;e<this._size;++e)yield this.at(e)}_reallocate(e){let t=[],i=e||this._bucketCount>>1||1;for(let r=0;r<i;++r)t[r]=new Array(this._bucketSize);for(let r=this._bucketFirst;r<this._bucketCount;++r)t[t.length]=this._buckets[r];for(let r=0;r<this._bucketLast;++r)t[t.length]=this._buckets[r];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=i,this._bucketLast=t.length-1;for(let r=0;r<i;++r)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,i,r=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(r/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),i=(r+1)%this._bucketSize-1,i<0&&(i=this._bucketSize-1),{bucketIndex:t,indexInBucket:i}}};var v=class l extends k{constructor(e=[],t){super(t);d(this,"_elements",[]);d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:i}=t;i&&(this._comparator=i)}if(e)for(let i of e)this.toElementFn?this.add(this.toElementFn(i)):this.add(i)}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 l(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=e,this.fix()}has(e){return this.elements.includes(e)}delete(e){let t=this.elements.indexOf(e);return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}dfs(e="PRE"){let t=[],i=r=>{let s=2*r+1,o=s+1;r<this.size&&(e==="IN"?(i(s),t.push(this.elements[r]),i(o)):e==="PRE"?(t.push(this.elements[r]),i(s),i(o)):e==="POST"&&(i(s),i(o),t.push(this.elements[r])))};return i(0),t}toArray(){return[...this.elements]}clone(){return new l(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){let e=[],t=new l(this,{comparator:this.comparator});for(;t.size!==0;){let i=t.poll();i!==void 0&&e.push(i)}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 i=new l([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let s of this)e.call(t,s,r,this)&&i.add(s),r++;return i}map(e,t,i,r){let s=new l([],{comparator:t,toElementFn:i}),o=0;for(let a of this)s.add(e.call(r,a,o,this)),o++;return s}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let i=e-1>>1,r=this.elements[i];if(this.comparator(r,t)<=0)break;this.elements[e]=r,e=i}return this.elements[e]=t,!0}_sinkDown(e,t){let i=this.elements[e];for(;e<t;){let r=e<<1|1,s=r+1,o=this.elements[r];if(s<this.elements.length&&this.comparator(o,this.elements[s])>0&&(r=s,o=this.elements[s]),this.comparator(o,i)>=0)break;this.elements[e]=o,e=r}return this.elements[e]=i,!0}},le=class{constructor(n,e=0){d(this,"element");d(this,"degree");d(this,"left");d(this,"right");d(this,"child");d(this,"parent");d(this,"marked");this.element=n,this.degree=e,this.marked=!1}},Ke=class{constructor(n){d(this,"_root");d(this,"_size",0);d(this,"_min");d(this,"_comparator");if(this.clear(),this._comparator=n||this._defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap constructor: given comparator should be a function.")}get root(){return this._root}get size(){return this._size}get min(){return this._min}get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(n){return this.push(n)}push(n){let e=this.createNode(n);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this._min=e),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(n){let e=[];if(!n)return e;let t=n,i=!1;for(;!(t===n&&i);)t===n&&(i=!0),t&&(e.push(t),t=t.right);return e}mergeWithChild(n,e){n.child?(e.right=n.child.right,e.left=n.child,n.child.right.left=e,n.child.right=e):n.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let n=this.min;if(n.child){let e=this.consumeLinkedList(n.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(n),n===n.right?(this._min=void 0,this._root=void 0):(this._min=n.right,this._consolidate()),this._size--,n.element}merge(n){if(n.size!==0){if(this.root&&n.root){let e=this.root,t=n.root,i=e.right,r=t.left;e.right=t,t.left=e,i.left=r,r.right=i}(!this.min||n.min&&this.comparator(n.min.element,this.min.element)<0)&&(this._min=n.min),this._size+=n.size,n.clear()}}createNode(n){return new le(n)}_defaultComparator(n,e){return n<e?-1:n>e?1:0}mergeWithRoot(n){this.root?(n.right=this.root.right,n.left=this.root,this.root.right.left=n,this.root.right=n):this._root=n}removeFromRoot(n){this.root===n&&(this._root=n.right),n.left&&(n.left.right=n.right),n.right&&(n.right.left=n.left)}_link(n,e){this.removeFromRoot(n),n.left=n,n.right=n,this.mergeWithChild(e,n),e.degree++,n.parent=e}_consolidate(){let n=new Array(this._size),e=this.consumeLinkedList(this.root),t,i,r,s;for(let o of e){for(t=o,r=t.degree;n[r];)i=n[r],this.comparator(t.element,i.element)>0&&(s=t,t=i,i=s),this._link(i,t),n[r]=void 0,r++;n[r]=t}for(let o=0;o<this._size;o++)n[o]&&this.comparator(n[o].element,this.min.element)<=0&&(this._min=n[o])}};var ve=class l extends v{constructor(n=[],e){super(n,M({comparator:(t,i)=>{if(typeof t=="object"||typeof i=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<i?1:t>i?-1:0}},e))}clone(){return new l(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new l([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new l([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var Le=class l extends v{constructor(n=[],e){super(n,e)}clone(){return new l(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new l([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new l([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var T=class{constructor(n,e){d(this,"key");d(this,"value");this.key=n,this.value=e}},B=class{constructor(n,e){d(this,"value");d(this,"weight");d(this,"_hashCode");this.weight=n!==void 0?n:1,this.value=e,this._hashCode=_e()}get hashCode(){return this._hashCode}},H=class extends C{constructor(){super();d(this,"_vertexMap",new Map)}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof T)return this._addVertex(e);{let i=this.createVertex(e,t);return this._addVertex(i)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let i of e)t.push(this.deleteVertex(i));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,i,r){if(e instanceof B)return this._addEdge(e);if(t instanceof T||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof T&&(e=e.key),t instanceof T&&(t=t.key);let s=this.createEdge(e,t,i,r);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,i){let r=this.getEdge(e,t);return r?(r.weight=i,!0):!1}getAllPathsBetween(e,t,i=1e3){let r=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let a=[];for(a.push({vertex:s,path:[s]});a.length>0;){let{vertex:h,path:u}=a.pop();if(h===o&&(r.push(u),r.length>=i))return r;let f=this.getNeighbors(h);for(let p of f)if(!u.includes(p)){let c=[...u,p];a.push({vertex:p,path:c})}}return r}getPathSumWeight(e){var i;let t=0;for(let r=0;r<e.length;r++)t+=((i=this.getEdge(e[r],e[r+1]))==null?void 0:i.weight)||0;return t}getMinCostBetween(e,t,i){if(i===void 0&&(i=!1),i){let r=this.getAllPathsBetween(e,t),s=1/0;for(let o of r)s=Math.min(this.getPathSumWeight(o),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let o=new Map,a=new D([s]);o.set(s,!0);let h=0;for(;a.size>0;){for(let u=0;u<a.size;u++){let f=a.shift();if(f===r)return h;if(f!==void 0){let p=this.getNeighbors(f);for(let c of p)o.has(c)||(o.set(c,!0),a.push(c))}}h++}return}}getMinPathBetween(e,t,i,r=!1){var s,o;if(i===void 0&&(i=!1),i)if(r){let a=this.getAllPathsBetween(e,t,1e4),h=1/0,u=-1,f=0;for(let p of a){let c=this.getPathSumWeight(p);c<h&&(h=c,u=f),f++}return a[u]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let a=[],h=this._getVertex(e),u=this._getVertex(t);if(!(h&&u))return[];let f=(p,c,g,_)=>{if(g.add(p),p===c){a=[h,..._];return}let m=this.getNeighbors(p);for(let O of m)g.has(O)||(_.push(O),f(O,c,g,_),_.pop());g.delete(p)};return f(h,u,new Set,[]),a}}dijkstraWithoutHeap(e,t=void 0,i=!1,r=!1){let s=1/0,o,a=[],h=[],u=this._vertexMap,f=new Map,p=new Set,c=new Map,g=this._getVertex(e),_=t?this._getVertex(t):void 0;if(!g)return;for(let b of u){let E=b[1];E instanceof T&&f.set(E,1/0)}f.set(g,0),c.set(g,void 0);let m=()=>{let b=1/0,E;for(let[N,y]of f)p.has(N)||y<b&&(b=y,E=N);return E},O=b=>{for(let E of u){let N=E[1];if(N instanceof T){let y=[N],V=c.get(N);for(;V;)y.push(V),V=c.get(V);let R=y.reverse();E[1]===b&&(a=R),h.push(R)}}};for(let b=1;b<u.size;b++){let E=m();if(E){if(p.add(E),_&&_===E)return i&&(s=f.get(_)||1/0),r&&O(_),{distMap:f,preMap:c,seen:p,paths:h,minDist:s,minPath:a};let N=this.getNeighbors(E);for(let y of N)if(!p.has(y)){let V=this.getEdge(E,y);if(V){let R=f.get(E),x=f.get(y);R!==void 0&&x!==void 0&&V.weight+R<x&&(f.set(y,V.weight+R),c.set(y,E))}}}}return i&&f.forEach((b,E)=>{E!==g&&b<s&&(s=b,r&&(o=E))}),r&&O(o),{distMap:f,preMap:c,seen:p,paths:h,minDist:s,minPath:a}}dijkstra(e,t=void 0,i=!1,r=!1){var b;let s=1/0,o,a=[],h=[],u=this._vertexMap,f=new Map,p=new Set,c=new Map,g=this._getVertex(e),_=t?this._getVertex(t):void 0;if(!g)return;for(let E of u){let N=E[1];N instanceof T&&f.set(N,1/0)}let m=new v([],{comparator:(E,N)=>E.key-N.key});m.add({key:0,value:g}),f.set(g,0),c.set(g,void 0);let O=E=>{for(let N of u){let y=N[1];if(y instanceof T){let V=[y],R=c.get(y);for(;R;)V.push(R),R=c.get(R);let x=V.reverse();N[1]===E&&(a=x),h.push(x)}}};for(;m.size>0;){let E=m.poll(),N=E==null?void 0:E.key,y=E==null?void 0:E.value;if(N!==void 0&&y){if(p.add(y),_&&_===y)return i&&(s=f.get(_)||1/0),r&&O(_),{distMap:f,preMap:c,seen:p,paths:h,minDist:s,minPath:a};let V=this.getNeighbors(y);for(let R of V)if(!p.has(R)){let x=(b=this.getEdge(y,R))==null?void 0:b.weight;if(typeof x=="number"){let A=f.get(R);A&&N+x<A&&(m.add({key:N+x,value:R}),c.set(R,y),f.set(R,N+x))}}}}return i&&f.forEach((E,N)=>{N!==g&&E<s&&(s=E,r&&(o=N))}),r&&O(o),{distMap:f,preMap:c,seen:p,paths:h,minDist:s,minPath:a}}bellmanFord(e,t,i,r){i===void 0&&(i=!1),r===void 0&&(r=!1);let s=this._getVertex(e),o=[],a=new Map,h=new Map,u=1/0,f=[],p;if(t&&(p=!1),!s)return{hasNegativeCycle:p,distMap:a,preMap:h,paths:o,min:u,minPath:f};let c=this._vertexMap,g=c.size,_=this.edgeSet(),m=_.length;this._vertexMap.forEach(b=>{a.set(b,1/0)}),a.set(s,0);for(let b=1;b<g;++b)for(let E=0;E<m;++E){let N=this.getEndsOfEdge(_[E]);if(N){let[y,V]=N,R=_[E].weight,x=a.get(y),A=a.get(V);x!==void 0&&A!==void 0&&a.get(y)!==1/0&&x+R<A&&(a.set(V,x+R),r&&h.set(V,y))}}let O;if(i&&a.forEach((b,E)=>{E!==s&&b<u&&(u=b,r&&(O=E))}),r)for(let b of c){let E=b[1];if(E instanceof T){let N=[E],y=h.get(E);for(;y!==void 0;)N.push(y),y=h.get(y);let V=N.reverse();b[1]===O&&(f=V),o.push(V)}}for(let b=0;b<m;++b){let E=this.getEndsOfEdge(_[b]);if(E){let[N]=E,y=_[b].weight,V=a.get(N);V&&V!==1/0&&V+y<V&&(p=!0)}}return{hasNegativeCycle:p,distMap:a,preMap:h,paths:o,min:u,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,i=[],r=[];for(let o=0;o<t;o++){i[o]=[],r[o]=[];for(let a=0;a<t;a++)r[o][a]=void 0}for(let o=0;o<t;o++)for(let a=0;a<t;a++)i[o][a]=((s=this.getEdge(e[o][1],e[a][1]))==null?void 0:s.weight)||1/0;for(let o=0;o<t;o++)for(let a=0;a<t;a++)for(let h=0;h<t;h++)i[a][h]>i[a][o]+i[o][h]&&(i[a][h]=i[a][o]+i[o][h],r[a][h]=e[o][1]);return{costs:i,predecessor:r}}getCycles(e=!1){let t=[],i=new Set,r=(o,a,h)=>{if(h.has(o)){(!e&&a.length>2||e&&a.length>=2)&&a[0]===o.key&&t.push([...a]);return}h.add(o),a.push(o.key);for(let u of this.getNeighbors(o))u&&r(u,a,h);h.delete(o),a.pop()};for(let o of this.vertexMap.values())r(o,[],i);let s=new Map;for(let o of t){let a=[...o].sort().toString();s.has(a)||s.set(a,o)}return[...s].map(o=>o[1])}filter(e,t){let i=[],r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&i.push([s,o]),r++;return i}map(e,t){let i=[],r=0;for(let[s,o]of this)i.push(e.call(t,o,s,r,this)),r++;return i}*_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 T?e.key:e}};var P=class extends T{constructor(n,e){super(n,e)}},W=class extends B{constructor(e,t,i,r){super(i,r);d(this,"src");d(this,"dest");this.src=e,this.dest=t}},ee=class l extends H{constructor(){super();d(this,"_outEdgeMap",new Map);d(this,"_inEdgeMap",new Map)}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(e){this._outEdgeMap=e}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(e){this._inEdgeMap=e}createVertex(e,t){return new P(e,t)}createEdge(e,t,i,r){return new W(e,t,i!=null?i:1,r)}getEdge(e,t){let i=[];if(e!==void 0&&t!==void 0){let r=this._getVertex(e),s=this._getVertex(t);if(r&&s){let o=this._outEdgeMap.get(r);o&&(i=o.filter(a=>a.dest===s.key))}}return i[0]||void 0}deleteEdgeSrcToDest(e,t){let i=this._getVertex(e),r=this._getVertex(t),s;if(!i||!r)return;let o=this._outEdgeMap.get(i);o&&w(o,h=>h.dest===r.key);let a=this._inEdgeMap.get(r);return a&&(s=w(a,h=>h.src===i.key)[0]||void 0),s}deleteEdge(e,t){let i,r,s;if(this.isVertexKey(e))if(this.isVertexKey(t))r=this._getVertex(e),s=this._getVertex(t);else return;else r=this._getVertex(e.src),s=this._getVertex(e.dest);if(r&&s){let o=this._outEdgeMap.get(r);o&&o.length>0&&w(o,h=>h.src===r.key&&h.dest===(s==null?void 0:s.key));let a=this._inEdgeMap.get(s);a&&a.length>0&&(i=w(a,h=>h.src===r.key&&h.dest===s.key)[0])}return i}deleteVertex(e){let t,i;if(this.isVertexKey(e)?(i=this.getVertex(e),t=e):(i=e,t=this._getVertexKey(e)),i){let r=this.getNeighbors(i);for(let s of r)this.deleteEdgeSrcToDest(i,s);this._outEdgeMap.delete(i),this._inEdgeMap.delete(i)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let i=[];if(e&&t){let r=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);r&&i.push(r),s&&i.push(s)}return i}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=[],i=this.outgoingEdgesOf(e);for(let r of i){let s=this.getEdgeDest(r);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 i=[],r=!1,s=o=>{t.set(o,1);let a=this.getDestinations(o);for(let h of a){let u=t.get(h);u===0?s(h):u===1&&(r=!0)}t.set(o,2),i.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!r)return e==="key"&&(i=i.map(o=>o instanceof P?o.key:o)),i.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],i=this._getVertex(e);if(i){let r=this.outgoingEdgesOf(i);for(let s of r){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),i=this._getVertex(e.dest);if(t&&i)return[t,i]}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 l;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,i=new Map,r=0,s=[],o=new Set,a=h=>{e.set(h,r),t.set(h,r),r++,s.push(h),o.add(h);let u=this.getNeighbors(h);for(let f of u)e.has(f)?o.has(f)&&t.set(h,Math.min(t.get(h),e.get(f))):(a(f),t.set(h,Math.min(t.get(h),t.get(f))));if(e.get(h)===t.get(h)){let f=[],p;do p=s.pop(),o.delete(p),f.push(p);while(p!==h);i.set(i.size,f)}};for(let h of this.vertexMap.values())e.has(h)||a(h);return{dfnMap:e,lowMap:t,SCCs:i}}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),i=this._getVertex(e.dest);if(t&&i){let r=this._outEdgeMap.get(t);r?r.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(i);return s?s.push(e):this._inEdgeMap.set(i,[e]),!0}else return!1}};var ue=class extends T{constructor(n,e){super(n,e)}},de=class extends B{constructor(e,t,i,r){super(i,r);d(this,"endpoints");this.endpoints=[e,t]}},Ce=class l extends H{constructor(){super();d(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}createVertex(e,t){return new ue(e,t!=null?t:e)}createEdge(e,t,i,r){return new de(e,t,i!=null?i:1,r)}getEdge(e,t){var r;let i=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(i=(r=this._edgeMap.get(s))==null?void 0:r.filter(a=>a.endpoints.includes(o.key)))}return i&&i[0]||void 0}deleteEdgeBetween(e,t){let i=this._getVertex(e),r=this._getVertex(t);if(!i||!r)return;let s=this._edgeMap.get(i),o;s&&(o=w(s,h=>h.endpoints.includes(r.key))[0]||void 0);let a=this._edgeMap.get(r);return a&&w(a,h=>h.endpoints.includes(i.key)),o}deleteEdge(e,t){let i,r;if(this.isVertexKey(e))if(this.isVertexKey(t))i=this._getVertex(e),r=this._getVertex(t);else return;else i=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(i&&r)return this.deleteEdgeBetween(i,r)}deleteVertex(e){let t,i;this.isVertexKey(e)?(i=this.getVertex(e),t=e):(i=e,t=this._getVertexKey(e));let r=this.getNeighbors(e);return i&&(r.forEach(s=>{let o=this._edgeMap.get(s);if(o){let a=o.filter(h=>!h.endpoints.includes(t));this._edgeMap.set(s,a)}}),this._edgeMap.delete(i)),this._vertexMap.delete(t)}degreeOf(e){var i;let t=this._getVertex(e);return t&&((i=this._edgeMap.get(t))==null?void 0:i.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(i=>{e.add(i)})}),[...e]}getNeighbors(e){let t=[],i=this._getVertex(e);if(i){let r=this.edgesOf(i);for(let s of r){let o=this._getVertex(s.endpoints.filter(a=>a!==i.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]),i=this._getVertex(e.endpoints[1]);if(t&&i)return[t,i]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){let e=new l;return e.vertexMap=new Map(this.vertexMap),e.edgeMap=new Map(this.edgeMap),e}tarjan(){let e=new Map,t=new Map,i=[],r=[],s=0,o=(a,h)=>{e.set(a,s),t.set(a,s),s++;let u=this.getNeighbors(a),f=0;for(let p of u)if(e.has(p))p!==h&&t.set(a,Math.min(t.get(a),e.get(p)));else{if(f++,o(p,a),t.set(a,Math.min(t.get(a),t.get(p))),t.get(p)>e.get(a)){let c=this.getEdge(a,p);c&&i.push(c)}h!==void 0&&t.get(p)>=e.get(a)&&r.push(a)}h===void 0&&f>1&&r.push(a)};for(let a of this.vertexMap.values())e.has(a)||o(a,void 0);return{dfnMap:e,lowMap:t,bridges:i,cutVertices:r}}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 i=this._getVertex(t);if(i===void 0)return!1;if(i){let r=this._edgeMap.get(i);r?r.push(e):this._edgeMap.set(i,[e])}}return!0}};var fe=class extends P{constructor(e,t,i,r){super(e,t);d(this,"lat");d(this,"long");this.lat=i,this.long=r}},ce=class extends W{constructor(n,e,t,i){super(n,e,t,i)}},we=class l extends ee{constructor(e,t){super();d(this,"_originCoord",[0,0]);d(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,i=this.originCoord[0],r=this.originCoord[1]){return new fe(e,t,i,r)}createEdge(e,t,i,r){return new ce(e,t,i,r)}clone(){let e=new l(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 Fe=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(Fe||{});var S=class{constructor(n,e){d(this,"key");d(this,"value");d(this,"parent");d(this,"_left");d(this,"_right");this.key=n,this.value=e}get left(){return this._left}set left(n){n&&(n.parent=this),this._left=n}get right(){return this._right}set right(n){n&&(n.parent=this),this._right=n}get familyPosition(){let n=this;return this.parent?this.parent.left===n?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===n?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},te=class l extends C{constructor(e=[],t){super();d(this,"iterationType","ITERATIVE");d(this,"_isMapMode",!0);d(this,"_store",new Map);d(this,"_root");d(this,"_size",0);d(this,"_NIL",new S(NaN));d(this,"_toEntryFn");d(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:i,toEntryFn:r,isMapMode:s}=t;if(i&&(this.iterationType=i),s!==void 0&&(this._isMapMode=s),typeof r=="function")this._toEntryFn=r;else if(r)throw TypeError("toEntryFn must be a function type")}e&&this.addMany(e)}get isMapMode(){return this._isMapMode}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 S(e,this._isMapMode?void 0:t)}createTree(e){return new l([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,toEntryFn:this._toEntryFn},e))}keyValueNodeEntryRawToNodeAndValue(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[i,r]=e;if(i===void 0)return[void 0,void 0];if(i===null)return[null,void 0];let s=t!=null?t:r;return[this.createNode(i,s),s]}if(this.isKey(e))return[this.createNode(e,t),t];if(this.isRaw(e)){if(this._toEntryFn){let[i,r]=this._toEntryFn(e),s=t!=null?t:r;if(this.isKey(i))return[this.createNode(i,s),s]}return[void 0,void 0]}return[void 0,void 0]}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 i=e[0];return i===null?null:i===void 0?void 0:this.getNodeByKey(i,t)}if(this._toEntryFn){let[i]=this._toEntryFn(e);if(this.isKey(i))return this.getNodeByKey(i)}if(this.isKey(e))return this.getNodeByKey(e,t)}}isNode(e){return e instanceof S}isRaw(e){return 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}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}isKey(e){return e===null?!0:J(e)}add(e,t){let[i,r]=this.keyValueNodeEntryRawToNodeAndValue(e,t);if(i===void 0)return!1;if(!this._root)return this._setRoot(i),this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size=1,!0;let s=new D([this._root]),o;for(;s.size>0;){let a=s.shift();if(a){if(i!==null&&a.key===i.key)return this._replaceNode(a,i),this._isMapMode&&this._setValue(a.key,r),!0;o===void 0&&(a.left===void 0||a.right===void 0)&&(o=a),a.left!==null&&a.left&&s.push(a.left),a.right!==null&&a.right&&s.push(a.right)}}return o?(o.left===void 0?o.left=i:o.right===void 0&&(o.right=i),this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0):!1}addMany(e,t){let i=[],r;t&&(r=t[Symbol.iterator]());for(let s of e){let o;if(r){let a=r.next();a.done||(o=a.value)}i.push(this.add(s,o))}return i}refill(e,t){this.clear(),this.addMany(e,t)}delete(e){let t=[];if(!this._root)return t;let i=this.getNode(e);if(!i)return t;let r=i==null?void 0:i.parent,s,o=i;if(!i.left&&!i.right&&!r)this._setRoot(void 0);else if(i.left){let a=this.getRightMost(h=>h,i.left);if(a){let h=a.parent;o=this._swapProperties(i,a),h&&(h.right===a?h.right=a.left:h.left=a.left,s=h)}}else if(r){let{familyPosition:a}=i;a==="LEFT"||a==="ROOT_LEFT"?r.left=i.right:(a==="RIGHT"||a==="ROOT_RIGHT")&&(r.right=i.right),s=r}else this._setRoot(i.right),i.right=void 0;return this._size=this._size-1,t.push({deleted:o,needBalanced:s}),this._isMapMode&&o&&this._store.delete(o.key),t}getNodes(e,t=!1,i=this._root,r=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let s=this._ensurePredicate(e),o=[];if(r==="RECURSIVE"){let a=h=>{s(h)&&(o.push(h),t)||!this.isRealNode(h.left)&&!this.isRealNode(h.right)||(this.isRealNode(h.left)&&a(h.left),this.isRealNode(h.right)&&a(h.right))};a(i)}else{let a=[i];for(;a.length>0;){let h=a.pop();if(this.isRealNode(h)){if(s(h)&&(o.push(h),t))return o;this.isRealNode(h.left)&&a.push(h.left),this.isRealNode(h.right)&&a.push(h.right)}}}return o}getNode(e,t=this._root,i=this.iterationType){var r;return(r=this.getNodes(e,!0,t,i)[0])!=null?r:null}getNodeByKey(e,t=this.iterationType){return this.getNode(e,this._root,t)}get(e,t=this._root,i=this.iterationType){var r;if(this._isMapMode){let s=this._getKey(e);return s==null?void 0:this._store.get(s)}return(r=this.getNode(e,t,i))==null?void 0:r.value}has(e,t=this._root,i=this.iterationType){return this.getNodes(e,!0,t,i).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 i=(o,a,h)=>{if(!this.isRealNode(o))return!0;let u=Number(o.key);return u<=a||u>=h?!1:i(o.left,a,u)&&i(o.right,u,h)},r=i(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=i(e,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||s}else{let i=(o=!1)=>{let a=[],h=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,u=e;for(;this.isRealNode(u)||a.length>0;){for(;this.isRealNode(u);)a.push(u),u=u.left;u=a.pop();let f=Number(u.key);if(!this.isRealNode(u)||!o&&h>=f||o&&h<=f)return!1;h=f,u=u.right}return!0},r=i(!1),s=i(!0);return r||s}}getDepth(e,t=this._root){let i=this.ensureNode(e),r=this.ensureNode(t),s=0;for(;i!=null&&i.parent;){if(i===r)return s;s++,i=i.parent}return s}getHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let i=r=>{if(!this.isRealNode(r))return-1;let s=i(r.left),o=i(r.right);return Math.max(s,o)+1};return i(e)}else{let i=[{node:e,depth:0}],r=0;for(;i.length>0;){let{node:s,depth:o}=i.pop();this.isRealNode(s.left)&&i.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&i.push({node:s.right,depth:o+1}),r=Math.max(r,o)}return r}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let i=r=>{if(!this.isRealNode(r)||!this.isRealNode(r.left)&&!this.isRealNode(r.right))return 0;let s=i(r.left),o=i(r.right);return Math.min(s,o)+1};return i(e)}else{let i=[],r=e,s=null,o=new Map;for(;i.length>0||r;)if(this.isRealNode(r))i.push(r),r=r.left;else if(r=i[i.length-1],!this.isRealNode(r.right)||s===r.right){if(r=i.pop(),this.isRealNode(r)){let a=this.isRealNode(r.left)?o.get(r.left):-1,h=this.isRealNode(r.right)?o.get(r.right):-1;o.set(r,1+Math.min(a,h)),s=r,r=null}}else r=r.right;return o.get(e)}}getPathToRoot(e=this._DEFAULT_NODE_CALLBACK,t,i=!0){let r=[],s=this.ensureNode(t);if(!s)return r;for(;s.parent;)r.push(e(s)),s=s.parent;return r.push(e(s)),i?r.reverse():r}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!this.isRealNode(t))return e(t);if(i==="RECURSIVE"){let r=s=>this.isRealNode(s.left)?r(s.left):s;return e(r(t))}else{let r=ae(s=>this.isRealNode(s.left)?r.cont(s.left):s);return e(r(t))}}getRightMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!t)return e(t);if(i==="RECURSIVE"){let r=s=>this.isRealNode(s.right)?r(s.right):s;return e(r(t))}else{let r=ae(s=>this.isRealNode(s.right)?r.cont(s.right):s);return e(r(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(i=>i,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",i=this._root,r=this.iterationType,s=!1){return i=this.ensureNode(i),i?this._dfs(e,t,i,r,s):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType,r=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(i==="RECURSIVE"){let o=new D([t]),a=h=>{if(o.size===0)return;let u=o.shift();s.push(e(u)),r?(u&&this.isRealNodeOrNull(u.left)&&o.push(u.left),u&&this.isRealNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right)),a(h+1)};a(0)}else{let o=new D([t]);for(;o.size>0;){let a=o.size;for(let h=0;h<a;h++){let u=o.shift();s.push(e(u)),r?(u&&this.isRealNodeOrNull(u.left)&&o.push(u.left),u&&this.isRealNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right))}}}return s}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){t=this.ensureNode(t);let r=[];if(!this.isRealNode(t))return[];if(i==="RECURSIVE"){let s=o=>{this.isLeaf(o)&&r.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 D([t]);for(;s.size>0;){let o=s.shift();this.isRealNode(o)&&(this.isLeaf(o)&&r.push(e(o)),this.isRealNode(o.left)&&s.push(o.left),this.isRealNode(o.right)&&s.push(o.right))}}return r}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType,r=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(i==="RECURSIVE"){let o=(a,h)=>{s[h]||(s[h]=[]),s[h].push(e(a)),r?(a&&this.isRealNodeOrNull(a.left)&&o(a.left,h+1),a&&this.isRealNodeOrNull(a.right)&&o(a.right,h+1)):(a&&a.left&&o(a.left,h+1),a&&a.right&&o(a.right,h+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let a=o.pop(),[h,u]=a;s[u]||(s[u]=[]),s[u].push(e(h)),r?(h&&this.isRealNodeOrNull(h.right)&&o.push([h.right,u+1]),h&&this.isRealNodeOrNull(h.left)&&o.push([h.left,u+1])):(h&&h.right&&o.push([h.right,u+1]),h&&h.left&&o.push([h.left,u+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",i=this._root){if(i=this.ensureNode(i),!i)return[];let r=[],s=i,o=h=>{let u=null,f=null;for(;h;)f=h.right,h.right=u,u=h,h=f;return u},a=h=>{let u=o(h),f=u;for(;f;)r.push(e(f)),f=f.right;o(u)};switch(t){case"IN":for(;s;){if(s.left){let h=this.getPredecessor(s);if(h.right)h.right=null;else{h.right=s,s=s.left;continue}}r.push(e(s)),s=s.right}break;case"PRE":for(;s;){if(s.left){let h=this.getPredecessor(s);if(h.right)h.right=null;else{h.right=s,r.push(e(s)),s=s.left;continue}}else r.push(e(s));s=s.right}break;case"POST":for(;s;){if(s.left){let h=this.getPredecessor(s);if(h.right===null){h.right=s,s=s.left;continue}else h.right=null,a(s.left)}s=s.right}a(i);break}return r}clone(){let e=this.createTree();return 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),e}filter(e,t){let i=this.createTree(),r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&i.add([s,o]);return i}map(e,t){let i=this.createTree(),r=0;for(let[s,o]of this)i.add([s,e.call(t,o,s,r++,this)]);return i}toVisual(e=this._root,t){let i=M({isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1},t);e=this.ensureNode(e);let r="";return e&&(i.isShowUndefined&&(r+=`U for undefined
|
|
1
|
+
"use strict";var dataStructureTyped=(()=>{var oe=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames,Qe=Object.getOwnPropertySymbols;var Ge=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var Ee=(h,n)=>(n=Symbol[h])?n:Symbol.for("Symbol."+h),et=h=>{throw TypeError(h)};var me=(h,n,e)=>n in h?oe(h,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[n]=e,M=(h,n)=>{for(var e in n||(n={}))Ge.call(n,e)&&me(h,e,n[e]);if(Qe)for(var e of Qe(n))$e.call(n,e)&&me(h,e,n[e]);return h};var tt=(h,n)=>{for(var e in n)oe(h,e,{get:n[e],enumerable:!0})},it=(h,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Ze(n))!Ge.call(h,i)&&i!==e&&oe(h,i,{get:()=>n[i],enumerable:!(t=Je(n,i))||t.enumerable});return h};var rt=h=>it(oe({},"__esModule",{value:!0}),h);var d=(h,n,e)=>me(h,typeof n!="symbol"?n+"":n,e);var We=(h,n,e)=>new Promise((t,i)=>{var r=a=>{try{o(e.next(a))}catch(l){i(l)}},s=a=>{try{o(e.throw(a))}catch(l){i(l)}},o=a=>a.done?t(a.value):Promise.resolve(a.value).then(r,s);o((e=e.apply(h,n)).next())}),nt=function(h,n){this[0]=h,this[1]=n};var L=h=>{var n=h[Ee("asyncIterator")],e=!1,t,i={};return n==null?(n=h[Ee("iterator")](),t=r=>i[r]=s=>n[r](s)):(n=n.call(h),t=r=>i[r]=s=>{if(e){if(e=!1,r==="throw")throw s;return s}return e=!0,{done:!1,value:new nt(new Promise(o=>{var a=n[r](s);a instanceof Object||et("Object expected"),o(a)}),1)}}),i[Ee("iterator")]=()=>i,t("next"),"throw"in n?t("throw"):i.throw=r=>{throw r},"return"in n&&t("return"),i};var ht={};tt(ht,{AVLTree:()=>ie,AVLTreeMultiMap:()=>Se,AVLTreeMultiMapNode:()=>ne,AVLTreeNode:()=>P,AbstractEdge:()=>I,AbstractGraph:()=>A,AbstractVertex:()=>T,BST:()=>H,BSTNode:()=>F,BinaryIndexedTree:()=>Ie,BinaryTree:()=>te,BinaryTreeNode:()=>B,Character:()=>pe,DFSOperation:()=>Fe,Deque:()=>De,DirectedEdge:()=>G,DirectedGraph:()=>ee,DirectedVertex:()=>z,DoublyLinkedList:()=>xe,DoublyLinkedListNode:()=>Z,FibonacciHeap:()=>Ke,FibonacciHeapNode:()=>he,HashMap:()=>Oe,Heap:()=>K,IterableElementBase:()=>k,IterableEntryBase:()=>v,LinkedHashMap:()=>Re,LinkedListQueue:()=>Te,MapEdge:()=>ce,MapGraph:()=>we,MapVertex:()=>fe,Matrix:()=>Pe,MaxHeap:()=>Le,MaxPriorityQueue:()=>He,MinHeap:()=>ve,MinPriorityQueue:()=>ze,Navigator:()=>je,PriorityQueue:()=>U,Queue:()=>D,RedBlackTree:()=>re,RedBlackTreeNode:()=>j,SegmentTree:()=>Be,SegmentTreeNode:()=>W,SinglyLinkedList:()=>J,SinglyLinkedListNode:()=>Q,SkipList:()=>Me,SkipListNode:()=>$,Stack:()=>ke,THUNK_SYMBOL:()=>be,TreeMultiMap:()=>Ae,TreeMultiMapNode:()=>se,TreeNode:()=>qe,Trie:()=>Ue,TrieNode:()=>X,UndirectedEdge:()=>de,UndirectedGraph:()=>Ce,UndirectedVertex:()=>ue,arrayRemove:()=>C,calcMinUnitsRequired:()=>le,getMSB:()=>Ve,isComparable:()=>Y,isThunk:()=>Ne,isWeakKey:()=>q,rangeCheck:()=>w,roundFixed:()=>at,throwRangeError:()=>ot,toBinaryString:()=>lt,toThunk:()=>ye,trampoline:()=>ae,trampolineAsync:()=>st,uuidV4:()=>_e});var v=class{*[Symbol.iterator](...n){yield*L(this._getIterator(...n))}*entries(){for(let n of this)yield n}*keys(){for(let n of this)yield n[0]}*values(){for(let n of this)yield n[1]}every(n,e){let t=0;for(let i of this)if(!n.call(e,i[1],i[0],t++,this))return!1;return!0}some(n,e){let t=0;for(let i of this)if(n.call(e,i[1],i[0],t++,this))return!0;return!1}forEach(n,e){let t=0;for(let i of this){let[r,s]=i;n.call(e,s,r,t++,this)}}find(n,e){let t=0;for(let i of this){let[r,s]=i;if(n.call(e,s,r,t++,this))return i}}has(n){for(let e of this){let[t]=e;if(t===n)return!0}return!1}hasValue(n){for(let[,e]of this)if(e===n)return!0;return!1}get(n){for(let e of this){let[t,i]=e;if(t===n)return i}}reduce(n,e){let t=e,i=0;for(let r of this){let[s,o]=r;t=n(t,o,s,i++,this)}return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var k=class{constructor(n){d(this,"_toElementFn");if(n){let{toElementFn:e}=n;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...n){yield*L(this._getIterator(...n))}*values(){for(let n of this)yield n}every(n,e){let t=0;for(let i of this)if(!n.call(e,i,t++,this))return!1;return!0}some(n,e){let t=0;for(let i of this)if(n.call(e,i,t++,this))return!0;return!1}forEach(n,e){let t=0;for(let i of this)n.call(e,i,t++,this)}find(n,e){let t=0;for(let i of this)if(n.call(e,i,t++,this))return i}has(n){for(let e of this)if(e===n)return!0;return!1}reduce(n,e){let t=e,i=0;for(let r of this)t=n(t,r,i++,this);return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var _e=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(h){let n=Math.random()*16|0;return(h=="x"?n:n&3|8).toString(16)})},C=function(h,n){let e=-1,t=h?h.length:0,i=[];for(;++e<t;){let r=h[e];n(r,e,h)&&(i.push(r),Array.prototype.splice.call(h,e--,1),t--)}return i},be=Symbol("thunk"),Ne=h=>typeof h=="function"&&h.__THUNK__===be,ye=h=>{let n=()=>h();return n.__THUNK__=be,n},ae=h=>Object.assign((...e)=>{let t=h(...e);for(;Ne(t)&&typeof t=="function";)t=t();return t},{cont:(...e)=>ye(()=>h(...e))}),st=h=>Object.assign((...e)=>We(void 0,null,function*(){let t=yield h(...e);for(;Ne(t)&&typeof t=="function";)t=yield t();return t}),{cont:(...e)=>ye(()=>h(...e))}),Ve=h=>h<=0?0:1<<31-Math.clz32(h),w=(h,n,e,t="Index out of bounds.")=>{if(h<n||h>e)throw new RangeError(t)},ot=(h="The value is off-limits.")=>{throw new RangeError(h)},q=h=>{let n=typeof h;return n==="object"&&h!==null||n==="function"},le=(h,n)=>Math.floor((h+n-1)/n),at=(h,n=10)=>{let e=Math.pow(10,n);return Math.round(h*e)/e};function ge(h){let n=typeof h;return n==="number"?!Number.isNaN(h):n==="bigint"||n==="string"||n==="boolean"}function Xe(h){if(typeof h.valueOf=="function"){let n=h.valueOf();if(n!==h){if(ge(n))return n;if(typeof n=="object"&&n!==null)return Xe(n)}}if(typeof h.toString=="function"){let n=h.toString();if(n!=="[object Object]")return n}return null}function Y(h,n=!1){if(h==null)return!1;if(ge(h))return!0;if(typeof h!="object")return!1;if(h instanceof Date)return!Number.isNaN(h.getTime());if(n)return!0;let e=Xe(h);return e==null?!1:ge(e)}function lt(h,n=32){let e=(h>>>0).toString(2);return e=e.padStart(n,"0"),e}var Oe=class h extends v{constructor(e=[],t){super();d(this,"_store",{});d(this,"_objMap",new Map);d(this,"_toEntryFn");d(this,"_size",0);d(this,"_hashFn",e=>String(e));if(t){let{hashFn:i,toEntryFn:r}=t;i&&(this._hashFn=i),r&&(this._toEntryFn=r)}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 i=this._getNoObjKey(e);this.store[i]===void 0&&this._size++,this._store[i]={key:e,value:t}}return!0}setMany(e){let t=[];for(let i of e){let r,s;if(this.isEntry(i))r=i[0],s=i[1];else if(this._toEntryFn){let o=this._toEntryFn(i);r=o[0],s=o[1]}r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}get(e){var t;if(this._isObjKey(e))return this.objMap.get(e);{let i=this._getNoObjKey(e);return(t=this._store[i])==null?void 0:t.value}}has(e){return this._isObjKey(e)?this.objMap.has(e):this._getNoObjKey(e)in this.store}delete(e){if(this._isObjKey(e))return this.objMap.has(e)&&this._size--,this.objMap.delete(e);{let t=this._getNoObjKey(e);return t in this.store?(delete this.store[t],this._size--,!0):!1}}clone(){return new h(this,{hashFn:this._hashFn,toEntryFn:this._toEntryFn})}map(e,t){let i=new h,r=0;for(let[s,o]of this)i.set(s,e.call(t,o,s,r++,this));return i}filter(e,t){let i=new h,r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&i.set(s,o);return i}*_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,i;return t!=="string"&&t!=="number"&&t!=="symbol"?i=this._hashFn(e):i=e,i}},Re=class h extends v{constructor(e=[],t){super();d(this,"_sentinel");d(this,"_hashFn",e=>String(e));d(this,"_objHashFn",e=>e);d(this,"_noObjMap",{});d(this,"_objMap",new WeakMap);d(this,"_head");d(this,"_tail");d(this,"_toEntryFn",e=>{if(this.isEntry(e))return e;throw new Error("If the provided entryOrRawElements does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified.")});d(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:i,objHashFn:r,toEntryFn:s}=t;i&&(this._hashFn=i),r&&(this._objHashFn=r),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 i,r=!this.has(e);if(q(e)){let s=this._objHashFn(e);i=this.objMap.get(s),!i&&r?(i={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,i)):i&&(i.value=t)}else{let s=this._hashFn(e);i=this.noObjMap[s],!i&&r?this.noObjMap[s]=i={key:e,value:t,prev:this.tail,next:this._sentinel}:i&&(i.value=t)}return i&&r&&(this._size===0?(this._head=i,this._sentinel.next=i):(this.tail.next=i,i.prev=this.tail),this._tail=i,this._sentinel.prev=i,this._size++),!0}setMany(e){let t=[];for(let i of e){let r,s;if(this.isEntry(i))r=i[0],s=i[1];else if(this._toEntryFn){let o=this._toEntryFn(i);r=o[0],s=o[1]}r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}has(e){if(q(e)){let t=this._objHashFn(e);return this.objMap.has(t)}else return this._hashFn(e)in this.noObjMap}get(e){if(q(e)){let t=this._objHashFn(e),i=this.objMap.get(t);return i?i.value:void 0}else{let t=this._hashFn(e),i=this.noObjMap[t];return i?i.value:void 0}}at(e){w(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(q(e)){let i=this._objHashFn(e);if(t=this.objMap.get(i),!t)return!1;this.objMap.delete(i)}else{let i=this._hashFn(e);if(t=this.noObjMap[i],!t)return!1;delete this.noObjMap[i]}return this._deleteNode(t),!0}deleteAt(e){w(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return this._deleteNode(t)}isEmpty(){return this._size===0}isEntry(e){return Array.isArray(e)&&e.length===2}clear(){this._noObjMap={},this._size=0,this._head=this._tail=this._sentinel.prev=this._sentinel.next=this._sentinel}clone(){let e=new h([],{hashFn:this._hashFn,objHashFn:this._objHashFn});for(let t of this){let[i,r]=t;e.set(i,r)}return e}filter(e,t){let i=new h,r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&i.set(s,o),r++;return i}map(e,t){let i=new h,r=0;for(let[s,o]of this){let a=e.call(t,o,s,r,this);i.set(s,a),r++}return i}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:i}=e;return t.next=i,i.prev=t,e===this.head&&(this._head=i),e===this.tail&&(this._tail=t),this._size-=1,!0}};var Q=class{constructor(n){d(this,"_value");d(this,"_next");this._value=n,this._next=void 0}get value(){return this._value}set value(n){this._value=n}get next(){return this._next}set next(n){this._next=n}},J=class h extends k{constructor(e=[],t){super(t);d(this,"_head");d(this,"_tail");d(this,"_size",0);if(e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get head(){return this._head}get tail(){return this._tail}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}get size(){return this._size}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._size++,!0}pop(){if(!this.head)return;if(this.head===this.tail){let i=this.head.value;return this._head=void 0,this._tail=void 0,this._size--,i}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._size--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._size--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):(this._head=t,this._tail=t),this._size++,!0}get(e){let t=this._ensurePredicate(e),i=this.head;for(;i;){if(t(i))return i.value;i=i.next}}at(e){if(e<0||e>=this._size)return;let t=this.head;for(let i=0;i<e;i++)t=t.next;return t.value}isNode(e){return e instanceof Q}getNodeAt(e){let t=this.head;for(let i=0;i<e;i++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._size)return!1;if(e===0)return this.shift(),!0;if(e===this._size-1)return this.pop(),!0;let t=this.getNodeAt(e-1),i=t.next;return t.next=i.next,this._size--,!0}delete(e){if(e===void 0)return!1;let t;e instanceof Q?t=e.value:t=e;let i=this.head,r;for(;i;){if(i.value===t)return r===void 0?(this._head=i.next,i===this.tail&&(this._tail=void 0)):(r.next=i.next,i===this.tail&&(this._tail=r)),this._size--,!0;r=i,i=i.next}return!1}addAt(e,t){if(e<0||e>this._size)return!1;if(e===0)return this.unshift(t),!0;if(e===this._size)return this.push(t),!0;let i=this._ensureNode(t),r=this.getNodeAt(e-1);return i.next=r.next,r.next=i,this._size++,!0}isEmpty(){return this._size===0}clear(){this._head=void 0,this._tail=void 0,this._size=0}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,i;for(;t;)i=t.next,t.next=e,e=t,t=i;return[this._head,this._tail]=[this.tail,this.head],this}indexOf(e){let t=this._ensurePredicate(e),i=0,r=this.head;for(;r;){if(t(r))return i;i++,r=r.next}return-1}getNode(e){if(e===void 0)return;let t=this._ensurePredicate(e),i=this.head;for(;i;){if(t(i))return i;i=i.next}}addBefore(e,t){if(!this.head)return!1;let i;if(this.isNode(e)?i=e.value:i=e,this.head.value===i)return this.unshift(t),!0;let r=this.head;for(;r.next;){if(r.next.value===i){let s=this._ensureNode(t);return s.next=r.next,r.next=s,this._size++,!0}r=r.next}return!1}addAfter(e,t){let i=this.getNode(e);if(i){let r=this._ensureNode(t);return r.next=i.next,i.next=r,i===this.tail&&(this._tail=r),this._size++,!0}return!1}countOccurrences(e){let t=this._ensurePredicate(e),i=0,r=this.head;for(;r;)t(r)&&i++,r=r.next;return i}clone(){return new h(this,{toElementFn:this.toElementFn})}filter(e,t){let i=new h([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new h([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}static fromArray(e){let t=new h;for(let i of e)t.push(i);return t}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new Q(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}};var Z=class{constructor(n){d(this,"_value");d(this,"_next");d(this,"_prev");this._value=n,this._next=void 0,this._prev=void 0}get value(){return this._value}set value(n){this._value=n}get next(){return this._next}set next(n){this._next=n}get prev(){return this._prev}set prev(n){this._prev=n}},xe=class h extends k{constructor(e=[],t){super(t);d(this,"_head");d(this,"_tail");d(this,"_size");if(this._head=void 0,this._tail=void 0,this._size=0,e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get head(){return this._head}get tail(){return this._tail}get size(){return this._size}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}isNode(e){return e instanceof Z}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._size++,!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._size--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._size--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._size++,!0}at(e){if(e<0||e>=this._size)return;let t=this.head;for(let i=0;i<e;i++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this._size)return;let t=this.head;for(let i=0;i<e;i++)t=t.next;return t}getNode(e){if(e===void 0)return;let t=this._ensurePredicate(e),i=this.head;for(;i;){if(t(i))return i;i=i.next}}addAt(e,t){if(e<0||e>this._size)return!1;if(e===0)return this.unshift(t),!0;if(e===this._size)return this.push(t),!0;let i=this._ensureNode(t),r=this.getNodeAt(e-1),s=r.next;return i.prev=r,i.next=s,r.next=i,s.prev=i,this._size++,!0}addBefore(e,t){let i=this.getNode(e);if(i){let r=this._ensureNode(t);return r.prev=i.prev,i.prev&&(i.prev.next=r),r.next=i,i.prev=r,i===this.head&&(this._head=r),this._size++,!0}return!1}addAfter(e,t){let i=this.getNode(e);if(i){let r=this._ensureNode(t);return r.next=i.next,i.next&&(i.next.prev=r),r.prev=i,i.next=r,i===this.tail&&(this._tail=r),this._size++,!0}return!1}deleteAt(e){if(e<0||e>=this._size)return!1;if(e===0)return this.shift(),!0;if(e===this._size-1)return this.pop(),!0;let t=this.getNodeAt(e),i=t.prev,r=t.next;return i.next=r,r.prev=i,this._size--,!0}delete(e){let t=this.getNode(e);if(t){if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let i=t.prev,r=t.next;i&&(i.next=r),r&&(r.prev=i),this._size--}return!0}return!1}isEmpty(){return this._size===0}clear(){this._head=void 0,this._tail=void 0,this._size=0}indexOf(e){let t=this._ensurePredicate(e),i=0,r=this.head;for(;r;){if(t(r))return i;i++,r=r.next}return-1}get(e){let t=this._ensurePredicate(e),i=this.head;for(;i;){if(t(i))return i.value;i=i.next}}getBackward(e){let t=this._ensurePredicate(e),i=this.tail;for(;i;){if(t(i))return i.value;i=i.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}toArray(){let e=[],t=this.head;for(;t;)e.push(t.value),t=t.next;return e}toReversedArray(){let e=[],t=this.tail;for(;t;)e.push(t.value),t=t.prev;return e}clone(){return new h(this)}filter(e,t){let i=new h([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new h([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}countOccurrences(e){let t=this._ensurePredicate(e),i=0,r=this.head;for(;r;)t(r)&&i++,r=r.next;return i}static fromArray(e){return new h(e)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:new Z(e)}_ensurePredicate(e){return this.isNode(e)?t=>t===e:this._isPredicate(e)?e:t=>t.value===e}};var $=class{constructor(n,e,t){d(this,"key");d(this,"value");d(this,"forward");this.key=n,this.value=e,this.forward=new Array(t)}},Me=class{constructor(n=[],e){d(this,"_head",new $(void 0,void 0,this.maxLevel));d(this,"_level",0);d(this,"_maxLevel",16);d(this,"_probability",.5);if(e){let{maxLevel:t,probability:i}=e;typeof t=="number"&&(this._maxLevel=t),typeof i=="number"&&(this._probability=i)}if(n)for(let[t,i]of n)this.add(t,i)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let n=this.head.forward[0];return n?n.value:void 0}get last(){let n=this.head;for(let e=this.level-1;e>=0;e--)for(;n.forward[e];)n=n.forward[e];return n.value}add(n,e){let t=new $(n,e,this._randomLevel()),i=new Array(this.maxLevel).fill(this.head),r=this.head;for(let s=this.level-1;s>=0;s--){for(;r.forward[s]&&r.forward[s].key<n;)r=r.forward[s];i[s]=r}for(let s=0;s<t.forward.length;s++)t.forward[s]=i[s].forward[s],i[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(n){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<n;)e=e.forward[t];if(e=e.forward[0],e&&e.key===n)return e.value}has(n){return this.get(n)!==void 0}delete(n){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let i=this.level-1;i>=0;i--){for(;t.forward[i]&&t.forward[i].key<n;)t=t.forward[i];e[i]=t}if(t=t.forward[0],t&&t.key===n){for(let i=0;i<this.level&&e[i].forward[i]===t;i++)e[i].forward[i]=t.forward[i];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(n){let e=this.head;for(let i=this.level-1;i>=0;i--)for(;e.forward[i]&&e.forward[i].key<=n;)e=e.forward[i];let t=e.forward[0];return t?t.value:void 0}lower(n){let e=this.head,t;for(let i=this.level-1;i>=0;i--){for(;e.forward[i]&&e.forward[i].key<n;)e=e.forward[i];e.key<n&&(t=e)}return t?t.value:void 0}_randomLevel(){let n=1;for(;Math.random()<this.probability&&n<this.maxLevel;)n++;return n}};var ke=class h extends k{constructor(e=[],t){super(t);d(this,"_elements",[]);if(e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e){return new h(e)}isEmpty(){return this.elements.length===0}peek(){if(!this.isEmpty())return this.elements[this.elements.length-1]}push(e){return this.elements.push(e),!0}pop(){if(!this.isEmpty())return this.elements.pop()}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}toArray(){return this.elements.slice()}clear(){this._elements=[]}clone(){return new h(this,{toElementFn:this.toElementFn})}filter(e,t){let i=new h([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new h([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var D=class h extends k{constructor(e=[],t){super(t);d(this,"_elements",[]);d(this,"_offset",0);d(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:i=.5}=t;this._autoCompactRatio=i}if(e)for(let i of e)this.toElementFn?this.push(this.toElementFn(i)):this.push(i)}get elements(){return this._elements}get offset(){return this._offset}get size(){return this.elements.length-this.offset}get first(){return this.size>0?this.elements[this.offset]:void 0}get last(){return this.size>0?this.elements[this.elements.length-1]:void 0}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}static fromArray(e){return new h(e)}push(e){return this.elements.push(e),!0}shift(){if(this.size===0)return;let e=this.first;return this._offset+=1,this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){let t=this.elements.indexOf(e);return this.deleteAt(t)}deleteAt(e){return this.elements.splice(e,1).length===1}at(e){return this.elements[e+this._offset]}isEmpty(){return this.size===0}toArray(){return this.elements.slice(this.offset)}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this.offset),this._offset=0,!0}clone(){return new h(this.elements.slice(this.offset),{toElementFn:this.toElementFn})}filter(e,t){let i=new h([],{toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new h([],{toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){for(let e of this.elements.slice(this.offset))yield e}},Te=class h extends J{clone(){return new h(this,{toElementFn:this.toElementFn})}};var De=class h extends k{constructor(e=[],t){super(t);d(this,"_bucketSize",4096);d(this,"_maxLen",-1);d(this,"_bucketFirst",0);d(this,"_firstInBucket",0);d(this,"_bucketLast",0);d(this,"_lastInBucket",0);d(this,"_bucketCount",0);d(this,"_buckets",[]);d(this,"_size",0);if(t){let{bucketSize:s,maxLen:o}=t;typeof s=="number"&&(this._bucketSize=s),typeof o=="number"&&o>0&&o%1===0&&(this._maxLen=o)}let i;"length"in e?e.length instanceof Function?i=e.length():i=e.length:e.size instanceof Function?i=e.size():i=e.size,this._bucketCount=le(i,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let r=le(i,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(r>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-i%this._bucketSize>>1;for(let s of e)this.toElementFn?this.push(this.toElementFn(s)):this.push(s)}get bucketSize(){return this._bucketSize}get maxLen(){return this._maxLen}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get size(){return this._size}get first(){if(this._size!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._size!==0)return this._buckets[this._bucketLast][this._lastInBucket]}push(e){return this._size&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._size+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._size>this._maxLen&&this.shift(),!0}pop(){if(this._size===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._size!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._size-=1,e}unshift(e){return this._size&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._size+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._size>this._maxLen&&this.pop(),!0}shift(){if(this._size===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._size!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._size-=1,e}isEmpty(){return this._size===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._size=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}*begin(){let e=0;for(;e<this._size;)yield this.at(e),e++}*reverseBegin(){let e=this._size-1;for(;e>=0;)yield this.at(e),e--}at(e){w(e,0,this._size-1);let{bucketIndex:t,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[t][i]}setAt(e,t){w(e,0,this._size-1);let{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);return this._buckets[i][r]=t,!0}addAt(e,t,i=1){let r=this._size;if(w(e,0,r),e===0)for(;i--;)this.unshift(t);else if(e===this._size)for(;i--;)this.push(t);else{let s=[];for(let o=e;o<this._size;++o)s.push(this.at(o));this.cut(e-1,!0);for(let o=0;o<i;++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:i,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketLast=i,this._lastInBucket=r,this._size=e+1,this}else{let i=new h([],{bucketSize:this._bucketSize});for(let r=0;r<=e;r++)i.push(this.at(r));return i}}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketFirst=i,this._firstInBucket=r,this._size=this._size-e,this}else{let i=new h([],{bucketSize:this._bucketSize});e<0&&(e=0);for(let r=e;r<this._size;r++)i.push(this.at(r));return i}}deleteAt(e){if(w(e,0,this._size-1),e===0)this.shift();else if(e===this._size-1)this.pop();else{let t=this._size-1,{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);for(let s=e;s<t;++s){let{bucketIndex:o,indexInBucket:a}=this._getBucketAndPosition(e+1);this._buckets[i][r]=this._buckets[o][a],i=o,r=a}this.pop()}return!0}delete(e){let t=this._size;if(t===0)return!1;let i=0,r=0;for(;i<t;){let s=this.at(i);s!==e&&(this.setAt(r,s),r+=1),i+=1}return this.cut(r-1,!0),!0}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:i,_lastInBucket:r}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-r-1,this._lastInBucket=this._bucketSize-i-1,this}unique(){if(this._size<=1)return this;let e=1,t=this.at(0);for(let i=1;i<this._size;++i){let r=this.at(i);r!==t&&(t=r,this.setAt(e++,r))}return this.cut(e-1,!0),this}sort(e){let t=[];for(let i=0;i<this._size;++i)t.push(this.at(i));t.sort(e);for(let i=0;i<this._size;++i)this.setAt(i,t[i]);return this}shrinkToFit(){if(this._size===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}indexOf(e){for(let t=0;t<this._size;++t)if(this.at(t)===e)return t;return-1}toArray(){return[...this]}clone(){return new h(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn})}filter(e,t){let i=new h([],{bucketSize:this._bucketSize,toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&i.push(s),r++;return i}map(e,t,i){let r=new h([],{bucketSize:this._bucketSize,toElementFn:t}),s=0;for(let o of this)r.push(e.call(i,o,s,this)),s++;return r}*_getIterator(){for(let e=0;e<this._size;++e)yield this.at(e)}_reallocate(e){let t=[],i=e||this._bucketCount>>1||1;for(let r=0;r<i;++r)t[r]=new Array(this._bucketSize);for(let r=this._bucketFirst;r<this._bucketCount;++r)t[t.length]=this._buckets[r];for(let r=0;r<this._bucketLast;++r)t[t.length]=this._buckets[r];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=i,this._bucketLast=t.length-1;for(let r=0;r<i;++r)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,i,r=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(r/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),i=(r+1)%this._bucketSize-1,i<0&&(i=this._bucketSize-1),{bucketIndex:t,indexInBucket:i}}};var K=class h extends k{constructor(e=[],t){super(t);d(this,"_elements",[]);d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:i}=t;i&&(this._comparator=i)}if(e)for(let i of e)this.toElementFn?this.add(this.toElementFn(i)):this.add(i)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var e;return(e=this.elements[this.size-1])!=null?e:void 0}static heapify(e,t){return new h(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=e,this.fix()}has(e){return this.elements.includes(e)}delete(e){let t=this.elements.indexOf(e);return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}dfs(e="PRE"){let t=[],i=r=>{let s=2*r+1,o=s+1;r<this.size&&(e==="IN"?(i(s),t.push(this.elements[r]),i(o)):e==="PRE"?(t.push(this.elements[r]),i(s),i(o)):e==="POST"&&(i(s),i(o),t.push(this.elements[r])))};return i(0),t}toArray(){return[...this.elements]}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}sort(){let e=[],t=new h(this,{comparator:this.comparator});for(;t.size!==0;){let i=t.poll();i!==void 0&&e.push(i)}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 i=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),r=0;for(let s of this)e.call(t,s,r,this)&&i.add(s),r++;return i}map(e,t,i,r){let s=new h([],{comparator:t,toElementFn:i}),o=0;for(let a of this)s.add(e.call(r,a,o,this)),o++;return s}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let i=e-1>>1,r=this.elements[i];if(this.comparator(r,t)<=0)break;this.elements[e]=r,e=i}return this.elements[e]=t,!0}_sinkDown(e,t){let i=this.elements[e];for(;e<t;){let r=e<<1|1,s=r+1,o=this.elements[r];if(s<this.elements.length&&this.comparator(o,this.elements[s])>0&&(r=s,o=this.elements[s]),this.comparator(o,i)>=0)break;this.elements[e]=o,e=r}return this.elements[e]=i,!0}},he=class{constructor(n,e=0){d(this,"element");d(this,"degree");d(this,"left");d(this,"right");d(this,"child");d(this,"parent");d(this,"marked");this.element=n,this.degree=e,this.marked=!1}},Ke=class{constructor(n){d(this,"_root");d(this,"_size",0);d(this,"_min");d(this,"_comparator");if(this.clear(),this._comparator=n||this._defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap constructor: given comparator should be a function.")}get root(){return this._root}get size(){return this._size}get min(){return this._min}get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(n){return this.push(n)}push(n){let e=this.createNode(n);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this._min=e),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(n){let e=[];if(!n)return e;let t=n,i=!1;for(;!(t===n&&i);)t===n&&(i=!0),t&&(e.push(t),t=t.right);return e}mergeWithChild(n,e){n.child?(e.right=n.child.right,e.left=n.child,n.child.right.left=e,n.child.right=e):n.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let n=this.min;if(n.child){let e=this.consumeLinkedList(n.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(n),n===n.right?(this._min=void 0,this._root=void 0):(this._min=n.right,this._consolidate()),this._size--,n.element}merge(n){if(n.size!==0){if(this.root&&n.root){let e=this.root,t=n.root,i=e.right,r=t.left;e.right=t,t.left=e,i.left=r,r.right=i}(!this.min||n.min&&this.comparator(n.min.element,this.min.element)<0)&&(this._min=n.min),this._size+=n.size,n.clear()}}createNode(n){return new he(n)}_defaultComparator(n,e){return n<e?-1:n>e?1:0}mergeWithRoot(n){this.root?(n.right=this.root.right,n.left=this.root,this.root.right.left=n,this.root.right=n):this._root=n}removeFromRoot(n){this.root===n&&(this._root=n.right),n.left&&(n.left.right=n.right),n.right&&(n.right.left=n.left)}_link(n,e){this.removeFromRoot(n),n.left=n,n.right=n,this.mergeWithChild(e,n),e.degree++,n.parent=e}_consolidate(){let n=new Array(this._size),e=this.consumeLinkedList(this.root),t,i,r,s;for(let o of e){for(t=o,r=t.degree;n[r];)i=n[r],this.comparator(t.element,i.element)>0&&(s=t,t=i,i=s),this._link(i,t),n[r]=void 0,r++;n[r]=t}for(let o=0;o<this._size;o++)n[o]&&this.comparator(n[o].element,this.min.element)<=0&&(this._min=n[o])}};var Le=class h extends K{constructor(n=[],e){super(n,M({comparator:(t,i)=>{if(typeof t=="object"||typeof i=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<i?1:t>i?-1:0}},e))}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var ve=class h extends K{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var T=class{constructor(n,e){d(this,"key");d(this,"value");this.key=n,this.value=e}},I=class{constructor(n,e){d(this,"value");d(this,"weight");d(this,"_hashCode");this.weight=n!==void 0?n:1,this.value=e,this._hashCode=_e()}get hashCode(){return this._hashCode}},A=class extends v{constructor(){super();d(this,"_vertexMap",new Map)}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof T)return this._addVertex(e);{let i=this.createVertex(e,t);return this._addVertex(i)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let i of e)t.push(this.deleteVertex(i));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,i,r){if(e instanceof I)return this._addEdge(e);if(t instanceof T||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof T&&(e=e.key),t instanceof T&&(t=t.key);let s=this.createEdge(e,t,i,r);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,i){let r=this.getEdge(e,t);return r?(r.weight=i,!0):!1}getAllPathsBetween(e,t,i=1e3){let r=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let a=[];for(a.push({vertex:s,path:[s]});a.length>0;){let{vertex:l,path:u}=a.pop();if(l===o&&(r.push(u),r.length>=i))return r;let f=this.getNeighbors(l);for(let p of f)if(!u.includes(p)){let c=[...u,p];a.push({vertex:p,path:c})}}return r}getPathSumWeight(e){var i;let t=0;for(let r=0;r<e.length;r++)t+=((i=this.getEdge(e[r],e[r+1]))==null?void 0:i.weight)||0;return t}getMinCostBetween(e,t,i){if(i===void 0&&(i=!1),i){let r=this.getAllPathsBetween(e,t),s=1/0;for(let o of r)s=Math.min(this.getPathSumWeight(o),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let o=new Map,a=new D([s]);o.set(s,!0);let l=0;for(;a.size>0;){for(let u=0;u<a.size;u++){let f=a.shift();if(f===r)return l;if(f!==void 0){let p=this.getNeighbors(f);for(let c of p)o.has(c)||(o.set(c,!0),a.push(c))}}l++}return}}getMinPathBetween(e,t,i,r=!1){var s,o;if(i===void 0&&(i=!1),i)if(r){let a=this.getAllPathsBetween(e,t,1e4),l=1/0,u=-1,f=0;for(let p of a){let c=this.getPathSumWeight(p);c<l&&(l=c,u=f),f++}return a[u]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let a=[],l=this._getVertex(e),u=this._getVertex(t);if(!(l&&u))return[];let f=(p,c,g,_)=>{if(g.add(p),p===c){a=[l,..._];return}let m=this.getNeighbors(p);for(let O of m)g.has(O)||(_.push(O),f(O,c,g,_),_.pop());g.delete(p)};return f(l,u,new Set,[]),a}}dijkstraWithoutHeap(e,t=void 0,i=!1,r=!1){let s=1/0,o,a=[],l=[],u=this._vertexMap,f=new Map,p=new Set,c=new Map,g=this._getVertex(e),_=t?this._getVertex(t):void 0;if(!g)return;for(let b of u){let E=b[1];E instanceof T&&f.set(E,1/0)}f.set(g,0),c.set(g,void 0);let m=()=>{let b=1/0,E;for(let[N,y]of f)p.has(N)||y<b&&(b=y,E=N);return E},O=b=>{for(let E of u){let N=E[1];if(N instanceof T){let y=[N],V=c.get(N);for(;V;)y.push(V),V=c.get(V);let R=y.reverse();E[1]===b&&(a=R),l.push(R)}}};for(let b=1;b<u.size;b++){let E=m();if(E){if(p.add(E),_&&_===E)return i&&(s=f.get(_)||1/0),r&&O(_),{distMap:f,preMap:c,seen:p,paths:l,minDist:s,minPath:a};let N=this.getNeighbors(E);for(let y of N)if(!p.has(y)){let V=this.getEdge(E,y);if(V){let R=f.get(E),x=f.get(y);R!==void 0&&x!==void 0&&V.weight+R<x&&(f.set(y,V.weight+R),c.set(y,E))}}}}return i&&f.forEach((b,E)=>{E!==g&&b<s&&(s=b,r&&(o=E))}),r&&O(o),{distMap:f,preMap:c,seen:p,paths:l,minDist:s,minPath:a}}dijkstra(e,t=void 0,i=!1,r=!1){var b;let s=1/0,o,a=[],l=[],u=this._vertexMap,f=new Map,p=new Set,c=new Map,g=this._getVertex(e),_=t?this._getVertex(t):void 0;if(!g)return;for(let E of u){let N=E[1];N instanceof T&&f.set(N,1/0)}let m=new K([],{comparator:(E,N)=>E.key-N.key});m.add({key:0,value:g}),f.set(g,0),c.set(g,void 0);let O=E=>{for(let N of u){let y=N[1];if(y instanceof T){let V=[y],R=c.get(y);for(;R;)V.push(R),R=c.get(R);let x=V.reverse();N[1]===E&&(a=x),l.push(x)}}};for(;m.size>0;){let E=m.poll(),N=E==null?void 0:E.key,y=E==null?void 0:E.value;if(N!==void 0&&y){if(p.add(y),_&&_===y)return i&&(s=f.get(_)||1/0),r&&O(_),{distMap:f,preMap:c,seen:p,paths:l,minDist:s,minPath:a};let V=this.getNeighbors(y);for(let R of V)if(!p.has(R)){let x=(b=this.getEdge(y,R))==null?void 0:b.weight;if(typeof x=="number"){let S=f.get(R);S&&N+x<S&&(m.add({key:N+x,value:R}),c.set(R,y),f.set(R,N+x))}}}}return i&&f.forEach((E,N)=>{N!==g&&E<s&&(s=E,r&&(o=N))}),r&&O(o),{distMap:f,preMap:c,seen:p,paths:l,minDist:s,minPath:a}}bellmanFord(e,t,i,r){i===void 0&&(i=!1),r===void 0&&(r=!1);let s=this._getVertex(e),o=[],a=new Map,l=new Map,u=1/0,f=[],p;if(t&&(p=!1),!s)return{hasNegativeCycle:p,distMap:a,preMap:l,paths:o,min:u,minPath:f};let c=this._vertexMap,g=c.size,_=this.edgeSet(),m=_.length;this._vertexMap.forEach(b=>{a.set(b,1/0)}),a.set(s,0);for(let b=1;b<g;++b)for(let E=0;E<m;++E){let N=this.getEndsOfEdge(_[E]);if(N){let[y,V]=N,R=_[E].weight,x=a.get(y),S=a.get(V);x!==void 0&&S!==void 0&&a.get(y)!==1/0&&x+R<S&&(a.set(V,x+R),r&&l.set(V,y))}}let O;if(i&&a.forEach((b,E)=>{E!==s&&b<u&&(u=b,r&&(O=E))}),r)for(let b of c){let E=b[1];if(E instanceof T){let N=[E],y=l.get(E);for(;y!==void 0;)N.push(y),y=l.get(y);let V=N.reverse();b[1]===O&&(f=V),o.push(V)}}for(let b=0;b<m;++b){let E=this.getEndsOfEdge(_[b]);if(E){let[N]=E,y=_[b].weight,V=a.get(N);V&&V!==1/0&&V+y<V&&(p=!0)}}return{hasNegativeCycle:p,distMap:a,preMap:l,paths:o,min:u,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,i=[],r=[];for(let o=0;o<t;o++){i[o]=[],r[o]=[];for(let a=0;a<t;a++)r[o][a]=void 0}for(let o=0;o<t;o++)for(let a=0;a<t;a++)i[o][a]=((s=this.getEdge(e[o][1],e[a][1]))==null?void 0:s.weight)||1/0;for(let o=0;o<t;o++)for(let a=0;a<t;a++)for(let l=0;l<t;l++)i[a][l]>i[a][o]+i[o][l]&&(i[a][l]=i[a][o]+i[o][l],r[a][l]=e[o][1]);return{costs:i,predecessor:r}}getCycles(e=!1){let t=[],i=new Set,r=(o,a,l)=>{if(l.has(o)){(!e&&a.length>2||e&&a.length>=2)&&a[0]===o.key&&t.push([...a]);return}l.add(o),a.push(o.key);for(let u of this.getNeighbors(o))u&&r(u,a,l);l.delete(o),a.pop()};for(let o of this.vertexMap.values())r(o,[],i);let s=new Map;for(let o of t){let a=[...o].sort().toString();s.has(a)||s.set(a,o)}return[...s].map(o=>o[1])}filter(e,t){let i=[],r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&i.push([s,o]),r++;return i}map(e,t){let i=[],r=0;for(let[s,o]of this)i.push(e.call(t,o,s,r,this)),r++;return i}*_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 T?e.key:e}};var z=class extends T{constructor(n,e){super(n,e)}},G=class extends I{constructor(e,t,i,r){super(i,r);d(this,"src");d(this,"dest");this.src=e,this.dest=t}},ee=class h extends A{constructor(){super();d(this,"_outEdgeMap",new Map);d(this,"_inEdgeMap",new Map)}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(e){this._outEdgeMap=e}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(e){this._inEdgeMap=e}createVertex(e,t){return new z(e,t)}createEdge(e,t,i,r){return new G(e,t,i!=null?i:1,r)}getEdge(e,t){let i=[];if(e!==void 0&&t!==void 0){let r=this._getVertex(e),s=this._getVertex(t);if(r&&s){let o=this._outEdgeMap.get(r);o&&(i=o.filter(a=>a.dest===s.key))}}return i[0]||void 0}deleteEdgeSrcToDest(e,t){let i=this._getVertex(e),r=this._getVertex(t),s;if(!i||!r)return;let o=this._outEdgeMap.get(i);o&&C(o,l=>l.dest===r.key);let a=this._inEdgeMap.get(r);return a&&(s=C(a,l=>l.src===i.key)[0]||void 0),s}deleteEdge(e,t){let i,r,s;if(this.isVertexKey(e))if(this.isVertexKey(t))r=this._getVertex(e),s=this._getVertex(t);else return;else r=this._getVertex(e.src),s=this._getVertex(e.dest);if(r&&s){let o=this._outEdgeMap.get(r);o&&o.length>0&&C(o,l=>l.src===r.key&&l.dest===(s==null?void 0:s.key));let a=this._inEdgeMap.get(s);a&&a.length>0&&(i=C(a,l=>l.src===r.key&&l.dest===s.key)[0])}return i}deleteVertex(e){let t,i;if(this.isVertexKey(e)?(i=this.getVertex(e),t=e):(i=e,t=this._getVertexKey(e)),i){let r=this.getNeighbors(i);for(let s of r)this.deleteEdgeSrcToDest(i,s);this._outEdgeMap.delete(i),this._inEdgeMap.delete(i)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let i=[];if(e&&t){let r=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);r&&i.push(r),s&&i.push(s)}return i}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=[],i=this.outgoingEdgesOf(e);for(let r of i){let s=this.getEdgeDest(r);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 i=[],r=!1,s=o=>{t.set(o,1);let a=this.getDestinations(o);for(let l of a){let u=t.get(l);u===0?s(l):u===1&&(r=!0)}t.set(o,2),i.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!r)return e==="key"&&(i=i.map(o=>o instanceof z?o.key:o)),i.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],i=this._getVertex(e);if(i){let r=this.outgoingEdgesOf(i);for(let s of r){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),i=this._getVertex(e.dest);if(t&&i)return[t,i]}isEmpty(){return this.vertexMap.size===0&&this.inEdgeMap.size===0&&this.outEdgeMap.size===0}clear(){this._vertexMap=new Map,this._inEdgeMap=new Map,this._outEdgeMap=new Map}clone(){let e=new h;return e.vertexMap=new Map(this.vertexMap),e.inEdgeMap=new Map(this.inEdgeMap),e.outEdgeMap=new Map(this.outEdgeMap),e}tarjan(){let e=new Map,t=new Map,i=new Map,r=0,s=[],o=new Set,a=l=>{e.set(l,r),t.set(l,r),r++,s.push(l),o.add(l);let u=this.getNeighbors(l);for(let f of u)e.has(f)?o.has(f)&&t.set(l,Math.min(t.get(l),e.get(f))):(a(f),t.set(l,Math.min(t.get(l),t.get(f))));if(e.get(l)===t.get(l)){let f=[],p;do p=s.pop(),o.delete(p),f.push(p);while(p!==l);i.set(i.size,f)}};for(let l of this.vertexMap.values())e.has(l)||a(l);return{dfnMap:e,lowMap:t,SCCs:i}}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),i=this._getVertex(e.dest);if(t&&i){let r=this._outEdgeMap.get(t);r?r.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(i);return s?s.push(e):this._inEdgeMap.set(i,[e]),!0}else return!1}};var ue=class extends T{constructor(n,e){super(n,e)}},de=class extends I{constructor(e,t,i,r){super(i,r);d(this,"endpoints");this.endpoints=[e,t]}},Ce=class h extends A{constructor(){super();d(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}createVertex(e,t){return new ue(e,t!=null?t:e)}createEdge(e,t,i,r){return new de(e,t,i!=null?i:1,r)}getEdge(e,t){var r;let i=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(i=(r=this._edgeMap.get(s))==null?void 0:r.filter(a=>a.endpoints.includes(o.key)))}return i&&i[0]||void 0}deleteEdgeBetween(e,t){let i=this._getVertex(e),r=this._getVertex(t);if(!i||!r)return;let s=this._edgeMap.get(i),o;s&&(o=C(s,l=>l.endpoints.includes(r.key))[0]||void 0);let a=this._edgeMap.get(r);return a&&C(a,l=>l.endpoints.includes(i.key)),o}deleteEdge(e,t){let i,r;if(this.isVertexKey(e))if(this.isVertexKey(t))i=this._getVertex(e),r=this._getVertex(t);else return;else i=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(i&&r)return this.deleteEdgeBetween(i,r)}deleteVertex(e){let t,i;this.isVertexKey(e)?(i=this.getVertex(e),t=e):(i=e,t=this._getVertexKey(e));let r=this.getNeighbors(e);return i&&(r.forEach(s=>{let o=this._edgeMap.get(s);if(o){let a=o.filter(l=>!l.endpoints.includes(t));this._edgeMap.set(s,a)}}),this._edgeMap.delete(i)),this._vertexMap.delete(t)}degreeOf(e){var i;let t=this._getVertex(e);return t&&((i=this._edgeMap.get(t))==null?void 0:i.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(i=>{e.add(i)})}),[...e]}getNeighbors(e){let t=[],i=this._getVertex(e);if(i){let r=this.edgesOf(i);for(let s of r){let o=this._getVertex(s.endpoints.filter(a=>a!==i.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]),i=this._getVertex(e.endpoints[1]);if(t&&i)return[t,i]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){let e=new h;return e.vertexMap=new Map(this.vertexMap),e.edgeMap=new Map(this.edgeMap),e}tarjan(){let e=new Map,t=new Map,i=[],r=[],s=0,o=(a,l)=>{e.set(a,s),t.set(a,s),s++;let u=this.getNeighbors(a),f=0;for(let p of u)if(e.has(p))p!==l&&t.set(a,Math.min(t.get(a),e.get(p)));else{if(f++,o(p,a),t.set(a,Math.min(t.get(a),t.get(p))),t.get(p)>e.get(a)){let c=this.getEdge(a,p);c&&i.push(c)}l!==void 0&&t.get(p)>=e.get(a)&&r.push(a)}l===void 0&&f>1&&r.push(a)};for(let a of this.vertexMap.values())e.has(a)||o(a,void 0);return{dfnMap:e,lowMap:t,bridges:i,cutVertices:r}}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 i=this._getVertex(t);if(i===void 0)return!1;if(i){let r=this._edgeMap.get(i);r?r.push(e):this._edgeMap.set(i,[e])}}return!0}};var fe=class extends z{constructor(e,t,i,r){super(e,t);d(this,"lat");d(this,"long");this.lat=i,this.long=r}},ce=class extends G{constructor(n,e,t,i){super(n,e,t,i)}},we=class h extends ee{constructor(e,t){super();d(this,"_originCoord",[0,0]);d(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,i=this.originCoord[0],r=this.originCoord[1]){return new fe(e,t,i,r)}createEdge(e,t,i,r){return new ce(e,t,i,r)}clone(){let e=new h(this.originCoord,this.bottomRight);return e.vertexMap=new Map(this.vertexMap),e.inEdgeMap=new Map(this.inEdgeMap),e.outEdgeMap=new Map(this.outEdgeMap),e}};var Fe=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(Fe||{});var B=class{constructor(n,e){d(this,"key");d(this,"value");d(this,"parent");d(this,"_left");d(this,"_right");this.key=n,this.value=e}get left(){return this._left}set left(n){n&&(n.parent=this),this._left=n}get right(){return this._right}set right(n){n&&(n.parent=this),this._right=n}get familyPosition(){let n=this;return this.parent?this.parent.left===n?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===n?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},te=class h extends v{constructor(e=[],t){super();d(this,"iterationType","ITERATIVE");d(this,"_isMapMode",!0);d(this,"_store",new Map);d(this,"_root");d(this,"_size",0);d(this,"_NIL",new B(NaN));d(this,"_toEntryFn");d(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:i,toEntryFn:r,isMapMode:s}=t;if(i&&(this.iterationType=i),s!==void 0&&(this._isMapMode=s),typeof r=="function")this._toEntryFn=r;else if(r)throw TypeError("toEntryFn must be a function type")}e&&this.addMany(e)}get isMapMode(){return this._isMapMode}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 B(e,this._isMapMode?void 0:t)}createTree(e){return new h([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,toEntryFn:this._toEntryFn},e))}keyValueNodeEntryRawToNodeAndValue(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[i,r]=e;if(i===void 0)return[void 0,void 0];if(i===null)return[null,void 0];let s=t!=null?t:r;return[this.createNode(i,s),s]}if(this.isKey(e))return[this.createNode(e,t),t];if(this.isRaw(e)){if(this._toEntryFn){let[i,r]=this._toEntryFn(e),s=t!=null?t:r;if(this.isKey(i))return[this.createNode(i,s),s]}return[void 0,void 0]}return[void 0,void 0]}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 i=e[0];return i===null?null:i===void 0?void 0:this.getNodeByKey(i,t)}if(this._toEntryFn){let[i]=this._toEntryFn(e);if(this.isKey(i))return this.getNodeByKey(i)}if(this.isKey(e))return this.getNodeByKey(e,t)}}isNode(e){return e instanceof B}isRaw(e){return 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}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}isKey(e){return e===null?!0:Y(e)}add(e,t){let[i,r]=this.keyValueNodeEntryRawToNodeAndValue(e,t);if(i===void 0)return!1;if(!this._root)return this._setRoot(i),this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size=1,!0;let s=new D([this._root]),o;for(;s.size>0;){let a=s.shift();if(a){if(i!==null&&a.key===i.key)return this._replaceNode(a,i),this._isMapMode&&this._setValue(a.key,r),!0;o===void 0&&(a.left===void 0||a.right===void 0)&&(o=a),a.left!==null&&a.left&&s.push(a.left),a.right!==null&&a.right&&s.push(a.right)}}return o?(o.left===void 0?o.left=i:o.right===void 0&&(o.right=i),this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0):!1}addMany(e,t){let i=[],r;t&&(r=t[Symbol.iterator]());for(let s of e){let o;if(r){let a=r.next();a.done||(o=a.value)}i.push(this.add(s,o))}return i}refill(e,t){this.clear(),this.addMany(e,t)}delete(e){let t=[];if(!this._root)return t;let i=this.getNode(e);if(!i)return t;let r=i==null?void 0:i.parent,s,o=i;if(!i.left&&!i.right&&!r)this._setRoot(void 0);else if(i.left){let a=this.getRightMost(l=>l,i.left);if(a){let l=a.parent;o=this._swapProperties(i,a),l&&(l.right===a?l.right=a.left:l.left=a.left,s=l)}}else if(r){let{familyPosition:a}=i;a==="LEFT"||a==="ROOT_LEFT"?r.left=i.right:(a==="RIGHT"||a==="ROOT_RIGHT")&&(r.right=i.right),s=r}else this._setRoot(i.right),i.right=void 0;return this._size=this._size-1,t.push({deleted:o,needBalanced:s}),this._isMapMode&&o&&this._store.delete(o.key),t}getNodes(e,t=!1,i=this._root,r=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let s=this._ensurePredicate(e),o=[];if(r==="RECURSIVE"){let a=l=>{s(l)&&(o.push(l),t)||!this.isRealNode(l.left)&&!this.isRealNode(l.right)||(this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right))};a(i)}else{let a=[i];for(;a.length>0;){let l=a.pop();if(this.isRealNode(l)){if(s(l)&&(o.push(l),t))return o;this.isRealNode(l.left)&&a.push(l.left),this.isRealNode(l.right)&&a.push(l.right)}}}return o}getNode(e,t=this._root,i=this.iterationType){var r;return(r=this.getNodes(e,!0,t,i)[0])!=null?r:null}getNodeByKey(e,t=this.iterationType){return this.getNode(e,this._root,t)}get(e,t=this._root,i=this.iterationType){var r;if(this._isMapMode){let s=this._getKey(e);return s==null?void 0:this._store.get(s)}return(r=this.getNode(e,t,i))==null?void 0:r.value}has(e,t=this._root,i=this.iterationType){return this.getNodes(e,!0,t,i).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 i=(o,a,l)=>{if(!this.isRealNode(o))return!0;let u=Number(o.key);return u<=a||u>=l?!1:i(o.left,a,u)&&i(o.right,u,l)},r=i(e,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=i(e,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||s}else{let i=(o=!1)=>{let a=[],l=o?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,u=e;for(;this.isRealNode(u)||a.length>0;){for(;this.isRealNode(u);)a.push(u),u=u.left;u=a.pop();let f=Number(u.key);if(!this.isRealNode(u)||!o&&l>=f||o&&l<=f)return!1;l=f,u=u.right}return!0},r=i(!1),s=i(!0);return r||s}}getDepth(e,t=this._root){let i=this.ensureNode(e),r=this.ensureNode(t),s=0;for(;i!=null&&i.parent;){if(i===r)return s;s++,i=i.parent}return s}getHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let i=r=>{if(!this.isRealNode(r))return-1;let s=i(r.left),o=i(r.right);return Math.max(s,o)+1};return i(e)}else{let i=[{node:e,depth:0}],r=0;for(;i.length>0;){let{node:s,depth:o}=i.pop();this.isRealNode(s.left)&&i.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&i.push({node:s.right,depth:o+1}),r=Math.max(r,o)}return r}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let i=r=>{if(!this.isRealNode(r)||!this.isRealNode(r.left)&&!this.isRealNode(r.right))return 0;let s=i(r.left),o=i(r.right);return Math.min(s,o)+1};return i(e)}else{let i=[],r=e,s=null,o=new Map;for(;i.length>0||r;)if(this.isRealNode(r))i.push(r),r=r.left;else if(r=i[i.length-1],!this.isRealNode(r.right)||s===r.right){if(r=i.pop(),this.isRealNode(r)){let a=this.isRealNode(r.left)?o.get(r.left):-1,l=this.isRealNode(r.right)?o.get(r.right):-1;o.set(r,1+Math.min(a,l)),s=r,r=null}}else r=r.right;return o.get(e)}}getPathToRoot(e=this._DEFAULT_NODE_CALLBACK,t,i=!0){let r=[],s=this.ensureNode(t);if(!s)return r;for(;s.parent;)r.push(e(s)),s=s.parent;return r.push(e(s)),i?r.reverse():r}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!this.isRealNode(t))return e(t);if(i==="RECURSIVE"){let r=s=>this.isRealNode(s.left)?r(s.left):s;return e(r(t))}else{let r=ae(s=>this.isRealNode(s.left)?r.cont(s.left):s);return e(r(t))}}getRightMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){if(this.isNIL(t))return e(void 0);if(t=this.ensureNode(t),!t)return e(t);if(i==="RECURSIVE"){let r=s=>this.isRealNode(s.right)?r(s.right):s;return e(r(t))}else{let r=ae(s=>this.isRealNode(s.right)?r.cont(s.right):s);return e(r(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(i=>i,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",i=this._root,r=this.iterationType,s=!1){return i=this.ensureNode(i),i?this._dfs(e,t,i,r,s):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType,r=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(i==="RECURSIVE"){let o=new D([t]),a=l=>{if(o.size===0)return;let u=o.shift();s.push(e(u)),r?(u&&this.isRealNodeOrNull(u.left)&&o.push(u.left),u&&this.isRealNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right)),a(l+1)};a(0)}else{let o=new D([t]);for(;o.size>0;){let a=o.size;for(let l=0;l<a;l++){let u=o.shift();s.push(e(u)),r?(u&&this.isRealNodeOrNull(u.left)&&o.push(u.left),u&&this.isRealNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right))}}}return s}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){t=this.ensureNode(t);let r=[];if(!this.isRealNode(t))return[];if(i==="RECURSIVE"){let s=o=>{this.isLeaf(o)&&r.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 D([t]);for(;s.size>0;){let o=s.shift();this.isRealNode(o)&&(this.isLeaf(o)&&r.push(e(o)),this.isRealNode(o.left)&&s.push(o.left),this.isRealNode(o.right)&&s.push(o.right))}}return r}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType,r=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(i==="RECURSIVE"){let o=(a,l)=>{s[l]||(s[l]=[]),s[l].push(e(a)),r?(a&&this.isRealNodeOrNull(a.left)&&o(a.left,l+1),a&&this.isRealNodeOrNull(a.right)&&o(a.right,l+1)):(a&&a.left&&o(a.left,l+1),a&&a.right&&o(a.right,l+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let a=o.pop(),[l,u]=a;s[u]||(s[u]=[]),s[u].push(e(l)),r?(l&&this.isRealNodeOrNull(l.right)&&o.push([l.right,u+1]),l&&this.isRealNodeOrNull(l.left)&&o.push([l.left,u+1])):(l&&l.right&&o.push([l.right,u+1]),l&&l.left&&o.push([l.left,u+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",i=this._root){if(i=this.ensureNode(i),!i)return[];let r=[],s=i,o=l=>{let u=null,f=null;for(;l;)f=l.right,l.right=u,u=l,l=f;return u},a=l=>{let u=o(l),f=u;for(;f;)r.push(e(f)),f=f.right;o(u)};switch(t){case"IN":for(;s;){if(s.left){let l=this.getPredecessor(s);if(l.right)l.right=null;else{l.right=s,s=s.left;continue}}r.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,r.push(e(s)),s=s.left;continue}}else r.push(e(s));s=s.right}break;case"POST":for(;s;){if(s.left){let l=this.getPredecessor(s);if(l.right===null){l.right=s,s=s.left;continue}else l.right=null,a(s.left)}s=s.right}a(i);break}return r}clone(){let e=this.createTree();return 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),e}filter(e,t){let i=this.createTree(),r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&i.add([s,o]);return i}map(e,t){let i=this.createTree(),r=0;for(let[s,o]of this)i.add([s,e.call(t,o,s,r++,this)]);return i}toVisual(e=this._root,t){let i=M({isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1},t);e=this.ensureNode(e);let r="";return e&&(i.isShowUndefined&&(r+=`U for undefined
|
|
2
2
|
`),i.isShowNull&&(r+=`N for null
|
|
3
3
|
`),i.isShowRedBlackNIL&&(r+=`S for Sentinel Node(NIL)
|
|
4
|
-
`),(o=>{let[a,,,]=this._displayAux(o,i),
|
|
5
|
-
`;r+=h})(e)),r}print(e,t=this._root){console.log(this.toVisual(t,e))}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",i=this._root,r=this.iterationType,s=!1,o=f=>!!f,a=f=>!!f,h=f=>s?this.isRealNodeOrNull(f):this.isRealNode(f),u=f=>this.isRealNodeOrNull(f)){if(i=this.ensureNode(i),!i)return[];let f=[];if(r==="RECURSIVE"){let p=c=>{if(!h(c))return;let g=()=>{o(c)&&p(c==null?void 0:c.left)},_=()=>{a(c)&&p(c==null?void 0:c.right)};switch(t){case"IN":g(),u(c)&&f.push(e(c)),_();break;case"PRE":u(c)&&f.push(e(c)),g(),_();break;case"POST":g(),_(),u(c)&&f.push(e(c));break}};p(i)}else{let p=[{opt:0,node:i}],c=m=>{var O;o(m.node)&&p.push({opt:0,node:(O=m.node)==null?void 0:O.left})},g=m=>{var O;a(m.node)&&p.push({opt:0,node:(O=m.node)==null?void 0:O.right})},_=m=>{h(m.node)&&p.push({opt:1,node:m.node})};for(;p.length>0;){let m=p.pop();if(m!==void 0&&h(m.node))if(m.opt===1)u(m.node)&&f.push(e(m.node));else switch(t){case"IN":g(m),_(m),c(m);break;case"PRE":g(m),c(m),_(m);break;case"POST":_(m),g(m),c(m);break}}}return f}*_getIterator(e=this._root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],i=e;for(;i||t.length>0;){for(;this.isRealNode(i);)t.push(i),i=i.left;i=t.pop(),this.isRealNode(i)&&(this._isMapMode?yield[i.key,this._store.get(i.key)]:yield[i.key,i.value],i=i.right)}}else e.left&&this.isRealNode(e)&&(yield*L(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*L(this[Symbol.iterator](e.right)))}_displayAux(e,t){let{isShowNull:i,isShowUndefined:r,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!i)return o;if(e===void 0&&!r)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let h=e.key,u=this.isNIL(e)?"S":String(h),f=u.length;return a(u,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let h=e===void 0?"U":"N",u=h.length;return a(h,u,[[""],1,0,0],[[""],1,0,0])}function a(h,u,f,p){let[c,g,_,m]=f,[O,b,E,N]=p,y=" ".repeat(Math.max(0,m+1))+"_".repeat(Math.max(0,g-m-1))+h+"_".repeat(Math.max(0,N))+" ".repeat(Math.max(0,b-N)),V=(_>0?" ".repeat(m)+"/"+" ".repeat(g-m-1):" ".repeat(g))+" ".repeat(u)+(E>0?" ".repeat(N)+"\\"+" ".repeat(b-N-1):" ".repeat(b)),R=[y,V];for(let x=0;x<Math.max(_,E);x++){let A=x<_?c[x]:" ".repeat(g),Ye=x<E?O[x]:" ".repeat(b);R.push(A+" ".repeat(u)+Ye)}return[R,g+u+b,Math.max(_,E)+2,g+Math.floor(u/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:i,value:r}=t,s=this.createNode(i,r);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 i=>i.key===t}if(this.isKey(e))return t=>t.key===e;if(this._toEntryFn){let[t]=this._toEntryFn(e);return i=>i.key===t}return t=>t.key===e}_isPredicate(e){return typeof e=="function"}_getKey(e){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e.key;if(this.isEntry(e))return e[0];if(this.isRaw(e)){if(this._toEntryFn){let[t]=this._toEntryFn(e);return t}return}return 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 I=class extends S{constructor(e,t){super(e,t);d(this,"parent");d(this,"_left");d(this,"_right");this.parent=void 0,this._left=void 0,this._right=void 0}get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},j=class l extends te{constructor(e=[],t){super([],t);d(this,"_root");d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:i}=t;i&&(this._comparator=i)}e&&this.addMany(e)}get root(){return this._root}createNode(e,t){return new I(e,this._isMapMode?void 0:t)}createTree(e){return new l([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}keyValueNodeEntryRawToNodeAndValue(e,t){let[i,r]=super.keyValueNodeEntryRawToNodeAndValue(e,t);return i===null?[void 0,void 0]:[i,t!=null?t:r]}ensureNode(e,t=this.iterationType){var i;return(i=super.ensureNode(e,t))!=null?i:void 0}isNode(e){return e instanceof I}isKey(e){return J(e,this.comparator!==this._DEFAULT_COMPARATOR)}add(e,t){let[i,r]=this.keyValueNodeEntryRawToNodeAndValue(e,t);if(i===void 0)return!1;if(this._root===void 0)return this._setRoot(i),this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0;let s=this._root;for(;s!==void 0;){if(this.comparator(s.key,i.key)===0)return this._replaceNode(s,i),this._isMapMode&&this._setValue(s.key,r),!0;if(this.comparator(s.key,i.key)>0){if(s.left===void 0)return s.left=i,this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0;s=s.left}else{if(s.right===void 0)return s.right=i,this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0;s=s.right}}return!1}addMany(e,t,i=!0,r=this.iterationType){let s=[],o;if(t&&(o=t[Symbol.iterator]()),!i){for(let c of e){let g=o==null?void 0:o.next().value;s.push(this.add(c,g))}return s}let a=[],h=0;for(let c of e)a.push({key:c,value:o==null?void 0:o.next().value,orgIndex:h}),h++;let u=[];u=a.sort(({key:c},{key:g})=>{let _,m;return this.isEntry(c)?_=c[0]:this.isRealNode(c)?_=c.key:this._toEntryFn?_=this._toEntryFn(c)[0]:_=c,this.isEntry(g)?m=g[0]:this.isRealNode(g)?m=g.key:this._toEntryFn?m=this._toEntryFn(g)[0]:m=g,_!=null&&m!==void 0&&m!==null?this.comparator(_,m):0});let f=c=>{if(c.length===0)return;let g=Math.floor((c.length-1)/2),{key:_,value:m,orgIndex:O}=c[g];s[O]=this.add(_,m),f(c.slice(0,g)),f(c.slice(g+1))};return r==="RECURSIVE"?f(u):(()=>{let g=[[0,u.length-1]];for(;g.length>0;){let _=g.pop();if(_){let[m,O]=_;if(m<=O){let b=m+Math.floor((O-m)/2),{key:E,value:N,orgIndex:y}=u[b];s[y]=this.add(E,N),g.push([b+1,O]),g.push([m,b-1])}}}})(),s}getNodes(e,t=!1,i=this._root,r=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let s=this._ensurePredicate(e),o=[];if(r==="RECURSIVE"){let a=h=>{if(!(s(h)&&(o.push(h),t))&&!(!this.isRealNode(h.left)&&!this.isRealNode(h.right)))if(this._isPredicate(e))this.isRealNode(h.left)&&a(h.left),this.isRealNode(h.right)&&a(h.right);else{let u=this._getKey(e);this.isRealNode(h.left)&&u!==null&&u!==void 0&&this.comparator(h.key,u)>0&&a(h.left),this.isRealNode(h.right)&&u!==null&&u!==void 0&&this.comparator(h.key,u)<0&&a(h.right)}};a(i)}else{let a=[i];for(;a.length>0;){let h=a.pop();if(s(h)&&(o.push(h),t))return o;if(this._isPredicate(e))this.isRealNode(h.right)&&a.push(h.right),this.isRealNode(h.left)&&a.push(h.left);else{let u=this._getKey(e);this.isRealNode(h.right)&&u!==null&&u!==void 0&&this.comparator(h.key,u)<0&&a.push(h.right),this.isRealNode(h.left)&&u!==null&&u!==void 0&&this.comparator(h.key,u)>0&&a.push(h.left)}}}return o}getNode(e,t=this._root,i=this.iterationType){var r;return(r=this.getNodes(e,!0,t,i)[0])!=null?r:void 0}getNodeByKey(e,t=this.iterationType){return this.getNode(e,this._root,t)}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",i=this._root,r=this.iterationType){return super.dfs(e,t,i,r)}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){return super.bfs(e,t,i,!1)}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){return super.listLevels(e,t,i,!1)}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,i=this._root,r=this.iterationType){let s=this.ensureNode(i),o=[];if(!this._root||!s)return o;let a=s.key;if(r==="RECURSIVE"){let h=u=>{let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&h(u.left),this.isRealNode(u.right)&&h(u.right)};return h(this._root),o}else{let h=new D([this._root]);for(;h.size>0;){let u=h.shift();if(this.isRealNode(u)){let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&h.push(u.left),this.isRealNode(u.right)&&h.push(u.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN"),i=t.length;if(this._clearNodes(),t.length<1)return!1;if(e==="RECURSIVE"){let r=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),h=t[a];this._isMapMode?this.add(h.key):this.add([h.key,h.value]),r(s,a-1),r(a+1,o)};return r(0,i-1),!0}else{let r=[[0,i-1]];for(;r.length>0;){let s=r.pop();if(s){let[o,a]=s;if(o<=a){let h=o+Math.floor((a-o)/2),u=t[h];this._isMapMode?this.add(u.key):this.add([u.key,u.value]),r.push([h+1,a]),r.push([o,h-1])}}}return!0}}isAVLBalanced(e=this.iterationType){if(!this._root)return!0;let t=!0;if(e==="RECURSIVE"){let i=r=>{if(!r)return 0;let s=i(r.left),o=i(r.right);return Math.abs(s-o)>1&&(t=!1),Math.max(s,o)+1};i(this._root)}else{let i=[],r=this._root,s,o=new Map;for(;i.length>0||r;)if(r)i.push(r),r=r.left;else if(r=i[i.length-1],!r.right||s===r.right){if(r=i.pop(),r){let a=r.left?o.get(r.left):-1,h=r.right?o.get(r.right):-1;if(Math.abs(a-h)>1)return!1;o.set(r,1+Math.max(a,h)),s=r,r=void 0}}else r=r.right}return t}get comparator(){return this._comparator}_setRoot(e){e&&(e.parent=void 0),this._root=e}};var Ie=class{constructor({frequency:n=0,max:e}){d(this,"_freq");d(this,"_max");d(this,"_freqMap");d(this,"_msb");d(this,"_negativeCount");this._freq=n,this._max=e,this._freqMap={0:0},this._msb=Ve(e),this._negativeCount=n<0?e:0}get freqMap(){return this._freqMap}get msb(){return this._msb}get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(n){return this._checkIndex(n),this._readSingle(n)}update(n,e){this._checkIndex(n);let t=this._readSingle(n);this._update(n,e),this._updateNegativeCount(t,t+e)}writeSingle(n,e){this._checkIndex(n),this._writeSingle(n,e)}read(n){if(!Number.isInteger(n))throw new Error("Invalid count");return this._read(Math.max(Math.min(n,this.max),0))}lowerBound(n){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(n,(e,t)=>e<t)}upperBound(n){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(n,(e,t)=>e<=t)}getPrefixSum(n){this._checkIndex(n),n++;let e=0;for(;n>0;)e+=this._getFrequency(n),n-=n&-n;return e}_getFrequency(n){return n in this.freqMap?this.freqMap[n]:this.freq*(n&-n)}_updateFrequency(n,e){this.freqMap[n]=this._getFrequency(n)+e}_checkIndex(n){if(!Number.isInteger(n))throw new Error("Invalid index: Index must be an integer.");if(n<0||n>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(n){n=n+1;let e=this._getFrequency(n),t=n-(n&-n);for(n--;n!==t;)e-=this._getFrequency(n),n-=n&-n;return e}_updateNegativeCount(n,e){n<0&&e>=0?this._negativeCount--:n>=0&&e<0&&this._negativeCount++}_update(n,e){for(n=n+1;n<=this.max;)this._updateFrequency(n,e),n+=n&-n}_writeSingle(n,e){let t=this._readSingle(n);this._update(n,e-t),this._updateNegativeCount(t,e)}_read(n){let e=n,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(n,e){let t=0,i=this.msb<<1,r=n;for(;i>t+1;){let s=t+i>>1,o=this._getFrequency(s);s<=this.max&&e(o,r)?(r-=o,t=s):i=s}return t}};var X=class{constructor(n,e,t,i){d(this,"_start",0);d(this,"_end",0);d(this,"_value");d(this,"_sum",0);d(this,"_left");d(this,"_right");this._start=n,this._end=e,this._sum=t,this._value=i||void 0}get start(){return this._start}set start(n){this._start=n}get end(){return this._end}set end(n){this._end=n}get value(){return this._value}set value(n){this._value=n}get sum(){return this._sum}set sum(n){this._sum=n}get left(){return this._left}set left(n){this._left=n}get right(){return this._right}set right(n){this._right=n}},Be=class{constructor(n,e,t){d(this,"_values",[]);d(this,"_start",0);d(this,"_end");d(this,"_root");e=e||0,t=t||n.length-1,this._values=n,this._start=e,this._end=t,n.length>0?this._root=this.build(e,t):(this._root=void 0,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(n,e){if(n>e)return new X(n,e,0);if(n===e)return new X(n,e,this._values[n]);let t=n+Math.floor((e-n)/2),i=this.build(n,t),r=this.build(t+1,e),s=new X(n,e,i.sum+r.sum);return s.left=i,s.right=r,s}updateNode(n,e,t){let i=this.root||void 0;if(!i)return;let r=(s,o,a,h)=>{if(s.start===s.end&&s.start===o){s.sum=a,h!==void 0&&(s.value=h);return}let u=s.start+Math.floor((s.end-s.start)/2);o<=u?s.left&&r(s.left,o,a,h):s.right&&r(s.right,o,a,h),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};r(i,n,e,t)}querySumByRange(n,e){let t=this.root||void 0;if(!t)return 0;if(n<0||e>=this.values.length||n>e)return NaN;let i=(r,s,o)=>{if(s<=r.start&&o>=r.end)return r.sum;let a=r.start+Math.floor((r.end-r.start)/2);if(o<=a)return r.left?i(r.left,s,o):NaN;if(s>a)return r.right?i(r.right,s,o):NaN;{let h=0,u=0;return r.left&&(h=i(r.left,s,a)),r.right&&(u=i(r.right,a+1,o)),h+u}};return i(t,n,e)}};var U=class extends I{constructor(e,t){super(e,t);d(this,"_height");this._height=0}get height(){return this._height}set height(e){this._height=e}},ie=class l extends j{constructor(n=[],e){super([],e),n&&super.addMany(n)}createNode(n,e){return new U(n,this._isMapMode?void 0:e)}createTree(n){return new l([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},n))}isNode(n){return n instanceof U}add(n,e){if(n===null)return!1;let t=super.add(n,e);return t&&this._balancePath(n),t}delete(n){let e=super.delete(n);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}_swapProperties(n,e){let t=this.ensureNode(n),i=this.ensureNode(e);if(t&&i){let{key:r,value:s,height:o}=i,a=this.createNode(r,s);return a&&(a.height=o,i.key=t.key,this._isMapMode||(i.value=t.value),i.height=t.height,t.key=a.key,this._isMapMode||(t.value=a.value),t.height=a.height),i}}_balanceFactor(n){return n.right?n.left?n.right.height-n.left.height:+n.height:-n.height}_updateHeight(n){if(!n.left&&!n.right)n.height=0;else if(n.left)n.right?n.height=1+Math.max(n.right.height,n.left.height):n.height=1+n.left.height;else{let e=n.right?n.right.height:0;n.height=1+e}}_balanceLL(n){let e=n.parent,t=n.left;n.parent=t,t&&t.right&&(t.right.parent=n),t&&(t.parent=e),n===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===n?e.left=t:e&&(e.right=t),t&&(n.left=t.right,t.right=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceLR(n){let e=n.parent,t=n.left,i;t&&(i=t.right),n&&(n.parent=i),t&&(t.parent=i),i&&(i.left&&(i.left.parent=t),i.right&&(i.right.parent=n),i.parent=e),n===this.root?i&&this._setRoot(i):e&&(e.left===n?e.left=i:e.right=i),i&&(n.left=i.right,t&&(t.right=i.left),i.left=t,i.right=n),this._updateHeight(n),t&&this._updateHeight(t),i&&this._updateHeight(i)}_balanceRR(n){let e=n.parent,t=n.right;n.parent=t,t&&(t.left&&(t.left.parent=n),t.parent=e),n===this.root?t&&this._setRoot(t):e&&(e.left===n?e.left=t:e.right=t),t&&(n.right=t.left,t.left=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceRL(n){let e=n.parent,t=n.right,i;t&&(i=t.left),n.parent=i,t&&(t.parent=i),i&&(i.left&&(i.left.parent=n),i.right&&(i.right.parent=t),i.parent=e),n===this.root?i&&this._setRoot(i):e&&(e.left===n?e.left=i:e.right=i),i&&(n.right=i.left),t&&i&&(t.left=i.right),i&&(i.left=n),i&&(i.right=t),this._updateHeight(n),t&&this._updateHeight(t),i&&this._updateHeight(i)}_balancePath(n){n=this.ensureNode(n);let e=this.getPathToRoot(t=>t,n,!1);for(let t=0;t<e.length;t++){let i=e[t];if(i)switch(this._updateHeight(i),this._balanceFactor(i)){case-2:i&&i.left&&(this._balanceFactor(i.left)<=0?this._balanceLL(i):this._balanceLR(i));break;case 2:i&&i.right&&(this._balanceFactor(i.right)>=0?this._balanceRR(i):this._balanceRL(i))}}}_replaceNode(n,e){return e.height=n.height,super._replaceNode(n,e)}};var q=class extends I{constructor(e,t,i="BLACK"){super(e,t);d(this,"_color");this._color=i}get color(){return this._color}set color(e){this._color=e}},re=class l extends j{constructor(e=[],t){super([],t);d(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,i="BLACK"){return new q(e,this._isMapMode?void 0:t,i)}createTree(e){return new l([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof q}clear(){super.clear(),this._root=this.NIL}add(e,t){let[i,r]=this.keyValueNodeEntryRawToNodeAndValue(e,t);if(!this.isRealNode(i))return!1;let s=this._insert(i);if(s==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._isMapMode&&this._setValue(i.key,r),this._size++,!0}return s==="UPDATED"?(this._isMapMode&&this._setValue(i.key,r),!0):!1}delete(e){if(e===null)return[];let t=[],i;if(this._isPredicate(e)?i=this.getNode(e):i=this.isRealNode(e)?e:this.getNode(e),!i)return t;let r=i.color,s;if(!this.isRealNode(i.left))s=i.right,this._transplant(i,i.right);else if(!this.isRealNode(i.right))s=i.left,this._transplant(i,i.left);else{let o=this.getLeftMost(a=>a,i.right);o&&(r=o.color,s=o.right,o.parent===i?this.isRealNode(s)&&(s.parent=o):(this._transplant(o,o.right),o.right=i.right,this.isRealNode(o.right)&&(o.right.parent=o)),this._transplant(i,o),o.left=i.left,this.isRealNode(o.left)&&(o.left.parent=o),o.color=i.color)}return this._isMapMode&&this._store.delete(i.key),this._size--,r==="BLACK"&&this._deleteFixup(s),t.push({deleted:i,needBalanced:void 0}),t}_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 r,s;let t=this.root,i;for(;this.isRealNode(t);){i=t;let o=this.comparator(e.key,t.key);if(o<0)t=(r=t.left)!=null?r:this.NIL;else if(o>0)t=(s=t.right)!=null?s:this.NIL;else return this._replaceNode(t,e),"UPDATED"}return e.parent=i,i?e.key<i.key?i.left=e:i.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,i,r,s;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((i=e.parent.parent)==null?void 0:i.left)){let o=e.parent.parent.right;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._rightRotate(e.parent.parent)))}else{let o=(s=(r=e==null?void 0:e.parent)==null?void 0:r.parent)==null?void 0:s.left;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._leftRotate(e.parent.parent)))}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,i,r,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let o=e.parent;if(!o)break;if(e===o.left){let a=o.right;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o.color="RED",this._leftRotate(o),a=o.right),((i=(t=a==null?void 0:a.left)==null?void 0:t.color)!=null?i:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.left&&(a.left.color="BLACK"),a&&(a.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let a=o.left;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(a=o.left)),((s=(r=a==null?void 0:a.right)==null?void 0:r.color)!=null?s:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.right&&(a.right.color="BLACK"),a&&(a.color=o.color),o&&(o.color="BLACK"),this._leftRotate(o),e=this.root)}}e&&(e.color="BLACK")}_leftRotate(e){if(!e||!e.right)return;let t=e.right;e.right=t.left,this.isRealNode(t.left)&&(t.left.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.left=e,e.parent=t}_rightRotate(e){if(!e||!e.left)return;let t=e.left;e.left=t.right,this.isRealNode(t.right)&&(t.right.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.right=e,e.parent=t}};var ne=class extends U{constructor(e,t,i=1){super(e,t);d(this,"_count",1);this.count=i}get count(){return this._count}set count(e){this._count=e}},Se=class l extends ie{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,i){return new ne(e,this._isMapMode?void 0:t,i)}createTree(e){return new l([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof ne}keyValueNodeEntryRawToNodeAndValue(e,t,i=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[r,s]=e;if(r==null)return[void 0,void 0];let o=t!=null?t:s;return[this.createNode(r,o,i),o]}if(this.isKey(e))return[this.createNode(e,t,i),t];if(this.isRaw(e)){if(this._toEntryFn){let[r,s]=this._toEntryFn(e),o=t!=null?t:s;if(this.isKey(r))return[this.createNode(r,o,i),o]}return[void 0,void 0]}return[void 0,void 0]}add(e,t,i=1){let[r,s]=this.keyValueNodeEntryRawToNodeAndValue(e,t,i);if(r===void 0)return!1;let o=(r==null?void 0:r.count)||0;return super.add(r,s)&&(this._count+=o),!0}delete(e,t=!1){var h;let i=[];if(!this.root)return i;let r=(h=this.getNode(e))!=null?h:void 0;if(!r)return i;let s=r!=null&&r.parent?r.parent:void 0,o,a=r;if(r.count>1&&!t)r.count--,this._count--;else{if(r.left){let u=r.left?this.getRightMost(f=>f,r.left):void 0;if(u){let f=u.parent;a=this._swapProperties(r,u),f&&(f.right===u?f.right=u.left:f.left=u.left,o=f)}}else if(!s)r.right!==void 0&&this._setRoot(r.right);else{let{familyPosition:u}=r;u==="LEFT"||u==="ROOT_LEFT"?s.left=r.right:(u==="RIGHT"||u==="ROOT_RIGHT")&&(s.right=r.right),o=s}this._size=this._size-1,a&&(this._count-=a.count)}return i.push({deleted:a,needBalanced:o}),o&&this._balancePath(o),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN"),i=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let r=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),h=t[a];this._isMapMode?this.add(h.key,void 0,h.count):this.add(h.key,h.value,h.count),r(s,a-1),r(a+1,o)};return r(0,i-1),!0}else{let r=[[0,i-1]];for(;r.length>0;){let s=r.pop();if(s){let[o,a]=s;if(o<=a){let h=o+Math.floor((a-o)/2),u=t[h];this._isMapMode?this.add(u.key,void 0,u.count):this.add(u.key,u.value,u.count),r.push([h+1,a]),r.push([o,h-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}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:i,value:r,count:s,height:o}=t,a=this.createNode(i,r,s);return a&&(a.height=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.height=e.height,e.key=a.key,this._isMapMode||(e.value=a.value),e.count=a.count,e.height=a.height),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var se=class extends q{constructor(e,t,i=1,r="BLACK"){super(e,t,r);d(this,"_count",1);this.count=i}get count(){return this._count}set count(e){this._count=e}},Ae=class l extends re{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,i="BLACK",r){return new se(e,this._isMapMode?void 0:t,r,i)}createTree(e){return new l([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}keyValueNodeEntryRawToNodeAndValue(e,t,i=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[r,s]=e;if(r==null)return[void 0,void 0];let o=t!=null?t:s;if(this.isKey(r))return[this.createNode(r,o,"BLACK",i),o]}if(this._toEntryFn){let[r,s]=this._toEntryFn(e),o=t!=null?t:s;if(this.isKey(r))return[this.createNode(r,o,"BLACK",i),o]}return this.isKey(e)?[this.createNode(e,t,"BLACK",i),t]:[void 0,void 0]}isNode(e){return e instanceof se}add(e,t,i=1){let[r,s]=this.keyValueNodeEntryRawToNodeAndValue(e,t,i),o=(r==null?void 0:r.count)||0;return super.add(r,s)?(this._count+=o,!0):!1}delete(e,t=!1){if(e===null)return[];let i=[],r;if(this._isPredicate(e)?r=this.getNode(e):r=this.isRealNode(e)?e:this.getNode(e),!r)return i;let s=r.color,o;if(this.isRealNode(r.left))if(this.isRealNode(r.right)){let a=this.getLeftMost(h=>h,r.right);if(a){if(s=a.color,o=a.right,a.parent===r)this.isRealNode(o)&&(o.parent=a);else{if(t||r.count<=1)this._transplant(a,a.right),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;a.right=r.right,this.isRealNode(a.right)&&(a.right.parent=a)}if(t||r.count<=1)this._transplant(r,a),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;a.left=r.left,this.isRealNode(a.left)&&(a.left.parent=a),a.color=r.color}}else if(o=r.left,t||r.count<=1)this._transplant(r,r.left),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;else if(o=r.right,t||r.count<=1)this._transplant(r,r.right),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;return this._size--,s==="BLACK"&&this._deleteFixup(o),i.push({deleted:r,needBalanced:void 0}),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN"),i=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let r=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),h=t[a];this._isMapMode?this.add(h.key,void 0,h.count):this.add(h.key,h.value,h.count),r(s,a-1),r(a+1,o)};return r(0,i-1),!0}else{let r=[[0,i-1]];for(;r.length>0;){let s=r.pop();if(s){let[o,a]=s;if(o<=a){let h=o+Math.floor((a-o)/2),u=t[h];this._isMapMode?this.add(u.key,void 0,u.count):this.add(u.key,u.value,u.count),r.push([h+1,a]),r.push([o,h-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t.key,void 0,t.count)),this._isMapMode&&(e._store=this._store),e}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:i,value:r,count:s,color:o}=t,a=this.createNode(i,r,o,s);return a&&(a.color=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.color=e.color,e.key=a.key,this._isMapMode||(e.value=a.value),e.count=a.count,e.color=a.color),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var Q=class l extends v{constructor(n=[],e){super(n,e)}clone(){return new l(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new l([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new l([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var ze=class l extends Q{constructor(n=[],e){super(n,e)}clone(){return new l(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new l([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new l([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var He=class l extends Q{constructor(n=[],e){super(n,M({comparator:(t,i)=>{if(typeof t=="object"||typeof i=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<i?1:t>i?-1:0}},e))}clone(){return new l(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new l([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new l([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var Pe=class l{constructor(n,e){d(this,"_rows",0);d(this,"_cols",0);d(this,"_data");var t,i,r;if(e){let{rows:s,cols:o,addFn:a,subtractFn:h,multiplyFn:u}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=n.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=n[0])==null?void 0:t.length)||0,a&&(this._addFn=a),h&&(this._subtractFn=h),u&&(this._multiplyFn=u)}else this._rows=n.length,this._cols=(r=(i=n[0])==null?void 0:i.length)!=null?r:0;if(n.length>0)this._data=n;else{this._data=[];for(let s=0;s<this.rows;s++)this._data[s]=new Array(this.cols).fill(0)}}get rows(){return this._rows}get cols(){return this._cols}get data(){return this._data}get addFn(){return this._addFn}get subtractFn(){return this._subtractFn}get multiplyFn(){return this._multiplyFn}get(n,e){if(this.isValidIndex(n,e))return this.data[n][e]}set(n,e,t){return this.isValidIndex(n,e)?(this.data[n][e]=t,!0):!1}isMatchForCalculate(n){return this.rows===n.rows&&this.cols===n.cols}add(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<this.cols;i++){let r=this.get(t,i),s=n.get(t,i);if(r!==void 0&&s!==void 0){let o=this._addFn(r,s);o&&(e[t][i]=o)}}}return new l(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<this.cols;i++){let r=this.get(t,i),s=n.get(t,i);if(r!==void 0&&s!==void 0){let o=this._subtractFn(r,s);o&&(e[t][i]=o)}}}return new l(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(n){if(this.cols!==n.rows)throw new Error("Matrix dimensions must be compatible for multiplication (A.cols = B.rows).");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<n.cols;i++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,i);if(o!==void 0&&a!==void 0){let h=this.multiplyFn(o,a);h!==void 0&&(r=this.addFn(r,h))}}r!==void 0&&(e[t][i]=r)}}return new l(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){if(this.data.some(e=>e.length!==this.rows))throw new Error("Matrix must be rectangular for transposition.");let n=[];for(let e=0;e<this.cols;e++){n[e]=[];for(let t=0;t<this.rows;t++){let i=this.get(t,e);i!==void 0&&(n[e][t]=i)}}return new l(n,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var i;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let n=[];for(let r=0;r<this.rows;r++){n[r]=this.data[r].slice();for(let s=0;s<this.cols;s++)n[r][this.cols+s]=r===s?1:0}let e=new l(n,{rows:this.rows,cols:this.cols*2,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn});for(let r=0;r<this.rows;r++){let s=r;for(;s<this.rows&&e.get(s,r)===0;)s++;if(s===this.rows)throw new Error("Matrix is singular, and its inverse does not exist.");e._swapRows(r,s);let o=(i=e.get(r,r))!=null?i:1;if(o===0)throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");e._scaleRow(r,1/o);for(let a=0;a<this.rows;a++)if(a!==r){let h=e.get(a,r);h===void 0&&(h=0),e._addScaledRow(a,r,-h)}}let t=[];for(let r=0;r<this.rows;r++)t[r]=e.data[r].slice(this.cols);return new l(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(n){if(this.cols!==n.rows)throw new Error("Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<n.cols;i++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,i);if(o!==void 0&&a!==void 0){let h=this.multiplyFn(o,a);h!==void 0&&(r=this.addFn(r,h))}}r!==void 0&&(e[t][i]=r)}}return new l(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(n,e){return n>=0&&n<this.rows&&e>=0&&e<this.cols}clone(){return new l(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(n,e){return n===void 0?e:n+e}_subtractFn(n,e){return n-e}_multiplyFn(n,e){return n*e}_swapRows(n,e){let t=this.data[n];this.data[n]=this.data[e],this.data[e]=t}_scaleRow(n,e){for(let t=0;t<this.cols;t++){let i=this.multiplyFn(this.data[n][t],e);i===void 0&&(i=0),this.data[n][t]=i}}_addScaledRow(n,e,t){for(let i=0;i<this.cols;i++){let r=this.multiplyFn(this.data[e][i],t);r===void 0&&(r=0);let s=r,o=this.addFn(this.data[n][i],s);o===void 0&&(o=0),this.data[n][i]=o}}};var pe=class l{constructor(n,e){d(this,"direction");d(this,"turn");this.direction=n,this.turn=()=>new l(e[n],e)}},je=class{constructor({matrix:n,turning:e,onMove:t,init:{cur:i,charDir:r,VISITED:s}}){d(this,"onMove");d(this,"_matrix");d(this,"_cur");d(this,"_character");d(this,"_VISITED");this._matrix=n,this._cur=i,this._character=new pe(r,e),this.onMove=t,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:n}=this._character;this.check(n)?this.move(n):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(n){let e,t,i=this._matrix,[r,s]=this._cur;switch(n){case"up":if(t=i[r-1],!t)return!1;e=t[s];break;case"right":e=i[r][s+1];break;case"down":if(t=i[r+1],!t)return!1;e=t[s];break;case"left":e=i[r][s-1];break}return e!==void 0&&e!==this._VISITED}move(n){switch(n){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[e,t]=this._cur;this._matrix[e][t]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var Y=class{constructor(n){d(this,"_key");d(this,"_children");d(this,"_isEnd");this._key=n,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(n){this._key=n}get children(){return this._children}set children(n){this._children=n}get isEnd(){return this._isEnd}set isEnd(n){this._isEnd=n}},Ue=class l extends k{constructor(e=[],t){super(t);d(this,"_size",0);d(this,"_caseSensitive",!0);d(this,"_root",new Y(""));if(t){let{caseSensitive:i}=t;i!==void 0&&(this._caseSensitive=i)}if(e)for(let i of e)this.toElementFn?this.add(this.toElementFn(i)):this.add(i)}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,i=!1;for(let r of e){let s=t.children.get(r);s||(s=new Y(r),t.children.set(r,s)),t=s}return t.isEnd||(i=!0,t.isEnd=!0,this._size++),i}has(e){e=this._caseProcess(e);let t=this.root;for(let i of e){let r=t.children.get(i);if(!r)return!1;t=r}return t.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new Y("")}delete(e){e=this._caseProcess(e);let t=!1,i=(r,s)=>{let o=e[s],a=r.children.get(o);return a?s===e.length-1?a.isEnd?(a.children.size>0?a.isEnd=!1:r.children.delete(o),t=!0,!0):!1:i(a,s+1)&&!r.isEnd&&a.children.size===0?(r.children.delete(o),!0):!1:!1};return i(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let i=(r,s)=>{s>t&&(t=s);let{children:o}=r;if(o)for(let a of o.entries())i(a[1],s+1)};i(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let i of e){let r=t.children.get(i);if(!r)return!1;t=r}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let i of e){let r=t.children.get(i);if(!r)return!1;t=r}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",i=r=>{if(t+=r.key,t!==e&&!r.isEnd)if(r&&r.children&&r.children.size===1)i(Array.from(r.children.values())[0]);else return};return i(this.root),t===e}getLongestCommonPrefix(){let e="",t=i=>{if(e+=i.key,!i.isEnd)if(i&&i.children&&i.children.size===1)t(Array.from(i.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,i=!1){e=this._caseProcess(e);let r=[],s=0;function o(h,u){for(let f of h.children.keys()){let p=h.children.get(f);p!==void 0&&o(p,u.concat(f))}if(h.isEnd){if(s>t-1)return;r.push(u),s++}}let a=this.root;if(e)for(let h of e){let u=a.children.get(h);if(u)a=u;else return[]}return(i||a!==this.root)&&o(a,e),r}clone(){return new l(this,{caseSensitive:this.caseSensitive,toElementFn:this.toElementFn})}filter(e,t){let i=new l([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive}),r=0;for(let s of this)e.call(t,s,r,this)&&i.add(s),r++;return i}map(e,t,i){let r=new l([],{toElementFn:t,caseSensitive:this.caseSensitive}),s=0;for(let o of this)r.add(e.call(i,o,s,this)),s++;return r}*_getIterator(){function*e(t,i){t.isEnd&&(yield i);for(let[r,s]of t.children)yield*L(e(s,i+r))}yield*L(e(this.root,""))}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var qe=class l{constructor(n,e,t){d(this,"_key");d(this,"_value");d(this,"_children");this._key=n,this._value=e||void 0,t&&(this._children=t)}get key(){return this._key}set key(n){this._key=n}get value(){return this._value}set value(n){this._value=n}get children(){return this._children}set children(n){this._children=n}addChildren(n){this._children||(this._children=[]),n instanceof l?this._children.push(n):this._children=this._children.concat(n)}getHeight(){let n=0;if(this){let e=(t,i)=>{i>n&&(n=i);let{_children:r}=t;if(r)for(let s=0,o=r.length;s<o;s++)e(r[s],i+1)};e(this,0)}return n}};return rt(lt);})();
|
|
4
|
+
`),(o=>{let[a,,,]=this._displayAux(o,i),l="";for(let u of a)l+=u+`
|
|
5
|
+
`;r+=l})(e)),r}print(e,t=this._root){console.log(this.toVisual(t,e))}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",i=this._root,r=this.iterationType,s=!1,o=f=>!!f,a=f=>!!f,l=f=>s?this.isRealNodeOrNull(f):this.isRealNode(f),u=f=>this.isRealNodeOrNull(f)){if(i=this.ensureNode(i),!i)return[];let f=[];if(r==="RECURSIVE"){let p=c=>{if(!l(c))return;let g=()=>{o(c)&&p(c==null?void 0:c.left)},_=()=>{a(c)&&p(c==null?void 0:c.right)};switch(t){case"IN":g(),u(c)&&f.push(e(c)),_();break;case"PRE":u(c)&&f.push(e(c)),g(),_();break;case"POST":g(),_(),u(c)&&f.push(e(c));break}};p(i)}else{let p=[{opt:0,node:i}],c=m=>{var O;o(m.node)&&p.push({opt:0,node:(O=m.node)==null?void 0:O.left})},g=m=>{var O;a(m.node)&&p.push({opt:0,node:(O=m.node)==null?void 0:O.right})},_=m=>{l(m.node)&&p.push({opt:1,node:m.node})};for(;p.length>0;){let m=p.pop();if(m!==void 0&&l(m.node))if(m.opt===1)u(m.node)&&f.push(e(m.node));else switch(t){case"IN":g(m),_(m),c(m);break;case"PRE":g(m),c(m),_(m);break;case"POST":_(m),g(m),c(m);break}}}return f}*_getIterator(e=this._root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],i=e;for(;i||t.length>0;){for(;this.isRealNode(i);)t.push(i),i=i.left;i=t.pop(),this.isRealNode(i)&&(this._isMapMode?yield[i.key,this._store.get(i.key)]:yield[i.key,i.value],i=i.right)}}else e.left&&this.isRealNode(e)&&(yield*L(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*L(this[Symbol.iterator](e.right)))}_displayAux(e,t){let{isShowNull:i,isShowUndefined:r,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!i)return o;if(e===void 0&&!r)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let l=e.key,u=this.isNIL(e)?"S":String(l),f=u.length;return a(u,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let l=e===void 0?"U":"N",u=l.length;return a(l,u,[[""],1,0,0],[[""],1,0,0])}function a(l,u,f,p){let[c,g,_,m]=f,[O,b,E,N]=p,y=" ".repeat(Math.max(0,m+1))+"_".repeat(Math.max(0,g-m-1))+l+"_".repeat(Math.max(0,N))+" ".repeat(Math.max(0,b-N)),V=(_>0?" ".repeat(m)+"/"+" ".repeat(g-m-1):" ".repeat(g))+" ".repeat(u)+(E>0?" ".repeat(N)+"\\"+" ".repeat(b-N-1):" ".repeat(b)),R=[y,V];for(let x=0;x<Math.max(_,E);x++){let S=x<_?c[x]:" ".repeat(g),Ye=x<E?O[x]:" ".repeat(b);R.push(S+" ".repeat(u)+Ye)}return[R,g+u+b,Math.max(_,E)+2,g+Math.floor(u/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:i,value:r}=t,s=this.createNode(i,r);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 i=>i.key===t}if(this.isKey(e))return t=>t.key===e;if(this._toEntryFn){let[t]=this._toEntryFn(e);return i=>i.key===t}return t=>t.key===e}_isPredicate(e){return typeof e=="function"}_getKey(e){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e.key;if(this.isEntry(e))return e[0];if(this.isRaw(e)){if(this._toEntryFn){let[t]=this._toEntryFn(e);return t}return}return 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 F=class extends B{constructor(e,t){super(e,t);d(this,"parent");d(this,"_left");d(this,"_right");this.parent=void 0,this._left=void 0,this._right=void 0}get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},H=class h extends te{constructor(e=[],t){super([],t);d(this,"_root");d(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return e>t?1:e<t?-1:0});d(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:i}=t;i&&(this._comparator=i)}e&&this.addMany(e)}get root(){return this._root}createNode(e,t){return new F(e,this._isMapMode?void 0:t)}createTree(e){return new h([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}keyValueNodeEntryRawToNodeAndValue(e,t){let[i,r]=super.keyValueNodeEntryRawToNodeAndValue(e,t);return i===null?[void 0,void 0]:[i,t!=null?t:r]}ensureNode(e,t=this.iterationType){var i;return(i=super.ensureNode(e,t))!=null?i:void 0}isNode(e){return e instanceof F}isKey(e){return Y(e,this.comparator!==this._DEFAULT_COMPARATOR)}add(e,t){let[i,r]=this.keyValueNodeEntryRawToNodeAndValue(e,t);if(i===void 0)return!1;if(this._root===void 0)return this._setRoot(i),this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0;let s=this._root;for(;s!==void 0;){if(this.comparator(s.key,i.key)===0)return this._replaceNode(s,i),this._isMapMode&&this._setValue(s.key,r),!0;if(this.comparator(s.key,i.key)>0){if(s.left===void 0)return s.left=i,this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0;s=s.left}else{if(s.right===void 0)return s.right=i,this._isMapMode&&this._setValue(i==null?void 0:i.key,r),this._size++,!0;s=s.right}}return!1}addMany(e,t,i=!0,r=this.iterationType){let s=[],o;if(t&&(o=t[Symbol.iterator]()),!i){for(let c of e){let g=o==null?void 0:o.next().value;s.push(this.add(c,g))}return s}let a=[],l=0;for(let c of e)a.push({key:c,value:o==null?void 0:o.next().value,orgIndex:l}),l++;let u=[];u=a.sort(({key:c},{key:g})=>{let _,m;return this.isEntry(c)?_=c[0]:this.isRealNode(c)?_=c.key:this._toEntryFn?_=this._toEntryFn(c)[0]:_=c,this.isEntry(g)?m=g[0]:this.isRealNode(g)?m=g.key:this._toEntryFn?m=this._toEntryFn(g)[0]:m=g,_!=null&&m!==void 0&&m!==null?this.comparator(_,m):0});let f=c=>{if(c.length===0)return;let g=Math.floor((c.length-1)/2),{key:_,value:m,orgIndex:O}=c[g];s[O]=this.add(_,m),f(c.slice(0,g)),f(c.slice(g+1))};return r==="RECURSIVE"?f(u):(()=>{let g=[[0,u.length-1]];for(;g.length>0;){let _=g.pop();if(_){let[m,O]=_;if(m<=O){let b=m+Math.floor((O-m)/2),{key:E,value:N,orgIndex:y}=u[b];s[y]=this.add(E,N),g.push([b+1,O]),g.push([m,b-1])}}}})(),s}getNodes(e,t=!1,i=this._root,r=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let s=this._ensurePredicate(e),o=[];if(r==="RECURSIVE"){let a=l=>{if(!(s(l)&&(o.push(l),t))&&!(!this.isRealNode(l.left)&&!this.isRealNode(l.right)))if(this._isPredicate(e))this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right);else{let u=this._getKey(e);this.isRealNode(l.left)&&u!==null&&u!==void 0&&this.comparator(l.key,u)>0&&a(l.left),this.isRealNode(l.right)&&u!==null&&u!==void 0&&this.comparator(l.key,u)<0&&a(l.right)}};a(i)}else{let a=[i];for(;a.length>0;){let l=a.pop();if(s(l)&&(o.push(l),t))return o;if(this._isPredicate(e))this.isRealNode(l.right)&&a.push(l.right),this.isRealNode(l.left)&&a.push(l.left);else{let u=this._getKey(e);this.isRealNode(l.right)&&u!==null&&u!==void 0&&this.comparator(l.key,u)<0&&a.push(l.right),this.isRealNode(l.left)&&u!==null&&u!==void 0&&this.comparator(l.key,u)>0&&a.push(l.left)}}}return o}getNode(e,t=this._root,i=this.iterationType){var r;return(r=this.getNodes(e,!0,t,i)[0])!=null?r:void 0}getNodeByKey(e,t=this.iterationType){return this.getNode(e,this._root,t)}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",i=this._root,r=this.iterationType){return super.dfs(e,t,i,r)}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){return super.bfs(e,t,i,!1)}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,i=this.iterationType){return super.listLevels(e,t,i,!1)}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,i=this._root,r=this.iterationType){let s=this.ensureNode(i),o=[];if(!this._root||!s)return o;let a=s.key;if(r==="RECURSIVE"){let l=u=>{let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&l(u.left),this.isRealNode(u.right)&&l(u.right)};return l(this._root),o}else{let l=new D([this._root]);for(;l.size>0;){let u=l.shift();if(this.isRealNode(u)){let f=this.comparator(u.key,a);Math.sign(f)===t&&o.push(e(u)),this.isRealNode(u.left)&&l.push(u.left),this.isRealNode(u.right)&&l.push(u.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN"),i=t.length;if(this._clearNodes(),t.length<1)return!1;if(e==="RECURSIVE"){let r=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this._isMapMode?this.add(l.key):this.add([l.key,l.value]),r(s,a-1),r(a+1,o)};return r(0,i-1),!0}else{let r=[[0,i-1]];for(;r.length>0;){let s=r.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this._isMapMode?this.add(u.key):this.add([u.key,u.value]),r.push([l+1,a]),r.push([o,l-1])}}}return!0}}isAVLBalanced(e=this.iterationType){if(!this._root)return!0;let t=!0;if(e==="RECURSIVE"){let i=r=>{if(!r)return 0;let s=i(r.left),o=i(r.right);return Math.abs(s-o)>1&&(t=!1),Math.max(s,o)+1};i(this._root)}else{let i=[],r=this._root,s,o=new Map;for(;i.length>0||r;)if(r)i.push(r),r=r.left;else if(r=i[i.length-1],!r.right||s===r.right){if(r=i.pop(),r){let a=r.left?o.get(r.left):-1,l=r.right?o.get(r.right):-1;if(Math.abs(a-l)>1)return!1;o.set(r,1+Math.max(a,l)),s=r,r=void 0}}else r=r.right}return t}get comparator(){return this._comparator}_setRoot(e){e&&(e.parent=void 0),this._root=e}};var Ie=class{constructor({frequency:n=0,max:e}){d(this,"_freq");d(this,"_max");d(this,"_freqMap");d(this,"_msb");d(this,"_negativeCount");this._freq=n,this._max=e,this._freqMap={0:0},this._msb=Ve(e),this._negativeCount=n<0?e:0}get freqMap(){return this._freqMap}get msb(){return this._msb}get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(n){return this._checkIndex(n),this._readSingle(n)}update(n,e){this._checkIndex(n);let t=this._readSingle(n);this._update(n,e),this._updateNegativeCount(t,t+e)}writeSingle(n,e){this._checkIndex(n),this._writeSingle(n,e)}read(n){if(!Number.isInteger(n))throw new Error("Invalid count");return this._read(Math.max(Math.min(n,this.max),0))}lowerBound(n){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(n,(e,t)=>e<t)}upperBound(n){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(n,(e,t)=>e<=t)}getPrefixSum(n){this._checkIndex(n),n++;let e=0;for(;n>0;)e+=this._getFrequency(n),n-=n&-n;return e}_getFrequency(n){return n in this.freqMap?this.freqMap[n]:this.freq*(n&-n)}_updateFrequency(n,e){this.freqMap[n]=this._getFrequency(n)+e}_checkIndex(n){if(!Number.isInteger(n))throw new Error("Invalid index: Index must be an integer.");if(n<0||n>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(n){n=n+1;let e=this._getFrequency(n),t=n-(n&-n);for(n--;n!==t;)e-=this._getFrequency(n),n-=n&-n;return e}_updateNegativeCount(n,e){n<0&&e>=0?this._negativeCount--:n>=0&&e<0&&this._negativeCount++}_update(n,e){for(n=n+1;n<=this.max;)this._updateFrequency(n,e),n+=n&-n}_writeSingle(n,e){let t=this._readSingle(n);this._update(n,e-t),this._updateNegativeCount(t,e)}_read(n){let e=n,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(n,e){let t=0,i=this.msb<<1,r=n;for(;i>t+1;){let s=t+i>>1,o=this._getFrequency(s);s<=this.max&&e(o,r)?(r-=o,t=s):i=s}return t}};var W=class{constructor(n,e,t,i){d(this,"_start",0);d(this,"_end",0);d(this,"_value");d(this,"_sum",0);d(this,"_left");d(this,"_right");this._start=n,this._end=e,this._sum=t,this._value=i||void 0}get start(){return this._start}set start(n){this._start=n}get end(){return this._end}set end(n){this._end=n}get value(){return this._value}set value(n){this._value=n}get sum(){return this._sum}set sum(n){this._sum=n}get left(){return this._left}set left(n){this._left=n}get right(){return this._right}set right(n){this._right=n}},Be=class{constructor(n,e,t){d(this,"_values",[]);d(this,"_start",0);d(this,"_end");d(this,"_root");e=e||0,t=t||n.length-1,this._values=n,this._start=e,this._end=t,n.length>0?this._root=this.build(e,t):(this._root=void 0,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(n,e){if(n>e)return new W(n,e,0);if(n===e)return new W(n,e,this._values[n]);let t=n+Math.floor((e-n)/2),i=this.build(n,t),r=this.build(t+1,e),s=new W(n,e,i.sum+r.sum);return s.left=i,s.right=r,s}updateNode(n,e,t){let i=this.root||void 0;if(!i)return;let r=(s,o,a,l)=>{if(s.start===s.end&&s.start===o){s.sum=a,l!==void 0&&(s.value=l);return}let u=s.start+Math.floor((s.end-s.start)/2);o<=u?s.left&&r(s.left,o,a,l):s.right&&r(s.right,o,a,l),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};r(i,n,e,t)}querySumByRange(n,e){let t=this.root||void 0;if(!t)return 0;if(n<0||e>=this.values.length||n>e)return NaN;let i=(r,s,o)=>{if(s<=r.start&&o>=r.end)return r.sum;let a=r.start+Math.floor((r.end-r.start)/2);if(o<=a)return r.left?i(r.left,s,o):NaN;if(s>a)return r.right?i(r.right,s,o):NaN;{let l=0,u=0;return r.left&&(l=i(r.left,s,a)),r.right&&(u=i(r.right,a+1,o)),l+u}};return i(t,n,e)}};var P=class extends F{constructor(e,t){super(e,t);d(this,"_height");this._height=0}get height(){return this._height}set height(e){this._height=e}},ie=class h extends H{constructor(n=[],e){super([],e),n&&super.addMany(n)}createNode(n,e){return new P(n,this._isMapMode?void 0:e)}createTree(n){return new h([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},n))}isNode(n){return n instanceof P}add(n,e){if(n===null)return!1;let t=super.add(n,e);return t&&this._balancePath(n),t}delete(n){let e=super.delete(n);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}_swapProperties(n,e){let t=this.ensureNode(n),i=this.ensureNode(e);if(t&&i){let{key:r,value:s,height:o}=i,a=this.createNode(r,s);return a&&(a.height=o,i.key=t.key,this._isMapMode||(i.value=t.value),i.height=t.height,t.key=a.key,this._isMapMode||(t.value=a.value),t.height=a.height),i}}_balanceFactor(n){return n.right?n.left?n.right.height-n.left.height:+n.height:-n.height}_updateHeight(n){if(!n.left&&!n.right)n.height=0;else if(n.left)n.right?n.height=1+Math.max(n.right.height,n.left.height):n.height=1+n.left.height;else{let e=n.right?n.right.height:0;n.height=1+e}}_balanceLL(n){let e=n.parent,t=n.left;n.parent=t,t&&t.right&&(t.right.parent=n),t&&(t.parent=e),n===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===n?e.left=t:e&&(e.right=t),t&&(n.left=t.right,t.right=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceLR(n){let e=n.parent,t=n.left,i;t&&(i=t.right),n&&(n.parent=i),t&&(t.parent=i),i&&(i.left&&(i.left.parent=t),i.right&&(i.right.parent=n),i.parent=e),n===this.root?i&&this._setRoot(i):e&&(e.left===n?e.left=i:e.right=i),i&&(n.left=i.right,t&&(t.right=i.left),i.left=t,i.right=n),this._updateHeight(n),t&&this._updateHeight(t),i&&this._updateHeight(i)}_balanceRR(n){let e=n.parent,t=n.right;n.parent=t,t&&(t.left&&(t.left.parent=n),t.parent=e),n===this.root?t&&this._setRoot(t):e&&(e.left===n?e.left=t:e.right=t),t&&(n.right=t.left,t.left=n),this._updateHeight(n),t&&this._updateHeight(t)}_balanceRL(n){let e=n.parent,t=n.right,i;t&&(i=t.left),n.parent=i,t&&(t.parent=i),i&&(i.left&&(i.left.parent=n),i.right&&(i.right.parent=t),i.parent=e),n===this.root?i&&this._setRoot(i):e&&(e.left===n?e.left=i:e.right=i),i&&(n.right=i.left),t&&i&&(t.left=i.right),i&&(i.left=n),i&&(i.right=t),this._updateHeight(n),t&&this._updateHeight(t),i&&this._updateHeight(i)}_balancePath(n){n=this.ensureNode(n);let e=this.getPathToRoot(t=>t,n,!1);for(let t=0;t<e.length;t++){let i=e[t];if(i)switch(this._updateHeight(i),this._balanceFactor(i)){case-2:i&&i.left&&(this._balanceFactor(i.left)<=0?this._balanceLL(i):this._balanceLR(i));break;case 2:i&&i.right&&(this._balanceFactor(i.right)>=0?this._balanceRR(i):this._balanceRL(i))}}}_replaceNode(n,e){return e.height=n.height,super._replaceNode(n,e)}};var j=class extends F{constructor(e,t,i="BLACK"){super(e,t);d(this,"_color");this._color=i}get color(){return this._color}set color(e){this._color=e}},re=class h extends H{constructor(e=[],t){super([],t);d(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,i="BLACK"){return new j(e,this._isMapMode?void 0:t,i)}createTree(e){return new h([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof j}clear(){super.clear(),this._root=this.NIL}add(e,t){let[i,r]=this.keyValueNodeEntryRawToNodeAndValue(e,t);if(!this.isRealNode(i))return!1;let s=this._insert(i);if(s==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._isMapMode&&this._setValue(i.key,r),this._size++,!0}return s==="UPDATED"?(this._isMapMode&&this._setValue(i.key,r),!0):!1}delete(e){if(e===null)return[];let t=[],i;if(this._isPredicate(e)?i=this.getNode(e):i=this.isRealNode(e)?e:this.getNode(e),!i)return t;let r=i.color,s;if(!this.isRealNode(i.left))s=i.right,this._transplant(i,i.right);else if(!this.isRealNode(i.right))s=i.left,this._transplant(i,i.left);else{let o=this.getLeftMost(a=>a,i.right);o&&(r=o.color,s=o.right,o.parent===i?this.isRealNode(s)&&(s.parent=o):(this._transplant(o,o.right),o.right=i.right,this.isRealNode(o.right)&&(o.right.parent=o)),this._transplant(i,o),o.left=i.left,this.isRealNode(o.left)&&(o.left.parent=o),o.color=i.color)}return this._isMapMode&&this._store.delete(i.key),this._size--,r==="BLACK"&&this._deleteFixup(s),t.push({deleted:i,needBalanced:void 0}),t}_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 r,s;let t=this.root,i;for(;this.isRealNode(t);){i=t;let o=this.comparator(e.key,t.key);if(o<0)t=(r=t.left)!=null?r:this.NIL;else if(o>0)t=(s=t.right)!=null?s:this.NIL;else return this._replaceNode(t,e),"UPDATED"}return e.parent=i,i?e.key<i.key?i.left=e:i.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,i,r,s;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((i=e.parent.parent)==null?void 0:i.left)){let o=e.parent.parent.right;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._rightRotate(e.parent.parent)))}else{let o=(s=(r=e==null?void 0:e.parent)==null?void 0:r.parent)==null?void 0:s.left;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e&&this.isRealNode(e.parent)&&this.isRealNode(e.parent.parent)&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._leftRotate(e.parent.parent)))}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,i,r,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let o=e.parent;if(!o)break;if(e===o.left){let a=o.right;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o.color="RED",this._leftRotate(o),a=o.right),((i=(t=a==null?void 0:a.left)==null?void 0:t.color)!=null?i:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.left&&(a.left.color="BLACK"),a&&(a.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let a=o.left;(a==null?void 0:a.color)==="RED"&&(a.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(a=o.left)),((s=(r=a==null?void 0:a.right)==null?void 0:r.color)!=null?s:"BLACK")==="BLACK"?(a&&(a.color="RED"),e=o):(a!=null&&a.right&&(a.right.color="BLACK"),a&&(a.color=o.color),o&&(o.color="BLACK"),this._leftRotate(o),e=this.root)}}e&&(e.color="BLACK")}_leftRotate(e){if(!e||!e.right)return;let t=e.right;e.right=t.left,this.isRealNode(t.left)&&(t.left.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.left=e,e.parent=t}_rightRotate(e){if(!e||!e.left)return;let t=e.left;e.left=t.right,this.isRealNode(t.right)&&(t.right.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.right=e,e.parent=t}};var ne=class extends P{constructor(e,t,i=1){super(e,t);d(this,"_count",1);this.count=i}get count(){return this._count}set count(e){this._count=e}},Se=class h extends ie{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,i){return new ne(e,this._isMapMode?void 0:t,i)}createTree(e){return new h([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}isNode(e){return e instanceof ne}keyValueNodeEntryRawToNodeAndValue(e,t,i=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[r,s]=e;if(r==null)return[void 0,void 0];let o=t!=null?t:s;return[this.createNode(r,o,i),o]}if(this.isKey(e))return[this.createNode(e,t,i),t];if(this.isRaw(e)){if(this._toEntryFn){let[r,s]=this._toEntryFn(e),o=t!=null?t:s;if(this.isKey(r))return[this.createNode(r,o,i),o]}return[void 0,void 0]}return[void 0,void 0]}add(e,t,i=1){let[r,s]=this.keyValueNodeEntryRawToNodeAndValue(e,t,i);if(r===void 0)return!1;let o=(r==null?void 0:r.count)||0;return super.add(r,s)&&(this._count+=o),!0}delete(e,t=!1){var l;let i=[];if(!this.root)return i;let r=(l=this.getNode(e))!=null?l:void 0;if(!r)return i;let s=r!=null&&r.parent?r.parent:void 0,o,a=r;if(r.count>1&&!t)r.count--,this._count--;else{if(r.left){let u=r.left?this.getRightMost(f=>f,r.left):void 0;if(u){let f=u.parent;a=this._swapProperties(r,u),f&&(f.right===u?f.right=u.left:f.left=u.left,o=f)}}else if(!s)r.right!==void 0&&this._setRoot(r.right);else{let{familyPosition:u}=r;u==="LEFT"||u==="ROOT_LEFT"?s.left=r.right:(u==="RIGHT"||u==="ROOT_RIGHT")&&(s.right=r.right),o=s}this._size=this._size-1,a&&(this._count-=a.count)}return i.push({deleted:a,needBalanced:o}),o&&this._balancePath(o),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN"),i=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let r=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this._isMapMode?this.add(l.key,void 0,l.count):this.add(l.key,l.value,l.count),r(s,a-1),r(a+1,o)};return r(0,i-1),!0}else{let r=[[0,i-1]];for(;r.length>0;){let s=r.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this._isMapMode?this.add(u.key,void 0,u.count):this.add(u.key,u.value,u.count),r.push([l+1,a]),r.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}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:i,value:r,count:s,height:o}=t,a=this.createNode(i,r,s);return a&&(a.height=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.height=e.height,e.key=a.key,this._isMapMode||(e.value=a.value),e.count=a.count,e.height=a.height),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var se=class extends j{constructor(e,t,i=1,r="BLACK"){super(e,t,r);d(this,"_count",1);this.count=i}get count(){return this._count}set count(e){this._count=e}},Ae=class h extends re{constructor(e=[],t){super([],t);d(this,"_count",0);e&&this.addMany(e)}get count(){return this._count}getComputedCount(){let e=0;return this.dfs(t=>e+=t.count),e}createNode(e,t,i="BLACK",r){return new se(e,this._isMapMode?void 0:t,r,i)}createTree(e){return new h([],M({iterationType:this.iterationType,isMapMode:this._isMapMode,comparator:this._comparator,toEntryFn:this._toEntryFn},e))}keyValueNodeEntryRawToNodeAndValue(e,t,i=1){if(e==null)return[void 0,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[r,s]=e;if(r==null)return[void 0,void 0];let o=t!=null?t:s;if(this.isKey(r))return[this.createNode(r,o,"BLACK",i),o]}if(this._toEntryFn){let[r,s]=this._toEntryFn(e),o=t!=null?t:s;if(this.isKey(r))return[this.createNode(r,o,"BLACK",i),o]}return this.isKey(e)?[this.createNode(e,t,"BLACK",i),t]:[void 0,void 0]}isNode(e){return e instanceof se}add(e,t,i=1){let[r,s]=this.keyValueNodeEntryRawToNodeAndValue(e,t,i),o=(r==null?void 0:r.count)||0;return super.add(r,s)?(this._count+=o,!0):!1}delete(e,t=!1){if(e===null)return[];let i=[],r;if(this._isPredicate(e)?r=this.getNode(e):r=this.isRealNode(e)?e:this.getNode(e),!r)return i;let s=r.color,o;if(this.isRealNode(r.left))if(this.isRealNode(r.right)){let a=this.getLeftMost(l=>l,r.right);if(a){if(s=a.color,o=a.right,a.parent===r)this.isRealNode(o)&&(o.parent=a);else{if(t||r.count<=1)this._transplant(a,a.right),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;a.right=r.right,this.isRealNode(a.right)&&(a.right.parent=a)}if(t||r.count<=1)this._transplant(r,a),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;a.left=r.left,this.isRealNode(a.left)&&(a.left.parent=a),a.color=r.color}}else if(o=r.left,t||r.count<=1)this._transplant(r,r.left),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;else if(o=r.right,t||r.count<=1)this._transplant(r,r.right),this._count-=r.count;else return r.count--,this._count--,i.push({deleted:r,needBalanced:void 0}),i;return this._size--,s==="BLACK"&&this._deleteFixup(o),i.push({deleted:r,needBalanced:void 0}),i}clear(){super.clear(),this._count=0}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN"),i=t.length;if(t.length<1)return!1;if(this.clear(),e==="RECURSIVE"){let r=(s,o)=>{if(s>o)return;let a=s+Math.floor((o-s)/2),l=t[a];this._isMapMode?this.add(l.key,void 0,l.count):this.add(l.key,l.value,l.count),r(s,a-1),r(a+1,o)};return r(0,i-1),!0}else{let r=[[0,i-1]];for(;r.length>0;){let s=r.pop();if(s){let[o,a]=s;if(o<=a){let l=o+Math.floor((a-o)/2),u=t[l];this._isMapMode?this.add(u.key,void 0,u.count):this.add(u.key,u.value,u.count),r.push([l+1,a]),r.push([o,l-1])}}}return!0}}clone(){let e=this.createTree();return this.bfs(t=>e.add(t.key,void 0,t.count)),this._isMapMode&&(e._store=this._store),e}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:i,value:r,count:s,color:o}=t,a=this.createNode(i,r,o,s);return a&&(a.color=o,t.key=e.key,this._isMapMode||(t.value=e.value),t.count=e.count,t.color=e.color,e.key=a.key,this._isMapMode||(e.value=a.value),e.count=a.count,e.color=a.color),t}}_replaceNode(e,t){return t.count=e.count+t.count,super._replaceNode(e,t)}};var U=class h extends K{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var ze=class h extends U{constructor(n=[],e){super(n,e)}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var He=class h extends U{constructor(n=[],e){super(n,M({comparator:(t,i)=>{if(typeof t=="object"||typeof i=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<i?1:t>i?-1:0}},e))}clone(){return new h(this,{comparator:this.comparator,toElementFn:this.toElementFn})}filter(n,e){let t=new h([],{toElementFn:this.toElementFn,comparator:this.comparator}),i=0;for(let r of this)n.call(e,r,i,this)&&t.add(r),i++;return t}map(n,e,t,i){let r=new h([],{comparator:e,toElementFn:t}),s=0;for(let o of this)r.add(n.call(i,o,s,this)),s++;return r}};var Pe=class h{constructor(n,e){d(this,"_rows",0);d(this,"_cols",0);d(this,"_data");var t,i,r;if(e){let{rows:s,cols:o,addFn:a,subtractFn:l,multiplyFn:u}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=n.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=n[0])==null?void 0:t.length)||0,a&&(this._addFn=a),l&&(this._subtractFn=l),u&&(this._multiplyFn=u)}else this._rows=n.length,this._cols=(r=(i=n[0])==null?void 0:i.length)!=null?r:0;if(n.length>0)this._data=n;else{this._data=[];for(let s=0;s<this.rows;s++)this._data[s]=new Array(this.cols).fill(0)}}get rows(){return this._rows}get cols(){return this._cols}get data(){return this._data}get addFn(){return this._addFn}get subtractFn(){return this._subtractFn}get multiplyFn(){return this._multiplyFn}get(n,e){if(this.isValidIndex(n,e))return this.data[n][e]}set(n,e,t){return this.isValidIndex(n,e)?(this.data[n][e]=t,!0):!1}isMatchForCalculate(n){return this.rows===n.rows&&this.cols===n.cols}add(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<this.cols;i++){let r=this.get(t,i),s=n.get(t,i);if(r!==void 0&&s!==void 0){let o=this._addFn(r,s);o&&(e[t][i]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(n){if(!this.isMatchForCalculate(n))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<this.cols;i++){let r=this.get(t,i),s=n.get(t,i);if(r!==void 0&&s!==void 0){let o=this._subtractFn(r,s);o&&(e[t][i]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(n){if(this.cols!==n.rows)throw new Error("Matrix dimensions must be compatible for multiplication (A.cols = B.rows).");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<n.cols;i++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,i);if(o!==void 0&&a!==void 0){let l=this.multiplyFn(o,a);l!==void 0&&(r=this.addFn(r,l))}}r!==void 0&&(e[t][i]=r)}}return new h(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){if(this.data.some(e=>e.length!==this.rows))throw new Error("Matrix must be rectangular for transposition.");let n=[];for(let e=0;e<this.cols;e++){n[e]=[];for(let t=0;t<this.rows;t++){let i=this.get(t,e);i!==void 0&&(n[e][t]=i)}}return new h(n,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var i;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let n=[];for(let r=0;r<this.rows;r++){n[r]=this.data[r].slice();for(let s=0;s<this.cols;s++)n[r][this.cols+s]=r===s?1:0}let e=new h(n,{rows:this.rows,cols:this.cols*2,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn});for(let r=0;r<this.rows;r++){let s=r;for(;s<this.rows&&e.get(s,r)===0;)s++;if(s===this.rows)throw new Error("Matrix is singular, and its inverse does not exist.");e._swapRows(r,s);let o=(i=e.get(r,r))!=null?i:1;if(o===0)throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");e._scaleRow(r,1/o);for(let a=0;a<this.rows;a++)if(a!==r){let l=e.get(a,r);l===void 0&&(l=0),e._addScaledRow(a,r,-l)}}let t=[];for(let r=0;r<this.rows;r++)t[r]=e.data[r].slice(this.cols);return new h(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(n){if(this.cols!==n.rows)throw new Error("Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let i=0;i<n.cols;i++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),a=n.get(s,i);if(o!==void 0&&a!==void 0){let l=this.multiplyFn(o,a);l!==void 0&&(r=this.addFn(r,l))}}r!==void 0&&(e[t][i]=r)}}return new h(e,{rows:this.rows,cols:n.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(n,e){return n>=0&&n<this.rows&&e>=0&&e<this.cols}clone(){return new h(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(n,e){return n===void 0?e:n+e}_subtractFn(n,e){return n-e}_multiplyFn(n,e){return n*e}_swapRows(n,e){let t=this.data[n];this.data[n]=this.data[e],this.data[e]=t}_scaleRow(n,e){for(let t=0;t<this.cols;t++){let i=this.multiplyFn(this.data[n][t],e);i===void 0&&(i=0),this.data[n][t]=i}}_addScaledRow(n,e,t){for(let i=0;i<this.cols;i++){let r=this.multiplyFn(this.data[e][i],t);r===void 0&&(r=0);let s=r,o=this.addFn(this.data[n][i],s);o===void 0&&(o=0),this.data[n][i]=o}}};var pe=class h{constructor(n,e){d(this,"direction");d(this,"turn");this.direction=n,this.turn=()=>new h(e[n],e)}},je=class{constructor({matrix:n,turning:e,onMove:t,init:{cur:i,charDir:r,VISITED:s}}){d(this,"onMove");d(this,"_matrix");d(this,"_cur");d(this,"_character");d(this,"_VISITED");this._matrix=n,this._cur=i,this._character=new pe(r,e),this.onMove=t,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:n}=this._character;this.check(n)?this.move(n):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(n){let e,t,i=this._matrix,[r,s]=this._cur;switch(n){case"up":if(t=i[r-1],!t)return!1;e=t[s];break;case"right":e=i[r][s+1];break;case"down":if(t=i[r+1],!t)return!1;e=t[s];break;case"left":e=i[r][s-1];break}return e!==void 0&&e!==this._VISITED}move(n){switch(n){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[e,t]=this._cur;this._matrix[e][t]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var X=class{constructor(n){d(this,"_key");d(this,"_children");d(this,"_isEnd");this._key=n,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(n){this._key=n}get children(){return this._children}set children(n){this._children=n}get isEnd(){return this._isEnd}set isEnd(n){this._isEnd=n}},Ue=class h extends k{constructor(e=[],t){super(t);d(this,"_size",0);d(this,"_caseSensitive",!0);d(this,"_root",new X(""));if(t){let{caseSensitive:i}=t;i!==void 0&&(this._caseSensitive=i)}if(e)for(let i of e)this.toElementFn?this.add(this.toElementFn(i)):this.add(i)}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,i=!1;for(let r of e){let s=t.children.get(r);s||(s=new X(r),t.children.set(r,s)),t=s}return t.isEnd||(i=!0,t.isEnd=!0,this._size++),i}has(e){e=this._caseProcess(e);let t=this.root;for(let i of e){let r=t.children.get(i);if(!r)return!1;t=r}return t.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new X("")}delete(e){e=this._caseProcess(e);let t=!1,i=(r,s)=>{let o=e[s],a=r.children.get(o);return a?s===e.length-1?a.isEnd?(a.children.size>0?a.isEnd=!1:r.children.delete(o),t=!0,!0):!1:i(a,s+1)&&!r.isEnd&&a.children.size===0?(r.children.delete(o),!0):!1:!1};return i(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let i=(r,s)=>{s>t&&(t=s);let{children:o}=r;if(o)for(let a of o.entries())i(a[1],s+1)};i(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let i of e){let r=t.children.get(i);if(!r)return!1;t=r}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let i of e){let r=t.children.get(i);if(!r)return!1;t=r}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",i=r=>{if(t+=r.key,t!==e&&!r.isEnd)if(r&&r.children&&r.children.size===1)i(Array.from(r.children.values())[0]);else return};return i(this.root),t===e}getLongestCommonPrefix(){let e="",t=i=>{if(e+=i.key,!i.isEnd)if(i&&i.children&&i.children.size===1)t(Array.from(i.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,i=!1){e=this._caseProcess(e);let r=[],s=0;function o(l,u){for(let f of l.children.keys()){let p=l.children.get(f);p!==void 0&&o(p,u.concat(f))}if(l.isEnd){if(s>t-1)return;r.push(u),s++}}let a=this.root;if(e)for(let l of e){let u=a.children.get(l);if(u)a=u;else return[]}return(i||a!==this.root)&&o(a,e),r}clone(){return new h(this,{caseSensitive:this.caseSensitive,toElementFn:this.toElementFn})}filter(e,t){let i=new h([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive}),r=0;for(let s of this)e.call(t,s,r,this)&&i.add(s),r++;return i}map(e,t,i){let r=new h([],{toElementFn:t,caseSensitive:this.caseSensitive}),s=0;for(let o of this)r.add(e.call(i,o,s,this)),s++;return r}*_getIterator(){function*e(t,i){t.isEnd&&(yield i);for(let[r,s]of t.children)yield*L(e(s,i+r))}yield*L(e(this.root,""))}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var qe=class h{constructor(n,e,t){d(this,"_key");d(this,"_value");d(this,"_children");this._key=n,this._value=e||void 0,t&&(this._children=t)}get key(){return this._key}set key(n){this._key=n}get value(){return this._value}set value(n){this._value=n}get children(){return this._children}set children(n){this._children=n}addChildren(n){this._children||(this._children=[]),n instanceof h?this._children.push(n):this._children=this._children.concat(n)}getHeight(){let n=0;if(this){let e=(t,i)=>{i>n&&(n=i);let{_children:r}=t;if(r)for(let s=0,o=r.length;s<o;s++)e(r[s],i+1)};e(this,0)}return n}};return rt(ht);})();
|
|
6
6
|
/**
|
|
7
7
|
* data-structure-typed
|
|
8
8
|
*
|