tree-multimap-typed 2.5.3 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  2. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  3. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
  4. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  5. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
  6. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
  7. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  8. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  9. package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
  10. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  11. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  12. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
  13. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  14. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  15. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  16. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  17. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
  18. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  19. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  20. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  21. package/dist/types/data-structures/queue/deque.d.ts +90 -1
  22. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  23. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  24. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  25. package/dist/umd/tree-multimap-typed.js +2383 -3
  26. package/dist/umd/tree-multimap-typed.js.map +1 -1
  27. package/dist/umd/tree-multimap-typed.min.js +4 -4
  28. package/dist/umd/tree-multimap-typed.min.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/data-structures/base/iterable-element-base.ts +32 -0
  31. package/src/data-structures/base/linear-base.ts +11 -0
  32. package/src/data-structures/binary-tree/avl-tree.ts +36 -0
  33. package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
  34. package/src/data-structures/binary-tree/binary-tree.ts +75 -0
  35. package/src/data-structures/binary-tree/bst.ts +72 -0
  36. package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
  37. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  38. package/src/data-structures/binary-tree/tree-map.ts +375 -0
  39. package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
  40. package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
  41. package/src/data-structures/binary-tree/tree-set.ts +492 -0
  42. package/src/data-structures/graph/directed-graph.ts +30 -0
  43. package/src/data-structures/graph/undirected-graph.ts +27 -0
  44. package/src/data-structures/hash/hash-map.ts +33 -0
  45. package/src/data-structures/heap/heap.ts +42 -0
  46. package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
  47. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  48. package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
  49. package/src/data-structures/matrix/matrix.ts +24 -0
  50. package/src/data-structures/queue/deque.ts +103 -1
  51. package/src/data-structures/queue/queue.ts +36 -0
  52. package/src/data-structures/stack/stack.ts +30 -0
  53. package/src/data-structures/trie/trie.ts +36 -0
@@ -1,10 +1,10 @@
1
- "use strict";var treeMultimapTyped=(()=>{var dt=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var ze=Object.prototype.hasOwnProperty;var Ve=(c,t)=>{for(var e in t)dt(c,e,{get:t[e],enumerable:!0})},Ke=(c,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of De(t))!ze.call(c,s)&&s!==e&&dt(c,s,{get:()=>t[s],enumerable:!(i=Be(t,s))||i.enumerable});return c};var je=c=>Ke(dt({},"__esModule",{value:!0}),c);var xi={};Ve(xi,{TreeMultiMap:()=>Le});var St=Object.defineProperty,Tt=c=>{throw TypeError(c)},He=(c,t,e)=>t in c?St(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,u=(c,t)=>St(c,"name",{value:t,configurable:!0}),f=(c,t,e)=>He(c,typeof t!="symbol"?t+"":t,e),At=(c,t,e)=>t.has(c)||Tt("Cannot "+e),d=(c,t,e)=>(At(c,t,"read from private field"),e?e.call(c):t.get(c)),V=(c,t,e)=>t.has(c)?Tt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(c):t.set(c,e),K=(c,t,e,i)=>(At(c,t,"write to private field"),t.set(c,e),e),Bt=class{*[Symbol.iterator](...t){yield*this._getIterator(...t)}*entries(){for(let t of this)yield t}*keys(){for(let t of this)yield t[0]}*values(){for(let t of this)yield t[1]}every(t,e){let i=0;for(let s of this)if(!t.call(e,s[1],s[0],i++,this))return!1;return!0}some(t,e){let i=0;for(let s of this)if(t.call(e,s[1],s[0],i++,this))return!0;return!1}forEach(t,e){let i=0;for(let s of this){let[r,n]=s;t.call(e,n,r,i++,this)}}find(t,e){let i=0;for(let s of this){let[r,n]=s;if(t.call(e,n,r,i++,this))return s}}has(t){for(let e of this){let[i]=e;if(i===t)return!0}return!1}hasValue(t){for(let[,e]of this)if(e===t)return!0;return!1}get(t){for(let e of this){let[i,s]=e;if(i===t)return s}}reduce(t,e){let i=e,s=0;for(let r of this){let[n,h]=r;i=t(i,h,n,s++,this)}return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};u(Bt,"IterableEntryBase");var it=Bt;function x(c,t){throw new c(t)}u(x,"raise");var R={indexOutOfRange:u((c,t,e,i)=>`${i?i+": ":""}Index ${c} is out of range [${t}, ${e}].`,"indexOutOfRange"),invalidIndex:u(c=>`${c?c+": ":""}Index must be an integer.`,"invalidIndex"),invalidArgument:u((c,t)=>`${t?t+": ":""}${c}`,"invalidArgument"),comparatorRequired:u(c=>`${c?c+": ":""}Comparator is required for non-number/non-string/non-Date keys.`,"comparatorRequired"),invalidKey:u((c,t)=>`${t?t+": ":""}${c}`,"invalidKey"),notAFunction:u((c,t)=>`${t?t+": ":""}${c} must be a function.`,"notAFunction"),invalidEntry:u(c=>`${c?c+": ":""}Each entry must be a [key, value] tuple.`,"invalidEntry"),invalidNaN:u(c=>`${c?c+": ":""}NaN is not a valid key.`,"invalidNaN"),invalidDate:u(c=>`${c?c+": ":""}Invalid Date key.`,"invalidDate"),reduceEmpty:u(c=>`${c?c+": ":""}Reduce of empty structure with no initial value.`,"reduceEmpty"),callbackReturnType:u((c,t,e)=>`${e?e+": ":""}Callback must return ${c}; got ${t}.`,"callbackReturnType"),invalidOperation:u((c,t)=>`${t?t+": ":""}${c}`,"invalidOperation"),matrixDimensionMismatch:u(c=>`Matrix: Dimensions must be compatible for ${c}.`,"matrixDimensionMismatch"),matrixSingular:u(()=>"Matrix: Singular matrix, inverse does not exist.","matrixSingular"),matrixNotSquare:u(()=>"Matrix: Must be square for inversion.","matrixNotSquare"),matrixNotRectangular:u(()=>"Matrix: Must be rectangular for transposition.","matrixNotRectangular"),matrixRowMismatch:u((c,t)=>`Matrix: Expected row length ${c}, but got ${t}.`,"matrixRowMismatch"),orderStatisticNotEnabled:u((c,t)=>`${t?t+": ":""}${c}() requires enableOrderStatistic: true.`,"orderStatisticNotEnabled")};var Dt=class{constructor(t,e,i=!0,s=!0){this.low=t,this.high=e,this.includeLow=i,this.includeHigh=s}isInRange(t,e){let i=this.includeLow?e(t,this.low)>=0:e(t,this.low)>0,s=this.includeHigh?e(t,this.high)<=0:e(t,this.high)<0;return i&&s}};u(Dt,"Range");var st=Dt,zt=class{constructor(t){if(f(this,"_toElementFn"),t){let{toElementFn:e}=t;typeof e=="function"?this._toElementFn=e:e&&x(TypeError,"toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...t){yield*this._getIterator(...t)}*values(){for(let t of this)yield t}every(t,e){let i=0;for(let s of this)if(e===void 0){if(!t(s,i++,this))return!1}else if(!t.call(e,s,i++,this))return!1;return!0}some(t,e){let i=0;for(let s of this)if(e===void 0){if(t(s,i++,this))return!0}else if(t.call(e,s,i++,this))return!0;return!1}forEach(t,e){let i=0;for(let s of this)e===void 0?t(s,i++,this):t.call(e,s,i++,this)}find(t,e){let i=0;for(let s of this)if(e===void 0){if(t(s,i++,this))return s}else if(t.call(e,s,i++,this))return s}has(t){for(let e of this)if(e===t)return!0;return!1}reduce(t,e){let i=0,s=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let n=s.next();n.done&&x(TypeError,"Reduce of empty structure with no initial value"),r=n.value,i=1}for(let n of s)r=t(r,n,i++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};u(zt,"IterableElementBase");var ut=zt,Vt=class{constructor(t){f(this,"_value"),f(this,"_next"),this._value=t,this._next=void 0}get value(){return this._value}set value(t){this._value=t}get next(){return this._next}set next(t){this._next=t}};u(Vt,"LinkedListNode");var Kt=Vt,jt=class Ht extends ut{constructor(t){if(super(t),f(this,"_maxLen",-1),t){let{maxLen:e}=t;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}get maxLen(){return this._maxLen}indexOf(t,e=0){if(this.length===0)return-1;e<0&&(e=this.length+e),e<0&&(e=0);for(let i=e;i<this.length;i++)if(this.at(i)===t)return i;return-1}lastIndexOf(t,e=this.length-1){if(this.length===0)return-1;e>=this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(let i=e;i>=0;i--)if(this.at(i)===t)return i;return-1}findIndex(t,e){for(let i=0;i<this.length;i++){let s=this.at(i);if(s!==void 0&&t.call(e,s,i,this))return i}return-1}concat(...t){let e=this.clone();for(let i of t)i instanceof Ht?e.pushMany(i):e.push(i);return e}sort(t){let e=this.toArray();e.sort(t),this.clear();for(let i of e)this.push(i);return this}splice(t,e=0,...i){let s=this._createInstance();t=t<0?this.length+t:t,t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,Math.min(e,this.length-t));for(let r=0;r<e;r++){let n=this.deleteAt(t);n!==void 0&&s.push(n)}for(let r=0;r<i.length;r++)this.addAt(t+r,i[r]);return s}join(t=","){return this.toArray().join(t)}toReversedArray(){let t=[];for(let e=this.length-1;e>=0;e--)t.push(this.at(e));return t}reduceRight(t,e){let i=e!=null?e:0;for(let s=this.length-1;s>=0;s--)i=t(i,this.at(s),s,this);return i}slice(t=0,e=this.length){t=t<0?this.length+t:t,e=e<0?this.length+e:e;let i=this._createInstance();for(let s=t;s<e;s++)i.push(this.at(s));return i}fill(t,e=0,i=this.length){if(e=e<0?this.length+e:e,i=i<0?this.length+i:i,e<0&&(e=0),i>this.length&&(i=this.length),e>=i)return this;for(let s=e;s<i;s++)this.setAt(s,t);return this}};u(jt,"LinearBase");var at=jt,Ut=class extends at{constructor(t){if(super(t),t){let{maxLen:e}=t;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(t,e=0){let i=this._getIterator(),s=i.next(),r=0;for(;r<e;)s=i.next(),r++;for(;!s.done;){if(s.value===t)return r;s=i.next(),r++}return-1}lastIndexOf(t,e=this.length-1){let i=this._getReverseIterator(),s=i.next(),r=this.length-1;for(;r>e;)s=i.next(),r--;for(;!s.done;){if(s.value===t)return r;s=i.next(),r--}return-1}concat(...t){let e=this.clone();for(let i of t)i instanceof at?e.pushMany(i):e.push(i);return e}slice(t=0,e=this.length){t=t<0?this.length+t:t,e=e<0?this.length+e:e;let i=this._createInstance(),s=this._getIterator(),r=s.next(),n=0;for(;n<t;)r=s.next(),n++;for(let h=t;h<e;h++)i.push(r.value),r=s.next();return i}splice(t,e=0,...i){let s=this._createInstance();t=t<0?this.length+t:t,t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,e);let r=0,n,h,o=this._getNodeIterator();for(let a of o){if(r===t){n=a;break}h=a,r++}for(let a=0;a<e&&n;a++){s.push(n.value);let l=n.next;this.delete(n),n=l}for(let a=0;a<i.length;a++)h?(this.addAfter(h,i[a]),h=h.next):(this.addAt(0,i[a]),h=this._getNodeIterator().next().value);return s}reduceRight(t,e){let i=e!=null?e:0,s=this.length-1;for(let r of this._getReverseIterator())i=t(i,r,s--,this);return i}};u(Ut,"LinearLinkedBase");var qt=Ut,Ue=u(function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(c){let t=Math.random()*16|0;return(c=="x"?t:t&3|8).toString(16)})},"uuidV4"),q=u(function(c,t){let e=-1,i=c?c.length:0,s=[];for(;++e<i;){let r=c[e];t(r,e,c)&&(s.push(r),Array.prototype.splice.call(c,e--,1),i--)}return s},"arrayRemove");var W=u((c,t,e,i)=>{if(c<t||c>e)throw new RangeError(i!=null?i:`Index ${c} is out of range [${t}, ${e}].`)},"rangeCheck");var H=u(c=>{let t=typeof c;return t==="object"&&c!==null||t==="function"},"isWeakKey"),Et=u((c,t)=>Math.floor((c+t-1)/t),"calcMinUnitsRequired");function lt(c){let t=typeof c;return t==="number"?!0:t==="bigint"||t==="string"||t==="boolean"}u(lt,"isPrimitiveComparable");function wt(c){if(typeof c.valueOf=="function"){let t=c.valueOf();if(t!==c){if(lt(t))return t;if(typeof t=="object"&&t!==null)return wt(t)}}if(typeof c.toString=="function"){let t=c.toString();if(t!=="[object Object]")return t}return null}u(wt,"tryObjectToPrimitive");function tt(c,t=!1){if(c==null)return!1;if(lt(c))return!0;if(typeof c!="object")return!1;if(c instanceof Date||t)return!0;let e=wt(c);return e==null?!1:lt(e)}u(tt,"isComparable");var Lt=u(c=>({isThunk:!0,fn:c}),"makeTrampolineThunk"),Wt=u(c=>typeof c=="object"&&c!==null&&"isThunk"in c&&c.isThunk,"isTrampolineThunk");function Gt(c){let t=c;for(;Wt(t);)t=t.fn();return t}u(Gt,"trampoline");function yt(c){return(...t)=>Gt(c(...t))}u(yt,"makeTrampoline");async function $t(c){let t=await c;for(;Wt(t);)t=await t.fn();return t}u($t,"asyncTrampoline");function qe(c){return async(...t)=>$t(c(...t))}u(qe,"makeAsyncTrampoline");function We(c,t=32){let e=(c>>>0).toString(2);return e=e.padStart(t,"0"),e}u(We,"toBinaryString");var Ge=class extends it{constructor(t=[],e){if(super(),f(this,"_store",{}),f(this,"_objMap",new Map),f(this,"_toEntryFn"),f(this,"_size",0),f(this,"_hashFn",u(i=>String(i),"_hashFn")),e){let{hashFn:i,toEntryFn:s}=e;i&&(this._hashFn=i),s&&(this._toEntryFn=s)}t&&this.setMany(t)}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}isEmpty(){return this._size===0}clear(){this._store={},this._objMap.clear(),this._size=0}isEntry(t){return Array.isArray(t)&&t.length===2}set(t,e){if(this._isObjKey(t))this.objMap.has(t)||this._size++,this.objMap.set(t,e);else{let i=this._getNoObjKey(t);this.store[i]===void 0&&this._size++,this._store[i]={key:t,value:e}}return this}setMany(t){let e=[];for(let i of t){let s,r;if(this.isEntry(i)?[s,r]=i:this._toEntryFn&&([s,r]=this._toEntryFn(i)),s!==void 0&&r!==void 0){let n=this._size;this.set(s,r),e.push(n<this._size)}}return e}get(t){var e;if(this._isObjKey(t))return this.objMap.get(t);let i=this._getNoObjKey(t);return(e=this._store[i])==null?void 0:e.value}has(t){return this._isObjKey(t)?this.objMap.has(t):this._getNoObjKey(t)in this.store}delete(t){if(this._isObjKey(t))return this.objMap.has(t)&&this._size--,this.objMap.delete(t);let e=this._getNoObjKey(t);return e in this.store?(delete this.store[e],this._size--,!0):!1}setHashFn(t){return this._hashFn===t?this:(this._hashFn=t,this._rehashNoObj(),this)}clone(){let t={hashFn:this._hashFn,toEntryFn:this._toEntryFn};return this._createLike(this,t)}map(t,e){let i=this._createLike(),s=0;for(let[r,n]of this)i.set(r,t.call(e,n,r,s++,this));return i}filter(t,e){let i=this._createLike(),s=0;for(let[r,n]of this)t.call(e,n,r,s++,this)&&i.set(r,n);return i}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_rehashNoObj(){let t={};for(let{key:e,value:i}of Object.values(this._store)){let s=this._getNoObjKey(e);t[s]={key:e,value:i}}this._store=t}*_getIterator(){for(let t of Object.values(this.store))yield[t.key,t.value];for(let t of this.objMap)yield t}_isObjKey(t){let e=typeof t;return(e==="object"||e==="function")&&t!==null}_getNoObjKey(t){let e=typeof t,i;return e!=="string"&&e!=="number"&&e!=="symbol"?i=this._hashFn(t):i=t,i}};u(Ge,"HashMap");var $e=class extends it{constructor(t=[],e){if(super(),f(this,"_sentinel"),f(this,"_hashFn",u(i=>String(i),"_hashFn")),f(this,"_objHashFn",u(i=>i,"_objHashFn")),f(this,"_noObjMap",{}),f(this,"_objMap",new WeakMap),f(this,"_head"),f(this,"_tail"),f(this,"_toEntryFn",u(i=>{if(this.isEntry(i))return i;x(TypeError,R.invalidArgument("If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.","HashMap"))},"_toEntryFn")),f(this,"_size",0),this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,e){let{hashFn:i,objHashFn:s,toEntryFn:r}=e;i&&(this._hashFn=i),s&&(this._objHashFn=s),r&&(this._toEntryFn=r)}t&&this.setMany(t)}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 t=this.head;for(;t!==this._sentinel;)yield[t.key,t.value],t=t.next}*reverseBegin(){let t=this.tail;for(;t!==this._sentinel;)yield[t.key,t.value],t=t.prev}set(t,e){let i,s=!this.has(t);if(H(t)){let r=this._objHashFn(t);i=this.objMap.get(r),!i&&s?(i={key:r,value:e,prev:this.tail,next:this._sentinel},this.objMap.set(r,i)):i&&(i.value=e)}else{let r=this._hashFn(t);i=this.noObjMap[r],!i&&s?this.noObjMap[r]=i={key:t,value:e,prev:this.tail,next:this._sentinel}:i&&(i.value=e)}return i&&s&&(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++),this}setMany(t){let e=[];for(let i of t){let s,r;if(this.isEntry(i)?[s,r]=i:this._toEntryFn&&([s,r]=this._toEntryFn(i)),s!==void 0&&r!==void 0){let n=this._size;this.set(s,r),e.push(n<this._size)}}return e}has(t){if(H(t)){let i=this._objHashFn(t);return this.objMap.has(i)}return this._hashFn(t)in this.noObjMap}get(t){if(H(t)){let s=this._objHashFn(t),r=this.objMap.get(s);return r?r.value:void 0}let e=this._hashFn(t),i=this.noObjMap[e];return i?i.value:void 0}at(t){W(t,0,this._size-1);let e=this.head;for(;t--;)e=e.next;return e.value}delete(t){let e;if(H(t)){let i=this._objHashFn(t);if(e=this.objMap.get(i),!e)return!1;this.objMap.delete(i)}else{let i=this._hashFn(t);if(e=this.noObjMap[i],!e)return!1;delete this.noObjMap[i]}return this._deleteNode(e)}deleteWhere(t){let e=this._head,i=0;for(;e!==this._sentinel;){let s=e;if(e=e.next,t(s.key,s.value,i++,this)){let r=s.key;if(H(r))this._objMap.delete(r);else{let n=this._hashFn(s.key);delete this._noObjMap[n]}return this._deleteNode(s)}}return!1}deleteAt(t){W(t,0,this._size-1);let e=this.head;for(;t--;)e=e.next;let i=[e.key,e.value];return this._deleteNode(e),i}isEmpty(){return this._size===0}isEntry(t){return Array.isArray(t)&&t.length===2}clear(){this._noObjMap={},this._size=0,this._head=this._tail=this._sentinel.prev=this._sentinel.next=this._sentinel}clone(){let t={hashFn:this._hashFn,objHashFn:this._objHashFn};return this._createLike(this,t)}filter(t,e){let i=this._createLike(),s=0;for(let[r,n]of this)t.call(e,n,r,s,this)&&i.set(r,n),s++;return i}map(t,e){let i=this._createLike(),s=0;for(let[r,n]of this){let[h,o]=t.call(e,n,r,s,this);i.set(h,o),s++}return i}*_getIterator(){let t=this.head;for(;t!==this._sentinel;)yield[t.key,t.value],t=t.next}_deleteNode(t){let e=t.key;if(H(e))this._objMap.delete(e);else{let r=this._hashFn(e);delete this._noObjMap[r]}let{prev:i,next:s}=t;return i.next=s,s.prev=i,t===this.head&&(this._head=s),t===this.tail&&(this._tail=i),this._size-=1,!0}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}};u($e,"LinkedHashMap");var Ot=class extends Kt{constructor(t){super(t),f(this,"_next"),this._value=t,this._next=void 0}get next(){return this._next}set next(t){this._next=t}};u(Ot,"SinglyLinkedListNode");var Mt=Ot,Pt=class extends qt{constructor(t=[],e){super(e),f(this,"_equals",u((i,s)=>Object.is(i,s),"_equals")),f(this,"_head"),f(this,"_tail"),f(this,"_length",0),this.pushMany(t)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var t;return(t=this.head)==null?void 0:t.value}get last(){var t;return(t=this.tail)==null?void 0:t.value}static from(t,e){let i=new this([],e);for(let s of t)i.push(s);return i}push(t){let e=this._ensureNode(t);return this.head?(this.tail.next=e,this._tail=e):this._head=this._tail=e,this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){var t;if(!this.head)return;if(this.head===this.tail){let s=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,s}let e=this.head;for(;e.next&&e.next!==this.tail;)e=e.next;let i=(t=this.tail)==null?void 0:t.value;return e.next=void 0,this._tail=e,this._length--,i}shift(){if(!this.head)return;let t=this.head;return this._head=this.head.next,this._head||(this._tail=void 0),this._length--,t.value}unshift(t){let e=this._ensureNode(t);return this.head?(e.next=this.head,this._head=e):this._head=this._tail=e,this._length++,!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}unshiftMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.unshift(this.toElementFn(i))):e.push(this.unshift(i));return e}search(t){let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i.value;i=i.next}}at(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e==null?void 0:e.value}isNode(t){return t instanceof Mt}getNodeAt(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e}deleteAt(t){if(t<0||t>=this._length)return;if(t===0)return this.shift();let e=this.getNodeAt(t),i=this._getPrevNode(e),s=e.value;return i.next=e.next,e===this.tail&&(this._tail=i),this._length--,s}delete(t){if(t===void 0||!this.head)return!1;let e=this.isNode(t)?t:this.getNode(t);if(!e)return!1;let i=this._getPrevNode(e);return i?(i.next=e.next,e===this.tail&&(this._tail=i)):(this._head=e.next,e===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(t,e){if(t<0||t>this._length)return!1;if(t===0)return this.unshift(e);if(t===this._length)return this.push(e);let i=this._ensureNode(e),s=this.getNodeAt(t-1);return i.next=s.next,s.next=i,this._length++,!0}setAt(t,e){let i=this.getNodeAt(t);return i?(i.value=e,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let t,e=this.head,i;for(;e;)i=e.next,e.next=t,t=e,e=i;return[this._head,this._tail]=[this.tail,this.head],this}getNode(t){if(t===void 0)return;if(this.isNode(t))return t;let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i;i=i.next}}addBefore(t,e){let i=this.getNode(t);if(!i)return!1;let s=this._getPrevNode(i),r=this._ensureNode(e);return s?(s.next=r,r.next=i,this._length++):(r.next=this._head,this._head=r,this._tail||(this._tail=r),this._length++),!0}addAfter(t,e){let i=this.getNode(t);if(!i)return!1;let s=this._ensureNode(e);return s.next=i.next,i.next=s,i===this.tail&&(this._tail=s),this._length++,!0}splice(t,e=0,...i){t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,e);let s=this._createInstance(),r=t===0?void 0:this.getNodeAt(t-1),n=r?r.next:this.head,h=0;for(;h<e&&n;)s.push(n.value),n=n.next,h++;let o=n;if(r?r.next=o:this._head=o,o||(this._tail=r),i.length>0){let a,l;for(let _ of i){let g=this._ensureNode(_);a||(a=g),l&&(l.next=g),l=g}r?r.next=a:this._head=a,l.next=o,o||(this._tail=l)}return this._length+=i.length-h,this._length===0&&(this._head=void 0,this._tail=void 0),s}countOccurrences(t){let e=Qt(t,this._equals),i=0,s=this.head;for(;s;)e(s)&&i++,s=s.next;return i}setEquality(t){return this._equals=t,this}deleteWhere(t){let e,i=this.head,s=0;for(;i;){if(t(i.value,s++,this))return e?(e.next=i.next,i===this._tail&&(this._tail=e)):(this._head=i.next,i===this._tail&&(this._tail=void 0)),this._length--,!0;e=i,i=i.next}return!1}clone(){let t=this._createInstance();for(let e of this)t.push(e);return t}filter(t,e){let i=this._createInstance(),s=0;for(let r of this)t.call(e,r,s++,this)&&i.push(r);return i}mapSame(t,e){let i=this._createInstance(),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{},maxLen:this._maxLen}),r=0;for(let n of this)s.push(t.call(i,n,r++,this));return s}createNode(t){return new Mt(t)}_isPredicate(t){return typeof t=="function"}_ensureNode(t){return this.isNode(t)?t:this.createNode(t)}_ensurePredicate(t){if(this.isNode(t))return i=>i===t;if(this._isPredicate(t))return t;let e=t;return i=>this._equals(i.value,e)}_getPrevNode(t){if(!this.head||this.head===t)return;let e=this.head;for(;e.next&&e.next!==t;)e=e.next;return e.next===t?e:void 0}*_getIterator(){let t=this.head;for(;t;)yield t.value,t=t.next}*_getReverseIterator(){let t=[...this].reverse();for(let e of t)yield e}*_getNodeIterator(){let t=this.head;for(;t;)yield t,t=t.next}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_spawnLike(t){return this._createLike([],t)}};u(Pt,"SinglyLinkedList");var Oe=Pt;function Qt(c,t){if(c instanceof Mt)return i=>i===c;if(typeof c=="function")return c;let e=c;return i=>t(i.value,e)}u(Qt,"elementOrPredicate");var Xt=class extends Kt{constructor(t){super(t),f(this,"_next"),f(this,"_prev"),this._value=t,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(t){this._next=t}get prev(){return this._prev}set prev(t){this._prev=t}};u(Xt,"DoublyLinkedListNode");var Ft=Xt,Pe=class extends qt{constructor(t=[],e){super(e),f(this,"_equals",u((i,s)=>Object.is(i,s),"_equals")),f(this,"_head"),f(this,"_tail"),f(this,"_length",0),this._head=void 0,this._tail=void 0,this._length=0,e!=null&&e.maxLen&&Number.isInteger(e.maxLen)&&e.maxLen>0&&(this._maxLen=e.maxLen),this.pushMany(t)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var t;return(t=this.head)==null?void 0:t.value}get last(){var t;return(t=this.tail)==null?void 0:t.value}static fromArray(t){return new this(t)}isNode(t){return t instanceof Ft}push(t){let e=this._ensureNode(t);return this.head?(e.prev=this.tail,this.tail.next=e,this._tail=e):(this._head=e,this._tail=e),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.tail)return;let t=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=t.prev,this.tail.next=void 0),this._length--,t.value}shift(){if(!this.head)return;let t=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=t.next,this.head.prev=void 0),this._length--,t.value}unshift(t){let e=this._ensureNode(t);return this.head?(e.next=this.head,this.head.prev=e,this._head=e):(this._head=e,this._tail=e),this._length++,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}unshiftMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.unshift(this.toElementFn(i))):e.push(this.unshift(i));return e}at(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e==null?void 0:e.value}getNodeAt(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e}getNode(t){if(t===void 0)return;if(this.isNode(t)){let s=t,r=this.head;for(;r;){if(r===s)return s;r=r.next}let n=u(h=>this._equals(h.value,s.value),"isMatch");for(r=this.head;r;){if(n(r))return r;r=r.next}return}let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i;i=i.next}}addAt(t,e){if(t<0||t>this._length)return!1;if(t===0)return this.unshift(e);if(t===this._length)return this.push(e);let i=this._ensureNode(e),s=this.getNodeAt(t-1),r=s.next;return i.prev=s,i.next=r,s.next=i,r.prev=i,this._length++,!0}addBefore(t,e){let i=this.isNode(t)?t:this.getNode(t);if(!i)return!1;let s=this._ensureNode(e);return s.prev=i.prev,i.prev&&(i.prev.next=s),s.next=i,i.prev=s,i===this.head&&(this._head=s),this._length++,!0}addAfter(t,e){let i=this.isNode(t)?t:this.getNode(t);if(!i)return!1;let s=this._ensureNode(e);return s.next=i.next,i.next&&(i.next.prev=s),s.prev=i,i.next=s,i===this.tail&&(this._tail=s),this._length++,!0}setAt(t,e){let i=this.getNodeAt(t);return i?(i.value=e,!0):!1}deleteAt(t){if(t<0||t>=this._length)return;if(t===0)return this.shift();if(t===this._length-1)return this.pop();let e=this.getNodeAt(t),i=e.prev,s=e.next;return i.next=s,s.prev=i,this._length--,e.value}delete(t){let e=this.getNode(t);if(!e)return!1;if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{let i=e.prev,s=e.next;i.next=s,s.prev=i,this._length--}return!0}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(t){let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i.value;i=i.next}}getBackward(t){let e=this._ensurePredicate(t),i=this.tail;for(;i;){if(e(i))return i.value;i=i.prev}}reverse(){let t=this.head;for([this._head,this._tail]=[this.tail,this.head];t;){let e=t.next;[t.prev,t.next]=[t.next,t.prev],t=e}return this}deleteWhere(t){let e=this.head,i=0;for(;e;){if(t(e.value,i,this))return this.delete(e),!0;e=e.next,i++}return!1}setEquality(t){return this._equals=t,this}clone(){let t=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});for(let e of this)t.push(e);return t}filter(t,e){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),s=0;for(let r of this)t.call(e,r,s++,this)&&i.push(r);return i}mapSame(t,e){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{},maxLen:this._maxLen}),r=0;for(let n of this)s.push(t.call(i,n,r++,this));return s}_ensureNode(t){return this.isNode(t)?t:new Ft(t)}_ensurePredicate(t){if(this.isNode(t)){let i=t;return s=>s===i}if(typeof t=="function")return t;let e=t;return i=>this._equals(i.value,e)}_getPrevNode(t){return t.prev}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}*_getIterator(){let t=this.head;for(;t;)yield t.value,t=t.next}*_getReverseIterator(){let t=this.tail;for(;t;)yield t.value,t=t.prev}*_getNodeIterator(){let t=this.head;for(;t;)yield t,t=t.next}};u(Pe,"DoublyLinkedList");var Jt=class{constructor(t,e,i){f(this,"key"),f(this,"value"),f(this,"forward"),this.key=t,this.value=e,this.forward=new Array(i).fill(void 0)}};u(Jt,"SkipListNode");var gt=Jt,A,G,Qe=class $ extends it{constructor(t=[],e={}){super(),V(this,A),V(this,G),f(this,"_head"),f(this,"_level",0),f(this,"_size",0),f(this,"_maxLevel",16),f(this,"_probability",.5);let{comparator:i,toEntryFn:s,maxLevel:r,probability:n}=e;typeof r=="number"&&r>0&&(this._maxLevel=r),typeof n=="number"&&n>0&&n<1&&(this._probability=n),K(this,G,i===void 0),K(this,A,i!=null?i:$.createDefaultComparator()),this._head=new gt(void 0,void 0,this._maxLevel);for(let h of t){let o,a;s?[o,a]=s(h):((!Array.isArray(h)||h.length<2)&&x(TypeError,R.invalidEntry("SkipList")),[o,a]=h),this.set(o,a)}}static createDefaultComparator(){return(t,e)=>{if(typeof t=="number"&&typeof e=="number")return(Number.isNaN(t)||Number.isNaN(e))&&x(TypeError,R.invalidNaN("SkipList")),t-e;if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&x(TypeError,R.invalidDate("SkipList")),i-s}if(typeof t=="bigint"&&typeof e=="bigint")return t<e?-1:t>e?1:0;x(TypeError,R.comparatorRequired("SkipList"))}}get size(){return this._size}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get comparator(){return d(this,A)}isEmpty(){return this._size===0}clear(){this._head=new gt(void 0,void 0,this._maxLevel),this._level=0,this._size=0}clone(){return new $(this,{comparator:d(this,G)?void 0:d(this,A),maxLevel:this._maxLevel,probability:this._probability})}set(t,e){let i=d(this,A),s=this._findUpdate(t),r=s[0].forward[0];if(r&&i(r.key,t)===0)return r.value=e,this;let n=this._randomLevel(),h=new gt(t,e,n);if(n>this._level){for(let o=this._level;o<n;o++)s[o]=this._head;this._level=n}for(let o=0;o<n;o++)h.forward[o]=s[o].forward[o],s[o].forward[o]=h;return this._size++,this}get(t){let e=this._findNode(t);return e?e.value:void 0}has(t){return this._findNode(t)!==void 0}delete(t){let e=d(this,A),i=this._findUpdate(t),s=i[0].forward[0];if(!s||e(s.key,t)!==0)return!1;for(let r=0;r<this._level&&i[r].forward[r]===s;r++)i[r].forward[r]=s.forward[r];for(;this._level>0&&!this._head.forward[this._level-1];)this._level--;return this._size--,!0}first(){let t=this._head.forward[0];return t?[t.key,t.value]:void 0}last(){let t=this._head;for(let e=this._level-1;e>=0;e--)for(;t.forward[e];)t=t.forward[e];return t===this._head?void 0:[t.key,t.value]}pollFirst(){let t=this.first();if(t)return this.delete(t[0]),t}pollLast(){let t=this.last();if(t)return this.delete(t[0]),t}ceiling(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<0;)i=i.forward[r];let s=i.forward[0];return s?[s.key,s.value]:void 0}floor(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<=0;)i=i.forward[r];let s=i===this._head?void 0:i;if(s&&e(s.key,t)<=0)return[s.key,s.value]}higher(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<=0;)i=i.forward[r];let s=i.forward[0];return s?[s.key,s.value]:void 0}lower(t){let e=d(this,A),i=this._head,s;for(let r=this._level-1;r>=0;r--){for(;i.forward[r]&&e(i.forward[r].key,t)<0;)i=i.forward[r];i!==this._head&&e(i.key,t)<0&&(s=i)}return s?[s.key,s.value]:void 0}rangeSearch(t,e={}){let{lowInclusive:i=!0,highInclusive:s=!0}=e,[r,n]=t,h=d(this,A),o=[],a=this._head;for(let l=this._level-1;l>=0;l--)for(;a.forward[l]&&h(a.forward[l].key,r)<0;)a=a.forward[l];for(a=a.forward[0];a;){let l=h(a.key,n);if(l>0||l===0&&!s)break;let _=h(a.key,r);(_>0||_===0&&i)&&o.push([a.key,a.value]),a=a.forward[0]}return o}map(t,e){let i=new $([],e!=null?e:{}),s=0;for(let[r,n]of this){let[h,o]=t(n,r,s++,this);i.set(h,o)}return i}filter(t,e){let i=new $([],{comparator:d(this,G)?void 0:d(this,A),maxLevel:this._maxLevel,probability:this._probability}),s=0;for(let[r,n]of this)t.call(e,n,r,s++,this)&&i.set(r,n);return i}_getIterator(){let t=this._head;return(function*(){let e=t.forward[0];for(;e;)yield[e.key,e.value],e=e.forward[0]})()}_findUpdate(t){let e=d(this,A),i=new Array(this._maxLevel).fill(this._head),s=this._head;for(let r=this._level-1;r>=0;r--){for(;s.forward[r]&&e(s.forward[r].key,t)<0;)s=s.forward[r];i[r]=s}return i}_findNode(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<0;)i=i.forward[r];let s=i.forward[0];if(s&&e(s.key,t)===0)return s}_randomLevel(){let t=1;for(;Math.random()<this._probability&&t<this._maxLevel;)t++;return t}};A=new WeakMap;G=new WeakMap;u(Qe,"SkipList");var Xe=class extends ut{constructor(t=[],e){super(e),f(this,"_equals",u((i,s)=>Object.is(i,s),"_equals")),f(this,"_elements",[]),this.pushMany(t)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(t,e){return new this(t,e)}isEmpty(){return this.elements.length===0}peek(){return this.isEmpty()?void 0:this.elements[this.elements.length-1]}push(t){return this.elements.push(t),!0}pop(){return this.isEmpty()?void 0:this.elements.pop()}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}delete(t){let e=this._indexOfByEquals(t);return this.deleteAt(e)!==void 0}deleteAt(t){return t<0||t>=this.elements.length?void 0:this.elements.splice(t,1)[0]}deleteWhere(t){for(let e=0;e<this.elements.length;e++)if(t(this.elements[e],e,this))return this.elements.splice(e,1),!0;return!1}clear(){this._elements=[]}clone(){let t=this._createInstance({toElementFn:this.toElementFn});for(let e of this)t.push(e);return t}filter(t,e){let i=this._createInstance({toElementFn:this.toElementFn}),s=0;for(let r of this)t.call(e,r,s,this)&&i.push(r),s++;return i}mapSame(t,e){let i=this._createInstance({toElementFn:this.toElementFn}),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{}}),r=0;for(let n of this)s.push(i===void 0?t(n,r,this):t.call(i,n,r,this)),r++;return s}setEquality(t){return this._equals=t,this}_indexOfByEquals(t){for(let e=0;e<this.elements.length;e++)if(this._equals(this.elements[e],t))return e;return-1}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}*_getIterator(){for(let t=0;t<this.elements.length;t++)yield this.elements[t]}};u(Xe,"Stack");var Yt=class Zt extends at{constructor(t=[],e){if(super(e),f(this,"_elements",[]),f(this,"_offset",0),f(this,"_autoCompactRatio",.5),e){let{autoCompactRatio:i=.5}=e;this._autoCompactRatio=i}this.pushMany(t)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(t){this._autoCompactRatio=t}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}peek(){return this.first}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(t){return new Zt(t)}isEmpty(){return this.length===0}push(t){return this.elements.push(t),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}shift(){if(this.length===0)return;let t=this.first;return this._offset+=1,this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),t}delete(t){for(let e=this._offset;e<this.elements.length;e++)if(Object.is(this.elements[e],t))return this.elements.splice(e,1),!0;return!1}at(t){if(!(t<0||t>=this.length))return this._elements[this._offset+t]}deleteAt(t){if(t<0||t>=this.length)return;let e=this._offset+t,[i]=this.elements.splice(e,1);return i}addAt(t,e){return t<0||t>this.length?!1:(this._elements.splice(this._offset+t,0,e),!0)}setAt(t,e){return t<0||t>=this.length?!1:(this._elements[this._offset+t]=e,!0)}deleteWhere(t){for(let e=0;e<this.length;e++)if(t(this._elements[this._offset+e],e,this))return this.deleteAt(e),!0;return!1}reverse(){return this._elements=this.elements.slice(this._offset).reverse(),this._offset=0,this}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this._offset),this._offset=0,!0}splice(t,e=0,...i){t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,Math.min(e,this.length-t));let s=this._offset+t,r=this._elements.splice(s,e,...i);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return n._setAutoCompactRatio(this._autoCompactRatio),n.pushMany(r),n}clone(){let t=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});t._setAutoCompactRatio(this._autoCompactRatio);for(let e=this._offset;e<this.elements.length;e++)t.push(this.elements[e]);return t}filter(t,e){let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});i._setAutoCompactRatio(this._autoCompactRatio);let s=0;for(let r of this)t.call(e,r,s,this)&&i.push(r),s++;return i}map(t,e,i){var s,r;let n=new this.constructor([],{toElementFn:e==null?void 0:e.toElementFn,maxLen:(s=e==null?void 0:e.maxLen)!=null?s:this._maxLen,autoCompactRatio:(r=e==null?void 0:e.autoCompactRatio)!=null?r:this._autoCompactRatio}),h=0;for(let o of this)n.push(i===void 0?t(o,h++,this):t.call(i,o,h++,this));return n}mapSame(t,e){var i;let s=this.constructor,r=new s([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(i=r._setAutoCompactRatio)==null||i.call(r,this._autoCompactRatio);let n=0;for(let h of this){let o=e===void 0?t(h,n++,this):t.call(e,h,n++,this);r.push(o)}return r}_setAutoCompactRatio(t){this._autoCompactRatio=t}*_getIterator(){for(let t=this._offset;t<this.elements.length;t++)yield this.elements[t]}*_getReverseIterator(){for(let t=this.length-1;t>=0;t--){let e=this.at(t);e!==void 0&&(yield e)}}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}};u(Yt,"Queue");var et=Yt,Je=class extends Oe{clone(){let t=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});for(let e of this)t.push(e);return t}};u(Je,"LinkedListQueue");var Ye=class extends at{constructor(t=[],e){if(super(e),f(this,"_equals",u((r,n)=>Object.is(r,n),"_equals")),f(this,"_bucketSize",4096),f(this,"_autoCompactRatio",.5),f(this,"_compactCounter",0),f(this,"_bucketFirst",0),f(this,"_firstInBucket",0),f(this,"_bucketLast",0),f(this,"_lastInBucket",0),f(this,"_bucketCount",0),f(this,"_buckets",[]),f(this,"_length",0),e){let{bucketSize:r,autoCompactRatio:n}=e;typeof r=="number"&&(this._bucketSize=r),typeof n=="number"&&(this._autoCompactRatio=n)}let i;"length"in t?i=typeof t.length=="function"?t.length():t.length:i=typeof t.size=="function"?t.size():t.size,this._bucketCount=Et(i,this._bucketSize)||1;for(let r=0;r<this._bucketCount;++r)this._buckets.push(new Array(this._bucketSize));let s=Et(i,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(s>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-i%this._bucketSize>>1,this.pushMany(t)}get bucketSize(){return this._bucketSize}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(t){this._autoCompactRatio=t}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get length(){return this._length}peek(){return this.first}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}static fromArray(t,e){return new this(t,e)}push(t){return this._length&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=t,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let t=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._length-=1,this._autoCompact(),t}shift(){if(this._length===0)return;let t=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._length-=1,this._autoCompact(),t}unshift(t){return this._length&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=t,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}unshiftMany(t=[]){let e=[];for(let i of t)this.toElementFn?e.push(this.unshift(this.toElementFn(i))):e.push(this.unshift(i));return e}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(t){if(t<0||t>=this._length)return;let{bucketIndex:e,indexInBucket:i}=this._getBucketAndPosition(t);return this._buckets[e][i]}setAt(t,e){W(t,0,this._length-1);let{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(t);return this._buckets[i][s]=e,!0}addAt(t,e,i=1){let s=this._length;if(W(t,0,s),t===0)for(;i--;)this.unshift(e);else if(t===this._length)for(;i--;)this.push(e);else{let r=[];for(let n=t;n<this._length;++n){let h=this.at(n);h!==void 0&&r.push(h)}this.cut(t-1,!0);for(let n=0;n<i;++n)this.push(e);for(let n=0;n<r.length;++n)this.push(r[n])}return!0}cut(t,e=!1){if(e){if(t<0)return this.clear(),this;let{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(t);return this._bucketLast=i,this._lastInBucket=s,this._length=t+1,this}else{let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);for(let s=0;s<=t;s++){let r=this.at(s);r!==void 0&&i.push(r)}return i}}splice(t,e=this._length-t,...i){W(t,0,this._length),e<0&&(e=0),t+e>this._length&&(e=this._length-t);let s=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});s._setBucketSize(this._bucketSize);for(let n=0;n<e;n++){let h=this.at(t+n);h!==void 0&&s.push(h)}let r=[];for(let n=t+e;n<this._length;n++){let h=this.at(n);h!==void 0&&r.push(h)}this.cut(t-1,!0);for(let n of i)this.push(n);for(let n of r)this.push(n);return s}cutRest(t,e=!1){if(e){if(t<0)return this;let{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(t);return this._bucketFirst=i,this._firstInBucket=s,this._length=this._length-t,this}else{let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize),t<0&&(t=0);for(let s=t;s<this._length;s++){let r=this.at(s);r!==void 0&&i.push(r)}return i}}deleteAt(t){W(t,0,this._length-1);let e;if(t===0)return this.shift();if(t===this._length-1)return e=this.last,this.pop(),e;{let i=this._length-1,{bucketIndex:s,indexInBucket:r}=this._getBucketAndPosition(t);e=this._buckets[s][r];for(let n=t;n<i;n++){let{bucketIndex:h,indexInBucket:o}=this._getBucketAndPosition(n),{bucketIndex:a,indexInBucket:l}=this._getBucketAndPosition(n+1);this._buckets[h][o]=this._buckets[a][l]}return this.pop(),e}}delete(t){let e=this._length;if(e===0)return!1;let i=0,s=0;for(;i<e;){let r=this.at(i);this._equals(r,t)||(this.setAt(s,r),s+=1),i+=1}return this.cut(s-1,!0),!0}deleteWhere(t){for(let e=0;e<this._length;e++){let i=this.at(e);if(t(i,e,this))return this.deleteAt(e),!0}return!1}setEquality(t){return this._equals=t,this}reverse(){this._buckets.reverse().forEach(function(r){r.reverse()});let{_bucketFirst:t,_bucketLast:e,_firstInBucket:i,_lastInBucket:s}=this;return this._bucketFirst=this._bucketCount-e-1,this._bucketLast=this._bucketCount-t-1,this._firstInBucket=this._bucketSize-s-1,this._lastInBucket=this._bucketSize-i-1,this}unique(){if(this._length<=1)return this;let t=1,e=this.at(0);for(let i=1;i<this._length;++i){let s=this.at(i);this._equals(s,e)||(e=s,this.setAt(t++,s))}return this.cut(t-1,!0),this}_autoCompact(){if(this._autoCompactRatio<=0||this._bucketCount<=1||(this._compactCounter++,this._compactCounter<this._bucketSize))return;this._compactCounter=0,this._length/(this._bucketCount*this._bucketSize)<this._autoCompactRatio&&this.shrinkToFit()}compact(){let t=this._bucketCount;return this.shrinkToFit(),this._bucketCount<t}shrinkToFit(){if(this._length===0)return;let t=[];if(this._bucketFirst<=this._bucketLast)for(let e=this._bucketFirst;e<=this._bucketLast;++e)t.push(this._buckets[e]);else{for(let e=this._bucketFirst;e<this._bucketCount;++e)t.push(this._buckets[e]);for(let e=0;e<=this._bucketLast;++e)t.push(this._buckets[e])}this._bucketFirst=0,this._bucketLast=t.length-1,this._buckets=t,this._bucketCount=t.length,this._compactCounter=0}clone(){return this._createLike(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(t,e){let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);let s=0;for(let r of this)t.call(e,r,s,this)&&i.push(r),s++;return i}mapSame(t,e){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);let s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{},bucketSize:this._bucketSize,maxLen:this._maxLen}),r=0;for(let n of this){let h=i===void 0?t(n,r,this):t.call(i,n,r,this);s.push(h),r++}return s}_setBucketSize(t){this._bucketSize=t,this._length===0&&(this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1)}*_getIterator(){for(let t=0;t<this._length;++t){let e=this.at(t);e!==void 0&&(yield e)}}_reallocate(t){let e=[],i=t||this._bucketCount>>1||1;for(let s=0;s<i;++s)e[s]=new Array(this._bucketSize);for(let s=this._bucketFirst;s<this._bucketCount;++s)e[e.length]=this._buckets[s];for(let s=0;s<this._bucketLast;++s)e[e.length]=this._buckets[s];e[e.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=i,this._bucketLast=e.length-1;for(let s=0;s<i;++s)e[e.length]=new Array(this._bucketSize);this._buckets=e,this._bucketCount=e.length}_getBucketAndPosition(t){let e,i,s=this._firstInBucket+t;return e=this._bucketFirst+Math.floor(s/this._bucketSize),e>=this._bucketCount&&(e-=this._bucketCount),i=(s+1)%this._bucketSize-1,i<0&&(i=this._bucketSize-1),{bucketIndex:e,indexInBucket:i}}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}*_getReverseIterator(){for(let t=this._length-1;t>-1;t--){let e=this.at(t);e!==void 0&&(yield e)}}};u(Ye,"Deque");var te=class ee extends ut{constructor(t=[],e){if(super(e),f(this,"_equals",Object.is),f(this,"_elements",[]),f(this,"_DEFAULT_COMPARATOR",u((i,s)=>((typeof i=="object"||typeof s=="object")&&x(TypeError,R.comparatorRequired("Heap")),i>s?1:i<s?-1:0),"_DEFAULT_COMPARATOR")),f(this,"_comparator",this._DEFAULT_COMPARATOR),e){let{comparator:i}=e;i&&(this._comparator=i)}this.addMany(t)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var t;return(t=this.elements[this.size-1])!=null?t:void 0}static from(t,e){return new this(t,e)}static heapify(t,e){return new ee(t,e)}add(t){return this._elements.push(t),this._bubbleUp(this.elements.length-1)}addMany(t){let e=[];for(let i of t)if(this.toElementFn){let s=this.add(this.toElementFn(i));e.push(s)}else{let s=this.add(i);e.push(s)}return e}poll(){return this.pop()}pop(){if(this.elements.length===0)return;let t=this.elements[0],e=this.elements.pop();return this.elements.length&&(this.elements[0]=e,this._sinkDown(0,this.elements.length>>1)),t}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}has(t){for(let e of this.elements)if(this._equals(e,t))return!0;return!1}delete(t){let e=-1;for(let i=0;i<this.elements.length;i++)if(this._equals(this.elements[i],t)){e=i;break}return e<0?!1:(e===0?this.pop():e===this.elements.length-1?this.elements.pop():(this.elements.splice(e,1,this.elements.pop()),this._bubbleUp(e),this._sinkDown(e,this.elements.length>>1)),!0)}deleteBy(t){return this.deleteWhere(t)}deleteWhere(t){let e=-1;for(let i=0;i<this.elements.length;i++)if(t(this.elements[i],i,this)){e=i;break}return e<0?!1:(e===0?this.pop():e===this.elements.length-1?this.elements.pop():(this.elements.splice(e,1,this.elements.pop()),this._bubbleUp(e),this._sinkDown(e,this.elements.length>>1)),!0)}setEquality(t){return this._equals=t,this}dfs(t="PRE"){let e=[],i=u(s=>{let r=2*s+1,n=r+1;s<this.size&&(t==="IN"?(i(r),e.push(this.elements[s]),i(n)):t==="PRE"?(e.push(this.elements[s]),i(r),i(n)):t==="POST"&&(i(r),i(n),e.push(this.elements[s])))},"_dfs");return i(0),e}fix(){let t=[];for(let e=Math.floor(this.size/2)-1;e>=0;e--)t.push(this._sinkDown(e,this.elements.length>>1));return t}sort(){let t=[],e=this._createInstance();for(let i of this.elements)e.add(i);for(;!e.isEmpty();){let i=e.poll();i!==void 0&&t.push(i)}return t}clone(){let t=this._createInstance();for(let e of this.elements)t.add(e);return t}filter(t,e){let i=this._createInstance(),s=0;for(let r of this)(e===void 0?t(r,s++,this):t.call(e,r,s++,this))?i.add(r):s++;return i}map(t,e,i){let{comparator:s,toElementFn:r,...n}=e!=null?e:{};s||x(TypeError,R.comparatorRequired("Heap.map"));let h=this._createLike([],{...n,comparator:s,toElementFn:r}),o=0;for(let a of this){let l=i===void 0?t(a,o++,this):t.call(i,a,o++,this);h.add(l)}return h}mapSame(t,e){let i=this._createInstance(),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.add(n)}return i}get comparator(){return this._comparator}*_getIterator(){for(let t of this.elements)yield t}_bubbleUp(t){let e=this.elements[t];for(;t>0;){let i=t-1>>1,s=this.elements[i];if(this.comparator(s,e)<=0)break;this.elements[t]=s,t=i}return this.elements[t]=e,!0}_sinkDown(t,e){let i=this.elements[t];for(;t<e;){let s=t<<1|1,r=s+1,n=this.elements[s];if(r<this.elements.length&&this.comparator(n,this.elements[r])>0&&(s=r,n=this.elements[r]),this.comparator(n,i)>=0)break;this.elements[t]=n,t=s}return this.elements[t]=i,!0}_createInstance(t){let e=this.constructor;return new e([],{comparator:this.comparator,toElementFn:this.toElementFn,...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_spawnLike(t){return this._createLike([],t)}};u(te,"Heap");var ct=te,ie=class{constructor(t,e=0){f(this,"element"),f(this,"degree"),f(this,"left"),f(this,"right"),f(this,"child"),f(this,"parent"),f(this,"marked"),this.element=t,this.degree=e,this.marked=!1}};u(ie,"FibonacciHeapNode");var Ze=ie,ti=class{constructor(t){f(this,"_root"),f(this,"_size",0),f(this,"_min"),f(this,"_comparator"),this.clear(),this._comparator=t||this._defaultComparator,typeof this.comparator!="function"&&x(TypeError,R.notAFunction("comparator","FibonacciHeap"))}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(t){return this.push(t),!0}push(t){let e=this.createNode(t);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++,!0}peek(){return this.min?this.min.element:void 0}consumeLinkedList(t){let e=[];if(!t)return e;let i=t,s=!1;for(;!(i===t&&s);)i===t&&(s=!0),e.push(i),i=i.right;return e}mergeWithChild(t,e){t.child?(e.right=t.child.right,e.left=t.child,t.child.right.left=e,t.child.right=e):t.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let t=this.min;if(t.child){let e=this.consumeLinkedList(t.child);for(let i of e)this.mergeWithRoot(i),i.parent=void 0}return this.removeFromRoot(t),t===t.right?(this._min=void 0,this._root=void 0):(this._min=t.right,this._consolidate()),this._size--,t.element}merge(t){if(t.size!==0){if(this.root&&t.root){let e=this.root,i=t.root,s=e.right,r=i.left;e.right=i,i.left=e,s.left=r,r.right=s}else!this.root&&t.root&&(this._root=t.root);(!this.min||t.min&&this.comparator(t.min.element,this.min.element)<0)&&(this._min=t.min),this._size+=t.size,t.clear()}}createNode(t){return new Ze(t)}isEmpty(){return this._size===0}_defaultComparator(t,e){return t<e?-1:t>e?1:0}mergeWithRoot(t){this.root?(t.right=this.root.right,t.left=this.root,this.root.right.left=t,this.root.right=t):this._root=t}removeFromRoot(t){this.root===t&&(this._root=t.right),t.left&&(t.left.right=t.right),t.right&&(t.right.left=t.left)}_link(t,e){this.removeFromRoot(t),t.left=t,t.right=t,this.mergeWithChild(e,t),e.degree++,t.parent=e}_consolidate(){let t=new Array(this._size),e=this.consumeLinkedList(this.root),i,s,r,n;for(let h of e){for(i=h,r=i.degree;t[r];)s=t[r],this.comparator(i.element,s.element)>0&&(n=i,i=s,s=n),this._link(s,i),t[r]=void 0,r++;t[r]=i}for(let h=0;h<t.length;h++)t[h]&&(!this.min||this.comparator(t[h].element,this.min.element)<=0)&&(this._min=t[h])}};u(ti,"FibonacciHeap");var ei=class extends ct{constructor(t=[],e){super(t,{comparator:u((i,s)=>((typeof i=="object"||typeof s=="object")&&x(TypeError,R.comparatorRequired("MaxHeap")),i<s?1:i>s?-1:0),"comparator"),...e})}};u(ei,"MaxHeap");var ii=class extends ct{constructor(t=[],e){super(t,e)}};u(ii,"MinHeap");var se=class{constructor(t,e){f(this,"key"),f(this,"value"),this.key=t,this.value=e}};u(se,"AbstractVertex");var z=se,re=class{constructor(t,e){f(this,"value"),f(this,"weight"),f(this,"_hashCode"),this.weight=t!==void 0?t:1,this.value=e,this._hashCode=Ue()}get hashCode(){return this._hashCode}};u(re,"AbstractEdge");var Rt=re,ne=class extends it{constructor(t){super(),f(this,"_options",{defaultEdgeWeight:1}),f(this,"_vertexMap",new Map);let e=t==null?void 0:t.graph;this._options={defaultEdgeWeight:1,...e!=null?e:{}}}get options(){return this._options}get vertexMap(){return this._vertexMap}set vertexMap(t){this._vertexMap=t}get size(){return this._vertexMap.size}getVertex(t){return this._vertexMap.get(t)||void 0}hasVertex(t){return this._vertexMap.has(this._getVertexKey(t))}addVertex(t,e){if(t instanceof z)return this._addVertex(t);{let i=this.createVertex(t,e);return this._addVertex(i)}}isVertexKey(t){let e=typeof t;return e==="string"||e==="number"}removeManyVertices(t){let e=[];for(let i of t)e.push(this.deleteVertex(i));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,i,s){if(t instanceof Rt)return this._addEdge(t);if(e instanceof z||typeof e=="string"||typeof e=="number"){if(!(this.hasVertex(t)&&this.hasVertex(e)))return!1;t instanceof z&&(t=t.key),e instanceof z&&(e=e.key);let r=this.createEdge(t,e,i,s);return this._addEdge(r)}else x(TypeError,R.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.","Graph"))}setEdgeWeight(t,e,i){let s=this.getEdge(t,e);return s?(s.weight=i,!0):!1}getAllPathsBetween(t,e,i=1e3){let s=[],r=this._getVertex(t),n=this._getVertex(e);if(!(r&&n))return[];let h=[];for(h.push({vertex:r,path:[r]});h.length>0;){let{vertex:o,path:a}=h.pop();if(o===n&&(s.push(a),s.length>=i))return s;let l=this.getNeighbors(o);for(let _ of l)if(!a.includes(_)){let g=[...a,_];h.push({vertex:_,path:g})}}return s}getPathSumWeight(t){var e;let i=0;for(let s=0;s<t.length;s++)i+=((e=this.getEdge(t[s],t[s+1]))==null?void 0:e.weight)||0;return i}getMinCostBetween(t,e,i){if(i===void 0&&(i=!1),i){let s=this.getAllPathsBetween(t,e),r=Number.MAX_SAFE_INTEGER;for(let n of s)r=Math.min(this.getPathSumWeight(n),r);return r}else{let s=this._getVertex(e),r=this._getVertex(t);if(!(r&&s))return;let n=new Map,h=new et([r]);n.set(r,!0);let o=0;for(;h.length>0;){for(let a=0,l=h.length;a<l;a++){let _=h.shift();if(_===s)return o;if(_!==void 0){let g=this.getNeighbors(_);for(let p of g)n.has(p)||(n.set(p,!0),h.push(p))}}o++}return}}getMinPathBetween(t,e,i,s=!1){var r,n;if(i===void 0&&(i=!1),i)if(s){let h=this.getAllPathsBetween(t,e,1e4),o=Number.MAX_SAFE_INTEGER,a=-1,l=0;for(let _ of h){let g=this.getPathSumWeight(_);g<o&&(o=g,a=l),l++}return h[a]||void 0}else return(n=(r=this.dijkstra(t,e,!0,!0))==null?void 0:r.minPath)!=null?n:[];else{let h=[],o=this._getVertex(t),a=this._getVertex(e);if(!(o&&a))return[];let l=u((_,g,p,v)=>{if(p.add(_),_===g){h=[o,...v];return}let w=this.getNeighbors(_);for(let b of w)p.has(b)||(v.push(b),l(b,g,p,v),v.pop());p.delete(_)},"dfs");return l(o,a,new Set,[]),h}}dijkstraWithoutHeap(t,e=void 0,i=!1,s=!1){let r=Number.MAX_SAFE_INTEGER,n,h=[],o=[],a=this._vertexMap,l=new Map,_=new Set,g=new Map,p=this._getVertex(t),v=e?this._getVertex(e):void 0;if(!p)return;for(let M of a){let y=M[1];y instanceof z&&l.set(y,Number.MAX_SAFE_INTEGER)}l.set(p,0),g.set(p,void 0);let w=u(()=>{let M=Number.MAX_SAFE_INTEGER,y;for(let[N,m]of l)_.has(N)||m<M&&(M=m,y=N);return y},"getMinOfNoSeen"),b=u(M=>{for(let y of a){let N=y[1];if(N instanceof z){let m=[N],k=g.get(N);for(;k;)m.push(k),k=g.get(k);let E=m.reverse();y[1]===M&&(h=E),o.push(E)}}},"getPaths");for(let M=1;M<a.size;M++){let y=w();if(y){if(_.add(y),v&&v===y)return i&&(r=l.get(v)||Number.MAX_SAFE_INTEGER),s&&b(v),{distMap:l,preMap:g,seen:_,paths:o,minDist:r,minPath:h};let N=this.getNeighbors(y);for(let m of N)if(!_.has(m)){let k=this.getEdge(y,m);if(k){let E=l.get(y),I=l.get(m);E!==void 0&&I!==void 0&&k.weight+E<I&&(l.set(m,k.weight+E),g.set(m,y))}}}}return i&&l.forEach((M,y)=>{y!==p&&M<r&&(r=M,s&&(n=y))}),s&&b(n),{distMap:l,preMap:g,seen:_,paths:o,minDist:r,minPath:h}}dijkstra(t,e=void 0,i=!1,s=!1){var r;let n=Number.MAX_SAFE_INTEGER,h,o=[],a=[],l=this._vertexMap,_=new Map,g=new Set,p=new Map,v=this._getVertex(t),w=e?this._getVertex(e):void 0;if(!v)return;for(let y of l){let N=y[1];N instanceof z&&_.set(N,Number.MAX_SAFE_INTEGER)}let b=new ct([],{comparator:u((y,N)=>y.key-N.key,"comparator")});b.add({key:0,value:v}),_.set(v,0),p.set(v,void 0);let M=u(y=>{for(let N of l){let m=N[1];if(m instanceof z){let k=[m],E=p.get(m);for(;E;)k.push(E),E=p.get(E);let I=k.reverse();N[1]===y&&(o=I),a.push(I)}}},"getPaths");for(;b.size>0;){let y=b.poll(),N=y==null?void 0:y.key,m=y==null?void 0:y.value;if(N!==void 0&&m){if(g.add(m),w&&w===m)return i&&(n=_.get(w)||Number.MAX_SAFE_INTEGER),s&&M(w),{distMap:_,preMap:p,seen:g,paths:a,minDist:n,minPath:o};let k=this.getNeighbors(m);for(let E of k)if(!g.has(E)){let I=(r=this.getEdge(m,E))==null?void 0:r.weight;if(typeof I=="number"){let T=_.get(E);T!==void 0&&N+I<T&&(b.add({key:N+I,value:E}),p.set(E,m),_.set(E,N+I))}}}}return i&&_.forEach((y,N)=>{N!==v&&y<n&&(n=y,s&&(h=N))}),s&&M(h),{distMap:_,preMap:p,seen:g,paths:a,minDist:n,minPath:o}}bellmanFord(t,e,i,s){i===void 0&&(i=!1),s===void 0&&(s=!1);let r=this._getVertex(t),n=[],h=new Map,o=new Map,a=Number.MAX_SAFE_INTEGER,l=[],_;if(e&&(_=!1),!r)return{hasNegativeCycle:_,distMap:h,preMap:o,paths:n,min:a,minPath:l};let g=this._vertexMap,p=g.size,v=this.edgeSet(),w=v.length;this._vertexMap.forEach(M=>{h.set(M,Number.MAX_SAFE_INTEGER)}),h.set(r,0);for(let M=1;M<p;++M)for(let y=0;y<w;++y){let N=this.getEndsOfEdge(v[y]);if(N){let[m,k]=N,E=v[y].weight,I=h.get(m),T=h.get(k);I!==void 0&&T!==void 0&&h.get(m)!==Number.MAX_SAFE_INTEGER&&I+E<T&&(h.set(k,I+E),s&&o.set(k,m))}}let b;if(i&&h.forEach((M,y)=>{y!==r&&M<a&&(a=M,s&&(b=y))}),s)for(let M of g){let y=M[1];if(y instanceof z){let N=[y],m=o.get(y);for(;m!==void 0;)N.push(m),m=o.get(m);let k=N.reverse();M[1]===b&&(l=k),n.push(k)}}for(let M=0;M<w;++M){let y=this.getEndsOfEdge(v[M]);if(y){let[N]=y,m=v[M].weight,k=h.get(N);k&&k!==Number.MAX_SAFE_INTEGER&&k+m<k&&(_=!0)}}return{hasNegativeCycle:_,distMap:h,preMap:o,paths:n,min:a,minPath:l}}floydWarshall(){var t;let e=[...this._vertexMap],i=e.length,s=[],r=[];for(let n=0;n<i;n++){s[n]=[],r[n]=[];for(let h=0;h<i;h++)r[n][h]=void 0}for(let n=0;n<i;n++)for(let h=0;h<i;h++)s[n][h]=((t=this.getEdge(e[n][1],e[h][1]))==null?void 0:t.weight)||Number.MAX_SAFE_INTEGER;for(let n=0;n<i;n++)for(let h=0;h<i;h++)for(let o=0;o<i;o++)s[h][o]>s[h][n]+s[n][o]&&(s[h][o]=s[h][n]+s[n][o],r[h][o]=e[n][1]);return{costs:s,predecessor:r}}getCycles(t=!1){let e=[],i=new Set,s=u((n,h,o)=>{if(o.has(n)){(!t&&h.length>2||t&&h.length>=2)&&h[0]===n.key&&e.push([...h]);return}o.add(n),h.push(n.key);for(let a of this.getNeighbors(n))a&&s(a,h,o);o.delete(n),h.pop()},"dfs");for(let n of this.vertexMap.values())s(n,[],i);let r=new Map;for(let n of e){let h=[...n].sort().toString();r.has(h)||r.set(h,n)}return[...r].map(n=>n[1])}filter(t,e){let i=[],s=0;for(let[r,n]of this)t.call(e,n,r,s,this)&&i.push([r,n]),s++;return this._createLike(i,this._snapshotOptions())}filterEntries(t,e){let i=[],s=0;for(let[r,n]of this)t.call(e,n,r,s,this)&&i.push([r,n]),s++;return i}map(t,e){let i=[],s=0;for(let[r,n]of this)i.push(t.call(e,n,r,s,this)),s++;return i}clone(){return this._createLike(void 0,this._snapshotOptions())}*_getIterator(){for(let t of this._vertexMap.values())yield[t.key,t.value]}_snapshotOptions(){return{graph:{...this._options}}}_createInstance(t){let e=this.constructor,i=new e,s=t==null?void 0:t.graph;return s?i._options={...i._options,...s}:i._options={...i._options,...this._options},i}_createLike(t,e){let i=this._createInstance(e);if(t)for(let[r,n]of t)i.addVertex(r,n);else for(let[r,n]of this)i.addVertex(r,n);let s=this.edgeSet();for(let r of s){let n=this.getEndsOfEdge(r);if(!n)continue;let[h,o]=n,a=h.key,l=o.key,_=typeof i.hasVertex=="function"?i.hasVertex(a):!1,g=typeof i.hasVertex=="function"?i.hasVertex(l):!1;if(_&&g){let p=i.createEdge(a,l,r.weight,r.value);i._addEdge(p)}}return i}_addVertex(t){return this.hasVertex(t)?!1:(this._vertexMap.set(t.key,t),!0)}_getVertex(t){let e=this._getVertexKey(t);return this._vertexMap.get(e)||void 0}_getVertexKey(t){return t instanceof z?t.key:t}get _edgeConnector(){return"--"}toVisual(t){var e;let i=(e=t==null?void 0:t.showWeight)!=null?e:!0,s=[...this._vertexMap.values()],r=s.length,n=this.edgeSet().length,h=[`Graph (${r} vertices, ${n} edges):`];for(let o of s){let a=this.getNeighbors(o);if(a.length===0)h.push(` ${o.key} (isolated)`);else{let l=a.map(_=>{let g=this.getEdge(o,_);return g&&i&&g.weight!==void 0&&g.weight!==1?`${_.key} (${g.weight})`:`${_.key}`});h.push(` ${o.key} ${this._edgeConnector} ${l.join(", ")}`)}}return h.join(`
2
- `)}toDot(t){var e,i;let s=(e=t==null?void 0:t.name)!=null?e:"G",r=(i=t==null?void 0:t.showWeight)!=null?i:!0,n=this._edgeConnector==="->",h=n?"digraph":"graph",o=n?"->":"--",a=[`${h} ${s} {`];for(let _ of this._vertexMap.values())a.push(` "${_.key}";`);let l=new Set;for(let _ of this._vertexMap.values())for(let g of this.getNeighbors(_)){let p=n?`${_.key}->${g.key}`:[_.key,g.key].sort().join("--");if(l.has(p))continue;l.add(p);let v=this.getEdge(_,g),w=v&&r&&v.weight!==void 0&&v.weight!==1?` [label="${v.weight}"]`:"";a.push(` "${_.key}" ${o} "${g.key}"${w};`)}return a.push("}"),a.join(`
3
- `)}print(t){console.log(this.toVisual(t))}};u(ne,"AbstractGraph");var he=ne,oe=class extends z{constructor(t,e){super(t,e)}};u(oe,"DirectedVertex");var bt=oe,ae=class extends Rt{constructor(t,e,i,s){super(i,s),f(this,"src"),f(this,"dest"),this.src=t,this.dest=e}};u(ae,"DirectedEdge");var le=ae,ue=class kt extends he{constructor(t){super(t),f(this,"_outEdgeMap",new Map),f(this,"_inEdgeMap",new Map)}get _edgeConnector(){return"->"}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(t){this._outEdgeMap=t}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(t){this._inEdgeMap=t}static fromKeys(t){let e=new kt({vertexValueInitializer:u(i=>i,"vertexValueInitializer")});for(let i of t)e.addVertex(i);return e}static fromEntries(t){let e=new kt;for(let[i,s]of t)e.addVertex(i,s);return e}createVertex(t,e){return new bt(t,e)}createEdge(t,e,i,s){var r;return new le(t,e,(r=i!=null?i:this.options.defaultEdgeWeight)!=null?r:1,s)}getEdge(t,e){let i=[];if(t!==void 0&&e!==void 0){let s=this._getVertex(t),r=this._getVertex(e);if(s&&r){let n=this._outEdgeMap.get(s);n&&(i=n.filter(h=>h.dest===r.key))}}return i[0]||void 0}deleteEdgeSrcToDest(t,e){let i=this._getVertex(t),s=this._getVertex(e),r;if(!i||!s)return;let n=this._outEdgeMap.get(i);n&&q(n,o=>o.dest===s.key);let h=this._inEdgeMap.get(s);return h&&(r=q(h,o=>o.src===i.key)[0]||void 0),r}deleteEdge(t,e){let i,s,r;if(this.isVertexKey(t))if(this.isVertexKey(e))s=this._getVertex(t),r=this._getVertex(e);else return;else s=this._getVertex(t.src),r=this._getVertex(t.dest);if(s&&r){let n=this._outEdgeMap.get(s);n&&n.length>0&&q(n,o=>o.src===s.key&&o.dest===(r==null?void 0:r.key));let h=this._inEdgeMap.get(r);h&&h.length>0&&(i=q(h,o=>o.src===s.key&&o.dest===r.key)[0])}return i}deleteVertex(t){let e,i;if(this.isVertexKey(t)?(i=this.getVertex(t),e=t):(i=t,e=this._getVertexKey(t)),i){let s=this.getNeighbors(i);for(let r of s)this.deleteEdgeSrcToDest(i,r);this._outEdgeMap.delete(i),this._inEdgeMap.delete(i)}return this._vertexMap.delete(e)}deleteEdgesBetween(t,e){let i=[];if(t&&e){let s=this.deleteEdgeSrcToDest(t,e),r=this.deleteEdgeSrcToDest(e,t);s&&i.push(s),r&&i.push(r)}return i}incomingEdgesOf(t){let e=this._getVertex(t);return e?this.inEdgeMap.get(e)||[]:[]}outgoingEdgesOf(t){let e=this._getVertex(t);return e?this._outEdgeMap.get(e)||[]:[]}degreeOf(t){return this.outDegreeOf(t)+this.inDegreeOf(t)}inDegreeOf(t){return this.incomingEdgesOf(t).length}outDegreeOf(t){return this.outgoingEdgesOf(t).length}edgesOf(t){return[...this.outgoingEdgesOf(t),...this.incomingEdgesOf(t)]}getEdgeSrc(t){return this._getVertex(t.src)}getEdgeDest(t){return this._getVertex(t.dest)}getDestinations(t){if(t===void 0)return[];let e=[],i=this.outgoingEdgesOf(t);for(let s of i){let r=this.getEdgeDest(s);r&&e.push(r)}return e}topologicalSort(t){t=t!=null?t:"key";let e=new Map;for(let n of this.vertexMap)e.set(n[1],0);let i=[],s=!1,r=u(n=>{e.set(n,1);let h=this.getDestinations(n);for(let o of h){let a=e.get(o);a===0?r(o):a===1&&(s=!0)}e.set(n,2),i.push(n)},"dfs");for(let n of this.vertexMap)e.get(n[1])===0&&r(n[1]);if(!s)return t==="key"&&(i=i.map(n=>n instanceof bt?n.key:n)),i.reverse()}edgeSet(){let t=[];return this._outEdgeMap.forEach(e=>{t=[...t,...e]}),t}getNeighbors(t){let e=[],i=this._getVertex(t);if(i){let s=this.outgoingEdgesOf(i);for(let r of s){let n=this._getVertex(r.dest);n&&e.push(n)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return;let e=this._getVertex(t.src),i=this._getVertex(t.dest);if(e&&i)return[e,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(){return super.clone()}tarjan(){let t=new Map,e=new Map,i=new Map,s=0,r=[],n=new Set,h=u(o=>{t.set(o,s),e.set(o,s),s++,r.push(o),n.add(o);let a=this.getNeighbors(o);for(let l of a)t.has(l)?n.has(l)&&e.set(o,Math.min(e.get(o),t.get(l))):(h(l),e.set(o,Math.min(e.get(o),e.get(l))));if(t.get(o)===e.get(o)){let l=[],_;do _=r.pop(),n.delete(_),l.push(_);while(_!==o);i.set(i.size,l)}},"dfs");for(let o of this.vertexMap.values())t.has(o)||h(o);return{dfnMap:t,lowMap:e,SCCs:i}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(t){if(!(this.hasVertex(t.src)&&this.hasVertex(t.dest)))return!1;let e=this._getVertex(t.src),i=this._getVertex(t.dest);if(e&&i){let s=this._outEdgeMap.get(e);s?s.push(t):this._outEdgeMap.set(e,[t]);let r=this._inEdgeMap.get(i);return r?r.push(t):this._inEdgeMap.set(i,[t]),!0}else return!1}};u(ue,"DirectedGraph");var si=ue,ce=class extends z{constructor(t,e){super(t,e)}};u(ce,"UndirectedVertex");var ri=ce,fe=class extends Rt{constructor(t,e,i,s){super(i,s),f(this,"endpoints"),this.endpoints=[t,e]}};u(fe,"UndirectedEdge");var ni=fe,hi=class xt extends he{constructor(t){super(t),f(this,"_edgeMap"),this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(t){this._edgeMap=t}static fromKeys(t){let e=new xt({vertexValueInitializer:u(i=>i,"vertexValueInitializer")});for(let i of t)e.addVertex(i);return e}static fromEntries(t){let e=new xt;for(let[i,s]of t)e.addVertex(i,s);return e}createVertex(t,e){return new ri(t,e)}createEdge(t,e,i,s){var r;return new ni(t,e,(r=i!=null?i:this.options.defaultEdgeWeight)!=null?r:1,s)}getEdge(t,e){var i;let s=[];if(t!==void 0&&e!==void 0){let r=this._getVertex(t),n=this._getVertex(e);r&&n&&(s=(i=this._edgeMap.get(r))==null?void 0:i.filter(h=>h.endpoints.includes(n.key)))}return s&&s[0]||void 0}deleteEdgeBetween(t,e){let i=this._getVertex(t),s=this._getVertex(e);if(!i||!s)return;let r=this._edgeMap.get(i),n;r&&(n=q(r,o=>o.endpoints.includes(s.key))[0]||void 0);let h=this._edgeMap.get(s);return h&&q(h,o=>o.endpoints.includes(i.key)),n}deleteEdge(t,e){let i,s;if(this.isVertexKey(t))if(this.isVertexKey(e))i=this._getVertex(t),s=this._getVertex(e);else return;else i=this._getVertex(t.endpoints[0]),s=this._getVertex(t.endpoints[1]);if(i&&s)return this.deleteEdgeBetween(i,s)}deleteVertex(t){let e,i;this.isVertexKey(t)?(i=this.getVertex(t),e=t):(i=t,e=this._getVertexKey(t));let s=this.getNeighbors(t);return i&&(s.forEach(r=>{let n=this._edgeMap.get(r);if(n){let h=n.filter(o=>!o.endpoints.includes(e));this._edgeMap.set(r,h)}}),this._edgeMap.delete(i)),this._vertexMap.delete(e)}degreeOf(t){var e;let i=this._getVertex(t);return i&&((e=this._edgeMap.get(i))==null?void 0:e.length)||0}edgesOf(t){let e=this._getVertex(t);return e?this._edgeMap.get(e)||[]:[]}edgeSet(){let t=new Set;return this._edgeMap.forEach(e=>{e.forEach(i=>{t.add(i)})}),[...t]}getNeighbors(t){let e=[],i=this._getVertex(t);if(i){let s=this.edgesOf(i);for(let r of s){let n=this._getVertex(r.endpoints.filter(h=>h!==i.key)[0]);n&&e.push(n)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.endpoints[0],t.endpoints[1]))return;let e=this._getVertex(t.endpoints[0]),i=this._getVertex(t.endpoints[1]);if(e&&i)return[e,i]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){return super.clone()}tarjan(){let t=new Map,e=new Map,i=[],s=[],r=0,n=u((h,o)=>{t.set(h,r),e.set(h,r),r++;let a=this.getNeighbors(h),l=0;for(let _ of a)if(t.has(_))_!==o&&e.set(h,Math.min(e.get(h),t.get(_)));else{if(l++,n(_,h),e.set(h,Math.min(e.get(h),e.get(_))),e.get(_)>t.get(h)){let g=this.getEdge(h,_);g&&i.push(g)}o!==void 0&&e.get(_)>=t.get(h)&&s.push(h)}o===void 0&&l>1&&s.push(h)},"dfs");for(let h of this.vertexMap.values())t.has(h)||n(h,void 0);return{dfnMap:t,lowMap:e,bridges:i,cutVertices:s}}getBiconnectedComponents(){let t=new Map,e=new Map,i=[],s=[],r=0,n=u((h,o)=>{t.set(h,r),e.set(h,r),r++;let a=this.getNeighbors(h),l=0;for(let _ of a){let g=this.getEdge(h,_);if(g){if(t.has(_))_!==o&&t.get(_)<t.get(h)&&(i.push(g),e.set(h,Math.min(e.get(h),t.get(_))));else if(l++,i.push(g),n(_,h),e.set(h,Math.min(e.get(h),e.get(_))),o===void 0&&l>1||o!==void 0&&e.get(_)>=t.get(h)){let p=[],v;do v=i.pop(),v&&p.push(v);while(v&&v!==g);p.length>0&&s.push(p)}}}},"dfs");for(let h of this.vertexMap.values())t.has(h)||(n(h,void 0),i.length>0&&(s.push([...i]),i.length=0));return s}hasCycle(){let t=new Set,e=u((i,s)=>{t.add(i);for(let r of this.getNeighbors(i))if(t.has(r)){if(r!==s)return!0}else if(e(r,i))return!0;return!1},"dfs");for(let i of this.vertexMap.values())if(!t.has(i)&&e(i,void 0))return!0;return!1}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(t){for(let e of t.endpoints){let i=this._getVertex(e);if(i===void 0)return!1;if(i){let s=this._edgeMap.get(i);s?s.push(t):this._edgeMap.set(i,[t])}}return!0}};u(hi,"UndirectedGraph");var _e=class extends bt{constructor(t,e,i,s){super(t,e),f(this,"lat"),f(this,"long"),this.lat=i,this.long=s}};u(_e,"MapVertex");var oi=_e,de=class extends le{constructor(t,e,i,s){super(t,e,i,s)}};u(de,"MapEdge");var ai=de,li=class ge extends si{constructor(t,e){super(),f(this,"_originCoord",[0,0]),f(this,"_bottomRight"),this._originCoord=t,this._bottomRight=e}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(t,e,i=this.originCoord[0],s=this.originCoord[1]){return new oi(t,e,i,s)}createEdge(t,e,i,s){return new ai(t,e,i,s)}clone(){return super.clone()}_snapshotOptions(){return{...super._snapshotOptions(),originCoord:this.originCoord,bottomRight:this.bottomRight}}_createInstance(t){let{originCoord:e,bottomRight:i}=t||{},s=e!=null?e:this.originCoord,r=i!=null?i:this.bottomRight;return new ge(s,r)}};u(li,"MapGraph");var pe=class{constructor(t,e){f(this,"key"),f(this,"value"),f(this,"parent"),f(this,"_left"),f(this,"_right"),f(this,"_height",0),f(this,"_color","BLACK"),f(this,"_count",1),this.key=t,this.value=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}set count(t){this._count=t}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(pe,"BinaryTreeNode");var pt=pe,ve=class rt extends it{constructor(t=[],e){if(super(),f(this,"iterationType","ITERATIVE"),f(this,"_isMapMode",!0),f(this,"_isDuplicate",!1),f(this,"_store",new Map),f(this,"_root"),f(this,"_size",0),f(this,"_NIL",new pt(NaN)),f(this,"_toEntryFn"),f(this,"_DEFAULT_NODE_CALLBACK",u(i=>i==null?void 0:i.key,"_DEFAULT_NODE_CALLBACK")),e){let{iterationType:i,toEntryFn:s,isMapMode:r,isDuplicate:n}=e;i&&(this.iterationType=i),r!==void 0&&(this._isMapMode=r),n!==void 0&&(this._isDuplicate=n),typeof s=="function"?this._toEntryFn=s:s&&x(TypeError,R.notAFunction("toEntryFn","BinaryTree"))}t&&this.setMany(t)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(t,e){return new pt(t,e)}createTree(t){return this._createInstance(t)}ensureNode(t,e=this.iterationType){if(t===null)return null;if(t!==void 0&&t!==this._NIL){if(this.isNode(t))return t;if(this.isEntry(t)){let i=t[0];return i===null?null:i===void 0?void 0:this.getNode(i,this._root,e)}return this.getNode(t,this._root,e)}}isNode(t){return t instanceof pt}isRaw(t){return this._toEntryFn!==void 0&&typeof t=="object"}isRealNode(t){return t===this._NIL||t===null||t===void 0?!1:this.isNode(t)}isRealNodeOrNull(t){return t===null||this.isRealNode(t)}isNIL(t){return t===this._NIL}isRange(t){return t instanceof st}isLeaf(t){return t=this.ensureNode(t),t===void 0?!1:t===null?!0:!this.isRealNode(t.left)&&!this.isRealNode(t.right)}isEntry(t){return Array.isArray(t)&&t.length===2}isValidKey(t){return t===null?!0:tt(t)}add(t){return this.set(t)}set(t,e){let[i]=this._keyValueNodeOrEntryToNodeAndValue(t,e);if(i===void 0)return!1;if(!this._root)return this._setRoot(i),this._isMapMode&&i!==null&&i!==void 0&&this._store.set(i.key,i),i!==null&&(this._size=1),!0;let s=new et([this._root]),r;for(;s.length>0;){let n=s.shift();if(n){if(!this._isDuplicate&&i!==null&&n.key===i.key)return this._replaceNode(n,i),this._isMapMode&&i!==null&&this._store.set(n.key,i),!0;r===void 0&&(n.left===void 0||n.right===void 0)&&(r=n),n.left!==null&&n.left&&s.push(n.left),n.right!==null&&n.right&&s.push(n.right)}}return r?(r.left===void 0?r.left=i:r.right===void 0&&(r.right=i),this._isMapMode&&i!==null&&i!==void 0&&this._store.set(i.key,i),i!==null&&this._size++,!0):!1}addMany(t){return this.setMany(t)}setMany(t,e){let i=[],s;e&&(s=e[Symbol.iterator]());for(let r of t){let n;if(s){let h=s.next();h.done||(n=h.value)}this.isRaw(r)&&(r=this._toEntryFn(r)),i.push(this.set(r,n))}return i}merge(t){this.setMany(t,[])}_deleteInternal(t){let e=[];if(!this._root)return e;let i=this.getNode(t);if(!i)return e;let s=i==null?void 0:i.parent,r,n=i;if(!i.left&&!i.right&&!s)this._setRoot(void 0);else if(i.left){let h=this.getRightMost(o=>o,i.left);if(h){let o=h.parent;n=this._swapProperties(i,h),this._isMapMode&&(this._store.set(i.key,i),this._store.set(h.key,h)),o&&(o.right===h?o.right=h.left:o.left=h.left,r=o)}}else if(s){let{familyPosition:h}=i;h==="LEFT"||h==="ROOT_LEFT"?s.left=i.right:(h==="RIGHT"||h==="ROOT_RIGHT")&&(s.right=i.right),r=s}else this._setRoot(i.right),i.right=void 0;return this._size=this._size-1,e.push({deleted:n,needBalanced:r}),this._isMapMode&&n&&this._store.delete(n.key),e}delete(t){return this._deleteInternal(t).length>0}search(t,e=!1,i=this._DEFAULT_NODE_CALLBACK,s=this._root,r=this.iterationType){if(t===void 0)return[];if(t===null)return[];if(s=this.ensureNode(s),!s)return[];let n=this._ensurePredicate(t),h=[];if(r==="RECURSIVE"){let o=u(a=>{n(a)&&(h.push(i(a)),e)||!this.isRealNode(a.left)&&!this.isRealNode(a.right)||(this.isRealNode(a.left)&&o(a.left),this.isRealNode(a.right)&&o(a.right))},"dfs");o(s)}else{let o=[s];for(;o.length>0;){let a=o.pop();if(this.isRealNode(a)){if(n(a)&&(h.push(i(a)),e))return h;this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right)}}}return h}getNodes(t,e=!1,i=this._root,s=this.iterationType){return this.search(t,e,r=>r,i,s)}getNode(t,e=this._root,i=this.iterationType){if(this._isMapMode&&t!==null&&t!==void 0&&!this._isPredicate(t)){let s=this._extractKey(t);return s==null?void 0:this._store.get(s)}return this.search(t,!0,s=>s,e,i)[0]}get(t,e=this._root,i=this.iterationType){var s,r;if(this._isMapMode){let n=this._extractKey(t);return n==null||(s=this._store.get(n))==null?void 0:s.value}return(r=this.getNode(t,e,i))==null?void 0:r.value}has(t,e=this._root,i=this.iterationType){if(this._isMapMode&&t!==void 0&&t!==null&&!this._isPredicate(t)){let s=this._extractKey(t);return s==null?!1:this._store.has(s)}return this.search(t,!0,s=>s,e,i).length>0}clear(){this._clearNodes(),this._isMapMode&&this._clearValues()}isEmpty(){return this._size===0}isPerfectlyBalanced(t=this._root){return this.getMinHeight(t)+1>=this.getHeight(t)}isBST(t=this._root,e=this.iterationType){let i=this.ensureNode(t);if(!i)return!0;if(e==="RECURSIVE"){let s=u((h,o,a)=>{if(!this.isRealNode(h))return!0;let l=Number(h.key);return l<=o||l>=a?!1:s(h.left,o,l)&&s(h.right,l,a)},"dfs"),r=s(i,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),n=s(i,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||n}else{let s=u((h=!1)=>{let o=[],a=h?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,l=i;for(;this.isRealNode(l)||o.length>0;){for(;this.isRealNode(l);)o.push(l),l=l.left;l=o.pop();let _=Number(l.key);if(!this.isRealNode(l)||!h&&a>=_||h&&a<=_)return!1;a=_,l=l.right}return!0},"checkBST"),r=s(),n=s(!0);return r||n}}getDepth(t,e=this._root){let i=this.ensureNode(t),s=this.ensureNode(e),r=0;for(;i!=null&&i.parent;){if(i===s)return r;r++,i=i.parent}return r}getHeight(t=this._root,e=this.iterationType){if(t=this.ensureNode(t),!this.isRealNode(t))return-1;if(e==="RECURSIVE"){let i=u(s=>{if(!this.isRealNode(s))return-1;let r=i(s.left),n=i(s.right);return Math.max(r,n)+1},"_getMaxHeight");return i(t)}else{let i=[{node:t,depth:0}],s=0;for(;i.length>0;){let{node:r,depth:n}=i.pop();this.isRealNode(r.left)&&i.push({node:r.left,depth:n+1}),this.isRealNode(r.right)&&i.push({node:r.right,depth:n+1}),s=Math.max(s,n)}return s}}getMinHeight(t=this._root,e=this.iterationType){if(t=this.ensureNode(t),!t)return-1;if(e==="RECURSIVE"){let i=u(s=>{if(!this.isRealNode(s)||!this.isRealNode(s.left)&&!this.isRealNode(s.right))return 0;let r=i(s.left),n=i(s.right);return Math.min(r,n)+1},"_getMinHeight");return i(t)}else{let i=[],s=t,r=null,n=new Map;for(;i.length>0||s;)if(this.isRealNode(s))i.push(s),s=s.left;else if(s=i[i.length-1],!this.isRealNode(s.right)||r===s.right){if(s=i.pop(),this.isRealNode(s)){let h=this.isRealNode(s.left)?n.get(s.left):-1,o=this.isRealNode(s.right)?n.get(s.right):-1;n.set(s,1+Math.min(h,o)),r=s,s=null}}else s=s.right;return n.get(t)}}getPathToRoot(t,e=this._DEFAULT_NODE_CALLBACK,i=!1){let s=[],r=this.ensureNode(t);if(!r)return s;for(;r.parent;)s.push(e(r)),r=r.parent;return s.push(e(r)),i?s.reverse():s}getLeftMost(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){if(this.isNIL(e))return t(void 0);let s=this.ensureNode(e);if(!this.isRealNode(s))return t(void 0);if(i==="RECURSIVE"){let r=u(n=>{let{left:h}=n;return this.isRealNode(h)?r(h):n},"dfs");return t(r(s))}else{let r=yt(n=>{let{left:h}=n;return this.isRealNode(h)?Lt(()=>r(h)):n});return t(r(s))}}getRightMost(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){if(this.isNIL(e)||(e=this.ensureNode(e),!e))return t(void 0);if(i==="RECURSIVE"){let s=u(r=>{let{right:n}=r;return this.isRealNode(n)?s(n):r},"dfs");return t(s(e))}else{let s=yt(r=>{let{right:n}=r;return this.isRealNode(n)?Lt(()=>s(n)):r});return t(s(e))}}getPredecessor(t){if(this.isRealNode(t.left)){let e=t.left;for(;!this.isRealNode(e)||this.isRealNode(e.right)&&e.right!==t;)this.isRealNode(e)&&(e=e.right);return e}else return t}getSuccessor(t){if(t=this.ensureNode(t),!this.isRealNode(t))return;if(this.isRealNode(t.right))return this.getLeftMost(i=>i,t.right);let e=t.parent;for(;this.isRealNode(e)&&t===e.right;)t=e,e=e.parent;return e}dfs(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=!1,s=this._root,r=this.iterationType,n=!1){return s=this.ensureNode(s),s?this._dfs(t,e,i,s,r,n):[]}bfs(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType,s=!1){if(e=this.ensureNode(e),!e)return[];let r=[];if(i==="RECURSIVE"){let n=new et([e]),h=u(o=>{if(n.length===0)return;let a=n.shift();r.push(t(a)),s?(a&&this.isRealNodeOrNull(a.left)&&n.push(a.left),a&&this.isRealNodeOrNull(a.right)&&n.push(a.right)):(this.isRealNode(a.left)&&n.push(a.left),this.isRealNode(a.right)&&n.push(a.right)),h(o+1)},"dfs");h(0)}else{let n=new et([e]);for(;n.length>0;){let h=n.length;for(let o=0;o<h;o++){let a=n.shift();r.push(t(a)),s?(a&&this.isRealNodeOrNull(a.left)&&n.push(a.left),a&&this.isRealNodeOrNull(a.right)&&n.push(a.right)):(this.isRealNode(a.left)&&n.push(a.left),this.isRealNode(a.right)&&n.push(a.right))}}}return r}leaves(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){e=this.ensureNode(e);let s=[];if(!this.isRealNode(e))return[];if(i==="RECURSIVE"){let r=u(n=>{this.isLeaf(n)&&s.push(t(n)),!(!this.isRealNode(n.left)&&!this.isRealNode(n.right))&&(this.isRealNode(n.left)&&r(n.left),this.isRealNode(n.right)&&r(n.right))},"dfs");r(e)}else{let r=[e];for(;r.length>0;){let n=r.pop();this.isRealNode(n)&&(this.isLeaf(n)&&s.push(t(n)),this.isRealNode(n.right)&&r.push(n.right),this.isRealNode(n.left)&&r.push(n.left))}}return s}listLevels(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType,s=!1){e=this.ensureNode(e);let r=[];if(!e)return r;if(i==="RECURSIVE"){let n=u((h,o)=>{r[o]||(r[o]=[]),r[o].push(t(h)),s?(h&&this.isRealNodeOrNull(h.left)&&n(h.left,o+1),h&&this.isRealNodeOrNull(h.right)&&n(h.right,o+1)):(h&&h.left&&n(h.left,o+1),h&&h.right&&n(h.right,o+1))},"_recursive");n(e,0)}else{let n=[[e,0]];for(;n.length>0;){let h=n.pop(),[o,a]=h;r[a]||(r[a]=[]),r[a].push(t(o)),s?(o&&this.isRealNodeOrNull(o.right)&&n.push([o.right,a+1]),o&&this.isRealNodeOrNull(o.left)&&n.push([o.left,a+1])):(o&&o.right&&n.push([o.right,a+1]),o&&o.left&&n.push([o.left,a+1]))}}return r}morris(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=this._root){if(i=this.ensureNode(i),!i)return[];let s=[],r=i,n=u(o=>{let a=null,l=null;for(;o;)l=o.right,o.right=a,a=o,o=l;return a},"_reverseEdge"),h=u(o=>{let a=n(o),l=a;for(;l;)s.push(t(l)),l=l.right;n(a)},"_printEdge");switch(e){case"IN":for(;r;){if(r.left){let o=this.getPredecessor(r);if(o.right)o.right=null;else{o.right=r,r=r.left;continue}}s.push(t(r)),r=r.right}break;case"PRE":for(;r;){if(r.left){let o=this.getPredecessor(r);if(o.right)o.right=null;else{o.right=r,s.push(t(r)),r=r.left;continue}}else s.push(t(r));r=r.right}break;case"POST":for(;r;){if(r.left){let o=this.getPredecessor(r);if(o.right===null){o.right=r,r=r.left;continue}else o.right=null,h(r.left)}r=r.right}h(i);break}return s}clone(){let t=this._createInstance();return this._clone(t),t}filter(t,e){let i=this._createInstance(),s=0;for(let[r,n]of this)t.call(e,n,r,s++,this)&&i.set([r,n]);return i}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}toVisual(t=this._root,e){let i={isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1,...e};t=this.ensureNode(t);let s="";return t&&(i.isShowUndefined&&(s+=`U for undefined
1
+ "use strict";var treeMultimapTyped=(()=>{var dt=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var ze=Object.prototype.hasOwnProperty;var Ve=(f,t)=>{for(var e in t)dt(f,e,{get:t[e],enumerable:!0})},Ke=(f,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of De(t))!ze.call(f,s)&&s!==e&&dt(f,s,{get:()=>t[s],enumerable:!(i=Be(t,s))||i.enumerable});return f};var je=f=>Ke(dt({},"__esModule",{value:!0}),f);var wi={};Ve(wi,{TreeMultiMap:()=>Ee});var Ct=Object.defineProperty,Tt=f=>{throw TypeError(f)},He=(f,t,e)=>t in f?Ct(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,u=(f,t)=>Ct(f,"name",{value:t,configurable:!0}),c=(f,t,e)=>He(f,typeof t!="symbol"?t+"":t,e),At=(f,t,e)=>t.has(f)||Tt("Cannot "+e),d=(f,t,e)=>(At(f,t,"read from private field"),e?e.call(f):t.get(f)),K=(f,t,e)=>t.has(f)?Tt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(f):t.set(f,e),j=(f,t,e,i)=>(At(f,t,"write to private field"),t.set(f,e),e),Bt=class{*[Symbol.iterator](...t){yield*this._getIterator(...t)}*entries(){for(let t of this)yield t}*keys(){for(let t of this)yield t[0]}*values(){for(let t of this)yield t[1]}every(t,e){let i=0;for(let s of this)if(!t.call(e,s[1],s[0],i++,this))return!1;return!0}some(t,e){let i=0;for(let s of this)if(t.call(e,s[1],s[0],i++,this))return!0;return!1}forEach(t,e){let i=0;for(let s of this){let[r,n]=s;t.call(e,n,r,i++,this)}}find(t,e){let i=0;for(let s of this){let[r,n]=s;if(t.call(e,n,r,i++,this))return s}}has(t){for(let e of this){let[i]=e;if(i===t)return!0}return!1}hasValue(t){for(let[,e]of this)if(e===t)return!0;return!1}get(t){for(let e of this){let[i,s]=e;if(i===t)return s}}reduce(t,e){let i=e,s=0;for(let r of this){let[n,h]=r;i=t(i,h,n,s++,this)}return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};u(Bt,"IterableEntryBase");var it=Bt;function w(f,t){throw new f(t)}u(w,"raise");var R={indexOutOfRange:u((f,t,e,i)=>`${i?i+": ":""}Index ${f} is out of range [${t}, ${e}].`,"indexOutOfRange"),invalidIndex:u(f=>`${f?f+": ":""}Index must be an integer.`,"invalidIndex"),invalidArgument:u((f,t)=>`${t?t+": ":""}${f}`,"invalidArgument"),comparatorRequired:u(f=>`${f?f+": ":""}Comparator is required for non-number/non-string/non-Date keys.`,"comparatorRequired"),invalidKey:u((f,t)=>`${t?t+": ":""}${f}`,"invalidKey"),notAFunction:u((f,t)=>`${t?t+": ":""}${f} must be a function.`,"notAFunction"),invalidEntry:u(f=>`${f?f+": ":""}Each entry must be a [key, value] tuple.`,"invalidEntry"),invalidNaN:u(f=>`${f?f+": ":""}NaN is not a valid key.`,"invalidNaN"),invalidDate:u(f=>`${f?f+": ":""}Invalid Date key.`,"invalidDate"),reduceEmpty:u(f=>`${f?f+": ":""}Reduce of empty structure with no initial value.`,"reduceEmpty"),callbackReturnType:u((f,t,e)=>`${e?e+": ":""}Callback must return ${f}; got ${t}.`,"callbackReturnType"),invalidOperation:u((f,t)=>`${t?t+": ":""}${f}`,"invalidOperation"),matrixDimensionMismatch:u(f=>`Matrix: Dimensions must be compatible for ${f}.`,"matrixDimensionMismatch"),matrixSingular:u(()=>"Matrix: Singular matrix, inverse does not exist.","matrixSingular"),matrixNotSquare:u(()=>"Matrix: Must be square for inversion.","matrixNotSquare"),matrixNotRectangular:u(()=>"Matrix: Must be rectangular for transposition.","matrixNotRectangular"),matrixRowMismatch:u((f,t)=>`Matrix: Expected row length ${f}, but got ${t}.`,"matrixRowMismatch"),orderStatisticNotEnabled:u((f,t)=>`${t?t+": ":""}${f}() requires enableOrderStatistic: true.`,"orderStatisticNotEnabled")};var Dt=class{constructor(t,e,i=!0,s=!0){this.low=t,this.high=e,this.includeLow=i,this.includeHigh=s}isInRange(t,e){let i=this.includeLow?e(t,this.low)>=0:e(t,this.low)>0,s=this.includeHigh?e(t,this.high)<=0:e(t,this.high)<0;return i&&s}};u(Dt,"Range");var st=Dt,zt=class{constructor(t){if(c(this,"_toElementFn"),t){let{toElementFn:e}=t;typeof e=="function"?this._toElementFn=e:e&&w(TypeError,"toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...t){yield*this._getIterator(...t)}*values(){for(let t of this)yield t}every(t,e){let i=0;for(let s of this)if(e===void 0){if(!t(s,i++,this))return!1}else if(!t.call(e,s,i++,this))return!1;return!0}some(t,e){let i=0;for(let s of this)if(e===void 0){if(t(s,i++,this))return!0}else if(t.call(e,s,i++,this))return!0;return!1}forEach(t,e){let i=0;for(let s of this)e===void 0?t(s,i++,this):t.call(e,s,i++,this)}find(t,e){let i=0;for(let s of this)if(e===void 0){if(t(s,i++,this))return s}else if(t.call(e,s,i++,this))return s}has(t){for(let e of this)if(e===t)return!0;return!1}includes(t){return this.has(t)}*entries(){let t=0;for(let e of this)yield[t++,e]}*keys(){let t=0;for(let e of this)yield t++}reduce(t,e){let i=0,s=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let n=s.next();n.done&&w(TypeError,"Reduce of empty structure with no initial value"),r=n.value,i=1}for(let n of s)r=t(r,n,i++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};u(zt,"IterableElementBase");var ut=zt,Vt=class{constructor(t){c(this,"_value"),c(this,"_next"),this._value=t,this._next=void 0}get value(){return this._value}set value(t){this._value=t}get next(){return this._next}set next(t){this._next=t}};u(Vt,"LinkedListNode");var Kt=Vt,jt=class Ht extends ut{constructor(t){if(super(t),c(this,"_maxLen",-1),t){let{maxLen:e}=t;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}get maxLen(){return this._maxLen}indexOf(t,e=0){if(this.length===0)return-1;e<0&&(e=this.length+e),e<0&&(e=0);for(let i=e;i<this.length;i++)if(this.at(i)===t)return i;return-1}lastIndexOf(t,e=this.length-1){if(this.length===0)return-1;e>=this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(let i=e;i>=0;i--)if(this.at(i)===t)return i;return-1}findIndex(t,e){for(let i=0;i<this.length;i++){let s=this.at(i);if(s!==void 0&&t.call(e,s,i,this))return i}return-1}concat(...t){let e=this.clone();for(let i of t)i instanceof Ht?e.pushMany(i):e.push(i);return e}sort(t){let e=this.toArray();e.sort(t),this.clear();for(let i of e)this.push(i);return this}splice(t,e=0,...i){let s=this._createInstance();t=t<0?this.length+t:t,t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,Math.min(e,this.length-t));for(let r=0;r<e;r++){let n=this.deleteAt(t);n!==void 0&&s.push(n)}for(let r=0;r<i.length;r++)this.addAt(t+r,i[r]);return s}join(t=","){return this.toArray().join(t)}toReversedArray(){let t=[];for(let e=this.length-1;e>=0;e--)t.push(this.at(e));return t}reduceRight(t,e){let i=e!=null?e:0;for(let s=this.length-1;s>=0;s--)i=t(i,this.at(s),s,this);return i}slice(t=0,e=this.length){t=t<0?this.length+t:t,e=e<0?this.length+e:e;let i=this._createInstance();for(let s=t;s<e;s++)i.push(this.at(s));return i}fill(t,e=0,i=this.length){if(e=e<0?this.length+e:e,i=i<0?this.length+i:i,e<0&&(e=0),i>this.length&&(i=this.length),e>=i)return this;for(let s=e;s<i;s++)this.setAt(s,t);return this}toReversed(){let t=this.clone();return t.reverse(),t}};u(jt,"LinearBase");var at=jt,Ut=class extends at{constructor(t){if(super(t),t){let{maxLen:e}=t;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(t,e=0){let i=this._getIterator(),s=i.next(),r=0;for(;r<e;)s=i.next(),r++;for(;!s.done;){if(s.value===t)return r;s=i.next(),r++}return-1}lastIndexOf(t,e=this.length-1){let i=this._getReverseIterator(),s=i.next(),r=this.length-1;for(;r>e;)s=i.next(),r--;for(;!s.done;){if(s.value===t)return r;s=i.next(),r--}return-1}concat(...t){let e=this.clone();for(let i of t)i instanceof at?e.pushMany(i):e.push(i);return e}slice(t=0,e=this.length){t=t<0?this.length+t:t,e=e<0?this.length+e:e;let i=this._createInstance(),s=this._getIterator(),r=s.next(),n=0;for(;n<t;)r=s.next(),n++;for(let h=t;h<e;h++)i.push(r.value),r=s.next();return i}splice(t,e=0,...i){let s=this._createInstance();t=t<0?this.length+t:t,t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,e);let r=0,n,h,o=this._getNodeIterator();for(let a of o){if(r===t){n=a;break}h=a,r++}for(let a=0;a<e&&n;a++){s.push(n.value);let l=n.next;this.delete(n),n=l}for(let a=0;a<i.length;a++)h?(this.addAfter(h,i[a]),h=h.next):(this.addAt(0,i[a]),h=this._getNodeIterator().next().value);return s}reduceRight(t,e){let i=e!=null?e:0,s=this.length-1;for(let r of this._getReverseIterator())i=t(i,r,s--,this);return i}};u(Ut,"LinearLinkedBase");var qt=Ut,Ue=u(function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(f){let t=Math.random()*16|0;return(f=="x"?t:t&3|8).toString(16)})},"uuidV4"),$=u(function(f,t){let e=-1,i=f?f.length:0,s=[];for(;++e<i;){let r=f[e];t(r,e,f)&&(s.push(r),Array.prototype.splice.call(f,e--,1),i--)}return s},"arrayRemove");var O=u((f,t,e,i)=>{if(f<t||f>e)throw new RangeError(i!=null?i:`Index ${f} is out of range [${t}, ${e}].`)},"rangeCheck");var W=u(f=>{let t=typeof f;return t==="object"&&f!==null||t==="function"},"isWeakKey"),Lt=u((f,t)=>Math.floor((f+t-1)/t),"calcMinUnitsRequired");function lt(f){let t=typeof f;return t==="number"?!0:t==="bigint"||t==="string"||t==="boolean"}u(lt,"isPrimitiveComparable");function xt(f){if(typeof f.valueOf=="function"){let t=f.valueOf();if(t!==f){if(lt(t))return t;if(typeof t=="object"&&t!==null)return xt(t)}}if(typeof f.toString=="function"){let t=f.toString();if(t!=="[object Object]")return t}return null}u(xt,"tryObjectToPrimitive");function tt(f,t=!1){if(f==null)return!1;if(lt(f))return!0;if(typeof f!="object")return!1;if(f instanceof Date||t)return!0;let e=xt(f);return e==null?!1:lt(e)}u(tt,"isComparable");var Et=u(f=>({isThunk:!0,fn:f}),"makeTrampolineThunk"),Wt=u(f=>typeof f=="object"&&f!==null&&"isThunk"in f&&f.isThunk,"isTrampolineThunk");function Gt(f){let t=f;for(;Wt(t);)t=t.fn();return t}u(Gt,"trampoline");function yt(f){return(...t)=>Gt(f(...t))}u(yt,"makeTrampoline");async function $t(f){let t=await f;for(;Wt(t);)t=await t.fn();return t}u($t,"asyncTrampoline");function qe(f){return async(...t)=>$t(f(...t))}u(qe,"makeAsyncTrampoline");function We(f,t=32){let e=(f>>>0).toString(2);return e=e.padStart(t,"0"),e}u(We,"toBinaryString");var Ge=class extends it{constructor(t=[],e){if(super(),c(this,"_store",{}),c(this,"_objMap",new Map),c(this,"_toEntryFn"),c(this,"_size",0),c(this,"_hashFn",u(i=>String(i),"_hashFn")),e){let{hashFn:i,toEntryFn:s}=e;i&&(this._hashFn=i),s&&(this._toEntryFn=s)}t&&this.setMany(t)}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}isEmpty(){return this._size===0}clear(){this._store={},this._objMap.clear(),this._size=0}isEntry(t){return Array.isArray(t)&&t.length===2}set(t,e){if(this._isObjKey(t))this.objMap.has(t)||this._size++,this.objMap.set(t,e);else{let i=this._getNoObjKey(t);this.store[i]===void 0&&this._size++,this._store[i]={key:t,value:e}}return this}setMany(t){let e=[];for(let i of t){let s,r;if(this.isEntry(i)?[s,r]=i:this._toEntryFn&&([s,r]=this._toEntryFn(i)),s!==void 0&&r!==void 0){let n=this._size;this.set(s,r),e.push(n<this._size)}}return e}get(t){var e;if(this._isObjKey(t))return this.objMap.get(t);let i=this._getNoObjKey(t);return(e=this._store[i])==null?void 0:e.value}has(t){return this._isObjKey(t)?this.objMap.has(t):this._getNoObjKey(t)in this.store}delete(t){if(this._isObjKey(t))return this.objMap.has(t)&&this._size--,this.objMap.delete(t);let e=this._getNoObjKey(t);return e in this.store?(delete this.store[e],this._size--,!0):!1}setHashFn(t){return this._hashFn===t?this:(this._hashFn=t,this._rehashNoObj(),this)}clone(){let t={hashFn:this._hashFn,toEntryFn:this._toEntryFn};return this._createLike(this,t)}map(t,e){let i=this._createLike(),s=0;for(let[r,n]of this)i.set(r,t.call(e,n,r,s++,this));return i}filter(t,e){let i=this._createLike(),s=0;for(let[r,n]of this)t.call(e,n,r,s++,this)&&i.set(r,n);return i}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_rehashNoObj(){let t={};for(let{key:e,value:i}of Object.values(this._store)){let s=this._getNoObjKey(e);t[s]={key:e,value:i}}this._store=t}*_getIterator(){for(let t of Object.values(this.store))yield[t.key,t.value];for(let t of this.objMap)yield t}_isObjKey(t){let e=typeof t;return(e==="object"||e==="function")&&t!==null}_getNoObjKey(t){let e=typeof t,i;return e!=="string"&&e!=="number"&&e!=="symbol"?i=this._hashFn(t):i=t,i}};u(Ge,"HashMap");var $e=class extends it{constructor(t=[],e){if(super(),c(this,"_sentinel"),c(this,"_hashFn",u(i=>String(i),"_hashFn")),c(this,"_objHashFn",u(i=>i,"_objHashFn")),c(this,"_noObjMap",{}),c(this,"_objMap",new WeakMap),c(this,"_head"),c(this,"_tail"),c(this,"_toEntryFn",u(i=>{if(this.isEntry(i))return i;w(TypeError,R.invalidArgument("If elements do not adhere to [key, value], provide options.toEntryFn to transform raw records.","HashMap"))},"_toEntryFn")),c(this,"_size",0),this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,e){let{hashFn:i,objHashFn:s,toEntryFn:r}=e;i&&(this._hashFn=i),s&&(this._objHashFn=s),r&&(this._toEntryFn=r)}t&&this.setMany(t)}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 t=this.head;for(;t!==this._sentinel;)yield[t.key,t.value],t=t.next}*reverseBegin(){let t=this.tail;for(;t!==this._sentinel;)yield[t.key,t.value],t=t.prev}set(t,e){let i,s=!this.has(t);if(W(t)){let r=this._objHashFn(t);i=this.objMap.get(r),!i&&s?(i={key:r,value:e,prev:this.tail,next:this._sentinel},this.objMap.set(r,i)):i&&(i.value=e)}else{let r=this._hashFn(t);i=this.noObjMap[r],!i&&s?this.noObjMap[r]=i={key:t,value:e,prev:this.tail,next:this._sentinel}:i&&(i.value=e)}return i&&s&&(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++),this}setMany(t){let e=[];for(let i of t){let s,r;if(this.isEntry(i)?[s,r]=i:this._toEntryFn&&([s,r]=this._toEntryFn(i)),s!==void 0&&r!==void 0){let n=this._size;this.set(s,r),e.push(n<this._size)}}return e}has(t){if(W(t)){let i=this._objHashFn(t);return this.objMap.has(i)}return this._hashFn(t)in this.noObjMap}get(t){if(W(t)){let s=this._objHashFn(t),r=this.objMap.get(s);return r?r.value:void 0}let e=this._hashFn(t),i=this.noObjMap[e];return i?i.value:void 0}at(t){O(t,0,this._size-1);let e=this.head;for(;t--;)e=e.next;return e.value}delete(t){let e;if(W(t)){let i=this._objHashFn(t);if(e=this.objMap.get(i),!e)return!1;this.objMap.delete(i)}else{let i=this._hashFn(t);if(e=this.noObjMap[i],!e)return!1;delete this.noObjMap[i]}return this._deleteNode(e)}deleteWhere(t){let e=this._head,i=0;for(;e!==this._sentinel;){let s=e;if(e=e.next,t(s.key,s.value,i++,this)){let r=s.key;if(W(r))this._objMap.delete(r);else{let n=this._hashFn(s.key);delete this._noObjMap[n]}return this._deleteNode(s)}}return!1}deleteAt(t){O(t,0,this._size-1);let e=this.head;for(;t--;)e=e.next;let i=[e.key,e.value];return this._deleteNode(e),i}isEmpty(){return this._size===0}isEntry(t){return Array.isArray(t)&&t.length===2}clear(){this._noObjMap={},this._size=0,this._head=this._tail=this._sentinel.prev=this._sentinel.next=this._sentinel}clone(){let t={hashFn:this._hashFn,objHashFn:this._objHashFn};return this._createLike(this,t)}filter(t,e){let i=this._createLike(),s=0;for(let[r,n]of this)t.call(e,n,r,s,this)&&i.set(r,n),s++;return i}map(t,e){let i=this._createLike(),s=0;for(let[r,n]of this){let[h,o]=t.call(e,n,r,s,this);i.set(h,o),s++}return i}*_getIterator(){let t=this.head;for(;t!==this._sentinel;)yield[t.key,t.value],t=t.next}_deleteNode(t){let e=t.key;if(W(e))this._objMap.delete(e);else{let r=this._hashFn(e);delete this._noObjMap[r]}let{prev:i,next:s}=t;return i.next=s,s.prev=i,t===this.head&&(this._head=s),t===this.tail&&(this._tail=i),this._size-=1,!0}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}};u($e,"LinkedHashMap");var Ot=class extends Kt{constructor(t){super(t),c(this,"_next"),this._value=t,this._next=void 0}get next(){return this._next}set next(t){this._next=t}};u(Ot,"SinglyLinkedListNode");var Mt=Ot,Pt=class extends qt{constructor(t=[],e){super(e),c(this,"_equals",u((i,s)=>Object.is(i,s),"_equals")),c(this,"_head"),c(this,"_tail"),c(this,"_length",0),this.pushMany(t)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var t;return(t=this.head)==null?void 0:t.value}get last(){var t;return(t=this.tail)==null?void 0:t.value}static from(t,e){let i=new this([],e);for(let s of t)i.push(s);return i}push(t){let e=this._ensureNode(t);return this.head?(this.tail.next=e,this._tail=e):this._head=this._tail=e,this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){var t;if(!this.head)return;if(this.head===this.tail){let s=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,s}let e=this.head;for(;e.next&&e.next!==this.tail;)e=e.next;let i=(t=this.tail)==null?void 0:t.value;return e.next=void 0,this._tail=e,this._length--,i}shift(){if(!this.head)return;let t=this.head;return this._head=this.head.next,this._head||(this._tail=void 0),this._length--,t.value}unshift(t){let e=this._ensureNode(t);return this.head?(e.next=this.head,this._head=e):this._head=this._tail=e,this._length++,!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}unshiftMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.unshift(this.toElementFn(i))):e.push(this.unshift(i));return e}search(t){let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i.value;i=i.next}}at(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e==null?void 0:e.value}isNode(t){return t instanceof Mt}getNodeAt(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e}deleteAt(t){if(t<0||t>=this._length)return;if(t===0)return this.shift();let e=this.getNodeAt(t),i=this._getPrevNode(e),s=e.value;return i.next=e.next,e===this.tail&&(this._tail=i),this._length--,s}delete(t){if(t===void 0||!this.head)return!1;let e=this.isNode(t)?t:this.getNode(t);if(!e)return!1;let i=this._getPrevNode(e);return i?(i.next=e.next,e===this.tail&&(this._tail=i)):(this._head=e.next,e===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(t,e){if(t<0||t>this._length)return!1;if(t===0)return this.unshift(e);if(t===this._length)return this.push(e);let i=this._ensureNode(e),s=this.getNodeAt(t-1);return i.next=s.next,s.next=i,this._length++,!0}setAt(t,e){let i=this.getNodeAt(t);return i?(i.value=e,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let t,e=this.head,i;for(;e;)i=e.next,e.next=t,t=e,e=i;return[this._head,this._tail]=[this.tail,this.head],this}getNode(t){if(t===void 0)return;if(this.isNode(t))return t;let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i;i=i.next}}addBefore(t,e){let i=this.getNode(t);if(!i)return!1;let s=this._getPrevNode(i),r=this._ensureNode(e);return s?(s.next=r,r.next=i,this._length++):(r.next=this._head,this._head=r,this._tail||(this._tail=r),this._length++),!0}addAfter(t,e){let i=this.getNode(t);if(!i)return!1;let s=this._ensureNode(e);return s.next=i.next,i.next=s,i===this.tail&&(this._tail=s),this._length++,!0}splice(t,e=0,...i){t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,e);let s=this._createInstance(),r=t===0?void 0:this.getNodeAt(t-1),n=r?r.next:this.head,h=0;for(;h<e&&n;)s.push(n.value),n=n.next,h++;let o=n;if(r?r.next=o:this._head=o,o||(this._tail=r),i.length>0){let a,l;for(let _ of i){let g=this._ensureNode(_);a||(a=g),l&&(l.next=g),l=g}r?r.next=a:this._head=a,l.next=o,o||(this._tail=l)}return this._length+=i.length-h,this._length===0&&(this._head=void 0,this._tail=void 0),s}countOccurrences(t){let e=Qt(t,this._equals),i=0,s=this.head;for(;s;)e(s)&&i++,s=s.next;return i}setEquality(t){return this._equals=t,this}deleteWhere(t){let e,i=this.head,s=0;for(;i;){if(t(i.value,s++,this))return e?(e.next=i.next,i===this._tail&&(this._tail=e)):(this._head=i.next,i===this._tail&&(this._tail=void 0)),this._length--,!0;e=i,i=i.next}return!1}clone(){let t=this._createInstance();for(let e of this)t.push(e);return t}filter(t,e){let i=this._createInstance(),s=0;for(let r of this)t.call(e,r,s++,this)&&i.push(r);return i}mapSame(t,e){let i=this._createInstance(),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{},maxLen:this._maxLen}),r=0;for(let n of this)s.push(t.call(i,n,r++,this));return s}createNode(t){return new Mt(t)}_isPredicate(t){return typeof t=="function"}_ensureNode(t){return this.isNode(t)?t:this.createNode(t)}_ensurePredicate(t){if(this.isNode(t))return i=>i===t;if(this._isPredicate(t))return t;let e=t;return i=>this._equals(i.value,e)}_getPrevNode(t){if(!this.head||this.head===t)return;let e=this.head;for(;e.next&&e.next!==t;)e=e.next;return e.next===t?e:void 0}*_getIterator(){let t=this.head;for(;t;)yield t.value,t=t.next}*_getReverseIterator(){let t=[...this].reverse();for(let e of t)yield e}*_getNodeIterator(){let t=this.head;for(;t;)yield t,t=t.next}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_spawnLike(t){return this._createLike([],t)}};u(Pt,"SinglyLinkedList");var Oe=Pt;function Qt(f,t){if(f instanceof Mt)return i=>i===f;if(typeof f=="function")return f;let e=f;return i=>t(i.value,e)}u(Qt,"elementOrPredicate");var Xt=class extends Kt{constructor(t){super(t),c(this,"_next"),c(this,"_prev"),this._value=t,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(t){this._next=t}get prev(){return this._prev}set prev(t){this._prev=t}};u(Xt,"DoublyLinkedListNode");var St=Xt,Pe=class extends qt{constructor(t=[],e){super(e),c(this,"_equals",u((i,s)=>Object.is(i,s),"_equals")),c(this,"_head"),c(this,"_tail"),c(this,"_length",0),this._head=void 0,this._tail=void 0,this._length=0,e!=null&&e.maxLen&&Number.isInteger(e.maxLen)&&e.maxLen>0&&(this._maxLen=e.maxLen),this.pushMany(t)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var t;return(t=this.head)==null?void 0:t.value}get last(){var t;return(t=this.tail)==null?void 0:t.value}static fromArray(t){return new this(t)}isNode(t){return t instanceof St}push(t){let e=this._ensureNode(t);return this.head?(e.prev=this.tail,this.tail.next=e,this._tail=e):(this._head=e,this._tail=e),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.tail)return;let t=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=t.prev,this.tail.next=void 0),this._length--,t.value}shift(){if(!this.head)return;let t=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=t.next,this.head.prev=void 0),this._length--,t.value}unshift(t){let e=this._ensureNode(t);return this.head?(e.next=this.head,this.head.prev=e,this._head=e):(this._head=e,this._tail=e),this._length++,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}unshiftMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.unshift(this.toElementFn(i))):e.push(this.unshift(i));return e}at(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e==null?void 0:e.value}getNodeAt(t){if(t<0||t>=this._length)return;let e=this.head;for(let i=0;i<t&&e;i++)e=e.next;return e}getNode(t){if(t===void 0)return;if(this.isNode(t)){let s=t,r=this.head;for(;r;){if(r===s)return s;r=r.next}let n=u(h=>this._equals(h.value,s.value),"isMatch");for(r=this.head;r;){if(n(r))return r;r=r.next}return}let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i;i=i.next}}addAt(t,e){if(t<0||t>this._length)return!1;if(t===0)return this.unshift(e);if(t===this._length)return this.push(e);let i=this._ensureNode(e),s=this.getNodeAt(t-1),r=s.next;return i.prev=s,i.next=r,s.next=i,r.prev=i,this._length++,!0}addBefore(t,e){let i=this.isNode(t)?t:this.getNode(t);if(!i)return!1;let s=this._ensureNode(e);return s.prev=i.prev,i.prev&&(i.prev.next=s),s.next=i,i.prev=s,i===this.head&&(this._head=s),this._length++,!0}addAfter(t,e){let i=this.isNode(t)?t:this.getNode(t);if(!i)return!1;let s=this._ensureNode(e);return s.next=i.next,i.next&&(i.next.prev=s),s.prev=i,i.next=s,i===this.tail&&(this._tail=s),this._length++,!0}setAt(t,e){let i=this.getNodeAt(t);return i?(i.value=e,!0):!1}deleteAt(t){if(t<0||t>=this._length)return;if(t===0)return this.shift();if(t===this._length-1)return this.pop();let e=this.getNodeAt(t),i=e.prev,s=e.next;return i.next=s,s.prev=i,this._length--,e.value}delete(t){let e=this.getNode(t);if(!e)return!1;if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{let i=e.prev,s=e.next;i.next=s,s.prev=i,this._length--}return!0}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(t){let e=this._ensurePredicate(t),i=this.head;for(;i;){if(e(i))return i.value;i=i.next}}getBackward(t){return this.findLast(t)}findLast(t){let e=this._ensurePredicate(t),i=this.tail;for(;i;){if(e(i))return i.value;i=i.prev}}findLastIndex(t){let e=this.tail,i=this.length-1;for(;e;){if(t(e.value,i,this))return i;e=e.prev,i--}return-1}reverse(){let t=this.head;for([this._head,this._tail]=[this.tail,this.head];t;){let e=t.next;[t.prev,t.next]=[t.next,t.prev],t=e}return this}deleteWhere(t){let e=this.head,i=0;for(;e;){if(t(e.value,i,this))return this.delete(e),!0;e=e.next,i++}return!1}setEquality(t){return this._equals=t,this}clone(){let t=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});for(let e of this)t.push(e);return t}filter(t,e){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),s=0;for(let r of this)t.call(e,r,s++,this)&&i.push(r);return i}mapSame(t,e){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{},maxLen:this._maxLen}),r=0;for(let n of this)s.push(t.call(i,n,r++,this));return s}_ensureNode(t){return this.isNode(t)?t:new St(t)}_ensurePredicate(t){if(this.isNode(t)){let i=t;return s=>s===i}if(typeof t=="function")return t;let e=t;return i=>this._equals(i.value,e)}_getPrevNode(t){return t.prev}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}*_getIterator(){let t=this.head;for(;t;)yield t.value,t=t.next}*_getReverseIterator(){let t=this.tail;for(;t;)yield t.value,t=t.prev}*_getNodeIterator(){let t=this.head;for(;t;)yield t,t=t.next}};u(Pe,"DoublyLinkedList");var Jt=class{constructor(t,e,i){c(this,"key"),c(this,"value"),c(this,"forward"),this.key=t,this.value=e,this.forward=new Array(i).fill(void 0)}};u(Jt,"SkipListNode");var gt=Jt,A,P,Qe=class Q extends it{constructor(t=[],e={}){super(),K(this,A),K(this,P),c(this,"_head"),c(this,"_level",0),c(this,"_size",0),c(this,"_maxLevel",16),c(this,"_probability",.5);let{comparator:i,toEntryFn:s,maxLevel:r,probability:n}=e;typeof r=="number"&&r>0&&(this._maxLevel=r),typeof n=="number"&&n>0&&n<1&&(this._probability=n),j(this,P,i===void 0),j(this,A,i!=null?i:Q.createDefaultComparator()),this._head=new gt(void 0,void 0,this._maxLevel);for(let h of t){let o,a;s?[o,a]=s(h):((!Array.isArray(h)||h.length<2)&&w(TypeError,R.invalidEntry("SkipList")),[o,a]=h),this.set(o,a)}}static createDefaultComparator(){return(t,e)=>{if(typeof t=="number"&&typeof e=="number")return(Number.isNaN(t)||Number.isNaN(e))&&w(TypeError,R.invalidNaN("SkipList")),t-e;if(typeof t=="string"&&typeof e=="string")return t<e?-1:t>e?1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&w(TypeError,R.invalidDate("SkipList")),i-s}if(typeof t=="bigint"&&typeof e=="bigint")return t<e?-1:t>e?1:0;w(TypeError,R.comparatorRequired("SkipList"))}}get size(){return this._size}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get comparator(){return d(this,A)}isEmpty(){return this._size===0}clear(){this._head=new gt(void 0,void 0,this._maxLevel),this._level=0,this._size=0}clone(){return new Q(this,{comparator:d(this,P)?void 0:d(this,A),maxLevel:this._maxLevel,probability:this._probability})}set(t,e){let i=d(this,A),s=this._findUpdate(t),r=s[0].forward[0];if(r&&i(r.key,t)===0)return r.value=e,this;let n=this._randomLevel(),h=new gt(t,e,n);if(n>this._level){for(let o=this._level;o<n;o++)s[o]=this._head;this._level=n}for(let o=0;o<n;o++)h.forward[o]=s[o].forward[o],s[o].forward[o]=h;return this._size++,this}get(t){let e=this._findNode(t);return e?e.value:void 0}has(t){return this._findNode(t)!==void 0}delete(t){let e=d(this,A),i=this._findUpdate(t),s=i[0].forward[0];if(!s||e(s.key,t)!==0)return!1;for(let r=0;r<this._level&&i[r].forward[r]===s;r++)i[r].forward[r]=s.forward[r];for(;this._level>0&&!this._head.forward[this._level-1];)this._level--;return this._size--,!0}first(){let t=this._head.forward[0];return t?[t.key,t.value]:void 0}last(){let t=this._head;for(let e=this._level-1;e>=0;e--)for(;t.forward[e];)t=t.forward[e];return t===this._head?void 0:[t.key,t.value]}pollFirst(){let t=this.first();if(t)return this.delete(t[0]),t}pollLast(){let t=this.last();if(t)return this.delete(t[0]),t}ceiling(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<0;)i=i.forward[r];let s=i.forward[0];return s?[s.key,s.value]:void 0}floor(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<=0;)i=i.forward[r];let s=i===this._head?void 0:i;if(s&&e(s.key,t)<=0)return[s.key,s.value]}higher(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<=0;)i=i.forward[r];let s=i.forward[0];return s?[s.key,s.value]:void 0}lower(t){let e=d(this,A),i=this._head,s;for(let r=this._level-1;r>=0;r--){for(;i.forward[r]&&e(i.forward[r].key,t)<0;)i=i.forward[r];i!==this._head&&e(i.key,t)<0&&(s=i)}return s?[s.key,s.value]:void 0}rangeSearch(t,e={}){let{lowInclusive:i=!0,highInclusive:s=!0}=e,[r,n]=t,h=d(this,A),o=[],a=this._head;for(let l=this._level-1;l>=0;l--)for(;a.forward[l]&&h(a.forward[l].key,r)<0;)a=a.forward[l];for(a=a.forward[0];a;){let l=h(a.key,n);if(l>0||l===0&&!s)break;let _=h(a.key,r);(_>0||_===0&&i)&&o.push([a.key,a.value]),a=a.forward[0]}return o}map(t,e){let i=new Q([],e!=null?e:{}),s=0;for(let[r,n]of this){let[h,o]=t(n,r,s++,this);i.set(h,o)}return i}filter(t,e){let i=new Q([],{comparator:d(this,P)?void 0:d(this,A),maxLevel:this._maxLevel,probability:this._probability}),s=0;for(let[r,n]of this)t.call(e,n,r,s++,this)&&i.set(r,n);return i}_getIterator(){let t=this._head;return(function*(){let e=t.forward[0];for(;e;)yield[e.key,e.value],e=e.forward[0]})()}_findUpdate(t){let e=d(this,A),i=new Array(this._maxLevel).fill(this._head),s=this._head;for(let r=this._level-1;r>=0;r--){for(;s.forward[r]&&e(s.forward[r].key,t)<0;)s=s.forward[r];i[r]=s}return i}_findNode(t){let e=d(this,A),i=this._head;for(let r=this._level-1;r>=0;r--)for(;i.forward[r]&&e(i.forward[r].key,t)<0;)i=i.forward[r];let s=i.forward[0];if(s&&e(s.key,t)===0)return s}_randomLevel(){let t=1;for(;Math.random()<this._probability&&t<this._maxLevel;)t++;return t}};A=new WeakMap;P=new WeakMap;u(Qe,"SkipList");var Xe=class extends ut{constructor(t=[],e){super(e),c(this,"_equals",u((i,s)=>Object.is(i,s),"_equals")),c(this,"_elements",[]),this.pushMany(t)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(t,e){return new this(t,e)}isEmpty(){return this.elements.length===0}peek(){return this.isEmpty()?void 0:this.elements[this.elements.length-1]}push(t){return this.elements.push(t),!0}pop(){return this.isEmpty()?void 0:this.elements.pop()}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}delete(t){let e=this._indexOfByEquals(t);return this.deleteAt(e)!==void 0}deleteAt(t){return t<0||t>=this.elements.length?void 0:this.elements.splice(t,1)[0]}deleteWhere(t){for(let e=0;e<this.elements.length;e++)if(t(this.elements[e],e,this))return this.elements.splice(e,1),!0;return!1}clear(){this._elements=[]}clone(){let t=this._createInstance({toElementFn:this.toElementFn});for(let e of this)t.push(e);return t}filter(t,e){let i=this._createInstance({toElementFn:this.toElementFn}),s=0;for(let r of this)t.call(e,r,s,this)&&i.push(r),s++;return i}mapSame(t,e){let i=this._createInstance({toElementFn:this.toElementFn}),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{}}),r=0;for(let n of this)s.push(i===void 0?t(n,r,this):t.call(i,n,r,this)),r++;return s}setEquality(t){return this._equals=t,this}_indexOfByEquals(t){for(let e=0;e<this.elements.length;e++)if(this._equals(this.elements[e],t))return e;return-1}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}*_getIterator(){for(let t=0;t<this.elements.length;t++)yield this.elements[t]}};u(Xe,"Stack");var Yt=class Zt extends at{constructor(t=[],e){if(super(e),c(this,"_elements",[]),c(this,"_offset",0),c(this,"_autoCompactRatio",.5),e){let{autoCompactRatio:i=.5}=e;this._autoCompactRatio=i}this.pushMany(t)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(t){this._autoCompactRatio=t}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}peek(){return this.first}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(t){return new Zt(t)}isEmpty(){return this.length===0}push(t){return this.elements.push(t),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}shift(){if(this.length===0)return;let t=this.first;return this._offset+=1,this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),t}delete(t){for(let e=this._offset;e<this.elements.length;e++)if(Object.is(this.elements[e],t))return this.elements.splice(e,1),!0;return!1}at(t){if(!(t<0||t>=this.length))return this._elements[this._offset+t]}deleteAt(t){if(t<0||t>=this.length)return;let e=this._offset+t,[i]=this.elements.splice(e,1);return i}addAt(t,e){return t<0||t>this.length?!1:(this._elements.splice(this._offset+t,0,e),!0)}setAt(t,e){return t<0||t>=this.length?!1:(this._elements[this._offset+t]=e,!0)}deleteWhere(t){for(let e=0;e<this.length;e++)if(t(this._elements[this._offset+e],e,this))return this.deleteAt(e),!0;return!1}reverse(){return this._elements=this.elements.slice(this._offset).reverse(),this._offset=0,this}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this._offset),this._offset=0,!0}splice(t,e=0,...i){t=Math.max(0,Math.min(t,this.length)),e=Math.max(0,Math.min(e,this.length-t));let s=this._offset+t,r=this._elements.splice(s,e,...i);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return n._setAutoCompactRatio(this._autoCompactRatio),n.pushMany(r),n}clone(){let t=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});t._setAutoCompactRatio(this._autoCompactRatio);for(let e=this._offset;e<this.elements.length;e++)t.push(this.elements[e]);return t}filter(t,e){let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});i._setAutoCompactRatio(this._autoCompactRatio);let s=0;for(let r of this)t.call(e,r,s,this)&&i.push(r),s++;return i}map(t,e,i){var s,r;let n=new this.constructor([],{toElementFn:e==null?void 0:e.toElementFn,maxLen:(s=e==null?void 0:e.maxLen)!=null?s:this._maxLen,autoCompactRatio:(r=e==null?void 0:e.autoCompactRatio)!=null?r:this._autoCompactRatio}),h=0;for(let o of this)n.push(i===void 0?t(o,h++,this):t.call(i,o,h++,this));return n}mapSame(t,e){var i;let s=this.constructor,r=new s([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(i=r._setAutoCompactRatio)==null||i.call(r,this._autoCompactRatio);let n=0;for(let h of this){let o=e===void 0?t(h,n++,this):t.call(e,h,n++,this);r.push(o)}return r}_setAutoCompactRatio(t){this._autoCompactRatio=t}*_getIterator(){for(let t=this._offset;t<this.elements.length;t++)yield this.elements[t]}*_getReverseIterator(){for(let t=this.length-1;t>=0;t--){let e=this.at(t);e!==void 0&&(yield e)}}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}};u(Yt,"Queue");var et=Yt,Je=class extends Oe{clone(){let t=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});for(let e of this)t.push(e);return t}};u(Je,"LinkedListQueue");var Ye=class extends at{constructor(t=[],e){if(super(e),c(this,"_equals",u((r,n)=>Object.is(r,n),"_equals")),c(this,"_bucketSize",4096),c(this,"_autoCompactRatio",.5),c(this,"_compactCounter",0),c(this,"_bucketFirst",0),c(this,"_firstInBucket",0),c(this,"_bucketLast",0),c(this,"_lastInBucket",0),c(this,"_bucketCount",0),c(this,"_buckets",[]),c(this,"_length",0),e){let{bucketSize:r,autoCompactRatio:n}=e;typeof r=="number"&&(this._bucketSize=r),typeof n=="number"&&(this._autoCompactRatio=n)}let i;"length"in t?i=typeof t.length=="function"?t.length():t.length:i=typeof t.size=="function"?t.size():t.size,this._bucketCount=Lt(i,this._bucketSize)||1;for(let r=0;r<this._bucketCount;++r)this._buckets.push(new Array(this._bucketSize));let s=Lt(i,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(s>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-i%this._bucketSize>>1,this.pushMany(t)}get bucketSize(){return this._bucketSize}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(t){this._autoCompactRatio=t}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get length(){return this._length}peek(){return this.first}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}static fromArray(t,e){return new this(t,e)}push(t){return this._length&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=t,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let t=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._length-=1,this._autoCompact(),t}shift(){if(this._length===0)return;let t=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._length-=1,this._autoCompact(),t}unshift(t){return this._length&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=t,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.push(this.toElementFn(i))):e.push(this.push(i));return e}unshiftMany(t=[]){let e=[];for(let i of t)this.toElementFn?e.push(this.unshift(this.toElementFn(i))):e.push(this.unshift(i));return e}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(t){if(t<0||t>=this._length)return;let{bucketIndex:e,indexInBucket:i}=this._getBucketAndPosition(t);return this._buckets[e][i]}setAt(t,e){O(t,0,this._length-1);let{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(t);return this._buckets[i][s]=e,!0}addAt(t,e,i=1){let s=this._length;if(O(t,0,s),t===0)for(;i--;)this.unshift(e);else if(t===this._length)for(;i--;)this.push(e);else{let r=[];for(let n=t;n<this._length;++n){let h=this.at(n);h!==void 0&&r.push(h)}this.cut(t-1,!0);for(let n=0;n<i;++n)this.push(e);for(let n=0;n<r.length;++n)this.push(r[n])}return!0}cut(t,e=!1){if(e){if(t<0)return this.clear(),this;let{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(t);return this._bucketLast=i,this._lastInBucket=s,this._length=t+1,this}else{let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);for(let s=0;s<=t;s++){let r=this.at(s);r!==void 0&&i.push(r)}return i}}splice(t,e=this._length-t,...i){O(t,0,this._length),e<0&&(e=0),t+e>this._length&&(e=this._length-t);let s=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});s._setBucketSize(this._bucketSize);for(let n=0;n<e;n++){let h=this.at(t+n);h!==void 0&&s.push(h)}let r=[];for(let n=t+e;n<this._length;n++){let h=this.at(n);h!==void 0&&r.push(h)}this.cut(t-1,!0);for(let n of i)this.push(n);for(let n of r)this.push(n);return s}cutRest(t,e=!1){if(e){if(t<0)return this;let{bucketIndex:i,indexInBucket:s}=this._getBucketAndPosition(t);return this._bucketFirst=i,this._firstInBucket=s,this._length=this._length-t,this}else{let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize),t<0&&(t=0);for(let s=t;s<this._length;s++){let r=this.at(s);r!==void 0&&i.push(r)}return i}}deleteAt(t){O(t,0,this._length-1);let e;if(t===0)return this.shift();if(t===this._length-1)return e=this.last,this.pop(),e;{let i=this._length-1,{bucketIndex:s,indexInBucket:r}=this._getBucketAndPosition(t);e=this._buckets[s][r];for(let n=t;n<i;n++){let{bucketIndex:h,indexInBucket:o}=this._getBucketAndPosition(n),{bucketIndex:a,indexInBucket:l}=this._getBucketAndPosition(n+1);this._buckets[h][o]=this._buckets[a][l]}return this.pop(),e}}delete(t){let e=this._length;if(e===0)return!1;let i=0,s=0;for(;i<e;){let r=this.at(i);this._equals(r,t)||(this.setAt(s,r),s+=1),i+=1}return this.cut(s-1,!0),!0}deleteWhere(t){for(let e=0;e<this._length;e++){let i=this.at(e);if(t(i,e,this))return this.deleteAt(e),!0}return!1}setEquality(t){return this._equals=t,this}findLast(t){for(let e=this.length-1;e>=0;e--){let i=this.at(e);if(t(i,e,this))return i}}findLastIndex(t){for(let e=this.length-1;e>=0;e--)if(t(this.at(e),e,this))return e;return-1}reverse(){this._buckets.reverse().forEach(function(r){r.reverse()});let{_bucketFirst:t,_bucketLast:e,_firstInBucket:i,_lastInBucket:s}=this;return this._bucketFirst=this._bucketCount-e-1,this._bucketLast=this._bucketCount-t-1,this._firstInBucket=this._bucketSize-s-1,this._lastInBucket=this._bucketSize-i-1,this}unique(){if(this._length<=1)return this;let t=1,e=this.at(0);for(let i=1;i<this._length;++i){let s=this.at(i);this._equals(s,e)||(e=s,this.setAt(t++,s))}return this.cut(t-1,!0),this}_autoCompact(){if(this._autoCompactRatio<=0||this._bucketCount<=1||(this._compactCounter++,this._compactCounter<this._bucketSize))return;this._compactCounter=0,this._length/(this._bucketCount*this._bucketSize)<this._autoCompactRatio&&this.shrinkToFit()}compact(){let t=this._bucketCount;return this.shrinkToFit(),this._bucketCount<t}shrinkToFit(){if(this._length===0)return;let t=[];if(this._bucketFirst<=this._bucketLast)for(let e=this._bucketFirst;e<=this._bucketLast;++e)t.push(this._buckets[e]);else{for(let e=this._bucketFirst;e<this._bucketCount;++e)t.push(this._buckets[e]);for(let e=0;e<=this._bucketLast;++e)t.push(this._buckets[e])}this._bucketFirst=0,this._bucketLast=t.length-1,this._buckets=t,this._bucketCount=t.length,this._compactCounter=0}clone(){return this._createLike(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(t,e){let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);let s=0;for(let r of this)t.call(e,r,s,this)&&i.push(r),s++;return i}mapSame(t,e){let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);let s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.push(n)}return i}map(t,e,i){let s=this._createLike([],{...e!=null?e:{},bucketSize:this._bucketSize,maxLen:this._maxLen}),r=0;for(let n of this){let h=i===void 0?t(n,r,this):t.call(i,n,r,this);s.push(h),r++}return s}_setBucketSize(t){this._bucketSize=t,this._length===0&&(this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1)}*_getIterator(){for(let t=0;t<this._length;++t){let e=this.at(t);e!==void 0&&(yield e)}}_reallocate(t){let e=[],i=t||this._bucketCount>>1||1;for(let s=0;s<i;++s)e[s]=new Array(this._bucketSize);for(let s=this._bucketFirst;s<this._bucketCount;++s)e[e.length]=this._buckets[s];for(let s=0;s<this._bucketLast;++s)e[e.length]=this._buckets[s];e[e.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=i,this._bucketLast=e.length-1;for(let s=0;s<i;++s)e[e.length]=new Array(this._bucketSize);this._buckets=e,this._bucketCount=e.length}_getBucketAndPosition(t){let e,i,s=this._firstInBucket+t;return e=this._bucketFirst+Math.floor(s/this._bucketSize),e>=this._bucketCount&&(e-=this._bucketCount),i=(s+1)%this._bucketSize-1,i<0&&(i=this._bucketSize-1),{bucketIndex:e,indexInBucket:i}}_createInstance(t){let e=this.constructor;return new e([],t)}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}*_getReverseIterator(){for(let t=this._length-1;t>-1;t--){let e=this.at(t);e!==void 0&&(yield e)}}};u(Ye,"Deque");var te=class ee extends ut{constructor(t=[],e){if(super(e),c(this,"_equals",Object.is),c(this,"_elements",[]),c(this,"_DEFAULT_COMPARATOR",u((i,s)=>((typeof i=="object"||typeof s=="object")&&w(TypeError,R.comparatorRequired("Heap")),i>s?1:i<s?-1:0),"_DEFAULT_COMPARATOR")),c(this,"_comparator",this._DEFAULT_COMPARATOR),e){let{comparator:i}=e;i&&(this._comparator=i)}this.addMany(t)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var t;return(t=this.elements[this.size-1])!=null?t:void 0}static from(t,e){return new this(t,e)}static heapify(t,e){return new ee(t,e)}add(t){return this._elements.push(t),this._bubbleUp(this.elements.length-1)}addMany(t){let e=[];for(let i of t)if(this.toElementFn){let s=this.add(this.toElementFn(i));e.push(s)}else{let s=this.add(i);e.push(s)}return e}poll(){return this.pop()}pop(){if(this.elements.length===0)return;let t=this.elements[0],e=this.elements.pop();return this.elements.length&&(this.elements[0]=e,this._sinkDown(0,this.elements.length>>1)),t}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}has(t){for(let e of this.elements)if(this._equals(e,t))return!0;return!1}delete(t){let e=-1;for(let i=0;i<this.elements.length;i++)if(this._equals(this.elements[i],t)){e=i;break}return e<0?!1:(e===0?this.pop():e===this.elements.length-1?this.elements.pop():(this.elements.splice(e,1,this.elements.pop()),this._bubbleUp(e),this._sinkDown(e,this.elements.length>>1)),!0)}deleteBy(t){return this.deleteWhere(t)}deleteWhere(t){let e=-1;for(let i=0;i<this.elements.length;i++)if(t(this.elements[i],i,this)){e=i;break}return e<0?!1:(e===0?this.pop():e===this.elements.length-1?this.elements.pop():(this.elements.splice(e,1,this.elements.pop()),this._bubbleUp(e),this._sinkDown(e,this.elements.length>>1)),!0)}setEquality(t){return this._equals=t,this}dfs(t="PRE"){let e=[],i=u(s=>{let r=2*s+1,n=r+1;s<this.size&&(t==="IN"?(i(r),e.push(this.elements[s]),i(n)):t==="PRE"?(e.push(this.elements[s]),i(r),i(n)):t==="POST"&&(i(r),i(n),e.push(this.elements[s])))},"_dfs");return i(0),e}fix(){let t=[];for(let e=Math.floor(this.size/2)-1;e>=0;e--)t.push(this._sinkDown(e,this.elements.length>>1));return t}sort(){let t=[],e=this._createInstance();for(let i of this.elements)e.add(i);for(;!e.isEmpty();){let i=e.poll();i!==void 0&&t.push(i)}return t}clone(){let t=this._createInstance();for(let e of this.elements)t.add(e);return t}filter(t,e){let i=this._createInstance(),s=0;for(let r of this)(e===void 0?t(r,s++,this):t.call(e,r,s++,this))?i.add(r):s++;return i}map(t,e,i){let{comparator:s,toElementFn:r,...n}=e!=null?e:{};s||w(TypeError,R.comparatorRequired("Heap.map"));let h=this._createLike([],{...n,comparator:s,toElementFn:r}),o=0;for(let a of this){let l=i===void 0?t(a,o++,this):t.call(i,a,o++,this);h.add(l)}return h}mapSame(t,e){let i=this._createInstance(),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.add(n)}return i}get comparator(){return this._comparator}*_getIterator(){for(let t of this.elements)yield t}_bubbleUp(t){let e=this.elements[t];for(;t>0;){let i=t-1>>1,s=this.elements[i];if(this.comparator(s,e)<=0)break;this.elements[t]=s,t=i}return this.elements[t]=e,!0}_sinkDown(t,e){let i=this.elements[t];for(;t<e;){let s=t<<1|1,r=s+1,n=this.elements[s];if(r<this.elements.length&&this.comparator(n,this.elements[r])>0&&(s=r,n=this.elements[r]),this.comparator(n,i)>=0)break;this.elements[t]=n,t=s}return this.elements[t]=i,!0}_createInstance(t){let e=this.constructor;return new e([],{comparator:this.comparator,toElementFn:this.toElementFn,...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_spawnLike(t){return this._createLike([],t)}};u(te,"Heap");var ft=te,ie=class{constructor(t,e=0){c(this,"element"),c(this,"degree"),c(this,"left"),c(this,"right"),c(this,"child"),c(this,"parent"),c(this,"marked"),this.element=t,this.degree=e,this.marked=!1}};u(ie,"FibonacciHeapNode");var Ze=ie,ti=class{constructor(t){c(this,"_root"),c(this,"_size",0),c(this,"_min"),c(this,"_comparator"),this.clear(),this._comparator=t||this._defaultComparator,typeof this.comparator!="function"&&w(TypeError,R.notAFunction("comparator","FibonacciHeap"))}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(t){return this.push(t),!0}push(t){let e=this.createNode(t);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++,!0}peek(){return this.min?this.min.element:void 0}consumeLinkedList(t){let e=[];if(!t)return e;let i=t,s=!1;for(;!(i===t&&s);)i===t&&(s=!0),e.push(i),i=i.right;return e}mergeWithChild(t,e){t.child?(e.right=t.child.right,e.left=t.child,t.child.right.left=e,t.child.right=e):t.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let t=this.min;if(t.child){let e=this.consumeLinkedList(t.child);for(let i of e)this.mergeWithRoot(i),i.parent=void 0}return this.removeFromRoot(t),t===t.right?(this._min=void 0,this._root=void 0):(this._min=t.right,this._consolidate()),this._size--,t.element}merge(t){if(t.size!==0){if(this.root&&t.root){let e=this.root,i=t.root,s=e.right,r=i.left;e.right=i,i.left=e,s.left=r,r.right=s}else!this.root&&t.root&&(this._root=t.root);(!this.min||t.min&&this.comparator(t.min.element,this.min.element)<0)&&(this._min=t.min),this._size+=t.size,t.clear()}}createNode(t){return new Ze(t)}isEmpty(){return this._size===0}_defaultComparator(t,e){return t<e?-1:t>e?1:0}mergeWithRoot(t){this.root?(t.right=this.root.right,t.left=this.root,this.root.right.left=t,this.root.right=t):this._root=t}removeFromRoot(t){this.root===t&&(this._root=t.right),t.left&&(t.left.right=t.right),t.right&&(t.right.left=t.left)}_link(t,e){this.removeFromRoot(t),t.left=t,t.right=t,this.mergeWithChild(e,t),e.degree++,t.parent=e}_consolidate(){let t=new Array(this._size),e=this.consumeLinkedList(this.root),i,s,r,n;for(let h of e){for(i=h,r=i.degree;t[r];)s=t[r],this.comparator(i.element,s.element)>0&&(n=i,i=s,s=n),this._link(s,i),t[r]=void 0,r++;t[r]=i}for(let h=0;h<t.length;h++)t[h]&&(!this.min||this.comparator(t[h].element,this.min.element)<=0)&&(this._min=t[h])}};u(ti,"FibonacciHeap");var ei=class extends ft{constructor(t=[],e){super(t,{comparator:u((i,s)=>((typeof i=="object"||typeof s=="object")&&w(TypeError,R.comparatorRequired("MaxHeap")),i<s?1:i>s?-1:0),"comparator"),...e})}};u(ei,"MaxHeap");var ii=class extends ft{constructor(t=[],e){super(t,e)}};u(ii,"MinHeap");var se=class{constructor(t,e){c(this,"key"),c(this,"value"),this.key=t,this.value=e}};u(se,"AbstractVertex");var V=se,re=class{constructor(t,e){c(this,"value"),c(this,"weight"),c(this,"_hashCode"),this.weight=t!==void 0?t:1,this.value=e,this._hashCode=Ue()}get hashCode(){return this._hashCode}};u(re,"AbstractEdge");var Rt=re,ne=class extends it{constructor(t){super(),c(this,"_options",{defaultEdgeWeight:1}),c(this,"_vertexMap",new Map);let e=t==null?void 0:t.graph;this._options={defaultEdgeWeight:1,...e!=null?e:{}}}get options(){return this._options}get vertexMap(){return this._vertexMap}set vertexMap(t){this._vertexMap=t}get size(){return this._vertexMap.size}getVertex(t){return this._vertexMap.get(t)||void 0}hasVertex(t){return this._vertexMap.has(this._getVertexKey(t))}addVertex(t,e){if(t instanceof V)return this._addVertex(t);{let i=this.createVertex(t,e);return this._addVertex(i)}}isVertexKey(t){let e=typeof t;return e==="string"||e==="number"}removeManyVertices(t){let e=[];for(let i of t)e.push(this.deleteVertex(i));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,i,s){if(t instanceof Rt)return this._addEdge(t);if(e instanceof V||typeof e=="string"||typeof e=="number"){if(!(this.hasVertex(t)&&this.hasVertex(e)))return!1;t instanceof V&&(t=t.key),e instanceof V&&(e=e.key);let r=this.createEdge(t,e,i,s);return this._addEdge(r)}else w(TypeError,R.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.","Graph"))}setEdgeWeight(t,e,i){let s=this.getEdge(t,e);return s?(s.weight=i,!0):!1}getAllPathsBetween(t,e,i=1e3){let s=[],r=this._getVertex(t),n=this._getVertex(e);if(!(r&&n))return[];let h=[];for(h.push({vertex:r,path:[r]});h.length>0;){let{vertex:o,path:a}=h.pop();if(o===n&&(s.push(a),s.length>=i))return s;let l=this.getNeighbors(o);for(let _ of l)if(!a.includes(_)){let g=[...a,_];h.push({vertex:_,path:g})}}return s}getPathSumWeight(t){var e;let i=0;for(let s=0;s<t.length;s++)i+=((e=this.getEdge(t[s],t[s+1]))==null?void 0:e.weight)||0;return i}getMinCostBetween(t,e,i){if(i===void 0&&(i=!1),i){let s=this.getAllPathsBetween(t,e),r=Number.MAX_SAFE_INTEGER;for(let n of s)r=Math.min(this.getPathSumWeight(n),r);return r}else{let s=this._getVertex(e),r=this._getVertex(t);if(!(r&&s))return;let n=new Map,h=new et([r]);n.set(r,!0);let o=0;for(;h.length>0;){for(let a=0,l=h.length;a<l;a++){let _=h.shift();if(_===s)return o;if(_!==void 0){let g=this.getNeighbors(_);for(let p of g)n.has(p)||(n.set(p,!0),h.push(p))}}o++}return}}getMinPathBetween(t,e,i,s=!1){var r,n;if(i===void 0&&(i=!1),i)if(s){let h=this.getAllPathsBetween(t,e,1e4),o=Number.MAX_SAFE_INTEGER,a=-1,l=0;for(let _ of h){let g=this.getPathSumWeight(_);g<o&&(o=g,a=l),l++}return h[a]||void 0}else return(n=(r=this.dijkstra(t,e,!0,!0))==null?void 0:r.minPath)!=null?n:[];else{let h=[],o=this._getVertex(t),a=this._getVertex(e);if(!(o&&a))return[];let l=u((_,g,p,v)=>{if(p.add(_),_===g){h=[o,...v];return}let x=this.getNeighbors(_);for(let k of x)p.has(k)||(v.push(k),l(k,g,p,v),v.pop());p.delete(_)},"dfs");return l(o,a,new Set,[]),h}}dijkstraWithoutHeap(t,e=void 0,i=!1,s=!1){let r=Number.MAX_SAFE_INTEGER,n,h=[],o=[],a=this._vertexMap,l=new Map,_=new Set,g=new Map,p=this._getVertex(t),v=e?this._getVertex(e):void 0;if(!p)return;for(let M of a){let y=M[1];y instanceof V&&l.set(y,Number.MAX_SAFE_INTEGER)}l.set(p,0),g.set(p,void 0);let x=u(()=>{let M=Number.MAX_SAFE_INTEGER,y;for(let[N,m]of l)_.has(N)||m<M&&(M=m,y=N);return y},"getMinOfNoSeen"),k=u(M=>{for(let y of a){let N=y[1];if(N instanceof V){let m=[N],b=g.get(N);for(;b;)m.push(b),b=g.get(b);let L=m.reverse();y[1]===M&&(h=L),o.push(L)}}},"getPaths");for(let M=1;M<a.size;M++){let y=x();if(y){if(_.add(y),v&&v===y)return i&&(r=l.get(v)||Number.MAX_SAFE_INTEGER),s&&k(v),{distMap:l,preMap:g,seen:_,paths:o,minDist:r,minPath:h};let N=this.getNeighbors(y);for(let m of N)if(!_.has(m)){let b=this.getEdge(y,m);if(b){let L=l.get(y),F=l.get(m);L!==void 0&&F!==void 0&&b.weight+L<F&&(l.set(m,b.weight+L),g.set(m,y))}}}}return i&&l.forEach((M,y)=>{y!==p&&M<r&&(r=M,s&&(n=y))}),s&&k(n),{distMap:l,preMap:g,seen:_,paths:o,minDist:r,minPath:h}}dijkstra(t,e=void 0,i=!1,s=!1){var r;let n=Number.MAX_SAFE_INTEGER,h,o=[],a=[],l=this._vertexMap,_=new Map,g=new Set,p=new Map,v=this._getVertex(t),x=e?this._getVertex(e):void 0;if(!v)return;for(let y of l){let N=y[1];N instanceof V&&_.set(N,Number.MAX_SAFE_INTEGER)}let k=new ft([],{comparator:u((y,N)=>y.key-N.key,"comparator")});k.add({key:0,value:v}),_.set(v,0),p.set(v,void 0);let M=u(y=>{for(let N of l){let m=N[1];if(m instanceof V){let b=[m],L=p.get(m);for(;L;)b.push(L),L=p.get(L);let F=b.reverse();N[1]===y&&(o=F),a.push(F)}}},"getPaths");for(;k.size>0;){let y=k.poll(),N=y==null?void 0:y.key,m=y==null?void 0:y.value;if(N!==void 0&&m){if(g.add(m),x&&x===m)return i&&(n=_.get(x)||Number.MAX_SAFE_INTEGER),s&&M(x),{distMap:_,preMap:p,seen:g,paths:a,minDist:n,minPath:o};let b=this.getNeighbors(m);for(let L of b)if(!g.has(L)){let F=(r=this.getEdge(m,L))==null?void 0:r.weight;if(typeof F=="number"){let T=_.get(L);T!==void 0&&N+F<T&&(k.add({key:N+F,value:L}),p.set(L,m),_.set(L,N+F))}}}}return i&&_.forEach((y,N)=>{N!==v&&y<n&&(n=y,s&&(h=N))}),s&&M(h),{distMap:_,preMap:p,seen:g,paths:a,minDist:n,minPath:o}}bellmanFord(t,e,i,s){i===void 0&&(i=!1),s===void 0&&(s=!1);let r=this._getVertex(t),n=[],h=new Map,o=new Map,a=Number.MAX_SAFE_INTEGER,l=[],_;if(e&&(_=!1),!r)return{hasNegativeCycle:_,distMap:h,preMap:o,paths:n,min:a,minPath:l};let g=this._vertexMap,p=g.size,v=this.edgeSet(),x=v.length;this._vertexMap.forEach(M=>{h.set(M,Number.MAX_SAFE_INTEGER)}),h.set(r,0);for(let M=1;M<p;++M)for(let y=0;y<x;++y){let N=this.getEndsOfEdge(v[y]);if(N){let[m,b]=N,L=v[y].weight,F=h.get(m),T=h.get(b);F!==void 0&&T!==void 0&&h.get(m)!==Number.MAX_SAFE_INTEGER&&F+L<T&&(h.set(b,F+L),s&&o.set(b,m))}}let k;if(i&&h.forEach((M,y)=>{y!==r&&M<a&&(a=M,s&&(k=y))}),s)for(let M of g){let y=M[1];if(y instanceof V){let N=[y],m=o.get(y);for(;m!==void 0;)N.push(m),m=o.get(m);let b=N.reverse();M[1]===k&&(l=b),n.push(b)}}for(let M=0;M<x;++M){let y=this.getEndsOfEdge(v[M]);if(y){let[N]=y,m=v[M].weight,b=h.get(N);b&&b!==Number.MAX_SAFE_INTEGER&&b+m<b&&(_=!0)}}return{hasNegativeCycle:_,distMap:h,preMap:o,paths:n,min:a,minPath:l}}floydWarshall(){var t;let e=[...this._vertexMap],i=e.length,s=[],r=[];for(let n=0;n<i;n++){s[n]=[],r[n]=[];for(let h=0;h<i;h++)r[n][h]=void 0}for(let n=0;n<i;n++)for(let h=0;h<i;h++)s[n][h]=((t=this.getEdge(e[n][1],e[h][1]))==null?void 0:t.weight)||Number.MAX_SAFE_INTEGER;for(let n=0;n<i;n++)for(let h=0;h<i;h++)for(let o=0;o<i;o++)s[h][o]>s[h][n]+s[n][o]&&(s[h][o]=s[h][n]+s[n][o],r[h][o]=e[n][1]);return{costs:s,predecessor:r}}getCycles(t=!1){let e=[],i=new Set,s=u((n,h,o)=>{if(o.has(n)){(!t&&h.length>2||t&&h.length>=2)&&h[0]===n.key&&e.push([...h]);return}o.add(n),h.push(n.key);for(let a of this.getNeighbors(n))a&&s(a,h,o);o.delete(n),h.pop()},"dfs");for(let n of this.vertexMap.values())s(n,[],i);let r=new Map;for(let n of e){let h=[...n].sort().toString();r.has(h)||r.set(h,n)}return[...r].map(n=>n[1])}filter(t,e){let i=[],s=0;for(let[r,n]of this)t.call(e,n,r,s,this)&&i.push([r,n]),s++;return this._createLike(i,this._snapshotOptions())}filterEntries(t,e){let i=[],s=0;for(let[r,n]of this)t.call(e,n,r,s,this)&&i.push([r,n]),s++;return i}map(t,e){let i=[],s=0;for(let[r,n]of this)i.push(t.call(e,n,r,s,this)),s++;return i}clone(){return this._createLike(void 0,this._snapshotOptions())}*_getIterator(){for(let t of this._vertexMap.values())yield[t.key,t.value]}_snapshotOptions(){return{graph:{...this._options}}}_createInstance(t){let e=this.constructor,i=new e,s=t==null?void 0:t.graph;return s?i._options={...i._options,...s}:i._options={...i._options,...this._options},i}_createLike(t,e){let i=this._createInstance(e);if(t)for(let[r,n]of t)i.addVertex(r,n);else for(let[r,n]of this)i.addVertex(r,n);let s=this.edgeSet();for(let r of s){let n=this.getEndsOfEdge(r);if(!n)continue;let[h,o]=n,a=h.key,l=o.key,_=typeof i.hasVertex=="function"?i.hasVertex(a):!1,g=typeof i.hasVertex=="function"?i.hasVertex(l):!1;if(_&&g){let p=i.createEdge(a,l,r.weight,r.value);i._addEdge(p)}}return i}_addVertex(t){return this.hasVertex(t)?!1:(this._vertexMap.set(t.key,t),!0)}_getVertex(t){let e=this._getVertexKey(t);return this._vertexMap.get(e)||void 0}_getVertexKey(t){return t instanceof V?t.key:t}get _edgeConnector(){return"--"}toVisual(t){var e;let i=(e=t==null?void 0:t.showWeight)!=null?e:!0,s=[...this._vertexMap.values()],r=s.length,n=this.edgeSet().length,h=[`Graph (${r} vertices, ${n} edges):`];for(let o of s){let a=this.getNeighbors(o);if(a.length===0)h.push(` ${o.key} (isolated)`);else{let l=a.map(_=>{let g=this.getEdge(o,_);return g&&i&&g.weight!==void 0&&g.weight!==1?`${_.key} (${g.weight})`:`${_.key}`});h.push(` ${o.key} ${this._edgeConnector} ${l.join(", ")}`)}}return h.join(`
2
+ `)}toDot(t){var e,i;let s=(e=t==null?void 0:t.name)!=null?e:"G",r=(i=t==null?void 0:t.showWeight)!=null?i:!0,n=this._edgeConnector==="->",h=n?"digraph":"graph",o=n?"->":"--",a=[`${h} ${s} {`];for(let _ of this._vertexMap.values())a.push(` "${_.key}";`);let l=new Set;for(let _ of this._vertexMap.values())for(let g of this.getNeighbors(_)){let p=n?`${_.key}->${g.key}`:[_.key,g.key].sort().join("--");if(l.has(p))continue;l.add(p);let v=this.getEdge(_,g),x=v&&r&&v.weight!==void 0&&v.weight!==1?` [label="${v.weight}"]`:"";a.push(` "${_.key}" ${o} "${g.key}"${x};`)}return a.push("}"),a.join(`
3
+ `)}print(t){console.log(this.toVisual(t))}};u(ne,"AbstractGraph");var he=ne,oe=class extends V{constructor(t,e){super(t,e)}};u(oe,"DirectedVertex");var kt=oe,ae=class extends Rt{constructor(t,e,i,s){super(i,s),c(this,"src"),c(this,"dest"),this.src=t,this.dest=e}};u(ae,"DirectedEdge");var le=ae,ue=class bt extends he{constructor(t){super(t),c(this,"_outEdgeMap",new Map),c(this,"_inEdgeMap",new Map)}get _edgeConnector(){return"->"}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(t){this._outEdgeMap=t}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(t){this._inEdgeMap=t}static fromKeys(t){let e=new bt({vertexValueInitializer:u(i=>i,"vertexValueInitializer")});for(let i of t)e.addVertex(i);return e}static fromEntries(t){let e=new bt;for(let[i,s]of t)e.addVertex(i,s);return e}createVertex(t,e){return new kt(t,e)}createEdge(t,e,i,s){var r;return new le(t,e,(r=i!=null?i:this.options.defaultEdgeWeight)!=null?r:1,s)}getEdge(t,e){let i=[];if(t!==void 0&&e!==void 0){let s=this._getVertex(t),r=this._getVertex(e);if(s&&r){let n=this._outEdgeMap.get(s);n&&(i=n.filter(h=>h.dest===r.key))}}return i[0]||void 0}deleteEdgeSrcToDest(t,e){let i=this._getVertex(t),s=this._getVertex(e),r;if(!i||!s)return;let n=this._outEdgeMap.get(i);n&&$(n,o=>o.dest===s.key);let h=this._inEdgeMap.get(s);return h&&(r=$(h,o=>o.src===i.key)[0]||void 0),r}deleteEdge(t,e){let i,s,r;if(this.isVertexKey(t))if(this.isVertexKey(e))s=this._getVertex(t),r=this._getVertex(e);else return;else s=this._getVertex(t.src),r=this._getVertex(t.dest);if(s&&r){let n=this._outEdgeMap.get(s);n&&n.length>0&&$(n,o=>o.src===s.key&&o.dest===(r==null?void 0:r.key));let h=this._inEdgeMap.get(r);h&&h.length>0&&(i=$(h,o=>o.src===s.key&&o.dest===r.key)[0])}return i}deleteVertex(t){let e,i;if(this.isVertexKey(t)?(i=this.getVertex(t),e=t):(i=t,e=this._getVertexKey(t)),i){let s=this.getNeighbors(i);for(let r of s)this.deleteEdgeSrcToDest(i,r);this._outEdgeMap.delete(i),this._inEdgeMap.delete(i)}return this._vertexMap.delete(e)}deleteEdgesBetween(t,e){let i=[];if(t&&e){let s=this.deleteEdgeSrcToDest(t,e),r=this.deleteEdgeSrcToDest(e,t);s&&i.push(s),r&&i.push(r)}return i}incomingEdgesOf(t){let e=this._getVertex(t);return e?this.inEdgeMap.get(e)||[]:[]}outgoingEdgesOf(t){let e=this._getVertex(t);return e?this._outEdgeMap.get(e)||[]:[]}degreeOf(t){return this.outDegreeOf(t)+this.inDegreeOf(t)}inDegreeOf(t){return this.incomingEdgesOf(t).length}outDegreeOf(t){return this.outgoingEdgesOf(t).length}edgesOf(t){return[...this.outgoingEdgesOf(t),...this.incomingEdgesOf(t)]}getEdgeSrc(t){return this._getVertex(t.src)}getEdgeDest(t){return this._getVertex(t.dest)}getDestinations(t){if(t===void 0)return[];let e=[],i=this.outgoingEdgesOf(t);for(let s of i){let r=this.getEdgeDest(s);r&&e.push(r)}return e}topologicalSort(t){t=t!=null?t:"key";let e=new Map;for(let n of this.vertexMap)e.set(n[1],0);let i=[],s=!1,r=u(n=>{e.set(n,1);let h=this.getDestinations(n);for(let o of h){let a=e.get(o);a===0?r(o):a===1&&(s=!0)}e.set(n,2),i.push(n)},"dfs");for(let n of this.vertexMap)e.get(n[1])===0&&r(n[1]);if(!s)return t==="key"&&(i=i.map(n=>n instanceof kt?n.key:n)),i.reverse()}edgeSet(){let t=[];return this._outEdgeMap.forEach(e=>{t=[...t,...e]}),t}getNeighbors(t){let e=[],i=this._getVertex(t);if(i){let s=this.outgoingEdgesOf(i);for(let r of s){let n=this._getVertex(r.dest);n&&e.push(n)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return;let e=this._getVertex(t.src),i=this._getVertex(t.dest);if(e&&i)return[e,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(){return super.clone()}tarjan(){let t=new Map,e=new Map,i=new Map,s=0,r=[],n=new Set,h=u(o=>{t.set(o,s),e.set(o,s),s++,r.push(o),n.add(o);let a=this.getNeighbors(o);for(let l of a)t.has(l)?n.has(l)&&e.set(o,Math.min(e.get(o),t.get(l))):(h(l),e.set(o,Math.min(e.get(o),e.get(l))));if(t.get(o)===e.get(o)){let l=[],_;do _=r.pop(),n.delete(_),l.push(_);while(_!==o);i.set(i.size,l)}},"dfs");for(let o of this.vertexMap.values())t.has(o)||h(o);return{dfnMap:t,lowMap:e,SCCs:i}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(t){if(!(this.hasVertex(t.src)&&this.hasVertex(t.dest)))return!1;let e=this._getVertex(t.src),i=this._getVertex(t.dest);if(e&&i){let s=this._outEdgeMap.get(e);s?s.push(t):this._outEdgeMap.set(e,[t]);let r=this._inEdgeMap.get(i);return r?r.push(t):this._inEdgeMap.set(i,[t]),!0}else return!1}};u(ue,"DirectedGraph");var si=ue,fe=class extends V{constructor(t,e){super(t,e)}};u(fe,"UndirectedVertex");var ri=fe,ce=class extends Rt{constructor(t,e,i,s){super(i,s),c(this,"endpoints"),this.endpoints=[t,e]}};u(ce,"UndirectedEdge");var ni=ce,hi=class wt extends he{constructor(t){super(t),c(this,"_edgeMap"),this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(t){this._edgeMap=t}static fromKeys(t){let e=new wt({vertexValueInitializer:u(i=>i,"vertexValueInitializer")});for(let i of t)e.addVertex(i);return e}static fromEntries(t){let e=new wt;for(let[i,s]of t)e.addVertex(i,s);return e}createVertex(t,e){return new ri(t,e)}createEdge(t,e,i,s){var r;return new ni(t,e,(r=i!=null?i:this.options.defaultEdgeWeight)!=null?r:1,s)}getEdge(t,e){var i;let s=[];if(t!==void 0&&e!==void 0){let r=this._getVertex(t),n=this._getVertex(e);r&&n&&(s=(i=this._edgeMap.get(r))==null?void 0:i.filter(h=>h.endpoints.includes(n.key)))}return s&&s[0]||void 0}deleteEdgeBetween(t,e){let i=this._getVertex(t),s=this._getVertex(e);if(!i||!s)return;let r=this._edgeMap.get(i),n;r&&(n=$(r,o=>o.endpoints.includes(s.key))[0]||void 0);let h=this._edgeMap.get(s);return h&&$(h,o=>o.endpoints.includes(i.key)),n}deleteEdge(t,e){let i,s;if(this.isVertexKey(t))if(this.isVertexKey(e))i=this._getVertex(t),s=this._getVertex(e);else return;else i=this._getVertex(t.endpoints[0]),s=this._getVertex(t.endpoints[1]);if(i&&s)return this.deleteEdgeBetween(i,s)}deleteVertex(t){let e,i;this.isVertexKey(t)?(i=this.getVertex(t),e=t):(i=t,e=this._getVertexKey(t));let s=this.getNeighbors(t);return i&&(s.forEach(r=>{let n=this._edgeMap.get(r);if(n){let h=n.filter(o=>!o.endpoints.includes(e));this._edgeMap.set(r,h)}}),this._edgeMap.delete(i)),this._vertexMap.delete(e)}degreeOf(t){var e;let i=this._getVertex(t);return i&&((e=this._edgeMap.get(i))==null?void 0:e.length)||0}edgesOf(t){let e=this._getVertex(t);return e?this._edgeMap.get(e)||[]:[]}edgeSet(){let t=new Set;return this._edgeMap.forEach(e=>{e.forEach(i=>{t.add(i)})}),[...t]}getNeighbors(t){let e=[],i=this._getVertex(t);if(i){let s=this.edgesOf(i);for(let r of s){let n=this._getVertex(r.endpoints.filter(h=>h!==i.key)[0]);n&&e.push(n)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.endpoints[0],t.endpoints[1]))return;let e=this._getVertex(t.endpoints[0]),i=this._getVertex(t.endpoints[1]);if(e&&i)return[e,i]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){return super.clone()}tarjan(){let t=new Map,e=new Map,i=[],s=[],r=0,n=u((h,o)=>{t.set(h,r),e.set(h,r),r++;let a=this.getNeighbors(h),l=0;for(let _ of a)if(t.has(_))_!==o&&e.set(h,Math.min(e.get(h),t.get(_)));else{if(l++,n(_,h),e.set(h,Math.min(e.get(h),e.get(_))),e.get(_)>t.get(h)){let g=this.getEdge(h,_);g&&i.push(g)}o!==void 0&&e.get(_)>=t.get(h)&&s.push(h)}o===void 0&&l>1&&s.push(h)},"dfs");for(let h of this.vertexMap.values())t.has(h)||n(h,void 0);return{dfnMap:t,lowMap:e,bridges:i,cutVertices:s}}getBiconnectedComponents(){let t=new Map,e=new Map,i=[],s=[],r=0,n=u((h,o)=>{t.set(h,r),e.set(h,r),r++;let a=this.getNeighbors(h),l=0;for(let _ of a){let g=this.getEdge(h,_);if(g){if(t.has(_))_!==o&&t.get(_)<t.get(h)&&(i.push(g),e.set(h,Math.min(e.get(h),t.get(_))));else if(l++,i.push(g),n(_,h),e.set(h,Math.min(e.get(h),e.get(_))),o===void 0&&l>1||o!==void 0&&e.get(_)>=t.get(h)){let p=[],v;do v=i.pop(),v&&p.push(v);while(v&&v!==g);p.length>0&&s.push(p)}}}},"dfs");for(let h of this.vertexMap.values())t.has(h)||(n(h,void 0),i.length>0&&(s.push([...i]),i.length=0));return s}hasCycle(){let t=new Set,e=u((i,s)=>{t.add(i);for(let r of this.getNeighbors(i))if(t.has(r)){if(r!==s)return!0}else if(e(r,i))return!0;return!1},"dfs");for(let i of this.vertexMap.values())if(!t.has(i)&&e(i,void 0))return!0;return!1}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(t){for(let e of t.endpoints){let i=this._getVertex(e);if(i===void 0)return!1;if(i){let s=this._edgeMap.get(i);s?s.push(t):this._edgeMap.set(i,[t])}}return!0}};u(hi,"UndirectedGraph");var _e=class extends kt{constructor(t,e,i,s){super(t,e),c(this,"lat"),c(this,"long"),this.lat=i,this.long=s}};u(_e,"MapVertex");var oi=_e,de=class extends le{constructor(t,e,i,s){super(t,e,i,s)}};u(de,"MapEdge");var ai=de,li=class ge extends si{constructor(t,e){super(),c(this,"_originCoord",[0,0]),c(this,"_bottomRight"),this._originCoord=t,this._bottomRight=e}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(t,e,i=this.originCoord[0],s=this.originCoord[1]){return new oi(t,e,i,s)}createEdge(t,e,i,s){return new ai(t,e,i,s)}clone(){return super.clone()}_snapshotOptions(){return{...super._snapshotOptions(),originCoord:this.originCoord,bottomRight:this.bottomRight}}_createInstance(t){let{originCoord:e,bottomRight:i}=t||{},s=e!=null?e:this.originCoord,r=i!=null?i:this.bottomRight;return new ge(s,r)}};u(li,"MapGraph");var pe=class{constructor(t,e){c(this,"key"),c(this,"value"),c(this,"parent"),c(this,"_left"),c(this,"_right"),c(this,"_height",0),c(this,"_color","BLACK"),c(this,"_count",1),this.key=t,this.value=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}set count(t){this._count=t}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(pe,"BinaryTreeNode");var pt=pe,ve=class rt extends it{constructor(t=[],e){if(super(),c(this,"iterationType","ITERATIVE"),c(this,"_isMapMode",!0),c(this,"_isDuplicate",!1),c(this,"_store",new Map),c(this,"_root"),c(this,"_size",0),c(this,"_NIL",new pt(NaN)),c(this,"_toEntryFn"),c(this,"_DEFAULT_NODE_CALLBACK",u(i=>i==null?void 0:i.key,"_DEFAULT_NODE_CALLBACK")),e){let{iterationType:i,toEntryFn:s,isMapMode:r,isDuplicate:n}=e;i&&(this.iterationType=i),r!==void 0&&(this._isMapMode=r),n!==void 0&&(this._isDuplicate=n),typeof s=="function"?this._toEntryFn=s:s&&w(TypeError,R.notAFunction("toEntryFn","BinaryTree"))}t&&this.setMany(t)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(t,e){return new pt(t,e)}createTree(t){return this._createInstance(t)}ensureNode(t,e=this.iterationType){if(t===null)return null;if(t!==void 0&&t!==this._NIL){if(this.isNode(t))return t;if(this.isEntry(t)){let i=t[0];return i===null?null:i===void 0?void 0:this.getNode(i,this._root,e)}return this.getNode(t,this._root,e)}}isNode(t){return t instanceof pt}isRaw(t){return this._toEntryFn!==void 0&&typeof t=="object"}isRealNode(t){return t===this._NIL||t===null||t===void 0?!1:this.isNode(t)}isRealNodeOrNull(t){return t===null||this.isRealNode(t)}isNIL(t){return t===this._NIL}isRange(t){return t instanceof st}isLeaf(t){return t=this.ensureNode(t),t===void 0?!1:t===null?!0:!this.isRealNode(t.left)&&!this.isRealNode(t.right)}isEntry(t){return Array.isArray(t)&&t.length===2}isValidKey(t){return t===null?!0:tt(t)}add(t){return this.set(t)}set(t,e){let[i]=this._keyValueNodeOrEntryToNodeAndValue(t,e);if(i===void 0)return!1;if(!this._root)return this._setRoot(i),this._isMapMode&&i!==null&&i!==void 0&&this._store.set(i.key,i),i!==null&&(this._size=1),!0;let s=new et([this._root]),r;for(;s.length>0;){let n=s.shift();if(n){if(!this._isDuplicate&&i!==null&&n.key===i.key)return this._replaceNode(n,i),this._isMapMode&&i!==null&&this._store.set(n.key,i),!0;r===void 0&&(n.left===void 0||n.right===void 0)&&(r=n),n.left!==null&&n.left&&s.push(n.left),n.right!==null&&n.right&&s.push(n.right)}}return r?(r.left===void 0?r.left=i:r.right===void 0&&(r.right=i),this._isMapMode&&i!==null&&i!==void 0&&this._store.set(i.key,i),i!==null&&this._size++,!0):!1}addMany(t){return this.setMany(t)}setMany(t,e){let i=[],s;e&&(s=e[Symbol.iterator]());for(let r of t){let n;if(s){let h=s.next();h.done||(n=h.value)}this.isRaw(r)&&(r=this._toEntryFn(r)),i.push(this.set(r,n))}return i}merge(t){this.setMany(t,[])}_deleteInternal(t){let e=[];if(!this._root)return e;let i=this.getNode(t);if(!i)return e;let s=i==null?void 0:i.parent,r,n=i;if(!i.left&&!i.right&&!s)this._setRoot(void 0);else if(i.left){let h=this.getRightMost(o=>o,i.left);if(h){let o=h.parent;n=this._swapProperties(i,h),this._isMapMode&&(this._store.set(i.key,i),this._store.set(h.key,h)),o&&(o.right===h?o.right=h.left:o.left=h.left,r=o)}}else if(s){let{familyPosition:h}=i;h==="LEFT"||h==="ROOT_LEFT"?s.left=i.right:(h==="RIGHT"||h==="ROOT_RIGHT")&&(s.right=i.right),r=s}else this._setRoot(i.right),i.right=void 0;return this._size=this._size-1,e.push({deleted:n,needBalanced:r}),this._isMapMode&&n&&this._store.delete(n.key),e}delete(t){return this._deleteInternal(t).length>0}search(t,e=!1,i=this._DEFAULT_NODE_CALLBACK,s=this._root,r=this.iterationType){if(t===void 0)return[];if(t===null)return[];if(s=this.ensureNode(s),!s)return[];let n=this._ensurePredicate(t),h=[];if(r==="RECURSIVE"){let o=u(a=>{n(a)&&(h.push(i(a)),e)||!this.isRealNode(a.left)&&!this.isRealNode(a.right)||(this.isRealNode(a.left)&&o(a.left),this.isRealNode(a.right)&&o(a.right))},"dfs");o(s)}else{let o=[s];for(;o.length>0;){let a=o.pop();if(this.isRealNode(a)){if(n(a)&&(h.push(i(a)),e))return h;this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right)}}}return h}getNodes(t,e=!1,i=this._root,s=this.iterationType){return this.search(t,e,r=>r,i,s)}getNode(t,e=this._root,i=this.iterationType){if(this._isMapMode&&t!==null&&t!==void 0&&!this._isPredicate(t)){let s=this._extractKey(t);return s==null?void 0:this._store.get(s)}return this.search(t,!0,s=>s,e,i)[0]}get(t,e=this._root,i=this.iterationType){var s,r;if(this._isMapMode){let n=this._extractKey(t);return n==null||(s=this._store.get(n))==null?void 0:s.value}return(r=this.getNode(t,e,i))==null?void 0:r.value}has(t,e=this._root,i=this.iterationType){if(this._isMapMode&&t!==void 0&&t!==null&&!this._isPredicate(t)){let s=this._extractKey(t);return s==null?!1:this._store.has(s)}return this.search(t,!0,s=>s,e,i).length>0}clear(){this._clearNodes(),this._isMapMode&&this._clearValues()}isEmpty(){return this._size===0}isPerfectlyBalanced(t=this._root){return this.getMinHeight(t)+1>=this.getHeight(t)}isBST(t=this._root,e=this.iterationType){let i=this.ensureNode(t);if(!i)return!0;if(e==="RECURSIVE"){let s=u((h,o,a)=>{if(!this.isRealNode(h))return!0;let l=Number(h.key);return l<=o||l>=a?!1:s(h.left,o,l)&&s(h.right,l,a)},"dfs"),r=s(i,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),n=s(i,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||n}else{let s=u((h=!1)=>{let o=[],a=h?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,l=i;for(;this.isRealNode(l)||o.length>0;){for(;this.isRealNode(l);)o.push(l),l=l.left;l=o.pop();let _=Number(l.key);if(!this.isRealNode(l)||!h&&a>=_||h&&a<=_)return!1;a=_,l=l.right}return!0},"checkBST"),r=s(),n=s(!0);return r||n}}getDepth(t,e=this._root){let i=this.ensureNode(t),s=this.ensureNode(e),r=0;for(;i!=null&&i.parent;){if(i===s)return r;r++,i=i.parent}return r}getHeight(t=this._root,e=this.iterationType){if(t=this.ensureNode(t),!this.isRealNode(t))return-1;if(e==="RECURSIVE"){let i=u(s=>{if(!this.isRealNode(s))return-1;let r=i(s.left),n=i(s.right);return Math.max(r,n)+1},"_getMaxHeight");return i(t)}else{let i=[{node:t,depth:0}],s=0;for(;i.length>0;){let{node:r,depth:n}=i.pop();this.isRealNode(r.left)&&i.push({node:r.left,depth:n+1}),this.isRealNode(r.right)&&i.push({node:r.right,depth:n+1}),s=Math.max(s,n)}return s}}getMinHeight(t=this._root,e=this.iterationType){if(t=this.ensureNode(t),!t)return-1;if(e==="RECURSIVE"){let i=u(s=>{if(!this.isRealNode(s)||!this.isRealNode(s.left)&&!this.isRealNode(s.right))return 0;let r=i(s.left),n=i(s.right);return Math.min(r,n)+1},"_getMinHeight");return i(t)}else{let i=[],s=t,r=null,n=new Map;for(;i.length>0||s;)if(this.isRealNode(s))i.push(s),s=s.left;else if(s=i[i.length-1],!this.isRealNode(s.right)||r===s.right){if(s=i.pop(),this.isRealNode(s)){let h=this.isRealNode(s.left)?n.get(s.left):-1,o=this.isRealNode(s.right)?n.get(s.right):-1;n.set(s,1+Math.min(h,o)),r=s,s=null}}else s=s.right;return n.get(t)}}getPathToRoot(t,e=this._DEFAULT_NODE_CALLBACK,i=!1){let s=[],r=this.ensureNode(t);if(!r)return s;for(;r.parent;)s.push(e(r)),r=r.parent;return s.push(e(r)),i?s.reverse():s}getLeftMost(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){if(this.isNIL(e))return t(void 0);let s=this.ensureNode(e);if(!this.isRealNode(s))return t(void 0);if(i==="RECURSIVE"){let r=u(n=>{let{left:h}=n;return this.isRealNode(h)?r(h):n},"dfs");return t(r(s))}else{let r=yt(n=>{let{left:h}=n;return this.isRealNode(h)?Et(()=>r(h)):n});return t(r(s))}}getRightMost(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){if(this.isNIL(e)||(e=this.ensureNode(e),!e))return t(void 0);if(i==="RECURSIVE"){let s=u(r=>{let{right:n}=r;return this.isRealNode(n)?s(n):r},"dfs");return t(s(e))}else{let s=yt(r=>{let{right:n}=r;return this.isRealNode(n)?Et(()=>s(n)):r});return t(s(e))}}getPredecessor(t){if(this.isRealNode(t.left)){let e=t.left;for(;!this.isRealNode(e)||this.isRealNode(e.right)&&e.right!==t;)this.isRealNode(e)&&(e=e.right);return e}else return t}getSuccessor(t){if(t=this.ensureNode(t),!this.isRealNode(t))return;if(this.isRealNode(t.right))return this.getLeftMost(i=>i,t.right);let e=t.parent;for(;this.isRealNode(e)&&t===e.right;)t=e,e=e.parent;return e}dfs(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=!1,s=this._root,r=this.iterationType,n=!1){return s=this.ensureNode(s),s?this._dfs(t,e,i,s,r,n):[]}bfs(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType,s=!1){if(e=this.ensureNode(e),!e)return[];let r=[];if(i==="RECURSIVE"){let n=new et([e]),h=u(o=>{if(n.length===0)return;let a=n.shift();r.push(t(a)),s?(a&&this.isRealNodeOrNull(a.left)&&n.push(a.left),a&&this.isRealNodeOrNull(a.right)&&n.push(a.right)):(this.isRealNode(a.left)&&n.push(a.left),this.isRealNode(a.right)&&n.push(a.right)),h(o+1)},"dfs");h(0)}else{let n=new et([e]);for(;n.length>0;){let h=n.length;for(let o=0;o<h;o++){let a=n.shift();r.push(t(a)),s?(a&&this.isRealNodeOrNull(a.left)&&n.push(a.left),a&&this.isRealNodeOrNull(a.right)&&n.push(a.right)):(this.isRealNode(a.left)&&n.push(a.left),this.isRealNode(a.right)&&n.push(a.right))}}}return r}leaves(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){e=this.ensureNode(e);let s=[];if(!this.isRealNode(e))return[];if(i==="RECURSIVE"){let r=u(n=>{this.isLeaf(n)&&s.push(t(n)),!(!this.isRealNode(n.left)&&!this.isRealNode(n.right))&&(this.isRealNode(n.left)&&r(n.left),this.isRealNode(n.right)&&r(n.right))},"dfs");r(e)}else{let r=[e];for(;r.length>0;){let n=r.pop();this.isRealNode(n)&&(this.isLeaf(n)&&s.push(t(n)),this.isRealNode(n.right)&&r.push(n.right),this.isRealNode(n.left)&&r.push(n.left))}}return s}listLevels(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType,s=!1){e=this.ensureNode(e);let r=[];if(!e)return r;if(i==="RECURSIVE"){let n=u((h,o)=>{r[o]||(r[o]=[]),r[o].push(t(h)),s?(h&&this.isRealNodeOrNull(h.left)&&n(h.left,o+1),h&&this.isRealNodeOrNull(h.right)&&n(h.right,o+1)):(h&&h.left&&n(h.left,o+1),h&&h.right&&n(h.right,o+1))},"_recursive");n(e,0)}else{let n=[[e,0]];for(;n.length>0;){let h=n.pop(),[o,a]=h;r[a]||(r[a]=[]),r[a].push(t(o)),s?(o&&this.isRealNodeOrNull(o.right)&&n.push([o.right,a+1]),o&&this.isRealNodeOrNull(o.left)&&n.push([o.left,a+1])):(o&&o.right&&n.push([o.right,a+1]),o&&o.left&&n.push([o.left,a+1]))}}return r}morris(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=this._root){if(i=this.ensureNode(i),!i)return[];let s=[],r=i,n=u(o=>{let a=null,l=null;for(;o;)l=o.right,o.right=a,a=o,o=l;return a},"_reverseEdge"),h=u(o=>{let a=n(o),l=a;for(;l;)s.push(t(l)),l=l.right;n(a)},"_printEdge");switch(e){case"IN":for(;r;){if(r.left){let o=this.getPredecessor(r);if(o.right)o.right=null;else{o.right=r,r=r.left;continue}}s.push(t(r)),r=r.right}break;case"PRE":for(;r;){if(r.left){let o=this.getPredecessor(r);if(o.right)o.right=null;else{o.right=r,s.push(t(r)),r=r.left;continue}}else s.push(t(r));r=r.right}break;case"POST":for(;r;){if(r.left){let o=this.getPredecessor(r);if(o.right===null){o.right=r,r=r.left;continue}else o.right=null,h(r.left)}r=r.right}h(i);break}return s}clone(){let t=this._createInstance();return this._clone(t),t}filter(t,e){let i=this._createInstance(),s=0;for(let[r,n]of this)t.call(e,n,r,s++,this)&&i.set([r,n]);return i}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}toVisual(t=this._root,e){let i={isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1,...e};t=this.ensureNode(t);let s="";return t&&(i.isShowUndefined&&(s+=`U for undefined
4
4
  `),i.isShowNull&&(s+=`N for null
5
5
  `),i.isShowRedBlackNIL&&(s+=`S for Sentinel Node(NIL)
6
6
  `),u(n=>{let[h]=this._displayAux(n,i),o="";for(let a of h)o+=a+`
7
- `;s+=o},"display")(t)),s}print(t,e=this._root){console.log(this.toVisual(e,t))}_dfs(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=!1,s=this._root,r=this.iterationType,n=!1,h=_=>!!_,o=_=>!!_,a=_=>n?this.isRealNodeOrNull(_):this.isRealNode(_),l=_=>this.isRealNodeOrNull(_)){if(s=this.ensureNode(s),!s)return[];let _=[];if(r==="RECURSIVE"){let g=u(p=>{if(!a(p))return;let v=u(()=>{h(p)&&(p==null?void 0:p.left)!==void 0&&g(p==null?void 0:p.left)},"visitLeft"),w=u(()=>{o(p)&&(p==null?void 0:p.right)!==void 0&&g(p==null?void 0:p.right)},"visitRight");switch(e){case"IN":if(v(),l(p)&&(_.push(t(p)),i))return;w();break;case"PRE":if(l(p)&&(_.push(t(p)),i))return;v(),w();break;case"POST":if(v(),w(),l(p)&&(_.push(t(p)),i))return;break}},"dfs");g(s)}else{let g=[{opt:0,node:s}],p=u(b=>{var M;h(b.node)&&g.push({opt:0,node:(M=b.node)==null?void 0:M.left})},"pushLeft"),v=u(b=>{var M;o(b.node)&&g.push({opt:0,node:(M=b.node)==null?void 0:M.right})},"pushRight"),w=u(b=>{a(b.node)&&g.push({opt:1,node:b.node})},"pushRoot");for(;g.length>0;){let b=g.pop();if(b!==void 0&&a(b.node))if(b.opt===1){if(l(b.node)&&b.node!==void 0&&(_.push(t(b.node)),i))return _}else switch(e){case"IN":v(b),w(b),p(b);break;case"PRE":v(b),p(b),w(b);break;case"POST":w(b),v(b),p(b);break}}}return _}*_getIterator(t=this._root){if(t)if(this.iterationType==="ITERATIVE"){let e=[],i=t;for(;i||e.length>0;){for(;this.isRealNode(i);)e.push(i),i=i.left;i=e.pop(),this.isRealNode(i)&&(yield[i.key,i.value],i=i.right)}}else t.left&&this.isRealNode(t)&&(yield*this[Symbol.iterator](t.left)),yield[t.key,t.value],t.right&&this.isRealNode(t)&&(yield*this[Symbol.iterator](t.right))}_snapshotOptions(){return{iterationType:this.iterationType,toEntryFn:this.toEntryFn,isMapMode:this.isMapMode,isDuplicate:this.isDuplicate}}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_keyValueNodeOrEntryToNodeAndValue(t,e){if(t===void 0)return[void 0,void 0];if(t===null)return[null,void 0];if(this.isNode(t))return[t,e];if(this.isEntry(t)){let[i,s]=t;if(i===void 0)return[void 0,void 0];if(i===null)return[null,void 0];let r=e!=null?e:s;return[this.createNode(i,r),r]}return[this.createNode(t,e),e]}_clone(t){this.bfs(e=>{e===null?t.set(null):t.set([e.key,e.value])},this._root,this.iterationType,!0)}_displayAux(t,e){let i=[["\u2500"],1,0,0],s=u(o=>({node:o,stage:0,leftLayout:i,rightLayout:i}),"newFrame"),r=[s(t)],n=i,h=u(o=>{if(r.length===0){n=o;return}let a=r[r.length-1];a.stage===1?a.leftLayout=o:a.rightLayout=o},"setChildResult");for(;r.length>0;){let o=r[r.length-1],a=o.node;if(o.stage===0){if(this._isDisplayLeaf(a,e)){r.pop();let l=this._resolveDisplayLeaf(a,e,i);h(l);continue}o.stage=1,r.push(s(a.left))}else if(o.stage===1)o.stage=2,r.push(s(a.right));else{r.pop();let l=this.isNIL(a)?"S":String(a.key),_=rt._buildNodeDisplay(l,l.length,o.leftLayout,o.rightLayout);h(_)}}return n}static _buildNodeDisplay(t,e,i,s){let[r,n,h,o]=i,[a,l,_,g]=s,p=" ".repeat(Math.max(0,o+1))+"_".repeat(Math.max(0,n-o-1))+t+"_".repeat(Math.max(0,g))+" ".repeat(Math.max(0,l-g)),v=(h>0?" ".repeat(o)+"/"+" ".repeat(n-o-1):" ".repeat(n))+" ".repeat(e)+(_>0?" ".repeat(g)+"\\"+" ".repeat(l-g-1):" ".repeat(l)),w=[p,v];for(let b=0;b<Math.max(h,_);b++){let M=b<h?r[b]:" ".repeat(n),y=b<_?a[b]:" ".repeat(l);w.push(M+" ".repeat(e)+y)}return[w,n+e+l,Math.max(h,_)+2,n+Math.floor(e/2)]}_isDisplayLeaf(t,e){let{isShowNull:i,isShowUndefined:s,isShowRedBlackNIL:r}=e;if(t===null&&!i||t===void 0&&!s||this.isNIL(t)&&!r||t==null)return!0;let n=this._hasDisplayableChild(t.left,e),h=this._hasDisplayableChild(t.right,e);return!n&&!h}_hasDisplayableChild(t,e){return t===null?!!e.isShowNull:t===void 0?!!e.isShowUndefined:this.isNIL(t)?!!e.isShowRedBlackNIL:!0}_resolveDisplayLeaf(t,e,i){let{isShowNull:s,isShowUndefined:r,isShowRedBlackNIL:n}=e;if(t===null&&!s||t===void 0&&!r||this.isNIL(t)&&!n)return i;if(t!=null){let o=this.isNIL(t)?"S":String(t.key);return rt._buildNodeDisplay(o,o.length,i,i)}let h=t===void 0?"U":"N";return rt._buildNodeDisplay(h,h.length,[[""],1,0,0],[[""],1,0,0])}_swapProperties(t,e){if(t=this.ensureNode(t),e=this.ensureNode(e),t&&e){let{key:i,value:s}=e,r=this.createNode(i,s);return r&&(e.key=t.key,this._isMapMode||(e.value=t.value),t.key=r.key,this._isMapMode||(t.value=r.value)),e}}_replaceNode(t,e){return t.parent&&(t.parent.left===t?t.parent.left=e:t.parent.right===t&&(t.parent.right=e)),e.left=t.left,e.right=t.right,e.parent=t.parent,this._root===t&&this._setRoot(e),e}_setRoot(t){t&&(t.parent=void 0),this._root=t}_ensurePredicate(t){if(t==null)return e=>!1;if(this._isPredicate(t))return t;if(this.isRealNode(t))return e=>e===t;if(this.isEntry(t)){let[e]=t;return i=>i?i.key===e:!1}return e=>e?e.key===t:!1}_isPredicate(t){return typeof t=="function"}_extractKey(t){if(t===null)return null;if(t!==void 0&&t!==this._NIL)return this.isNode(t)?t.key:this.isEntry(t)?t[0]:t}_setValue(t,e){if(t==null)return!1;let i=this._store.get(t);return i?(i.value=e,!0):!1}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};u(ve,"BinaryTree");var ui=ve,me=class{constructor(t,e){f(this,"key"),f(this,"value"),f(this,"parent"),f(this,"_left"),f(this,"_right"),f(this,"_height",0),f(this,"_color","BLACK"),f(this,"_count",1),this.key=t,this.value=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}set count(t){this._count=t}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(me,"BSTNode");var It=me,ye=class extends ui{constructor(t=[],e){super([],e),f(this,"_root"),f(this,"_enableOrderStatistic",!1),f(this,"_comparator"),e?("comparator"in e&&e.comparator!==void 0?this._comparator=e.comparator:this._comparator=this._createDefaultComparator(),e.enableOrderStatistic&&(this._enableOrderStatistic=!0)):this._comparator=this._createDefaultComparator(),t&&this.setMany(t)}get root(){return this._root}get comparator(){return this._comparator}createNode(t,e){return new It(t,e)}ensureNode(t,e=this.iterationType){var i;return(i=super.ensureNode(t,e))!=null?i:void 0}isNode(t){return t instanceof It}isValidKey(t){return tt(t)}dfs(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=!1,s=this._root,r=this.iterationType){return super.dfs(t,e,i,s,r)}bfs(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){return super.bfs(t,e,i,!1)}listLevels(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){return super.listLevels(t,e,i,!1)}getNode(t,e=this._root,i=this.iterationType){var s,r;if(t==null)return;if(this._isPredicate(t))return(s=this.getNodes(t,!0,e,i)[0])!=null?s:void 0;if(t instanceof st)return(r=this.getNodes(t,!0,e,i)[0])!=null?r:void 0;let n;if(this.isNode(t))n=t.key;else if(this.isEntry(t)){let _=t[0];if(_==null)return;n=_}else n=t;let h=this.ensureNode(e);if(!h)return;let o=this._NIL,a=h,l=this._comparator;for(;a&&a!==o;){let _=l(n,a.key);if(_===0)return a;a=_<0?a._left:a._right}}search(t,e=!1,i=this._DEFAULT_NODE_CALLBACK,s=this._root,r=this.iterationType){if(t===void 0)return[];if(t===null)return[];if(s=this.ensureNode(s),!s)return[];let n=this.isRange(t),h=!n&&this._isPredicate(t);if(!n&&!h){let _;if(this.isNode(t))_=t.key;else if(this.isEntry(t)){let w=t[0];w!=null&&(_=w)}else _=t;if(_===void 0)return[];let g=this._NIL,p=this._comparator,v=s;for(;v&&v!==g;){let w=p(_,v.key);if(w===0)return[i(v)];v=w<0?v._left:v._right}return[]}let o;n?o=u(_=>_?t.isInRange(_.key,this._comparator):!1,"predicate"):o=this._ensurePredicate(t);let a=u(_=>{if(!_||!this.isRealNode(_.left))return!1;if(n){let g=t,p=g.low,v=g.includeLow;return v&&this._compare(_.key,p)>=0||!v&&this._compare(_.key,p)>0}if(!n&&!this._isPredicate(t)){let g=this._extractKey(t);return g!=null&&this._compare(_.key,g)>0}return!0},"shouldVisitLeft"),l=u(_=>{if(!_||!this.isRealNode(_.right))return!1;if(n){let g=t,p=g.high,v=g.includeHigh;return v&&this._compare(_.key,p)<=0||!v&&this._compare(_.key,p)<0}if(!n&&!this._isPredicate(t)){let g=this._extractKey(t);return g!=null&&this._compare(_.key,g)<0}return!0},"shouldVisitRight");return super._dfs(i,"IN",e,s,r,!1,a,l,()=>!0,_=>!!_&&o(_))}rangeSearch(t,e=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){let r=t instanceof st?t:new st(t[0],t[1]);return this.search(r,!1,e,i,s)}getByRank(t,e=this._DEFAULT_NODE_CALLBACK,i=this.iterationType){if(this._enableOrderStatistic||x(Error,R.orderStatisticNotEnabled("getByRank")),t<0||t>=this._size)return;let s,r=this.iterationType;typeof e=="string"?r=e:e&&(s=e,i&&(r=i));let n=r==="RECURSIVE"?this._getByRankRecursive(this._root,t):this._getByRankIterative(this._root,t);if(n)return s?s(n):n.key}getRank(t,e=this.iterationType){var i;if(this._enableOrderStatistic||x(Error,R.orderStatisticNotEnabled("getRank")),!this._root||this._size===0)return-1;let s=this.iterationType;e&&(s=e);let r;if(typeof t=="function"){let n=this.search(t,!0);if(n.length===0||n[0]===void 0)return-1;r=n[0]}else{if(t==null)return-1;if(this.isNode(t))r=t.key;else if(Array.isArray(t)){if(r=(i=t[0])!=null?i:void 0,r==null)return-1}else r=t}return r===void 0?-1:s==="RECURSIVE"?this._getRankRecursive(this._root,r):this._getRankIterative(this._root,r)}rangeByRank(t,e,i=this._DEFAULT_NODE_CALLBACK,s=this.iterationType){if(this._enableOrderStatistic||x(Error,R.orderStatisticNotEnabled("rangeByRank")),this._size===0)return[];let r=Math.max(0,t),n=Math.min(this._size-1,e);if(r>n)return[];let h,o=this.iterationType;typeof i=="string"?o=i:i&&(h=i,s&&(o=s));let a=[],l=n-r+1,_=o==="RECURSIVE"?this._getByRankRecursive(this._root,r):this._getByRankIterative(this._root,r);if(!_)return[];let g=0,p=h!=null?h:this._DEFAULT_NODE_CALLBACK,v=_;for(;v&&g<l;)a.push(p(v)),g++,g<l&&(v=this._next(v));return a}set(t,e){let[i]=this._keyValueNodeOrEntryToNodeAndValue(t,e);if(i===void 0)return!1;if(this._root===void 0)return this._setRoot(i),this._isMapMode&&this.isRealNode(i)&&this._store.set(i.key,i),this._size++,this._updateCount(i),!0;let s=this._root;for(;s!==void 0;){if(this._compare(s.key,i.key)===0)return this._replaceNode(s,i),this._isMapMode&&this.isRealNode(i)&&this._store.set(s.key,i),!0;if(this._compare(s.key,i.key)>0){if(s.left===void 0)return s.left=i,this._isMapMode&&this.isRealNode(i)&&this._store.set(i.key,i),this._size++,this._updateCountAlongPath(i),!0;s.left!==null&&(s=s.left)}else{if(s.right===void 0)return s.right=i,this._isMapMode&&this.isRealNode(i)&&this._store.set(i.key,i),this._size++,this._updateCountAlongPath(i),!0;s.right!==null&&(s=s.right)}}return!1}setMany(t,e,i=!0,s=this.iterationType){let r=[],n=e==null?void 0:e[Symbol.iterator]();if(!i){for(let g of t){let p=n==null?void 0:n.next().value;this.isRaw(g)&&(g=this._toEntryFn(g)),r.push(this.set(g,p))}return r}let h=[],o=0;for(let g of t)h.push({key:g,value:n==null?void 0:n.next().value,orgIndex:o++});let a=h.sort(({key:g},{key:p})=>{let v,w;return this.isRaw(g)?v=this._toEntryFn(g)[0]:this.isEntry(g)?v=g[0]:this.isRealNode(g)?v=g.key:v=g,this.isRaw(p)?w=this._toEntryFn(p)[0]:this.isEntry(p)?w=p[0]:this.isRealNode(p)?w=p.key:w=p,v!=null&&w!=null?this._compare(v,w):0}),l=u(g=>{if(g.length===0)return;let p=Math.floor((g.length-1)/2),{key:v,value:w,orgIndex:b}=g[p];if(this.isRaw(v)){let M=this._toEntryFn(v);r[b]=this.set(M)}else r[b]=this.set(v,w);l(g.slice(0,p)),l(g.slice(p+1))},"_dfs");return s==="RECURSIVE"?l(a):u(()=>{let p=[[0,a.length-1]];for(;p.length>0;){let v=p.pop();if(!v)continue;let[w,b]=v;if(w>b)continue;let M=w+Math.floor((b-w)/2),{key:y,value:N,orgIndex:m}=a[M];if(this.isRaw(y)){let k=this._toEntryFn(y);r[m]=this.set(k)}else r[m]=this.set(y,N);p.push([M+1,b]),p.push([w,M-1])}},"_iterate")(),r}ceiling(t,e=this._DEFAULT_NODE_CALLBACK,i){let s,r=this.iterationType;typeof e=="string"?r=e:e&&(s=e,i&&(r=i));let n=this._bound(t,!0,r);return s?n?s(n):void 0:n==null?void 0:n.key}higher(t,e=this._DEFAULT_NODE_CALLBACK,i){let s,r=this.iterationType;typeof e=="string"?r=e:e&&(s=e,i&&(r=i));let n=this._bound(t,!1,r);return s?n?s(n):void 0:n==null?void 0:n.key}floor(t,e=this._DEFAULT_NODE_CALLBACK,i){if(t==null)return void 0;let s,r=this.iterationType;if(typeof e=="string"?r=e:e&&(s=e,i&&(r=i)),this._isPredicate(t)){let h=this._floorByPredicate(t,r);return s?h?s(h):void 0:h==null?void 0:h.key}let n;if(this.isNode(t))n=t.key;else if(this.isEntry(t)){let h=t[0];if(h==null)return void 0;n=h}else n=t;if(n!==void 0){let h=this._floorByKey(n,r);return s?h?s(h):void 0:h==null?void 0:h.key}}lower(t,e,i){if(t==null)return void 0;let s,r=this.iterationType;if(typeof e=="string"?r=e:e&&(s=e,i&&(r=i)),this._isPredicate(t)){let h=this._lowerByPredicate(t,r);return s?h?s(h):void 0:h==null?void 0:h.key}let n;if(this.isNode(t))n=t.key;else if(this.isEntry(t)){let h=t[0];if(h==null)return void 0;n=h}else n=t;if(n!==void 0){let h=this._lowerByKey(n,r);return s?h?s(h):void 0:h==null?void 0:h.key}}lesserOrGreaterTraverse(t=this._DEFAULT_NODE_CALLBACK,e=-1,i=this._root,s=this.iterationType){let r=this.ensureNode(i),n=[];if(!this._root||!r)return n;let h=r.key;if(s==="RECURSIVE"){let o=u(a=>{let l=this._compare(a.key,h);Math.sign(l)==e&&n.push(t(a)),this.isRealNode(a.left)&&o(a.left),this.isRealNode(a.right)&&o(a.right)},"dfs");return o(this._root),n}else{let o=new et([this._root]);for(;o.length>0;){let a=o.shift();if(this.isRealNode(a)){let l=this._compare(a.key,h);Math.sign(l)==e&&n.push(t(a)),this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right)}}return n}}perfectlyBalance(t=this.iterationType){let e=this.dfs(n=>n,"IN",!1,this._root,t),i=e.length;if(this._clearNodes(),i===0)return!1;let s=u((n,h,o)=>{if(n>h)return;let a=n+(h-n>>1),l=e[a],_=s(n,a-1,l),g=s(a+1,h,l);return l.left=_,l.right=g,l.parent=o,l},"build"),r=s(0,i-1,void 0);return this._setRoot(r),this._size=i,!0}isAVLBalanced(t=this.iterationType){if(!this._root)return!0;let e=!0;if(t==="RECURSIVE"){let i=u(s=>{if(!s)return 0;let r=i(s.left),n=i(s.right);return Math.abs(r-n)>1&&(e=!1),Math.max(r,n)+1},"_height");i(this._root)}else{let i=[],s=this._root,r,n=new Map;for(;i.length>0||s;)if(s)i.push(s),s.left!==null&&(s=s.left);else if(s=i[i.length-1],!s.right||r===s.right){if(s=i.pop(),s){let h=s.left?n.get(s.left):-1,o=s.right?n.get(s.right):-1;if(Math.abs(h-o)>1)return!1;n.set(s,1+Math.max(h,o)),r=s,s=void 0}}else s=s.right}return e}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}deleteWhere(t,e=!1,i=this._root,s=this.iterationType){let r=this.search(t,e,h=>h,i,s),n=!1;for(let h of r)this.delete(h)&&(n=!0);return n}_createDefaultComparator(){return(t,e)=>{if(tt(t)&&tt(e))return t>e?1:t<e?-1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&x(TypeError,R.invalidDate("BST")),i>s?1:i<s?-1:0}return(typeof t=="object"||typeof e=="object")&&x(TypeError,R.comparatorRequired("BST")),0}}_floorByKey(t,e){var i,s;if(e==="RECURSIVE"){let r=u(n=>{if(!this.isRealNode(n))return;if(this.comparator(n.key,t)<=0){let o=r(n.right);return o!=null?o:n}else return r(n.left)},"dfs");return r(this.root)}else{let r=this.root,n;for(;this.isRealNode(r);)this.comparator(r.key,t)<=0?(n=r,r=(i=r.right)!=null?i:void 0):r=(s=r.left)!=null?s:void 0;return n}}_floorByPredicate(t,e){if(e==="RECURSIVE"){let i,s=u(r=>{this.isRealNode(r)&&(this.isRealNode(r.left)&&s(r.left),t(r)&&(i=r),this.isRealNode(r.right)&&s(r.right))},"dfs");return s(this.root),i}else{let i=[],s=this.root,r;for(;i.length>0||this.isRealNode(s);)if(this.isRealNode(s))i.push(s),s=s.left;else{let n=i.pop();if(!this.isRealNode(n))break;t(n)&&(r=n),s=n.right}return r}}_lowerByKey(t,e){var i,s;if(e==="RECURSIVE"){let r=u(n=>{if(!this.isRealNode(n))return;if(this.comparator(n.key,t)<0){let o=r(n.right);return o!=null?o:n}else return r(n.left)},"dfs");return r(this.root)}else{let r=this.root,n;for(;this.isRealNode(r);)this.comparator(r.key,t)<0?(n=r,r=(i=r.right)!=null?i:void 0):r=(s=r.left)!=null?s:void 0;return n}}_lowerByPredicate(t,e){if(e==="RECURSIVE"){let i,s=u(r=>{this.isRealNode(r)&&(this.isRealNode(r.left)&&s(r.left),t(r)&&(i=r),this.isRealNode(r.right)&&s(r.right))},"dfs");return s(this.root),i}else{let i=[],s=this.root,r;for(;i.length>0||this.isRealNode(s);)if(this.isRealNode(s))i.push(s),s=s.left;else{let n=i.pop();if(!this.isRealNode(n))break;t(n)&&(r=n),s=n.right}return r}}_bound(t,e,i){if(t==null)return;if(this._isPredicate(t))return this._boundByPredicate(t,i);let s;if(this.isNode(t))s=t.key;else if(this.isEntry(t)){let r=t[0];if(r==null)return;s=r}else s=t;if(s!==void 0)return this._boundByKey(s,e,i)}_boundByKey(t,e,i){var s,r;if(i==="RECURSIVE"){let n=u(h=>{if(!this.isRealNode(h))return;let o=this.comparator(h.key,t);if(e?o>=0:o>0){let l=n(h.left);return l!=null?l:h}else return n(h.right)},"dfs");return n(this.root)}else{let n=this.root,h;for(;this.isRealNode(n);){let o=this.comparator(n.key,t);(e?o>=0:o>0)?(h=n,n=(s=n.left)!=null?s:void 0):n=(r=n.right)!=null?r:void 0}return h}}_boundByPredicate(t,e){if(e==="RECURSIVE"){let i,s=u(r=>{i||!this.isRealNode(r)||(this.isRealNode(r.left)&&s(r.left),!i&&t(r)&&(i=r),!i&&this.isRealNode(r.right)&&s(r.right))},"dfs");return s(this.root),i}else{let i=[],s=this.root;for(;i.length>0||this.isRealNode(s);)if(this.isRealNode(s))i.push(s),s=s.left;else{let r=i.pop();if(!this.isRealNode(r))break;if(t(r))return r;s=r.right}return}}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_snapshotOptions(){return{...super._snapshotOptions(),comparator:this._comparator,enableOrderStatistic:this._enableOrderStatistic}}_keyValueNodeOrEntryToNodeAndValue(t,e){let[i,s]=super._keyValueNodeOrEntryToNodeAndValue(t,e);return i===null?[void 0,void 0]:[i,e!=null?e:s]}_updateCount(t){this._enableOrderStatistic&&(t._count=1+(this.isRealNode(t.left)?t.left._count:0)+(this.isRealNode(t.right)?t.right._count:0))}_updateCountAlongPath(t){if(!this._enableOrderStatistic)return;let e=t;for(;e;)this._updateCount(e),e=e.parent}_getByRankIterative(t,e){let i=t,s=e;for(;i;){let r=this.isRealNode(i.left)?i.left._count:0;if(s<r)i=i.left;else{if(s===r)return i;s=s-r-1,i=i.right}}}_getByRankRecursive(t,e){if(!t)return;let i=this.isRealNode(t.left)?t.left._count:0;return e<i?this._getByRankRecursive(t.left,e):e===i?t:this._getByRankRecursive(t.right,e-i-1)}_getRankIterative(t,e){let i=0,s=t;for(;this.isRealNode(s);){let r=this._compare(s.key,e);if(r>0)s=s.left;else if(r<0)i+=(this.isRealNode(s.left)?s.left._count:0)+1,s=s.right;else return i+=this.isRealNode(s.left)?s.left._count:0,i}return i}_getRankRecursive(t,e){if(!t)return 0;let i=this._compare(t.key,e);return i>0?this._getRankRecursive(t.left,e):i<0?(this.isRealNode(t.left)?t.left._count:0)+1+this._getRankRecursive(t.right,e):this.isRealNode(t.left)?t.left._count:0}_next(t){if(this.isRealNode(t.right)){let s=t.right;for(;this.isRealNode(s.left);)s=s.left;return s}let e=t,i=e.parent;for(;i&&e===i.right;)e=i,i=i.parent;return i}_setRoot(t){t&&(t.parent=void 0),this._root=t}_compare(t,e){return this._comparator(t,e)}_deleteByKey(t){let e=this._root;for(;e;){let n=this._compare(e.key,t);if(n===0)break;e=n>0?e.left:e.right}if(!e)return!1;let i=u((n,h)=>{let o=n==null?void 0:n.parent;o?o.left===n?o.left=h:o.right=h:this._setRoot(h),h&&(h.parent=o)},"transplant"),s=u(n=>{if(n){for(;n.left!==void 0&&n.left!==null;)n=n.left;return n}},"minNode"),r;if(e.left===void 0)r=e.parent,i(e,e.right);else if(e.right===void 0)r=e.parent,i(e,e.left);else{let n=s(e.right);n.parent!==e?(r=n.parent,i(n,n.right),n.right=e.right,n.right&&(n.right.parent=n)):r=n,i(e,n),n.left=e.left,n.left&&(n.left.parent=n)}return this._updateCountAlongPath(r),this._size=Math.max(0,this._size-1),!0}};u(ye,"BST");var Me=ye,ci=class be{constructor(t){if(f(this,"_size"),f(this,"_tree"),Array.isArray(t)){this._size=t.length,this._tree=new Array(this._size+1).fill(0);for(let e=0;e<this._size;e++)this._pointUpdate(e+1,t[e])}else(!Number.isInteger(t)||t<0)&&x(RangeError,R.invalidArgument("size must be a non-negative integer","BinaryIndexedTree")),this._size=t,this._tree=new Array(this._size+1).fill(0)}update(t,e){this._checkIndex(t),this._pointUpdate(t+1,e)}set(t,e){this._checkIndex(t);let i=this.get(t);this._pointUpdate(t+1,e-i)}get(t){return this._checkIndex(t),this._pointQuery(t+1)}query(t){return this._checkIndex(t),this._prefixSum(t+1)}queryRange(t,e){return this._checkIndex(t),this._checkIndex(e),t>e?0:t===0?this._prefixSum(e+1):this._prefixSum(e+1)-this._prefixSum(t)}lowerBound(t){let e=0,i=this._highBit(this._size);for(;i>0;){let s=e+i;s<=this._size&&this._tree[s]<t&&(t-=this._tree[s],e=s),i>>=1}return e}upperBound(t){let e=0,i=this._highBit(this._size);for(;i>0;){let s=e+i;s<=this._size&&this._tree[s]<=t&&(t-=this._tree[s],e=s),i>>=1}return e}get size(){return this._size}isEmpty(){return this._size===0}clear(){this._tree.fill(0)}clone(){return new be(this.toArray())}toArray(){let t=[];for(let e=0;e<this._size;e++)t.push(this._pointQuery(e+1));return t}[Symbol.iterator](){let t=this._size,e=0,i=this;return{[Symbol.iterator](){return this},next(){return e<t?{value:i._pointQuery(e+++1),done:!1}:{value:void 0,done:!0}}}}forEach(t){for(let e=0;e<this._size;e++)t(this._pointQuery(e+1),e)}print(){console.log(this.toArray())}_prefixSum(t){let e=0;for(;t>0;)e+=this._tree[t],t-=t&-t;return e}_pointUpdate(t,e){for(;t<=this._size;)this._tree[t]+=e,t+=t&-t}_pointQuery(t){let e=this._tree[t],i=t-(t&-t);for(t--;t>i;)e-=this._tree[t],t-=t&-t;return e}_checkIndex(t){Number.isInteger(t)||x(TypeError,R.invalidIndex("BinaryIndexedTree")),(t<0||t>=this._size)&&x(RangeError,R.indexOutOfRange(t,0,this._size-1,"BinaryIndexedTree"))}_highBit(t){let e=1;for(;e<=t;)e<<=1;return e>>1}};u(ci,"BinaryIndexedTree");var fi=class O{constructor(t,e){for(f(this,"_merger"),f(this,"_identity"),f(this,"_n"),f(this,"_tree"),f(this,"_treeSize"),this._merger=e.merger,this._identity=e.identity,this._n=t.length,this._treeSize=1;this._treeSize<this._n;)this._treeSize<<=1;this._tree=new Array(2*this._treeSize).fill(this._identity);for(let i=0;i<this._n;i++)this._tree[this._treeSize+i]=t[i];for(let i=this._treeSize-1;i>=1;i--)this._tree[i]=this._merger(this._tree[2*i],this._tree[2*i+1])}static sum(t){return new O(t,{merger:u((e,i)=>e+i,"merger"),identity:0})}static min(t){return new O(t,{merger:u((e,i)=>Math.min(e,i),"merger"),identity:1/0})}static max(t){return new O(t,{merger:u((e,i)=>Math.max(e,i),"merger"),identity:-1/0})}update(t,e){if(t<0||t>=this._n)return;let i=this._treeSize+t;for(this._tree[i]=e,i>>=1;i>=1;)this._tree[i]=this._merger(this._tree[2*i],this._tree[2*i+1]),i>>=1}query(t,e){if(t<0&&(t=0),e>=this._n&&(e=this._n-1),t>e)return this._identity;let i=this._identity,s=this._identity,r=this._treeSize+t,n=this._treeSize+e+1;for(;r<n;)r&1&&(i=this._merger(i,this._tree[r]),r++),n&1&&(n--,s=this._merger(this._tree[n],s)),r>>=1,n>>=1;return this._merger(i,s)}get(t){return t<0||t>=this._n?this._identity:this._tree[this._treeSize+t]}maxRight(t,e){if(t>=this._n)return this._n-1;let i=this._identity;if(!e(i))return t-1;let s=this._treeSize+t;for(;;){for(;s<this._treeSize;){let n=this._merger(i,this._tree[2*s]);e(n)?(i=n,s=2*s+1):s=2*s}let r=this._merger(i,this._tree[s]);if(!e(r))return s-this._treeSize-1;if(i=r,s++,s-this._treeSize>=this._n)return this._n-1;for(;s>1&&(s&1)===0;)s>>=1;if(s===1)return this._n-1}}minLeft(t,e){if(t<0)return 0;t>=this._n&&(t=this._n-1);let i=this._identity;if(!e(i))return t+1;let s=this._treeSize+t;for(;;){for(;s<this._treeSize;){let n=this._merger(this._tree[2*s+1],i);e(n)?(i=n,s=2*s):s=2*s+1}let r=this._merger(this._tree[s],i);if(!e(r))return s-this._treeSize+1;if(i=r,s===this._treeSize)return 0;for(s--;s>1&&(s&1)===1;)s>>=1;if(s===1)return 0}}get size(){return this._n}isEmpty(){return this._n===0}clone(){let t=[];for(let e=0;e<this._n;e++)t.push(this._tree[this._treeSize+e]);return new O(t,{merger:this._merger,identity:this._identity})}toArray(){let t=[];for(let e=0;e<this._n;e++)t.push(this._tree[this._treeSize+e]);return t}[Symbol.iterator](){let t=this._tree,e=this._treeSize,i=this._n,s=0;return{[Symbol.iterator](){return this},next(){return s<i?{value:t[e+s++],done:!1}:{value:void 0,done:!0}}}}forEach(t){for(let e=0;e<this._n;e++)t(this._tree[this._treeSize+e],e)}print(){console.log(this.toArray())}};u(fi,"SegmentTree");var ke=class{constructor(t,e){f(this,"key"),f(this,"value"),f(this,"parent"),f(this,"_left"),f(this,"_right"),f(this,"_height",0),f(this,"_color","BLACK"),f(this,"_count",1),this.key=t,this.value=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}set count(t){this._count=t}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(ke,"AVLTreeNode");var Ct=ke,_i=class extends Me{constructor(t=[],e){super([],e),t&&super.setMany(t)}createNode(t,e){return new Ct(t,e)}isNode(t){return t instanceof Ct}set(t,e){if(t===null)return!1;let i=super.set(t,e);return i&&this._balancePath(t),i}delete(t){let e=this._deleteInternal(t);for(let{needBalanced:i}of e)i&&this._balancePath(i);return e.length>0}perfectlyBalance(t=this.iterationType){let e=this.dfs(n=>n,"IN",!1,this._root,t),i=e.length;if(i===0)return!1;this._clearNodes();let s=u((n,h,o)=>{if(n>h)return;let a=n+(h-n>>1),l=e[a];l.left=s(n,a-1,l),l.right=s(a+1,h,l),l.parent=o;let _=l.left?l.left.height:-1,g=l.right?l.right.height:-1;return l.height=Math.max(_,g)+1,l},"build"),r=s(0,i-1,void 0);return this._setRoot(r),this._size=i,!0}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_swapProperties(t,e){let i=this.ensureNode(t),s=this.ensureNode(e);if(i&&s){let{key:r,value:n,height:h}=s,o=this.createNode(r,n);return o&&(o.height=h,s.key=i.key,this._isMapMode||(s.value=i.value),s.height=i.height,i.key=o.key,this._isMapMode||(i.value=o.value),i.height=o.height),s}}_balanceFactor(t){let e=t.left?t.left.height:-1;return(t.right?t.right.height:-1)-e}_updateHeight(t){let e=t.left?t.left.height:-1,i=t.right?t.right.height:-1;t.height=1+Math.max(e,i)}_balanceLL(t){let e=t.parent,i=t.left;i!==null&&(t.parent=i),i&&i.right&&(i.right.parent=t),i&&(i.parent=e),t===this.root?i&&this._setRoot(i):(e==null?void 0:e.left)===t?e.left=i:e&&(e.right=i),i&&(t.left=i.right,i.right=t),this._updateHeight(t),i&&this._updateHeight(i),this._updateCount(t),i&&this._updateCount(i)}_balanceLR(t){let e=t.parent,i=t.left,s;i&&(s=i.right),t&&s!==null&&(t.parent=s),i&&s!==null&&(i.parent=s),s&&(s.left&&i!==null&&(s.left.parent=i),s.right&&(s.right.parent=t),s.parent=e),t===this.root?s&&this._setRoot(s):e&&(e.left===t?e.left=s:e.right=s),s&&(t.left=s.right,i&&(i.right=s.left),s.left=i,s.right=t),this._updateHeight(t),i&&this._updateHeight(i),s&&this._updateHeight(s),this._updateCount(t),i&&this._updateCount(i),s&&this._updateCount(s)}_balanceRR(t){let e=t.parent,i=t.right;i!==null&&(t.parent=i),i&&(i.left&&(i.left.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.right=i.left,i.left=t),this._updateHeight(t),i&&this._updateHeight(i),this._updateCount(t),i&&this._updateCount(i)}_balanceRL(t){let e=t.parent,i=t.right,s;i&&(s=i.left),s!==null&&(t.parent=s),i&&s!==null&&(i.parent=s),s&&(s.left&&(s.left.parent=t),s.right&&i!==null&&(s.right.parent=i),s.parent=e),t===this.root?s&&this._setRoot(s):e&&(e.left===t?e.left=s:e.right=s),s&&(t.right=s.left),i&&s&&(i.left=s.right),s&&(s.left=t),s&&(s.right=i),this._updateHeight(t),i&&this._updateHeight(i),s&&this._updateHeight(s),this._updateCount(t),i&&this._updateCount(i),s&&this._updateCount(s)}_balancePath(t){t=this.ensureNode(t);let e=this.getPathToRoot(t,i=>i,!1);for(let i=0;i<e.length;i++){let s=e[i];if(s)switch(this._updateHeight(s),this._updateCount(s),this._balanceFactor(s)){case-2:s&&s.left&&(this._balanceFactor(s.left)<=0?this._balanceLL(s):this._balanceLR(s));break;case 2:s&&s.right&&(this._balanceFactor(s.right)>=0?this._balanceRR(s):this._balanceRL(s))}}}_replaceNode(t,e){return e.height=t.height,super._replaceNode(t,e)}};u(_i,"AVLTree");var xe=class{constructor(t,e,i="BLACK"){f(this,"key"),f(this,"value"),f(this,"parent"),f(this,"_left"),f(this,"_right"),f(this,"_height",0),f(this,"_color","BLACK"),f(this,"_count",1),this.key=t,this.value=e,this.color=i}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(xe,"RedBlackTreeNode");var vt=xe,we=class extends Me{constructor(t=[],e){super([],e),f(this,"_root"),f(this,"_header"),f(this,"_minNode"),f(this,"_maxNode"),this._root=this.NIL,this._header=new vt(void 0,void 0,"BLACK"),this._header.parent=this.NIL,this._header._left=this.NIL,this._header._right=this.NIL,t&&this.setMany(t)}get root(){return this._root}createNode(t,e,i="BLACK"){return new vt(t,e,i)}isNode(t){return t instanceof vt}clear(){super.clear(),this._root=this.NIL,this._header.parent=this.NIL,this._setMinCache(void 0),this._setMaxCache(void 0)}_findNodeByKey(t){var e,i,s;let r=this.NIL,n=this._compare.bind(this),h=(e=this._header.parent)!=null?e:r;for(;h!==r;){let o=n(t,h.key);if(o<0)h=(i=h.left)!=null?i:r;else if(o>0)h=(s=h.right)!=null?s:r;else return h}}_predecessorOf(t){let e=this.NIL;if(t.left&&t.left!==e){let r=t.left;for(;r.right&&r.right!==e;)r=r.right;return r}let i=t,s=t.parent;for(;s&&i===s.left;)i=s,s=s.parent;return s}_successorOf(t){let e=this.NIL;if(t.right&&t.right!==e){let r=t.right;for(;r.left&&r.left!==e;)r=r.left;return r}let i=t,s=t.parent;for(;s&&i===s.right;)i=s,s=s.parent;return s}_attachNewNode(t,e,i){let s=this.NIL;i.parent=t,e==="left"?t.left=i:t.right=i,i.left=s,i.right=s,i.color="RED",this._updateCountAlongPath(i),this._insertFixup(i),this.isRealNode(this._root)&&(this._root.color="BLACK")}_setMinCache(t){this._minNode=t,this._header._left=t!=null?t:this.NIL}_setMaxCache(t){this._maxNode=t,this._header._right=t!=null?t:this.NIL}_setKVNode(t,e){var i,s,r,n,h,o,a;let l=this.NIL,_=this._comparator,g=this._header,p=(i=g._left)!=null?i:l;if(p!==l){let I=_(t,p.key);if(I===0)return p.value=e,this._isMapMode&&this._store.set(t,p),{node:p,created:!1};let T=p.left;if(I<0&&(T===l||T===null||T===void 0)){let B=this.createNode(t,e);return this._attachNewNode(p,"left",B),this._isMapMode&&this._store.set(B.key,B),this._size++,this._setMinCache(B),g._right===l&&this._setMaxCache(B),{node:B,created:!0}}if(I>0){let B=(s=g._right)!=null?s:l,Nt=_(t,B.key);if(Nt===0)return B.value=e,this._isMapMode&&this._store.set(t,B),{node:B,created:!1};let _t=B.right;if(Nt>0&&(_t===l||_t===null||_t===void 0)){let j=this.createNode(t,e);return this._attachNewNode(B,"right",j),this._isMapMode&&this._store.set(j.key,j),this._size++,this._setMaxCache(j),g._left===l&&this._setMinCache(j),{node:j,created:!0}}}}let v=_,w=this._isMapMode,b=this._store,M=(r=this._header.parent)!=null?r:l,y,N=0;for(;M!==l;)if(y=M,N=v(t,M.key),N<0)M=(n=M.left)!=null?n:l;else if(N>0)M=(h=M.right)!=null?h:l;else return M.value=e,w&&b.set(t,M),{node:M,created:!1};let m=this.createNode(t,e);if(m.parent=y,y?N<0?y.left=m:y.right=m:this._setRoot(m),m.left=l,m.right=l,m.color="RED",this._updateCountAlongPath(m),this._insertFixup(m),this.isRealNode(this._root))this._root.color="BLACK";else return;w&&b.set(m.key,m),this._size++;let k=(o=this._header._left)!=null?o:l,E=(a=this._header._right)!=null?a:l;return k===l||E===l?(this._setMinCache(m),this._setMaxCache(m)):y===E&&N>0?this._setMaxCache(m):y===k&&N<0?this._setMinCache(m):(v(m.key,k.key)<0&&this._setMinCache(m),v(m.key,E.key)>0&&this._setMaxCache(m)),{node:m,created:!0}}_setKV(t,e){if(this._isMapMode){let s=this._store.get(t);if(s)return s.value=e,!0}return this._setKVNode(t,e)!==void 0}setWithHintNode(t,e,i){var s,r,n,h,o,a,l,_,g,p,v,w,b;if(!i||!this.isRealNode(i))return(s=this._setKVNode(t,e))==null?void 0:s.node;let M=this._compare.bind(this),y=M(t,i.key);if(y===0)return i.value=e,this._isMapMode&&this._store.set(t,i),i;if(y<0){if(!this.isRealNode(i.left)){let k=this.createNode(t,e);if(!this.isRealNode(k))return;this._attachNewNode(i,"left",k),this._isMapMode&&this._store.set(t,k),this._size++;let E=this.NIL,I=(r=this._header._left)!=null?r:E;(I===E||this._compare(k.key,I.key)<0)&&this._setMinCache(k);let T=(n=this._header._right)!=null?n:E;return(T===E||this._compare(k.key,T.key)>0)&&this._setMaxCache(k),k}let m=this._predecessorOf(i);if(m&&M(m.key,t)>=0)return(h=this._setKVNode(t,e))==null?void 0:h.node;if(m&&!this.isRealNode(m.right)){let k=this.createNode(t,e);if(!this.isRealNode(k))return;this._attachNewNode(m,"right",k),this._isMapMode&&this._store.set(t,k),this._size++;let E=this.NIL,I=(o=this._header._left)!=null?o:E;(I===E||this._compare(k.key,I.key)<0)&&this._setMinCache(k);let T=(a=this._header._right)!=null?a:E;return(T===E||this._compare(k.key,T.key)>0)&&this._setMaxCache(k),k}return(l=this._setKVNode(t,e))==null?void 0:l.node}if(!this.isRealNode(i.right)){let m=this.createNode(t,e);if(!this.isRealNode(m))return;this._attachNewNode(i,"right",m),this._isMapMode&&this._store.set(t,m),this._size++;let k=this.NIL,E=(_=this._header._left)!=null?_:k;(E===k||this._compare(m.key,E.key)<0)&&this._setMinCache(m);let I=(g=this._header._right)!=null?g:k;return(I===k||this._compare(m.key,I.key)>0)&&this._setMaxCache(m),m}let N=this._successorOf(i);if(N&&M(N.key,t)<=0)return(p=this._setKVNode(t,e))==null?void 0:p.node;if(N&&!this.isRealNode(N.left)){let m=this.createNode(t,e);if(!this.isRealNode(m))return;this._attachNewNode(N,"left",m),this._isMapMode&&this._store.set(t,m),this._size++;let k=this.NIL,E=(v=this._header._left)!=null?v:k;(E===k||this._compare(m.key,E.key)<0)&&this._setMinCache(m);let I=(w=this._header._right)!=null?w:k;return(I===k||this._compare(m.key,I.key)>0)&&this._setMaxCache(m),m}return(b=this._setKVNode(t,e))==null?void 0:b.node}setWithHint(t,e,i){return this.setWithHintNode(t,e,i)!==void 0}set(t,e){if(!this.isNode(t)){if(t==null)return!1;if(this.isEntry(t)){let n=t[0];if(n==null)return!1;let h=e!=null?e:t[1];return this._setKV(n,h)}return this._setKV(t,e)}let[i,s]=this._keyValueNodeOrEntryToNodeAndValue(t,e);if(!this.isRealNode(i))return!1;let r=this._insert(i);if(r==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;if(this._isMapMode){let n=this.getNode(i.key);this.isRealNode(n)&&(n.value=s,this._store.set(n.key,n))}return this._size++,!0}if(r==="UPDATED"){if(this._isMapMode){let n=this.getNode(i.key);this.isRealNode(n)&&(n.value=s,this._store.set(n.key,n))}return!0}return!1}delete(t){var e,i,s;if(t===null)return!1;let r;if(this._isPredicate(t)?r=this.getNode(t):r=this.isRealNode(t)?t:this.getNode(t),!r)return!1;let n=r===this._minNode,h=r===this._maxNode,o=n?this._successorOf(r):void 0,a=h?this._predecessorOf(r):void 0,l=r.color,_=this.NIL,g=_;if(!this.isRealNode(r.left))g=(e=r.right)!=null?e:_,this._transplant(r,g);else if(!this.isRealNode(r.right))g=r.left,this._transplant(r,g);else{let p=this.getLeftMost(v=>v,r.right);p&&(l=p.color,g=(i=p.right)!=null?i:_,p.parent===r?g.parent=p:(this._transplant(p,g),p.right=r.right,p.right&&(p.right.parent=p)),this._transplant(r,p),p.left=r.left,p.left&&(p.left.parent=p),p.color=r.color)}return this._isMapMode&&this._store.delete(r.key),this._size--,this._updateCountAlongPath((s=g==null?void 0:g.parent)!=null?s:g),this._size<=0?(this._setMinCache(void 0),this._setMaxCache(void 0)):(n&&this._setMinCache(o),h&&this._setMaxCache(a),(!this._minNode||!this.isRealNode(this._minNode))&&this._setMinCache(this.isRealNode(this._root)?this.getLeftMost(p=>p,this._root):void 0),(!this._maxNode||!this.isRealNode(this._maxNode))&&this._setMaxCache(this.isRealNode(this._root)?this.getRightMost(p=>p,this._root):void 0)),l==="BLACK"&&this._deleteFixup(g),!0}perfectlyBalance(t){let e=[];for(let[i,s]of this)e.push([i,s]);return e.length<=1||(this.clear(),this.setMany(e.map(([i])=>i),e.map(([,i])=>i),!0)),!0}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_setRoot(t){let e=this.NIL;t&&(t.parent=void 0),this._root=t,this._header.parent=t!=null?t:e}_replaceNode(t,e){return e.color=t.color,super._replaceNode(t,e)}_insert(t){var e,i,s;let r=this.NIL,n=this._compare.bind(this),h=(e=this._header.parent)!=null?e:r,o,a=0;for(;h!==r;)if(o=h,a=n(t.key,h.key),a<0)h=(i=h.left)!=null?i:r;else if(a>0)h=(s=h.right)!=null?s:r;else return this._replaceNode(h,t),"UPDATED";return t.parent=o,o?a<0?o.left=t:o.right=t:this._setRoot(t),t.left=r,t.right=r,t.color="RED",this._updateCountAlongPath(t),this._insertFixup(t),"CREATED"}_transplant(t,e){t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this._setRoot(e),e&&(e.parent=t.parent)}_insertFixup(t){let e=this._leftRotate.bind(this),i=this._rightRotate.bind(this);for(;t;){let s=t.parent;if(!s||s.color!=="RED")break;let r=s.parent;if(!r)break;if(s===r.left){let n=r.right;if((n==null?void 0:n.color)==="RED"){s.color="BLACK",n.color="BLACK",r.color="RED",t=r;continue}t===s.right&&(t=s,e(t));let h=t==null?void 0:t.parent,o=h==null?void 0:h.parent;h&&o&&(h.color="BLACK",o.color="RED",i(o))}else{let n=r.left;if((n==null?void 0:n.color)==="RED"){s.color="BLACK",n.color="BLACK",r.color="RED",t=r;continue}t===s.left&&(t=s,i(t));let h=t==null?void 0:t.parent,o=h==null?void 0:h.parent;h&&o&&(h.color="BLACK",o.color="RED",e(o))}break}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(t){if(!t)return;let e=this.NIL,i=t;for(;i!==this.root&&i.color==="BLACK";){let s=i.parent;if(!s)break;let r=i===s.left,n=r?s.right:s.left;n&&n.color==="RED"&&(n.color="BLACK",s.color="RED",r?(this._leftRotate(s),n=s.right):(this._rightRotate(s),n=s.left));let h=n==null?void 0:n.left,o=n==null?void 0:n.right,a=!h||h===e||h.color==="BLACK",l=!o||o===e||o.color==="BLACK";a&&l?(n&&(n.color="RED"),i=s):(r?(l&&(h&&(h.color="BLACK"),n&&(n.color="RED"),n&&this._rightRotate(n),n=s.right),n&&(n.color=s.color),s.color="BLACK",n!=null&&n.right&&(n.right.color="BLACK"),this._leftRotate(s)):(a&&(o&&(o.color="BLACK"),n&&(n.color="RED"),n&&this._leftRotate(n),n=s.left),n&&(n.color=s.color),s.color="BLACK",n!=null&&n.left&&(n.left.color="BLACK"),this._rightRotate(s)),i=this.root)}i.color="BLACK"}_leftRotate(t){if(!t||!t.right)return;let e=t.right;t.right=e.left,e.left&&e.left!==this.NIL&&(e.left.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this._setRoot(e),e.left=t,t.parent=e,this._updateCount(t),this._updateCount(e)}_rightRotate(t){if(!t||!t.left)return;let e=t.left;t.left=e.right,e.right&&e.right!==this.NIL&&(e.right.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this._setRoot(e),e.right=t,t.parent=e,this._updateCount(t),this._updateCount(e)}};u(we,"RedBlackTree");var ft=we,S,P,Q,Re=class X{constructor(t=[],e={}){V(this,S),V(this,P),V(this,Q);var i;K(this,Q,e.comparator);let s=e.toElementFn,r=(i=e.comparator)!=null?i:X.createDefaultComparator();K(this,P,e.comparator===void 0),K(this,S,new ft([],{comparator:r,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t){let h=s?s(n):n;this.add(h)}}static createDefaultComparator(){return(t,e)=>{if(typeof t=="number"&&typeof e=="number"){(Number.isNaN(t)||Number.isNaN(e))&&x(TypeError,R.invalidNaN("TreeSet"));let i=Object.is(t,-0)?0:t,s=Object.is(e,-0)?0:e;return i>s?1:i<s?-1:0}if(typeof t=="string"&&typeof e=="string")return t>e?1:t<e?-1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&x(TypeError,R.invalidDate("TreeSet")),i>s?1:i<s?-1:0}x(TypeError,R.comparatorRequired("TreeSet"))}}get size(){return d(this,S).size}isEmpty(){return this.size===0}_validateKey(t){if(d(this,P)){if(typeof t=="number"){Number.isNaN(t)&&x(TypeError,R.invalidNaN("TreeSet"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&x(TypeError,R.invalidDate("TreeSet"));return}x(TypeError,R.comparatorRequired("TreeSet"))}}}add(t){return this._validateKey(t),d(this,S).set(t,void 0),this}addMany(t){let e=[];for(let i of t)this._validateKey(i),e.push(d(this,S).set(i,void 0));return e}has(t){return this._validateKey(t),d(this,S).has(t)}delete(t){return this._validateKey(t),d(this,S).delete(t)}deleteWhere(t){let e=!1,i=0;for(let s of this)t(s,i++,this)&&(this.delete(s),e=!0);return e}clear(){d(this,S).clear()}keys(){return d(this,S).keys()}values(){return this.keys()}*entries(){for(let t of this.keys())yield[t,t]}[Symbol.iterator](){return this.keys()}forEach(t,e){for(let i of this)t.call(e,i,i,this)}map(t,e={},i){let s=new X([],e),r=0;for(let n of this){let h=i===void 0?t(n,r++,this):t.call(i,n,r++,this);s.add(h)}return s}filter(t,e){let i=new X([],{comparator:d(this,Q)}),s=0;for(let r of this)(e===void 0?t(r,s++,this):t.call(e,r,s++,this))&&i.add(r);return i}reduce(t,e){let i=e,s=0;for(let r of this)i=t(i,r,s++,this);return i}every(t,e){let i=0;for(let s of this)if(!(e===void 0?t(s,i++,this):t.call(e,s,i++,this)))return!1;return!0}some(t,e){let i=0;for(let s of this)if(e===void 0?t(s,i++,this):t.call(e,s,i++,this))return!0;return!1}find(t,e){let i=0;for(let s of this)if(e===void 0?t(s,i++,this):t.call(e,s,i++,this))return s}toArray(){return[...this]}print(){d(this,S).print()}first(){return d(this,S).getLeftMost()}last(){return d(this,S).getRightMost()}pollFirst(){let t=this.first();if(t!==void 0)return this.delete(t),t}pollLast(){let t=this.last();if(t!==void 0)return this.delete(t),t}ceiling(t){return this._validateKey(t),d(this,S).ceiling(t)}floor(t){return this._validateKey(t),d(this,S).floor(t)}higher(t){return this._validateKey(t),d(this,S).higher(t)}lower(t){return this._validateKey(t),d(this,S).lower(t)}rangeSearch(t,e={}){let{lowInclusive:i=!0,highInclusive:s=!0}=e,[r,n]=t;this._validateKey(r),this._validateKey(n);let h=d(this,S).rangeSearch([r,n]),o=[],a=d(this,S).comparator;for(let l of h)l!==void 0&&(!i&&a(l,r)===0||!s&&a(l,n)===0||o.push(l));return o}getByRank(t){return d(this,S).getByRank(t)}getRank(t){return d(this,S).getRank(t)}rangeByRank(t,e){return d(this,S).rangeByRank(t,e).filter(i=>i!==void 0)}clone(){return new X(this,{comparator:d(this,P)?void 0:d(this,Q),isMapMode:d(this,S).isMapMode})}};S=new WeakMap;P=new WeakMap;Q=new WeakMap;u(Re,"TreeSet");var Ne=Re,L,nt,Ee=class ht{constructor(t=[],e={}){V(this,L),V(this,nt);var i;let s=(i=e.comparator)!=null?i:Ne.createDefaultComparator();K(this,nt,e.comparator===void 0);let r=e.toEntryFn;K(this,L,new ft([],{...e,comparator:s,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t)if(n!=null){if(r){let[h,o]=r(n);if(h==null)continue;o!==void 0?d(this,L).set(h,Array.isArray(o)?[...o]:[o]):d(this,L).set(h,[]);continue}if(Array.isArray(n)){let[h,o]=n;if(h==null)continue;o!==void 0?d(this,L).set(h,[...o]):d(this,L).set(h,[]);continue}d(this,L).set(n,[])}}_validateKey(t){if(d(this,nt)){if(typeof t=="number"){Number.isNaN(t)&&x(TypeError,R.invalidNaN("TreeMultiMap"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&x(TypeError,R.invalidDate("TreeMultiMap"));return}x(TypeError,R.comparatorRequired("TreeMultiMap"))}}}get size(){return d(this,L).size}isEmpty(){return this.size===0}clear(){d(this,L).clear()}count(t){let e=this.get(t);return Array.isArray(e)?e.length:0}get totalSize(){let t=0;for(let[,e]of this)t+=e.length;return t}has(t){return this._validateKey(t),d(this,L).has(t)}get(t){return this._validateKey(t),d(this,L).get(t)}add(t,e){this._validateKey(t);let i=d(this,L).get(t);return i?(i.push(e),!0):d(this,L).set(t,[e])}set(t,e){if(t==null)return!1;if(Array.isArray(t)){let[i,s]=t;if(i==null)return!1;if(e!==void 0)return this.add(i,e);if(s===void 0)return d(this,L).set(i,[]);let r=d(this,L).get(i);return r?(r.push(...s),!0):d(this,L).set(i,[...s])}return e!==void 0?this.add(t,e):d(this,L).set(t,[])}delete(t){return this._validateKey(t),d(this,L).delete(t)}hasEntry(t,e,i=Object.is){let s=this.get(t);return Array.isArray(s)?s.some(r=>i(r,e)):!1}deleteValue(t,e,i=Object.is){let s=this.get(t);if(!Array.isArray(s))return!1;let r=s.findIndex(n=>i(n,e));return r===-1?!1:(s.splice(r,1),s.length===0&&this.delete(t),!0)}deleteValues(t,e,i=Object.is){let s=this.get(t);if(!Array.isArray(s)||s.length===0)return 0;let r=0;for(let n=s.length-1;n>=0;n--)i(s[n],e)&&(s.splice(n,1),r++);return s.length===0&&r>0&&this.delete(t),r}*[Symbol.iterator](){for(let[t,e]of d(this,L))yield[t,e!=null?e:[]]}*keys(){yield*d(this,L).keys()}*values(){for(let[,t]of this)yield t}*entriesOf(t){let e=this.get(t);if(Array.isArray(e))for(let i of e)yield[t,i]}*valuesOf(t){let e=this.get(t);Array.isArray(e)&&(yield*e)}*flatEntries(){for(let[t,e]of this)for(let i of e)yield[t,i]}first(){let t=d(this,L).getLeftMost();if(t===void 0)return;let e=this.get(t);return e===void 0?void 0:[t,e]}last(){let t=d(this,L).getRightMost();if(t===void 0)return;let e=this.get(t);return e===void 0?void 0:[t,e]}pollFirst(){let t=this.first();if(t)return this.delete(t[0]),t}pollLast(){let t=this.last();if(t)return this.delete(t[0]),t}ceiling(t){this._validateKey(t);let e=d(this,L).ceiling(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}floor(t){this._validateKey(t);let e=d(this,L).floor(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}higher(t){this._validateKey(t);let e=d(this,L).higher(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}lower(t){this._validateKey(t);let e=d(this,L).lower(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}print(){d(this,L).print()}forEach(t){for(let[e,i]of this)t(i,e,this)}filter(t){let e=[];for(let[i,s]of this)t(s,i,this)&&e.push([i,s]);return new ht(e,{comparator:this.comparator})}map(t){let e=[];for(let[i,s]of this)e.push(t(s,i,this));return new ht(e,{comparator:this.comparator})}reduce(t,e){let i=e;for(let[s,r]of this)i=t(i,r,s,this);return i}setMany(t){let e=[];for(let i of t)e.push(this.set(i));return e}rangeSearch(t,e){return d(this,L).rangeSearch(t,e)}getByRank(t){var e;let i=d(this,L).getByRank(t);if(i!==void 0)return[i,(e=d(this,L).get(i))!=null?e:[]]}getRank(t){return d(this,L).getRank(t)}rangeByRank(t,e){return d(this,L).rangeByRank(t,e).filter(s=>s!==void 0).map(s=>{var r;return[s,(r=d(this,L).get(s))!=null?r:[]]})}clone(){return new ht(this,{comparator:this.comparator,isMapMode:d(this,L).isMapMode})}get comparator(){return d(this,L).comparator}};L=new WeakMap;nt=new WeakMap;u(Ee,"TreeMultiMap");var Le=Ee,C,J,Y,di=class Z{constructor(t=[],e={}){V(this,C),V(this,J),V(this,Y);var i;K(this,Y,e.comparator);let s=e.toEntryFn,r=(i=e.comparator)!=null?i:Z.createDefaultComparator();K(this,J,e.comparator===void 0),K(this,C,new ft([],{comparator:r,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t){let h,o;s?[h,o]=s(n):((!Array.isArray(n)||n.length<2)&&x(TypeError,R.invalidEntry("TreeMap")),h=n[0],o=n[1]),this.set(h,o)}}static createDefaultComparator(){return(t,e)=>{if(typeof t=="number"&&typeof e=="number"){(Number.isNaN(t)||Number.isNaN(e))&&x(TypeError,R.invalidNaN("TreeMap"));let i=Object.is(t,-0)?0:t,s=Object.is(e,-0)?0:e;return i>s?1:i<s?-1:0}if(typeof t=="string"&&typeof e=="string")return t>e?1:t<e?-1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&x(TypeError,R.invalidDate("TreeMap")),i>s?1:i<s?-1:0}x(TypeError,R.comparatorRequired("TreeMap"))}}_validateKey(t){if(d(this,J)){if(typeof t=="number"){Number.isNaN(t)&&x(TypeError,R.invalidNaN("TreeMap"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&x(TypeError,R.invalidDate("TreeMap"));return}x(TypeError,R.comparatorRequired("TreeMap"))}}}get size(){return d(this,C).size}isEmpty(){return this.size===0}set(t,e){return this._validateKey(t),d(this,C).set(t,e),this}setMany(t){let e=[];for(let[i,s]of t)this._validateKey(i),e.push(d(this,C).set(i,s));return e}get(t){return this._validateKey(t),d(this,C).get(t)}has(t){return this._validateKey(t),d(this,C).has(t)}delete(t){return this._validateKey(t),d(this,C).delete(t)}deleteWhere(t){let e=!1,i=0;for(let[s,r]of this)t(s,r,i++,this)&&(this.delete(s),e=!0);return e}clear(){d(this,C).clear()}keys(){return d(this,C).keys()}_entryFromKey(t){return[t,d(this,C).get(t)]}*values(){for(let t of this.keys())yield this._entryFromKey(t)[1]}*entries(){for(let t of this.keys())yield this._entryFromKey(t)}[Symbol.iterator](){return this.entries()}forEach(t,e){for(let[i,s]of this)t.call(e,s,i,this)}map(t,e={},i){let s=new Z([],e),r=0;for(let[n,h]of this){let[o,a]=i===void 0?t(h,n,r++,this):t.call(i,h,n,r++,this);s.set(o,a)}return s}filter(t,e){let i=new Z([],{comparator:d(this,Y)}),s=0;for(let[r,n]of this)(e===void 0?t(n,r,s++,this):t.call(e,n,r,s++,this))&&i.set(r,n);return i}reduce(t,e){let i=e,s=0;for(let[r,n]of this)i=t(i,n,r,s++,this);return i}every(t,e){let i=0;for(let[s,r]of this)if(!(e===void 0?t(r,s,i++,this):t.call(e,r,s,i++,this)))return!1;return!0}some(t,e){let i=0;for(let[s,r]of this)if(e===void 0?t(r,s,i++,this):t.call(e,r,s,i++,this))return!0;return!1}find(t,e){let i=0;for(let[s,r]of this)if(e===void 0?t(r,s,i++,this):t.call(e,r,s,i++,this))return[s,r]}toArray(){return[...this]}print(){d(this,C).print()}first(){let t=d(this,C).getLeftMost();return t===void 0?void 0:this._entryFromKey(t)}last(){let t=d(this,C).getRightMost();return t===void 0?void 0:this._entryFromKey(t)}pollFirst(){let t=this.first();if(t)return this.delete(t[0]),t}pollLast(){let t=this.last();if(t)return this.delete(t[0]),t}ceiling(t){this._validateKey(t);let e=d(this,C).ceiling(t);return e===void 0?void 0:this._entryFromKey(e)}floor(t){this._validateKey(t);let e=d(this,C).floor(t);return e===void 0?void 0:this._entryFromKey(e)}higher(t){this._validateKey(t);let e=d(this,C).higher(t);return e===void 0?void 0:this._entryFromKey(e)}lower(t){this._validateKey(t);let e=d(this,C).lower(t);return e===void 0?void 0:this._entryFromKey(e)}rangeSearch(t,e={}){let{lowInclusive:i=!0,highInclusive:s=!0}=e,[r,n]=t;this._validateKey(r),this._validateKey(n);let h=d(this,C).rangeSearch([r,n]),o=[],a=d(this,C).comparator;for(let l of h)l!==void 0&&(!i&&a(l,r)===0||!s&&a(l,n)===0||o.push(this._entryFromKey(l)));return o}getByRank(t){let e=d(this,C).getByRank(t);if(e!==void 0)return[e,d(this,C).get(e)]}getRank(t){return d(this,C).getRank(t)}rangeByRank(t,e){return d(this,C).rangeByRank(t,e).filter(s=>s!==void 0).map(s=>[s,d(this,C).get(s)])}clone(){return new Z(this,{comparator:d(this,J)?void 0:d(this,Y),isMapMode:d(this,C).isMapMode})}};C=new WeakMap;J=new WeakMap;Y=new WeakMap;u(di,"TreeMap");var F,U,gi=class ot{constructor(t=[],e={}){V(this,F),V(this,U),f(this,"_size",0);var i;let s=e.toElementFn,r=(i=e.comparator)!=null?i:Ne.createDefaultComparator();K(this,U,e.comparator===void 0),K(this,F,new ft([],{comparator:r,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t){let h=s?s(n):n;this.add(h)}}_validateKey(t){if(d(this,U)){if(typeof t=="number"){Number.isNaN(t)&&x(TypeError,R.invalidNaN("TreeMultiSet"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&x(TypeError,R.invalidDate("TreeMultiSet"));return}x(TypeError,R.comparatorRequired("TreeMultiSet"))}}}_validateCount(t){(!Number.isSafeInteger(t)||t<0)&&x(RangeError,R.invalidArgument("count must be a safe integer >= 0.","TreeMultiSet"))}get size(){return this._size}get distinctSize(){return d(this,F).size}isEmpty(){return this.size===0}has(t){return this._validateKey(t),this.count(t)>0}count(t){var e;return this._validateKey(t),(e=d(this,F).get(t))!=null?e:0}add(t,e=1){var i;if(this._validateKey(t),this._validateCount(e),e===0)return!1;let r=((i=d(this,F).get(t))!=null?i:0)+e;return d(this,F).set(t,r),this._size+=e,!0}setCount(t,e){var i;this._validateKey(t),this._validateCount(e);let s=(i=d(this,F).get(t))!=null?i:0;return s===e?!1:(e===0?s!==0&&d(this,F).delete(t):d(this,F).set(t,e),this._size+=e-s,!0)}delete(t,e=1){var i;if(this._validateKey(t),this._validateCount(e),e===0)return!1;let s=(i=d(this,F).get(t))!=null?i:0;if(s===0)return!1;let r=Math.min(s,e),n=s-r;return n===0?d(this,F).delete(t):d(this,F).set(t,n),this._size-=r,!0}deleteAll(t){var e;this._validateKey(t);let i=(e=d(this,F).get(t))!=null?e:0;return i===0?!1:(d(this,F).delete(t),this._size-=i,!0)}*keysDistinct(){yield*d(this,F).keys()}*entries(){for(let[t,e]of d(this,F))yield[t,e!=null?e:0]}*[Symbol.iterator](){for(let[t,e]of this.entries())for(let i=0;i<e;i++)yield t}toArray(){return[...this]}toDistinctArray(){return[...this.keysDistinct()]}toEntries(){return[...this.entries()]}get comparator(){return d(this,F).comparator}clear(){d(this,F).clear(),this._size=0}first(){return d(this,F).getLeftMost()}last(){return d(this,F).getRightMost()}pollFirst(){let t=this.first();if(t!==void 0)return this.deleteAll(t),t}pollLast(){let t=this.last();if(t!==void 0)return this.deleteAll(t),t}ceiling(t){return this._validateKey(t),d(this,F).ceiling(t)}floor(t){return this._validateKey(t),d(this,F).floor(t)}higher(t){return this._validateKey(t),d(this,F).higher(t)}lower(t){return this._validateKey(t),d(this,F).lower(t)}forEach(t){for(let[e,i]of this.entries())t(e,i)}filter(t){let e=new ot([],{comparator:d(this,U)?void 0:this.comparator,isMapMode:d(this,F).isMapMode});for(let[i,s]of this.entries())t(i,s)&&e.add(i,s);return e}reduce(t,e){let i=e;for(let[s,r]of this.entries())i=t(i,s,r);return i}map(t,e){let i=new ot([],{comparator:e==null?void 0:e.comparator,isMapMode:d(this,F).isMapMode});for(let[s,r]of this.entries()){let[n,h]=t(s,r);i.add(n,h)}return i}getByRank(t){return d(this,F).getByRank(t)}getRank(t){return d(this,F).getRank(t)}rangeByRank(t,e){return d(this,F).rangeByRank(t,e).filter(i=>i!==void 0)}clone(){let t=new ot([],{comparator:d(this,U)?void 0:this.comparator,isMapMode:d(this,F).isMapMode});for(let[e,i]of this.entries())t.add(e,i);return t}rangeSearch(t,e){let i=e!=null?e:(s=>s);return d(this,F).rangeSearch(t,s=>i(s.key))}print(){d(this,F).print()}};F=new WeakMap;U=new WeakMap;u(gi,"TreeMultiSet");var Fe=class extends ct{constructor(t=[],e){super(t,e)}};u(Fe,"PriorityQueue");var Ie=Fe,pi=class extends Ie{constructor(t=[],e){super(t,e)}};u(pi,"MinPriorityQueue");var vi=class extends Ie{constructor(t=[],e){super(t,{comparator:u((i,s)=>((typeof i=="object"||typeof s=="object")&&x(TypeError,R.comparatorRequired("MaxPriorityQueue")),i<s?1:i>s?-1:0),"comparator"),...e})}};u(vi,"MaxPriorityQueue");var mi=class D{constructor(t,e){f(this,"_rows",0),f(this,"_cols",0),f(this,"_data");var i,s,r;if(e){let{rows:n,cols:h,addFn:o,subtractFn:a,multiplyFn:l}=e;typeof n=="number"&&n>0?this._rows=n:this._rows=t.length,typeof h=="number"&&h>0?this._cols=h:this._cols=((i=t[0])==null?void 0:i.length)||0,o&&(this._addFn=o),a&&(this._subtractFn=a),l&&(this._multiplyFn=l)}else this._rows=t.length,this._cols=(r=(s=t[0])==null?void 0:s.length)!=null?r:0;if(t.length>0)this._data=t;else{this._data=[];for(let n=0;n<this.rows;n++)this._data[n]=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(t,e){if(this.isValidIndex(t,e))return this.data[t][e]}set(t,e,i){return this.isValidIndex(t,e)?(this.data[t][e]=i,!0):!1}isMatchForCalculate(t){return this.rows===t.rows&&this.cols===t.cols}add(t){var e;this.isMatchForCalculate(t)||x(Error,R.matrixDimensionMismatch("addition"));let i=[];for(let s=0;s<this.rows;s++){i[s]=[];for(let r=0;r<this.cols;r++){let n=this.get(s,r),h=t.get(s,r);n!==void 0&&h!==void 0&&(i[s][r]=(e=this._addFn(n,h))!=null?e:0)}}return new D(i,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(t){var e;this.isMatchForCalculate(t)||x(Error,R.matrixDimensionMismatch("subtraction"));let i=[];for(let s=0;s<this.rows;s++){i[s]=[];for(let r=0;r<this.cols;r++){let n=this.get(s,r),h=t.get(s,r);n!==void 0&&h!==void 0&&(i[s][r]=(e=this._subtractFn(n,h))!=null?e:0)}}return new D(i,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(t){this.cols!==t.rows&&x(Error,R.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));let e=[];for(let i=0;i<this.rows;i++){e[i]=[];for(let s=0;s<t.cols;s++){let r;for(let n=0;n<this.cols;n++){let h=this.get(i,n),o=t.get(n,s);if(h!==void 0&&o!==void 0){let a=this.multiplyFn(h,o);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[i][s]=r)}}return new D(e,{rows:this.rows,cols:t.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){this.data.some(e=>e.length!==this.cols)&&x(Error,R.matrixNotRectangular());let t=[];for(let e=0;e<this.cols;e++){t[e]=[];for(let i=0;i<this.rows;i++){let s=this.get(i,e);s!==void 0&&(t[e][i]=s)}}return new D(t,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var t;this.rows!==this.cols&&x(Error,R.matrixNotSquare());let e=[];for(let r=0;r<this.rows;r++){e[r]=this.data[r].slice();for(let n=0;n<this.cols;n++)e[r][this.cols+n]=r===n?1:0}let i=new D(e,{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 n=r;for(;n<this.rows&&i.get(n,r)===0;)n++;n===this.rows&&x(Error,R.matrixSingular()),i._swapRows(r,n);let h=(t=i.get(r,r))!=null?t:1;h===0&&x(Error,R.matrixSingular()),i._scaleRow(r,1/h);for(let o=0;o<this.rows;o++)if(o!==r){let a=i.get(o,r);a===void 0&&(a=0),i._addScaledRow(o,r,-a)}}let s=[];for(let r=0;r<this.rows;r++)s[r]=i.data[r].slice(this.cols);return new D(s,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(t){this.cols!==t.rows&&x(Error,R.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));let e=[];for(let i=0;i<this.rows;i++){e[i]=[];for(let s=0;s<t.cols;s++){let r;for(let n=0;n<this.cols;n++){let h=this.get(i,n),o=t.get(n,s);if(h!==void 0&&o!==void 0){let a=this.multiplyFn(h,o);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[i][s]=r)}}return new D(e,{rows:this.rows,cols:t.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(t,e){return t>=0&&t<this.rows&&e>=0&&e<this.cols}clone(){return new D(this._data.map(t=>[...t]),{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}get size(){return[this._rows,this._cols]}isEmpty(){return this._rows===0||this._cols===0}toArray(){return this._data.map(t=>[...t])}flatten(){let t=[];for(let e of this._data)for(let i of e)t.push(i);return t}[Symbol.iterator](){let t=this._data,e=0;return{[Symbol.iterator](){return this},next(){return e<t.length?{value:[...t[e++]],done:!1}:{value:void 0,done:!0}}}}forEach(t){for(let e=0;e<this._rows;e++)for(let i=0;i<this._cols;i++)t(this._data[e][i],e,i)}map(t){let e=[];for(let i=0;i<this._rows;i++){e[i]=[];for(let s=0;s<this._cols;s++)e[i][s]=t(this._data[i][s],i,s)}return new D(e,{rows:this._rows,cols:this._cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}print(){for(let t of this._data)console.log(t.join(" "))}static zeros(t,e){let i=Array.from({length:t},()=>new Array(e).fill(0));return new D(i)}static identity(t){let e=Array.from({length:t},(i,s)=>Array.from({length:t},(r,n)=>s===n?1:0));return new D(e)}static from(t){return new D(t.map(e=>[...e]))}_addFn(t,e){return t===void 0?e:t+e}_subtractFn(t,e){return t-e}_multiplyFn(t,e){return t*e}_swapRows(t,e){let i=this.data[t];this.data[t]=this.data[e],this.data[e]=i}_scaleRow(t,e){for(let i=0;i<this.cols;i++){let s=this.multiplyFn(this.data[t][i],e);s===void 0&&(s=0),this.data[t][i]=s}}_addScaledRow(t,e,i){for(let s=0;s<this.cols;s++){let r=this.multiplyFn(this.data[e][s],i);r===void 0&&(r=0);let n=r,h=this.addFn(this.data[t][s],n);h===void 0&&(h=0),this.data[t][s]=h}}};u(mi,"Matrix");var Ce=class Se{constructor(t,e){f(this,"direction"),f(this,"turn"),this.direction=t,this.turn=()=>new Se(e[t],e)}};u(Ce,"Character");var yi=Ce,Mi=class{constructor({matrix:t,turning:e,onMove:i,init:{cur:s,charDir:r,VISITED:n}}){f(this,"onMove"),f(this,"_matrix"),f(this,"_cur"),f(this,"_character"),f(this,"_VISITED"),this._matrix=t,this._cur=s,this._character=new yi(r,e),this.onMove=i,this.onMove&&this.onMove(this._cur),this._VISITED=n,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:t}=this._character;this.check(t)?this.move(t):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(t){let e,i,s=this._matrix,[r,n]=this._cur;switch(t){case"up":if(i=s[r-1],!i)return!1;e=i[n];break;case"right":e=s[r][n+1];break;case"down":if(i=s[r+1],!i)return!1;e=i[n];break;case"left":e=s[r][n-1];break}return e!==void 0&&e!==this._VISITED}move(t){switch(t){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,i]=this._cur;this._matrix[e][i]=this._VISITED,this.onMove&&this.onMove(this._cur)}};u(Mi,"Navigator");var Te=class{constructor(t){f(this,"_key"),f(this,"_children"),f(this,"_isEnd"),this._key=t,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(t){this._key=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}};u(Te,"TrieNode");var mt=Te,bi=class extends ut{constructor(t=[],e){if(super(e),f(this,"_size",0),f(this,"_caseSensitive",!0),f(this,"_root",new mt("")),e){let{caseSensitive:i}=e;i!==void 0&&(this._caseSensitive=i)}t&&this.addMany(t)}get size(){return this._size}get caseSensitive(){return this._caseSensitive}get root(){return this._root}get _total(){return this._size}add(t){t=this._caseProcess(t);let e=this.root,i=!1;for(let s of t){let r=e.children.get(s);r||(r=new mt(s),e.children.set(s,r)),e=r}return e.isEnd||(i=!0,e.isEnd=!0,this._size++),i}addMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.add(this.toElementFn(i))):e.push(this.add(i));return e}has(t){t=this._caseProcess(t);let e=this.root;for(let i of t){let s=e.children.get(i);if(!s)return!1;e=s}return e.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new mt("")}delete(t){t=this._caseProcess(t);let e=!1,i=u((s,r)=>{let n=t[r],h=s.children.get(n);return h?r===t.length-1?h.isEnd?(h.children.size>0?h.isEnd=!1:s.children.delete(n),e=!0,!0):!1:i(h,r+1)&&!s.isEnd&&h.children.size===0?(s.children.delete(n),!0):!1:!1},"dfs");return i(this.root,0),e&&this._size--,e}getHeight(){let t=this.root,e=0;if(t){let i=u((s,r)=>{r>e&&(e=r);let{children:n}=s;if(n)for(let h of n.entries())i(h[1],r+1)},"bfs");i(t,0)}return e}hasPurePrefix(t){t=this._caseProcess(t);let e=this.root;for(let i of t){let s=e.children.get(i);if(!s)return!1;e=s}return!e.isEnd}hasPrefix(t){t=this._caseProcess(t);let e=this.root;for(let i of t){let s=e.children.get(i);if(!s)return!1;e=s}return!0}hasCommonPrefix(t){t=this._caseProcess(t);let e="",i=u(s=>{if(e+=s.key,e!==t&&!s.isEnd)if(s&&s.children&&s.children.size===1)i(Array.from(s.children.values())[0]);else return},"dfs");return i(this.root),e===t}getLongestCommonPrefix(){let t="",e=u(i=>{if(t+=i.key,!i.isEnd)if(i&&i.children&&i.children.size===1)e(Array.from(i.children.values())[0]);else return},"dfs");return e(this.root),t}getWords(t="",e=Number.MAX_SAFE_INTEGER,i=!1){t=this._caseProcess(t);let s=[],r=0,n=u((o,a)=>{for(let[l,_]of o.children){if(r>=e)return;n(_,a+l)}if(o.isEnd){if(r>=e)return;s.push(a),r++}},"dfs"),h=this.root;if(t)for(let o of t){let a=h.children.get(o);if(a)h=a;else return[]}return(i||h!==this.root)&&n(h,t),s}clone(){let t=this._createInstance();for(let e of this)t.add(e);return t}filter(t,e){let i=this._createInstance(),s=0;for(let r of this)t.call(e,r,s,this)&&i.add(r),s++;return i}map(t,e,i){let s=this._createLike([],e),r=0;for(let n of this){let h=i===void 0?t(n,r++,this):t.call(i,n,r++,this);typeof h!="string"&&x(TypeError,R.callbackReturnType("string",typeof h,"Trie.map")),s.add(h)}return s}mapSame(t,e){let i=this._createInstance(),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.add(n)}return i}_createInstance(t){let e=this.constructor;return new e([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive,...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_spawnLike(t){return this._createLike([],t)}*_getIterator(){function*t(e,i){e.isEnd&&(yield i);for(let[s,r]of e.children)yield*t(r,i+s)}u(t,"_dfs"),yield*t(this.root,"")}_caseProcess(t){return this._caseSensitive||(t=t.toLowerCase()),t}};u(bi,"Trie");var ki=class Ae{constructor(t,e,i){f(this,"_key"),f(this,"_value"),f(this,"_children"),this._key=t,this._value=e||void 0,i&&(this._children=i)}get key(){return this._key}set key(t){this._key=t}get value(){return this._value}set value(t){this._value=t}get children(){return this._children}set children(t){this._children=t}addChildren(t){this._children||(this._children=[]),t instanceof Ae?this._children.push(t):this._children=this._children.concat(t)}getHeight(){let t=0;if(this){let e=u((i,s)=>{s>t&&(t=s);let{_children:r}=i;if(r)for(let n=0,h=r.length;n<h;n++)e(r[n],s+1)},"bfs");e(this,0)}return t}};u(ki,"TreeNode");return je(xi);})();
7
+ `;s+=o},"display")(t)),s}print(t,e=this._root){console.log(this.toVisual(e,t))}_dfs(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=!1,s=this._root,r=this.iterationType,n=!1,h=_=>!!_,o=_=>!!_,a=_=>n?this.isRealNodeOrNull(_):this.isRealNode(_),l=_=>this.isRealNodeOrNull(_)){if(s=this.ensureNode(s),!s)return[];let _=[];if(r==="RECURSIVE"){let g=u(p=>{if(!a(p))return;let v=u(()=>{h(p)&&(p==null?void 0:p.left)!==void 0&&g(p==null?void 0:p.left)},"visitLeft"),x=u(()=>{o(p)&&(p==null?void 0:p.right)!==void 0&&g(p==null?void 0:p.right)},"visitRight");switch(e){case"IN":if(v(),l(p)&&(_.push(t(p)),i))return;x();break;case"PRE":if(l(p)&&(_.push(t(p)),i))return;v(),x();break;case"POST":if(v(),x(),l(p)&&(_.push(t(p)),i))return;break}},"dfs");g(s)}else{let g=[{opt:0,node:s}],p=u(k=>{var M;h(k.node)&&g.push({opt:0,node:(M=k.node)==null?void 0:M.left})},"pushLeft"),v=u(k=>{var M;o(k.node)&&g.push({opt:0,node:(M=k.node)==null?void 0:M.right})},"pushRight"),x=u(k=>{a(k.node)&&g.push({opt:1,node:k.node})},"pushRoot");for(;g.length>0;){let k=g.pop();if(k!==void 0&&a(k.node))if(k.opt===1){if(l(k.node)&&k.node!==void 0&&(_.push(t(k.node)),i))return _}else switch(e){case"IN":v(k),x(k),p(k);break;case"PRE":v(k),p(k),x(k);break;case"POST":x(k),v(k),p(k);break}}}return _}*_getIterator(t=this._root){if(t)if(this.iterationType==="ITERATIVE"){let e=[],i=t;for(;i||e.length>0;){for(;this.isRealNode(i);)e.push(i),i=i.left;i=e.pop(),this.isRealNode(i)&&(yield[i.key,i.value],i=i.right)}}else t.left&&this.isRealNode(t)&&(yield*this[Symbol.iterator](t.left)),yield[t.key,t.value],t.right&&this.isRealNode(t)&&(yield*this[Symbol.iterator](t.right))}_snapshotOptions(){return{iterationType:this.iterationType,toEntryFn:this.toEntryFn,isMapMode:this.isMapMode,isDuplicate:this.isDuplicate}}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_keyValueNodeOrEntryToNodeAndValue(t,e){if(t===void 0)return[void 0,void 0];if(t===null)return[null,void 0];if(this.isNode(t))return[t,e];if(this.isEntry(t)){let[i,s]=t;if(i===void 0)return[void 0,void 0];if(i===null)return[null,void 0];let r=e!=null?e:s;return[this.createNode(i,r),r]}return[this.createNode(t,e),e]}_clone(t){this.bfs(e=>{e===null?t.set(null):t.set([e.key,e.value])},this._root,this.iterationType,!0)}_displayAux(t,e){let i=[["\u2500"],1,0,0],s=u(o=>({node:o,stage:0,leftLayout:i,rightLayout:i}),"newFrame"),r=[s(t)],n=i,h=u(o=>{if(r.length===0){n=o;return}let a=r[r.length-1];a.stage===1?a.leftLayout=o:a.rightLayout=o},"setChildResult");for(;r.length>0;){let o=r[r.length-1],a=o.node;if(o.stage===0){if(this._isDisplayLeaf(a,e)){r.pop();let l=this._resolveDisplayLeaf(a,e,i);h(l);continue}o.stage=1,r.push(s(a.left))}else if(o.stage===1)o.stage=2,r.push(s(a.right));else{r.pop();let l=this.isNIL(a)?"S":String(a.key),_=rt._buildNodeDisplay(l,l.length,o.leftLayout,o.rightLayout);h(_)}}return n}static _buildNodeDisplay(t,e,i,s){let[r,n,h,o]=i,[a,l,_,g]=s,p=" ".repeat(Math.max(0,o+1))+"_".repeat(Math.max(0,n-o-1))+t+"_".repeat(Math.max(0,g))+" ".repeat(Math.max(0,l-g)),v=(h>0?" ".repeat(o)+"/"+" ".repeat(n-o-1):" ".repeat(n))+" ".repeat(e)+(_>0?" ".repeat(g)+"\\"+" ".repeat(l-g-1):" ".repeat(l)),x=[p,v];for(let k=0;k<Math.max(h,_);k++){let M=k<h?r[k]:" ".repeat(n),y=k<_?a[k]:" ".repeat(l);x.push(M+" ".repeat(e)+y)}return[x,n+e+l,Math.max(h,_)+2,n+Math.floor(e/2)]}_isDisplayLeaf(t,e){let{isShowNull:i,isShowUndefined:s,isShowRedBlackNIL:r}=e;if(t===null&&!i||t===void 0&&!s||this.isNIL(t)&&!r||t==null)return!0;let n=this._hasDisplayableChild(t.left,e),h=this._hasDisplayableChild(t.right,e);return!n&&!h}_hasDisplayableChild(t,e){return t===null?!!e.isShowNull:t===void 0?!!e.isShowUndefined:this.isNIL(t)?!!e.isShowRedBlackNIL:!0}_resolveDisplayLeaf(t,e,i){let{isShowNull:s,isShowUndefined:r,isShowRedBlackNIL:n}=e;if(t===null&&!s||t===void 0&&!r||this.isNIL(t)&&!n)return i;if(t!=null){let o=this.isNIL(t)?"S":String(t.key);return rt._buildNodeDisplay(o,o.length,i,i)}let h=t===void 0?"U":"N";return rt._buildNodeDisplay(h,h.length,[[""],1,0,0],[[""],1,0,0])}_swapProperties(t,e){if(t=this.ensureNode(t),e=this.ensureNode(e),t&&e){let{key:i,value:s}=e,r=this.createNode(i,s);return r&&(e.key=t.key,this._isMapMode||(e.value=t.value),t.key=r.key,this._isMapMode||(t.value=r.value)),e}}_replaceNode(t,e){return t.parent&&(t.parent.left===t?t.parent.left=e:t.parent.right===t&&(t.parent.right=e)),e.left=t.left,e.right=t.right,e.parent=t.parent,this._root===t&&this._setRoot(e),e}_setRoot(t){t&&(t.parent=void 0),this._root=t}_ensurePredicate(t){if(t==null)return e=>!1;if(this._isPredicate(t))return t;if(this.isRealNode(t))return e=>e===t;if(this.isEntry(t)){let[e]=t;return i=>i?i.key===e:!1}return e=>e?e.key===t:!1}_isPredicate(t){return typeof t=="function"}_extractKey(t){if(t===null)return null;if(t!==void 0&&t!==this._NIL)return this.isNode(t)?t.key:this.isEntry(t)?t[0]:t}_setValue(t,e){if(t==null)return!1;let i=this._store.get(t);return i?(i.value=e,!0):!1}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};u(ve,"BinaryTree");var ui=ve,me=class{constructor(t,e){c(this,"key"),c(this,"value"),c(this,"parent"),c(this,"_left"),c(this,"_right"),c(this,"_height",0),c(this,"_color","BLACK"),c(this,"_count",1),this.key=t,this.value=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}set count(t){this._count=t}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(me,"BSTNode");var Ft=me,ye=class extends ui{constructor(t=[],e){super([],e),c(this,"_root"),c(this,"_enableOrderStatistic",!1),c(this,"_comparator"),e?("comparator"in e&&e.comparator!==void 0?this._comparator=e.comparator:this._comparator=this._createDefaultComparator(),e.enableOrderStatistic&&(this._enableOrderStatistic=!0)):this._comparator=this._createDefaultComparator(),t&&this.setMany(t)}get root(){return this._root}get comparator(){return this._comparator}createNode(t,e){return new Ft(t,e)}ensureNode(t,e=this.iterationType){var i;return(i=super.ensureNode(t,e))!=null?i:void 0}isNode(t){return t instanceof Ft}isValidKey(t){return tt(t)}dfs(t=this._DEFAULT_NODE_CALLBACK,e="IN",i=!1,s=this._root,r=this.iterationType){return super.dfs(t,e,i,s,r)}bfs(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){return super.bfs(t,e,i,!1)}listLevels(t=this._DEFAULT_NODE_CALLBACK,e=this._root,i=this.iterationType){return super.listLevels(t,e,i,!1)}getNode(t,e=this._root,i=this.iterationType){var s,r;if(t==null)return;if(this._isPredicate(t))return(s=this.getNodes(t,!0,e,i)[0])!=null?s:void 0;if(t instanceof st)return(r=this.getNodes(t,!0,e,i)[0])!=null?r:void 0;let n;if(this.isNode(t))n=t.key;else if(this.isEntry(t)){let _=t[0];if(_==null)return;n=_}else n=t;let h=this.ensureNode(e);if(!h)return;let o=this._NIL,a=h,l=this._comparator;for(;a&&a!==o;){let _=l(n,a.key);if(_===0)return a;a=_<0?a._left:a._right}}search(t,e=!1,i=this._DEFAULT_NODE_CALLBACK,s=this._root,r=this.iterationType){if(t===void 0)return[];if(t===null)return[];if(s=this.ensureNode(s),!s)return[];let n=this.isRange(t),h=!n&&this._isPredicate(t);if(!n&&!h){let _;if(this.isNode(t))_=t.key;else if(this.isEntry(t)){let x=t[0];x!=null&&(_=x)}else _=t;if(_===void 0)return[];let g=this._NIL,p=this._comparator,v=s;for(;v&&v!==g;){let x=p(_,v.key);if(x===0)return[i(v)];v=x<0?v._left:v._right}return[]}let o;n?o=u(_=>_?t.isInRange(_.key,this._comparator):!1,"predicate"):o=this._ensurePredicate(t);let a=u(_=>{if(!_||!this.isRealNode(_.left))return!1;if(n){let g=t,p=g.low,v=g.includeLow;return v&&this._compare(_.key,p)>=0||!v&&this._compare(_.key,p)>0}if(!n&&!this._isPredicate(t)){let g=this._extractKey(t);return g!=null&&this._compare(_.key,g)>0}return!0},"shouldVisitLeft"),l=u(_=>{if(!_||!this.isRealNode(_.right))return!1;if(n){let g=t,p=g.high,v=g.includeHigh;return v&&this._compare(_.key,p)<=0||!v&&this._compare(_.key,p)<0}if(!n&&!this._isPredicate(t)){let g=this._extractKey(t);return g!=null&&this._compare(_.key,g)<0}return!0},"shouldVisitRight");return super._dfs(i,"IN",e,s,r,!1,a,l,()=>!0,_=>!!_&&o(_))}rangeSearch(t,e=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){let r=t instanceof st?t:new st(t[0],t[1]);return this.search(r,!1,e,i,s)}getByRank(t,e=this._DEFAULT_NODE_CALLBACK,i=this.iterationType){if(this._enableOrderStatistic||w(Error,R.orderStatisticNotEnabled("getByRank")),t<0||t>=this._size)return;let s,r=this.iterationType;typeof e=="string"?r=e:e&&(s=e,i&&(r=i));let n=r==="RECURSIVE"?this._getByRankRecursive(this._root,t):this._getByRankIterative(this._root,t);if(n)return s?s(n):n.key}getRank(t,e=this.iterationType){var i;if(this._enableOrderStatistic||w(Error,R.orderStatisticNotEnabled("getRank")),!this._root||this._size===0)return-1;let s=this.iterationType;e&&(s=e);let r;if(typeof t=="function"){let n=this.search(t,!0);if(n.length===0||n[0]===void 0)return-1;r=n[0]}else{if(t==null)return-1;if(this.isNode(t))r=t.key;else if(Array.isArray(t)){if(r=(i=t[0])!=null?i:void 0,r==null)return-1}else r=t}return r===void 0?-1:s==="RECURSIVE"?this._getRankRecursive(this._root,r):this._getRankIterative(this._root,r)}rangeByRank(t,e,i=this._DEFAULT_NODE_CALLBACK,s=this.iterationType){if(this._enableOrderStatistic||w(Error,R.orderStatisticNotEnabled("rangeByRank")),this._size===0)return[];let r=Math.max(0,t),n=Math.min(this._size-1,e);if(r>n)return[];let h,o=this.iterationType;typeof i=="string"?o=i:i&&(h=i,s&&(o=s));let a=[],l=n-r+1,_=o==="RECURSIVE"?this._getByRankRecursive(this._root,r):this._getByRankIterative(this._root,r);if(!_)return[];let g=0,p=h!=null?h:this._DEFAULT_NODE_CALLBACK,v=_;for(;v&&g<l;)a.push(p(v)),g++,g<l&&(v=this._next(v));return a}set(t,e){let[i]=this._keyValueNodeOrEntryToNodeAndValue(t,e);if(i===void 0)return!1;if(this._root===void 0)return this._setRoot(i),this._isMapMode&&this.isRealNode(i)&&this._store.set(i.key,i),this._size++,this._updateCount(i),!0;let s=this._root;for(;s!==void 0;){if(this._compare(s.key,i.key)===0)return this._replaceNode(s,i),this._isMapMode&&this.isRealNode(i)&&this._store.set(s.key,i),!0;if(this._compare(s.key,i.key)>0){if(s.left===void 0)return s.left=i,this._isMapMode&&this.isRealNode(i)&&this._store.set(i.key,i),this._size++,this._updateCountAlongPath(i),!0;s.left!==null&&(s=s.left)}else{if(s.right===void 0)return s.right=i,this._isMapMode&&this.isRealNode(i)&&this._store.set(i.key,i),this._size++,this._updateCountAlongPath(i),!0;s.right!==null&&(s=s.right)}}return!1}setMany(t,e,i=!0,s=this.iterationType){let r=[],n=e==null?void 0:e[Symbol.iterator]();if(!i){for(let g of t){let p=n==null?void 0:n.next().value;this.isRaw(g)&&(g=this._toEntryFn(g)),r.push(this.set(g,p))}return r}let h=[],o=0;for(let g of t)h.push({key:g,value:n==null?void 0:n.next().value,orgIndex:o++});let a=h.sort(({key:g},{key:p})=>{let v,x;return this.isRaw(g)?v=this._toEntryFn(g)[0]:this.isEntry(g)?v=g[0]:this.isRealNode(g)?v=g.key:v=g,this.isRaw(p)?x=this._toEntryFn(p)[0]:this.isEntry(p)?x=p[0]:this.isRealNode(p)?x=p.key:x=p,v!=null&&x!=null?this._compare(v,x):0}),l=u(g=>{if(g.length===0)return;let p=Math.floor((g.length-1)/2),{key:v,value:x,orgIndex:k}=g[p];if(this.isRaw(v)){let M=this._toEntryFn(v);r[k]=this.set(M)}else r[k]=this.set(v,x);l(g.slice(0,p)),l(g.slice(p+1))},"_dfs");return s==="RECURSIVE"?l(a):u(()=>{let p=[[0,a.length-1]];for(;p.length>0;){let v=p.pop();if(!v)continue;let[x,k]=v;if(x>k)continue;let M=x+Math.floor((k-x)/2),{key:y,value:N,orgIndex:m}=a[M];if(this.isRaw(y)){let b=this._toEntryFn(y);r[m]=this.set(b)}else r[m]=this.set(y,N);p.push([M+1,k]),p.push([x,M-1])}},"_iterate")(),r}ceiling(t,e=this._DEFAULT_NODE_CALLBACK,i){let s,r=this.iterationType;typeof e=="string"?r=e:e&&(s=e,i&&(r=i));let n=this._bound(t,!0,r);return s?n?s(n):void 0:n==null?void 0:n.key}higher(t,e=this._DEFAULT_NODE_CALLBACK,i){let s,r=this.iterationType;typeof e=="string"?r=e:e&&(s=e,i&&(r=i));let n=this._bound(t,!1,r);return s?n?s(n):void 0:n==null?void 0:n.key}floor(t,e=this._DEFAULT_NODE_CALLBACK,i){if(t==null)return void 0;let s,r=this.iterationType;if(typeof e=="string"?r=e:e&&(s=e,i&&(r=i)),this._isPredicate(t)){let h=this._floorByPredicate(t,r);return s?h?s(h):void 0:h==null?void 0:h.key}let n;if(this.isNode(t))n=t.key;else if(this.isEntry(t)){let h=t[0];if(h==null)return void 0;n=h}else n=t;if(n!==void 0){let h=this._floorByKey(n,r);return s?h?s(h):void 0:h==null?void 0:h.key}}lower(t,e,i){if(t==null)return void 0;let s,r=this.iterationType;if(typeof e=="string"?r=e:e&&(s=e,i&&(r=i)),this._isPredicate(t)){let h=this._lowerByPredicate(t,r);return s?h?s(h):void 0:h==null?void 0:h.key}let n;if(this.isNode(t))n=t.key;else if(this.isEntry(t)){let h=t[0];if(h==null)return void 0;n=h}else n=t;if(n!==void 0){let h=this._lowerByKey(n,r);return s?h?s(h):void 0:h==null?void 0:h.key}}lesserOrGreaterTraverse(t=this._DEFAULT_NODE_CALLBACK,e=-1,i=this._root,s=this.iterationType){let r=this.ensureNode(i),n=[];if(!this._root||!r)return n;let h=r.key;if(s==="RECURSIVE"){let o=u(a=>{let l=this._compare(a.key,h);Math.sign(l)==e&&n.push(t(a)),this.isRealNode(a.left)&&o(a.left),this.isRealNode(a.right)&&o(a.right)},"dfs");return o(this._root),n}else{let o=new et([this._root]);for(;o.length>0;){let a=o.shift();if(this.isRealNode(a)){let l=this._compare(a.key,h);Math.sign(l)==e&&n.push(t(a)),this.isRealNode(a.left)&&o.push(a.left),this.isRealNode(a.right)&&o.push(a.right)}}return n}}perfectlyBalance(t=this.iterationType){let e=this.dfs(n=>n,"IN",!1,this._root,t),i=e.length;if(this._clearNodes(),i===0)return!1;let s=u((n,h,o)=>{if(n>h)return;let a=n+(h-n>>1),l=e[a],_=s(n,a-1,l),g=s(a+1,h,l);return l.left=_,l.right=g,l.parent=o,l},"build"),r=s(0,i-1,void 0);return this._setRoot(r),this._size=i,!0}isAVLBalanced(t=this.iterationType){if(!this._root)return!0;let e=!0;if(t==="RECURSIVE"){let i=u(s=>{if(!s)return 0;let r=i(s.left),n=i(s.right);return Math.abs(r-n)>1&&(e=!1),Math.max(r,n)+1},"_height");i(this._root)}else{let i=[],s=this._root,r,n=new Map;for(;i.length>0||s;)if(s)i.push(s),s.left!==null&&(s=s.left);else if(s=i[i.length-1],!s.right||r===s.right){if(s=i.pop(),s){let h=s.left?n.get(s.left):-1,o=s.right?n.get(s.right):-1;if(Math.abs(h-o)>1)return!1;n.set(s,1+Math.max(h,o)),r=s,s=void 0}}else s=s.right}return e}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}deleteWhere(t,e=!1,i=this._root,s=this.iterationType){let r=this.search(t,e,h=>h,i,s),n=!1;for(let h of r)this.delete(h)&&(n=!0);return n}_createDefaultComparator(){return(t,e)=>{if(tt(t)&&tt(e))return t>e?1:t<e?-1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&w(TypeError,R.invalidDate("BST")),i>s?1:i<s?-1:0}return(typeof t=="object"||typeof e=="object")&&w(TypeError,R.comparatorRequired("BST")),0}}_floorByKey(t,e){var i,s;if(e==="RECURSIVE"){let r=u(n=>{if(!this.isRealNode(n))return;if(this.comparator(n.key,t)<=0){let o=r(n.right);return o!=null?o:n}else return r(n.left)},"dfs");return r(this.root)}else{let r=this.root,n;for(;this.isRealNode(r);)this.comparator(r.key,t)<=0?(n=r,r=(i=r.right)!=null?i:void 0):r=(s=r.left)!=null?s:void 0;return n}}_floorByPredicate(t,e){if(e==="RECURSIVE"){let i,s=u(r=>{this.isRealNode(r)&&(this.isRealNode(r.left)&&s(r.left),t(r)&&(i=r),this.isRealNode(r.right)&&s(r.right))},"dfs");return s(this.root),i}else{let i=[],s=this.root,r;for(;i.length>0||this.isRealNode(s);)if(this.isRealNode(s))i.push(s),s=s.left;else{let n=i.pop();if(!this.isRealNode(n))break;t(n)&&(r=n),s=n.right}return r}}_lowerByKey(t,e){var i,s;if(e==="RECURSIVE"){let r=u(n=>{if(!this.isRealNode(n))return;if(this.comparator(n.key,t)<0){let o=r(n.right);return o!=null?o:n}else return r(n.left)},"dfs");return r(this.root)}else{let r=this.root,n;for(;this.isRealNode(r);)this.comparator(r.key,t)<0?(n=r,r=(i=r.right)!=null?i:void 0):r=(s=r.left)!=null?s:void 0;return n}}_lowerByPredicate(t,e){if(e==="RECURSIVE"){let i,s=u(r=>{this.isRealNode(r)&&(this.isRealNode(r.left)&&s(r.left),t(r)&&(i=r),this.isRealNode(r.right)&&s(r.right))},"dfs");return s(this.root),i}else{let i=[],s=this.root,r;for(;i.length>0||this.isRealNode(s);)if(this.isRealNode(s))i.push(s),s=s.left;else{let n=i.pop();if(!this.isRealNode(n))break;t(n)&&(r=n),s=n.right}return r}}_bound(t,e,i){if(t==null)return;if(this._isPredicate(t))return this._boundByPredicate(t,i);let s;if(this.isNode(t))s=t.key;else if(this.isEntry(t)){let r=t[0];if(r==null)return;s=r}else s=t;if(s!==void 0)return this._boundByKey(s,e,i)}_boundByKey(t,e,i){var s,r;if(i==="RECURSIVE"){let n=u(h=>{if(!this.isRealNode(h))return;let o=this.comparator(h.key,t);if(e?o>=0:o>0){let l=n(h.left);return l!=null?l:h}else return n(h.right)},"dfs");return n(this.root)}else{let n=this.root,h;for(;this.isRealNode(n);){let o=this.comparator(n.key,t);(e?o>=0:o>0)?(h=n,n=(s=n.left)!=null?s:void 0):n=(r=n.right)!=null?r:void 0}return h}}_boundByPredicate(t,e){if(e==="RECURSIVE"){let i,s=u(r=>{i||!this.isRealNode(r)||(this.isRealNode(r.left)&&s(r.left),!i&&t(r)&&(i=r),!i&&this.isRealNode(r.right)&&s(r.right))},"dfs");return s(this.root),i}else{let i=[],s=this.root;for(;i.length>0||this.isRealNode(s);)if(this.isRealNode(s))i.push(s),s=s.left;else{let r=i.pop();if(!this.isRealNode(r))break;if(t(r))return r;s=r.right}return}}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_snapshotOptions(){return{...super._snapshotOptions(),comparator:this._comparator,enableOrderStatistic:this._enableOrderStatistic}}_keyValueNodeOrEntryToNodeAndValue(t,e){let[i,s]=super._keyValueNodeOrEntryToNodeAndValue(t,e);return i===null?[void 0,void 0]:[i,e!=null?e:s]}_updateCount(t){this._enableOrderStatistic&&(t._count=1+(this.isRealNode(t.left)?t.left._count:0)+(this.isRealNode(t.right)?t.right._count:0))}_updateCountAlongPath(t){if(!this._enableOrderStatistic)return;let e=t;for(;e;)this._updateCount(e),e=e.parent}_getByRankIterative(t,e){let i=t,s=e;for(;i;){let r=this.isRealNode(i.left)?i.left._count:0;if(s<r)i=i.left;else{if(s===r)return i;s=s-r-1,i=i.right}}}_getByRankRecursive(t,e){if(!t)return;let i=this.isRealNode(t.left)?t.left._count:0;return e<i?this._getByRankRecursive(t.left,e):e===i?t:this._getByRankRecursive(t.right,e-i-1)}_getRankIterative(t,e){let i=0,s=t;for(;this.isRealNode(s);){let r=this._compare(s.key,e);if(r>0)s=s.left;else if(r<0)i+=(this.isRealNode(s.left)?s.left._count:0)+1,s=s.right;else return i+=this.isRealNode(s.left)?s.left._count:0,i}return i}_getRankRecursive(t,e){if(!t)return 0;let i=this._compare(t.key,e);return i>0?this._getRankRecursive(t.left,e):i<0?(this.isRealNode(t.left)?t.left._count:0)+1+this._getRankRecursive(t.right,e):this.isRealNode(t.left)?t.left._count:0}_next(t){if(this.isRealNode(t.right)){let s=t.right;for(;this.isRealNode(s.left);)s=s.left;return s}let e=t,i=e.parent;for(;i&&e===i.right;)e=i,i=i.parent;return i}_setRoot(t){t&&(t.parent=void 0),this._root=t}_compare(t,e){return this._comparator(t,e)}_deleteByKey(t){let e=this._root;for(;e;){let n=this._compare(e.key,t);if(n===0)break;e=n>0?e.left:e.right}if(!e)return!1;let i=u((n,h)=>{let o=n==null?void 0:n.parent;o?o.left===n?o.left=h:o.right=h:this._setRoot(h),h&&(h.parent=o)},"transplant"),s=u(n=>{if(n){for(;n.left!==void 0&&n.left!==null;)n=n.left;return n}},"minNode"),r;if(e.left===void 0)r=e.parent,i(e,e.right);else if(e.right===void 0)r=e.parent,i(e,e.left);else{let n=s(e.right);n.parent!==e?(r=n.parent,i(n,n.right),n.right=e.right,n.right&&(n.right.parent=n)):r=n,i(e,n),n.left=e.left,n.left&&(n.left.parent=n)}return this._updateCountAlongPath(r),this._size=Math.max(0,this._size-1),!0}};u(ye,"BST");var Me=ye,fi=class ke{constructor(t){if(c(this,"_size"),c(this,"_tree"),Array.isArray(t)){this._size=t.length,this._tree=new Array(this._size+1).fill(0);for(let e=0;e<this._size;e++)this._pointUpdate(e+1,t[e])}else(!Number.isInteger(t)||t<0)&&w(RangeError,R.invalidArgument("size must be a non-negative integer","BinaryIndexedTree")),this._size=t,this._tree=new Array(this._size+1).fill(0)}update(t,e){this._checkIndex(t),this._pointUpdate(t+1,e)}set(t,e){this._checkIndex(t);let i=this.get(t);this._pointUpdate(t+1,e-i)}get(t){return this._checkIndex(t),this._pointQuery(t+1)}query(t){return this._checkIndex(t),this._prefixSum(t+1)}queryRange(t,e){return this._checkIndex(t),this._checkIndex(e),t>e?0:t===0?this._prefixSum(e+1):this._prefixSum(e+1)-this._prefixSum(t)}lowerBound(t){let e=0,i=this._highBit(this._size);for(;i>0;){let s=e+i;s<=this._size&&this._tree[s]<t&&(t-=this._tree[s],e=s),i>>=1}return e}upperBound(t){let e=0,i=this._highBit(this._size);for(;i>0;){let s=e+i;s<=this._size&&this._tree[s]<=t&&(t-=this._tree[s],e=s),i>>=1}return e}get size(){return this._size}isEmpty(){return this._size===0}clear(){this._tree.fill(0)}clone(){return new ke(this.toArray())}toArray(){let t=[];for(let e=0;e<this._size;e++)t.push(this._pointQuery(e+1));return t}[Symbol.iterator](){let t=this._size,e=0,i=this;return{[Symbol.iterator](){return this},next(){return e<t?{value:i._pointQuery(e+++1),done:!1}:{value:void 0,done:!0}}}}forEach(t){for(let e=0;e<this._size;e++)t(this._pointQuery(e+1),e)}print(){console.log(this.toArray())}_prefixSum(t){let e=0;for(;t>0;)e+=this._tree[t],t-=t&-t;return e}_pointUpdate(t,e){for(;t<=this._size;)this._tree[t]+=e,t+=t&-t}_pointQuery(t){let e=this._tree[t],i=t-(t&-t);for(t--;t>i;)e-=this._tree[t],t-=t&-t;return e}_checkIndex(t){Number.isInteger(t)||w(TypeError,R.invalidIndex("BinaryIndexedTree")),(t<0||t>=this._size)&&w(RangeError,R.indexOutOfRange(t,0,this._size-1,"BinaryIndexedTree"))}_highBit(t){let e=1;for(;e<=t;)e<<=1;return e>>1}};u(fi,"BinaryIndexedTree");var ci=class X{constructor(t,e){for(c(this,"_merger"),c(this,"_identity"),c(this,"_n"),c(this,"_tree"),c(this,"_treeSize"),this._merger=e.merger,this._identity=e.identity,this._n=t.length,this._treeSize=1;this._treeSize<this._n;)this._treeSize<<=1;this._tree=new Array(2*this._treeSize).fill(this._identity);for(let i=0;i<this._n;i++)this._tree[this._treeSize+i]=t[i];for(let i=this._treeSize-1;i>=1;i--)this._tree[i]=this._merger(this._tree[2*i],this._tree[2*i+1])}static sum(t){return new X(t,{merger:u((e,i)=>e+i,"merger"),identity:0})}static min(t){return new X(t,{merger:u((e,i)=>Math.min(e,i),"merger"),identity:1/0})}static max(t){return new X(t,{merger:u((e,i)=>Math.max(e,i),"merger"),identity:-1/0})}update(t,e){if(t<0||t>=this._n)return;let i=this._treeSize+t;for(this._tree[i]=e,i>>=1;i>=1;)this._tree[i]=this._merger(this._tree[2*i],this._tree[2*i+1]),i>>=1}query(t,e){if(t<0&&(t=0),e>=this._n&&(e=this._n-1),t>e)return this._identity;let i=this._identity,s=this._identity,r=this._treeSize+t,n=this._treeSize+e+1;for(;r<n;)r&1&&(i=this._merger(i,this._tree[r]),r++),n&1&&(n--,s=this._merger(this._tree[n],s)),r>>=1,n>>=1;return this._merger(i,s)}get(t){return t<0||t>=this._n?this._identity:this._tree[this._treeSize+t]}maxRight(t,e){if(t>=this._n)return this._n-1;let i=this._identity;if(!e(i))return t-1;let s=this._treeSize+t;for(;;){for(;s<this._treeSize;){let n=this._merger(i,this._tree[2*s]);e(n)?(i=n,s=2*s+1):s=2*s}let r=this._merger(i,this._tree[s]);if(!e(r))return s-this._treeSize-1;if(i=r,s++,s-this._treeSize>=this._n)return this._n-1;for(;s>1&&(s&1)===0;)s>>=1;if(s===1)return this._n-1}}minLeft(t,e){if(t<0)return 0;t>=this._n&&(t=this._n-1);let i=this._identity;if(!e(i))return t+1;let s=this._treeSize+t;for(;;){for(;s<this._treeSize;){let n=this._merger(this._tree[2*s+1],i);e(n)?(i=n,s=2*s):s=2*s+1}let r=this._merger(this._tree[s],i);if(!e(r))return s-this._treeSize+1;if(i=r,s===this._treeSize)return 0;for(s--;s>1&&(s&1)===1;)s>>=1;if(s===1)return 0}}get size(){return this._n}isEmpty(){return this._n===0}clone(){let t=[];for(let e=0;e<this._n;e++)t.push(this._tree[this._treeSize+e]);return new X(t,{merger:this._merger,identity:this._identity})}toArray(){let t=[];for(let e=0;e<this._n;e++)t.push(this._tree[this._treeSize+e]);return t}[Symbol.iterator](){let t=this._tree,e=this._treeSize,i=this._n,s=0;return{[Symbol.iterator](){return this},next(){return s<i?{value:t[e+s++],done:!1}:{value:void 0,done:!0}}}}forEach(t){for(let e=0;e<this._n;e++)t(this._tree[this._treeSize+e],e)}print(){console.log(this.toArray())}};u(ci,"SegmentTree");var be=class{constructor(t,e){c(this,"key"),c(this,"value"),c(this,"parent"),c(this,"_left"),c(this,"_right"),c(this,"_height",0),c(this,"_color","BLACK"),c(this,"_count",1),this.key=t,this.value=e}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}set count(t){this._count=t}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(be,"AVLTreeNode");var It=be,_i=class extends Me{constructor(t=[],e){super([],e),t&&super.setMany(t)}createNode(t,e){return new It(t,e)}isNode(t){return t instanceof It}set(t,e){if(t===null)return!1;let i=super.set(t,e);return i&&this._balancePath(t),i}delete(t){let e=this._deleteInternal(t);for(let{needBalanced:i}of e)i&&this._balancePath(i);return e.length>0}perfectlyBalance(t=this.iterationType){let e=this.dfs(n=>n,"IN",!1,this._root,t),i=e.length;if(i===0)return!1;this._clearNodes();let s=u((n,h,o)=>{if(n>h)return;let a=n+(h-n>>1),l=e[a];l.left=s(n,a-1,l),l.right=s(a+1,h,l),l.parent=o;let _=l.left?l.left.height:-1,g=l.right?l.right.height:-1;return l.height=Math.max(_,g)+1,l},"build"),r=s(0,i-1,void 0);return this._setRoot(r),this._size=i,!0}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_swapProperties(t,e){let i=this.ensureNode(t),s=this.ensureNode(e);if(i&&s){let{key:r,value:n,height:h}=s,o=this.createNode(r,n);return o&&(o.height=h,s.key=i.key,this._isMapMode||(s.value=i.value),s.height=i.height,i.key=o.key,this._isMapMode||(i.value=o.value),i.height=o.height),s}}_balanceFactor(t){let e=t.left?t.left.height:-1;return(t.right?t.right.height:-1)-e}_updateHeight(t){let e=t.left?t.left.height:-1,i=t.right?t.right.height:-1;t.height=1+Math.max(e,i)}_balanceLL(t){let e=t.parent,i=t.left;i!==null&&(t.parent=i),i&&i.right&&(i.right.parent=t),i&&(i.parent=e),t===this.root?i&&this._setRoot(i):(e==null?void 0:e.left)===t?e.left=i:e&&(e.right=i),i&&(t.left=i.right,i.right=t),this._updateHeight(t),i&&this._updateHeight(i),this._updateCount(t),i&&this._updateCount(i)}_balanceLR(t){let e=t.parent,i=t.left,s;i&&(s=i.right),t&&s!==null&&(t.parent=s),i&&s!==null&&(i.parent=s),s&&(s.left&&i!==null&&(s.left.parent=i),s.right&&(s.right.parent=t),s.parent=e),t===this.root?s&&this._setRoot(s):e&&(e.left===t?e.left=s:e.right=s),s&&(t.left=s.right,i&&(i.right=s.left),s.left=i,s.right=t),this._updateHeight(t),i&&this._updateHeight(i),s&&this._updateHeight(s),this._updateCount(t),i&&this._updateCount(i),s&&this._updateCount(s)}_balanceRR(t){let e=t.parent,i=t.right;i!==null&&(t.parent=i),i&&(i.left&&(i.left.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.right=i.left,i.left=t),this._updateHeight(t),i&&this._updateHeight(i),this._updateCount(t),i&&this._updateCount(i)}_balanceRL(t){let e=t.parent,i=t.right,s;i&&(s=i.left),s!==null&&(t.parent=s),i&&s!==null&&(i.parent=s),s&&(s.left&&(s.left.parent=t),s.right&&i!==null&&(s.right.parent=i),s.parent=e),t===this.root?s&&this._setRoot(s):e&&(e.left===t?e.left=s:e.right=s),s&&(t.right=s.left),i&&s&&(i.left=s.right),s&&(s.left=t),s&&(s.right=i),this._updateHeight(t),i&&this._updateHeight(i),s&&this._updateHeight(s),this._updateCount(t),i&&this._updateCount(i),s&&this._updateCount(s)}_balancePath(t){t=this.ensureNode(t);let e=this.getPathToRoot(t,i=>i,!1);for(let i=0;i<e.length;i++){let s=e[i];if(s)switch(this._updateHeight(s),this._updateCount(s),this._balanceFactor(s)){case-2:s&&s.left&&(this._balanceFactor(s.left)<=0?this._balanceLL(s):this._balanceLR(s));break;case 2:s&&s.right&&(this._balanceFactor(s.right)>=0?this._balanceRR(s):this._balanceRL(s))}}}_replaceNode(t,e){return e.height=t.height,super._replaceNode(t,e)}};u(_i,"AVLTree");var we=class{constructor(t,e,i="BLACK"){c(this,"key"),c(this,"value"),c(this,"parent"),c(this,"_left"),c(this,"_right"),c(this,"_height",0),c(this,"_color","BLACK"),c(this,"_count",1),this.key=t,this.value=e,this.color=i}get left(){return this._left}set left(t){t&&(t.parent=this),this._left=t}get right(){return this._right}set right(t){t&&(t.parent=this),this._right=t}get height(){return this._height}set height(t){this._height=t}get color(){return this._color}set color(t){this._color=t}get count(){return this._count}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}};u(we,"RedBlackTreeNode");var vt=we,xe=class extends Me{constructor(t=[],e){super([],e),c(this,"_root"),c(this,"_header"),c(this,"_minNode"),c(this,"_maxNode"),this._root=this.NIL,this._header=new vt(void 0,void 0,"BLACK"),this._header.parent=this.NIL,this._header._left=this.NIL,this._header._right=this.NIL,t&&this.setMany(t)}get root(){return this._root}createNode(t,e,i="BLACK"){return new vt(t,e,i)}isNode(t){return t instanceof vt}clear(){super.clear(),this._root=this.NIL,this._header.parent=this.NIL,this._setMinCache(void 0),this._setMaxCache(void 0)}_findNodeByKey(t){var e,i,s;let r=this.NIL,n=this._compare.bind(this),h=(e=this._header.parent)!=null?e:r;for(;h!==r;){let o=n(t,h.key);if(o<0)h=(i=h.left)!=null?i:r;else if(o>0)h=(s=h.right)!=null?s:r;else return h}}_predecessorOf(t){let e=this.NIL;if(t.left&&t.left!==e){let r=t.left;for(;r.right&&r.right!==e;)r=r.right;return r}let i=t,s=t.parent;for(;s&&i===s.left;)i=s,s=s.parent;return s}_successorOf(t){let e=this.NIL;if(t.right&&t.right!==e){let r=t.right;for(;r.left&&r.left!==e;)r=r.left;return r}let i=t,s=t.parent;for(;s&&i===s.right;)i=s,s=s.parent;return s}_attachNewNode(t,e,i){let s=this.NIL;i.parent=t,e==="left"?t.left=i:t.right=i,i.left=s,i.right=s,i.color="RED",this._updateCountAlongPath(i),this._insertFixup(i),this.isRealNode(this._root)&&(this._root.color="BLACK")}_setMinCache(t){this._minNode=t,this._header._left=t!=null?t:this.NIL}_setMaxCache(t){this._maxNode=t,this._header._right=t!=null?t:this.NIL}_setKVNode(t,e){var i,s,r,n,h,o,a;let l=this.NIL,_=this._comparator,g=this._header,p=(i=g._left)!=null?i:l;if(p!==l){let F=_(t,p.key);if(F===0)return p.value=e,this._isMapMode&&this._store.set(t,p),{node:p,created:!1};let T=p.left;if(F<0&&(T===l||T===null||T===void 0)){let B=this.createNode(t,e);return this._attachNewNode(p,"left",B),this._isMapMode&&this._store.set(B.key,B),this._size++,this._setMinCache(B),g._right===l&&this._setMaxCache(B),{node:B,created:!0}}if(F>0){let B=(s=g._right)!=null?s:l,Nt=_(t,B.key);if(Nt===0)return B.value=e,this._isMapMode&&this._store.set(t,B),{node:B,created:!1};let _t=B.right;if(Nt>0&&(_t===l||_t===null||_t===void 0)){let q=this.createNode(t,e);return this._attachNewNode(B,"right",q),this._isMapMode&&this._store.set(q.key,q),this._size++,this._setMaxCache(q),g._left===l&&this._setMinCache(q),{node:q,created:!0}}}}let v=_,x=this._isMapMode,k=this._store,M=(r=this._header.parent)!=null?r:l,y,N=0;for(;M!==l;)if(y=M,N=v(t,M.key),N<0)M=(n=M.left)!=null?n:l;else if(N>0)M=(h=M.right)!=null?h:l;else return M.value=e,x&&k.set(t,M),{node:M,created:!1};let m=this.createNode(t,e);if(m.parent=y,y?N<0?y.left=m:y.right=m:this._setRoot(m),m.left=l,m.right=l,m.color="RED",this._updateCountAlongPath(m),this._insertFixup(m),this.isRealNode(this._root))this._root.color="BLACK";else return;x&&k.set(m.key,m),this._size++;let b=(o=this._header._left)!=null?o:l,L=(a=this._header._right)!=null?a:l;return b===l||L===l?(this._setMinCache(m),this._setMaxCache(m)):y===L&&N>0?this._setMaxCache(m):y===b&&N<0?this._setMinCache(m):(v(m.key,b.key)<0&&this._setMinCache(m),v(m.key,L.key)>0&&this._setMaxCache(m)),{node:m,created:!0}}_setKV(t,e){if(this._isMapMode){let s=this._store.get(t);if(s)return s.value=e,!0}return this._setKVNode(t,e)!==void 0}setWithHintNode(t,e,i){var s,r,n,h,o,a,l,_,g,p,v,x,k;if(!i||!this.isRealNode(i))return(s=this._setKVNode(t,e))==null?void 0:s.node;let M=this._compare.bind(this),y=M(t,i.key);if(y===0)return i.value=e,this._isMapMode&&this._store.set(t,i),i;if(y<0){if(!this.isRealNode(i.left)){let b=this.createNode(t,e);if(!this.isRealNode(b))return;this._attachNewNode(i,"left",b),this._isMapMode&&this._store.set(t,b),this._size++;let L=this.NIL,F=(r=this._header._left)!=null?r:L;(F===L||this._compare(b.key,F.key)<0)&&this._setMinCache(b);let T=(n=this._header._right)!=null?n:L;return(T===L||this._compare(b.key,T.key)>0)&&this._setMaxCache(b),b}let m=this._predecessorOf(i);if(m&&M(m.key,t)>=0)return(h=this._setKVNode(t,e))==null?void 0:h.node;if(m&&!this.isRealNode(m.right)){let b=this.createNode(t,e);if(!this.isRealNode(b))return;this._attachNewNode(m,"right",b),this._isMapMode&&this._store.set(t,b),this._size++;let L=this.NIL,F=(o=this._header._left)!=null?o:L;(F===L||this._compare(b.key,F.key)<0)&&this._setMinCache(b);let T=(a=this._header._right)!=null?a:L;return(T===L||this._compare(b.key,T.key)>0)&&this._setMaxCache(b),b}return(l=this._setKVNode(t,e))==null?void 0:l.node}if(!this.isRealNode(i.right)){let m=this.createNode(t,e);if(!this.isRealNode(m))return;this._attachNewNode(i,"right",m),this._isMapMode&&this._store.set(t,m),this._size++;let b=this.NIL,L=(_=this._header._left)!=null?_:b;(L===b||this._compare(m.key,L.key)<0)&&this._setMinCache(m);let F=(g=this._header._right)!=null?g:b;return(F===b||this._compare(m.key,F.key)>0)&&this._setMaxCache(m),m}let N=this._successorOf(i);if(N&&M(N.key,t)<=0)return(p=this._setKVNode(t,e))==null?void 0:p.node;if(N&&!this.isRealNode(N.left)){let m=this.createNode(t,e);if(!this.isRealNode(m))return;this._attachNewNode(N,"left",m),this._isMapMode&&this._store.set(t,m),this._size++;let b=this.NIL,L=(v=this._header._left)!=null?v:b;(L===b||this._compare(m.key,L.key)<0)&&this._setMinCache(m);let F=(x=this._header._right)!=null?x:b;return(F===b||this._compare(m.key,F.key)>0)&&this._setMaxCache(m),m}return(k=this._setKVNode(t,e))==null?void 0:k.node}setWithHint(t,e,i){return this.setWithHintNode(t,e,i)!==void 0}set(t,e){if(!this.isNode(t)){if(t==null)return!1;if(this.isEntry(t)){let n=t[0];if(n==null)return!1;let h=e!=null?e:t[1];return this._setKV(n,h)}return this._setKV(t,e)}let[i,s]=this._keyValueNodeOrEntryToNodeAndValue(t,e);if(!this.isRealNode(i))return!1;let r=this._insert(i);if(r==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;if(this._isMapMode){let n=this.getNode(i.key);this.isRealNode(n)&&(n.value=s,this._store.set(n.key,n))}return this._size++,!0}if(r==="UPDATED"){if(this._isMapMode){let n=this.getNode(i.key);this.isRealNode(n)&&(n.value=s,this._store.set(n.key,n))}return!0}return!1}delete(t){var e,i,s;if(t===null)return!1;let r;if(this._isPredicate(t)?r=this.getNode(t):r=this.isRealNode(t)?t:this.getNode(t),!r)return!1;let n=r===this._minNode,h=r===this._maxNode,o=n?this._successorOf(r):void 0,a=h?this._predecessorOf(r):void 0,l=r.color,_=this.NIL,g=_;if(!this.isRealNode(r.left))g=(e=r.right)!=null?e:_,this._transplant(r,g);else if(!this.isRealNode(r.right))g=r.left,this._transplant(r,g);else{let p=this.getLeftMost(v=>v,r.right);p&&(l=p.color,g=(i=p.right)!=null?i:_,p.parent===r?g.parent=p:(this._transplant(p,g),p.right=r.right,p.right&&(p.right.parent=p)),this._transplant(r,p),p.left=r.left,p.left&&(p.left.parent=p),p.color=r.color)}return this._isMapMode&&this._store.delete(r.key),this._size--,this._updateCountAlongPath((s=g==null?void 0:g.parent)!=null?s:g),this._size<=0?(this._setMinCache(void 0),this._setMaxCache(void 0)):(n&&this._setMinCache(o),h&&this._setMaxCache(a),(!this._minNode||!this.isRealNode(this._minNode))&&this._setMinCache(this.isRealNode(this._root)?this.getLeftMost(p=>p,this._root):void 0),(!this._maxNode||!this.isRealNode(this._maxNode))&&this._setMaxCache(this.isRealNode(this._root)?this.getRightMost(p=>p,this._root):void 0)),l==="BLACK"&&this._deleteFixup(g),!0}perfectlyBalance(t){let e=[];for(let[i,s]of this)e.push([i,s]);return e.length<=1||(this.clear(),this.setMany(e.map(([i])=>i),e.map(([,i])=>i),!0)),!0}map(t,e,i){let s=this._createLike([],e),r=0;for(let[n,h]of this)s.set(t.call(i,h,n,r++,this));return s}_createInstance(t){let e=this.constructor;return new e([],{...this._snapshotOptions(),...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,{...this._snapshotOptions(),...e!=null?e:{}})}_setRoot(t){let e=this.NIL;t&&(t.parent=void 0),this._root=t,this._header.parent=t!=null?t:e}_replaceNode(t,e){return e.color=t.color,super._replaceNode(t,e)}_insert(t){var e,i,s;let r=this.NIL,n=this._compare.bind(this),h=(e=this._header.parent)!=null?e:r,o,a=0;for(;h!==r;)if(o=h,a=n(t.key,h.key),a<0)h=(i=h.left)!=null?i:r;else if(a>0)h=(s=h.right)!=null?s:r;else return this._replaceNode(h,t),"UPDATED";return t.parent=o,o?a<0?o.left=t:o.right=t:this._setRoot(t),t.left=r,t.right=r,t.color="RED",this._updateCountAlongPath(t),this._insertFixup(t),"CREATED"}_transplant(t,e){t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this._setRoot(e),e&&(e.parent=t.parent)}_insertFixup(t){let e=this._leftRotate.bind(this),i=this._rightRotate.bind(this);for(;t;){let s=t.parent;if(!s||s.color!=="RED")break;let r=s.parent;if(!r)break;if(s===r.left){let n=r.right;if((n==null?void 0:n.color)==="RED"){s.color="BLACK",n.color="BLACK",r.color="RED",t=r;continue}t===s.right&&(t=s,e(t));let h=t==null?void 0:t.parent,o=h==null?void 0:h.parent;h&&o&&(h.color="BLACK",o.color="RED",i(o))}else{let n=r.left;if((n==null?void 0:n.color)==="RED"){s.color="BLACK",n.color="BLACK",r.color="RED",t=r;continue}t===s.left&&(t=s,i(t));let h=t==null?void 0:t.parent,o=h==null?void 0:h.parent;h&&o&&(h.color="BLACK",o.color="RED",e(o))}break}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(t){if(!t)return;let e=this.NIL,i=t;for(;i!==this.root&&i.color==="BLACK";){let s=i.parent;if(!s)break;let r=i===s.left,n=r?s.right:s.left;n&&n.color==="RED"&&(n.color="BLACK",s.color="RED",r?(this._leftRotate(s),n=s.right):(this._rightRotate(s),n=s.left));let h=n==null?void 0:n.left,o=n==null?void 0:n.right,a=!h||h===e||h.color==="BLACK",l=!o||o===e||o.color==="BLACK";a&&l?(n&&(n.color="RED"),i=s):(r?(l&&(h&&(h.color="BLACK"),n&&(n.color="RED"),n&&this._rightRotate(n),n=s.right),n&&(n.color=s.color),s.color="BLACK",n!=null&&n.right&&(n.right.color="BLACK"),this._leftRotate(s)):(a&&(o&&(o.color="BLACK"),n&&(n.color="RED"),n&&this._leftRotate(n),n=s.left),n&&(n.color=s.color),s.color="BLACK",n!=null&&n.left&&(n.left.color="BLACK"),this._rightRotate(s)),i=this.root)}i.color="BLACK"}_leftRotate(t){if(!t||!t.right)return;let e=t.right;t.right=e.left,e.left&&e.left!==this.NIL&&(e.left.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this._setRoot(e),e.left=t,t.parent=e,this._updateCount(t),this._updateCount(e)}_rightRotate(t){if(!t||!t.left)return;let e=t.left;t.left=e.right,e.right&&e.right!==this.NIL&&(e.right.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this._setRoot(e),e.right=t,t.parent=e,this._updateCount(t),this._updateCount(e)}};u(xe,"RedBlackTree");var ct=xe,C,H,U,Re=class D{constructor(t=[],e={}){K(this,C),K(this,H),K(this,U);var i;j(this,U,e.comparator);let s=e.toElementFn,r=(i=e.comparator)!=null?i:D.createDefaultComparator();j(this,H,e.comparator===void 0),j(this,C,new ct([],{comparator:r,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t){let h=s?s(n):n;this.add(h)}}static createDefaultComparator(){return(t,e)=>{if(typeof t=="number"&&typeof e=="number"){(Number.isNaN(t)||Number.isNaN(e))&&w(TypeError,R.invalidNaN("TreeSet"));let i=Object.is(t,-0)?0:t,s=Object.is(e,-0)?0:e;return i>s?1:i<s?-1:0}if(typeof t=="string"&&typeof e=="string")return t>e?1:t<e?-1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&w(TypeError,R.invalidDate("TreeSet")),i>s?1:i<s?-1:0}w(TypeError,R.comparatorRequired("TreeSet"))}}get size(){return d(this,C).size}isEmpty(){return this.size===0}_validateKey(t){if(d(this,H)){if(typeof t=="number"){Number.isNaN(t)&&w(TypeError,R.invalidNaN("TreeSet"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&w(TypeError,R.invalidDate("TreeSet"));return}w(TypeError,R.comparatorRequired("TreeSet"))}}}add(t){return this._validateKey(t),d(this,C).set(t,void 0),this}addMany(t){let e=[];for(let i of t)this._validateKey(i),e.push(d(this,C).set(i,void 0));return e}has(t){return this._validateKey(t),d(this,C).has(t)}delete(t){return this._validateKey(t),d(this,C).delete(t)}deleteWhere(t){let e=!1,i=0;for(let s of this)t(s,i++,this)&&(this.delete(s),e=!0);return e}clear(){d(this,C).clear()}keys(){return d(this,C).keys()}values(){return this.keys()}*entries(){for(let t of this.keys())yield[t,t]}[Symbol.iterator](){return this.keys()}forEach(t,e){for(let i of this)t.call(e,i,i,this)}map(t,e={},i){let s=new D([],e),r=0;for(let n of this){let h=i===void 0?t(n,r++,this):t.call(i,n,r++,this);s.add(h)}return s}filter(t,e){let i=new D([],{comparator:d(this,U)}),s=0;for(let r of this)(e===void 0?t(r,s++,this):t.call(e,r,s++,this))&&i.add(r);return i}reduce(t,e){let i=e,s=0;for(let r of this)i=t(i,r,s++,this);return i}every(t,e){let i=0;for(let s of this)if(!(e===void 0?t(s,i++,this):t.call(e,s,i++,this)))return!1;return!0}some(t,e){let i=0;for(let s of this)if(e===void 0?t(s,i++,this):t.call(e,s,i++,this))return!0;return!1}find(t,e){let i=0;for(let s of this)if(e===void 0?t(s,i++,this):t.call(e,s,i++,this))return s}toArray(){return[...this]}print(){d(this,C).print()}first(){return d(this,C).getLeftMost()}last(){return d(this,C).getRightMost()}pollFirst(){let t=this.first();if(t!==void 0)return this.delete(t),t}pollLast(){let t=this.last();if(t!==void 0)return this.delete(t),t}ceiling(t){return this._validateKey(t),d(this,C).ceiling(t)}floor(t){return this._validateKey(t),d(this,C).floor(t)}higher(t){return this._validateKey(t),d(this,C).higher(t)}lower(t){return this._validateKey(t),d(this,C).lower(t)}rangeSearch(t,e={}){let{lowInclusive:i=!0,highInclusive:s=!0}=e,[r,n]=t;this._validateKey(r),this._validateKey(n);let h=d(this,C).rangeSearch([r,n]),o=[],a=d(this,C).comparator;for(let l of h)l!==void 0&&(!i&&a(l,r)===0||!s&&a(l,n)===0||o.push(l));return o}getByRank(t){return d(this,C).getByRank(t)}getRank(t){return d(this,C).getRank(t)}rangeByRank(t,e){return d(this,C).rangeByRank(t,e).filter(i=>i!==void 0)}union(t){let e=this.clone();for(let i of t)e.add(i);return e}intersection(t){let e=t instanceof D||t instanceof Set?t:new Set(t),i=new D([],{comparator:d(this,H)?void 0:d(this,U)});for(let s of this)e.has(s)&&i.add(s);return i}difference(t){let e=t instanceof D||t instanceof Set?t:new Set(t),i=new D([],{comparator:d(this,H)?void 0:d(this,U)});for(let s of this)e.has(s)||i.add(s);return i}symmetricDifference(t){let e=t instanceof D||t instanceof Set?t:new Set(t),i=new D([],{comparator:d(this,H)?void 0:d(this,U)});for(let s of this)e.has(s)||i.add(s);for(let s of e)this.has(s)||i.add(s);return i}isSubsetOf(t){let e=t instanceof D||t instanceof Set?t:new Set(t);for(let i of this)if(!e.has(i))return!1;return!0}isSupersetOf(t){for(let e of t)if(!this.has(e))return!1;return!0}isDisjointFrom(t){let e=t instanceof D||t instanceof Set?t:new Set(t);for(let i of this)if(e.has(i))return!1;return!0}clone(){return new D(this,{comparator:d(this,H)?void 0:d(this,U),isMapMode:d(this,C).isMapMode})}};C=new WeakMap;H=new WeakMap;U=new WeakMap;u(Re,"TreeSet");var Ne=Re,E,nt,Le=class ht{constructor(t=[],e={}){K(this,E),K(this,nt);var i;let s=(i=e.comparator)!=null?i:Ne.createDefaultComparator();j(this,nt,e.comparator===void 0);let r=e.toEntryFn;j(this,E,new ct([],{...e,comparator:s,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t)if(n!=null){if(r){let[h,o]=r(n);if(h==null)continue;o!==void 0?d(this,E).set(h,Array.isArray(o)?[...o]:[o]):d(this,E).set(h,[]);continue}if(Array.isArray(n)){let[h,o]=n;if(h==null)continue;o!==void 0?d(this,E).set(h,[...o]):d(this,E).set(h,[]);continue}d(this,E).set(n,[])}}_validateKey(t){if(d(this,nt)){if(typeof t=="number"){Number.isNaN(t)&&w(TypeError,R.invalidNaN("TreeMultiMap"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&w(TypeError,R.invalidDate("TreeMultiMap"));return}w(TypeError,R.comparatorRequired("TreeMultiMap"))}}}get size(){return d(this,E).size}isEmpty(){return this.size===0}clear(){d(this,E).clear()}count(t){let e=this.get(t);return Array.isArray(e)?e.length:0}get totalSize(){let t=0;for(let[,e]of this)t+=e.length;return t}has(t){return this._validateKey(t),d(this,E).has(t)}get(t){return this._validateKey(t),d(this,E).get(t)}add(t,e){this._validateKey(t);let i=d(this,E).get(t);return i?(i.push(e),!0):d(this,E).set(t,[e])}set(t,e){if(t==null)return!1;if(Array.isArray(t)){let[i,s]=t;if(i==null)return!1;if(e!==void 0)return this.add(i,e);if(s===void 0)return d(this,E).set(i,[]);let r=d(this,E).get(i);return r?(r.push(...s),!0):d(this,E).set(i,[...s])}return e!==void 0?this.add(t,e):d(this,E).set(t,[])}delete(t){return this._validateKey(t),d(this,E).delete(t)}hasEntry(t,e,i=Object.is){let s=this.get(t);return Array.isArray(s)?s.some(r=>i(r,e)):!1}deleteValue(t,e,i=Object.is){let s=this.get(t);if(!Array.isArray(s))return!1;let r=s.findIndex(n=>i(n,e));return r===-1?!1:(s.splice(r,1),s.length===0&&this.delete(t),!0)}deleteValues(t,e,i=Object.is){let s=this.get(t);if(!Array.isArray(s)||s.length===0)return 0;let r=0;for(let n=s.length-1;n>=0;n--)i(s[n],e)&&(s.splice(n,1),r++);return s.length===0&&r>0&&this.delete(t),r}*[Symbol.iterator](){for(let[t,e]of d(this,E))yield[t,e!=null?e:[]]}*keys(){yield*d(this,E).keys()}*values(){for(let[,t]of this)yield t}*entries(){yield*this}*entriesOf(t){let e=this.get(t);if(Array.isArray(e))for(let i of e)yield[t,i]}*valuesOf(t){let e=this.get(t);Array.isArray(e)&&(yield*e)}*flatEntries(){for(let[t,e]of this)for(let i of e)yield[t,i]}first(){let t=d(this,E).getLeftMost();if(t===void 0)return;let e=this.get(t);return e===void 0?void 0:[t,e]}last(){let t=d(this,E).getRightMost();if(t===void 0)return;let e=this.get(t);return e===void 0?void 0:[t,e]}pollFirst(){let t=this.first();if(t)return this.delete(t[0]),t}pollLast(){let t=this.last();if(t)return this.delete(t[0]),t}ceiling(t){this._validateKey(t);let e=d(this,E).ceiling(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}floor(t){this._validateKey(t);let e=d(this,E).floor(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}higher(t){this._validateKey(t);let e=d(this,E).higher(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}lower(t){this._validateKey(t);let e=d(this,E).lower(t);if(e===void 0)return;let i=this.get(e);return i===void 0?void 0:[e,i]}print(){d(this,E).print()}forEach(t){for(let[e,i]of this)t(i,e,this)}filter(t){let e=[];for(let[i,s]of this)t(s,i,this)&&e.push([i,s]);return new ht(e,{comparator:this.comparator})}map(t){let e=[];for(let[i,s]of this)e.push(t(s,i,this));return new ht(e,{comparator:this.comparator})}reduce(t,e){let i=e;for(let[s,r]of this)i=t(i,r,s,this);return i}setMany(t){let e=[];for(let i of t)e.push(this.set(i));return e}rangeSearch(t,e){return d(this,E).rangeSearch(t,e)}getByRank(t){var e;let i=d(this,E).getByRank(t);if(i!==void 0)return[i,(e=d(this,E).get(i))!=null?e:[]]}getRank(t){return d(this,E).getRank(t)}rangeByRank(t,e){return d(this,E).rangeByRank(t,e).filter(s=>s!==void 0).map(s=>{var r;return[s,(r=d(this,E).get(s))!=null?r:[]]})}clone(){return new ht(this,{comparator:this.comparator,isMapMode:d(this,E).isMapMode})}get comparator(){return d(this,E).comparator}};E=new WeakMap;nt=new WeakMap;u(Le,"TreeMultiMap");var Ee=Le,I,J,Y,di=class Z{constructor(t=[],e={}){K(this,I),K(this,J),K(this,Y);var i;j(this,Y,e.comparator);let s=e.toEntryFn,r=(i=e.comparator)!=null?i:Z.createDefaultComparator();j(this,J,e.comparator===void 0),j(this,I,new ct([],{comparator:r,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t){let h,o;s?[h,o]=s(n):((!Array.isArray(n)||n.length<2)&&w(TypeError,R.invalidEntry("TreeMap")),h=n[0],o=n[1]),this.set(h,o)}}static createDefaultComparator(){return(t,e)=>{if(typeof t=="number"&&typeof e=="number"){(Number.isNaN(t)||Number.isNaN(e))&&w(TypeError,R.invalidNaN("TreeMap"));let i=Object.is(t,-0)?0:t,s=Object.is(e,-0)?0:e;return i>s?1:i<s?-1:0}if(typeof t=="string"&&typeof e=="string")return t>e?1:t<e?-1:0;if(t instanceof Date&&e instanceof Date){let i=t.getTime(),s=e.getTime();return(Number.isNaN(i)||Number.isNaN(s))&&w(TypeError,R.invalidDate("TreeMap")),i>s?1:i<s?-1:0}w(TypeError,R.comparatorRequired("TreeMap"))}}_validateKey(t){if(d(this,J)){if(typeof t=="number"){Number.isNaN(t)&&w(TypeError,R.invalidNaN("TreeMap"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&w(TypeError,R.invalidDate("TreeMap"));return}w(TypeError,R.comparatorRequired("TreeMap"))}}}get size(){return d(this,I).size}isEmpty(){return this.size===0}set(t,e){return this._validateKey(t),d(this,I).set(t,e),this}setMany(t){let e=[];for(let[i,s]of t)this._validateKey(i),e.push(d(this,I).set(i,s));return e}get(t){return this._validateKey(t),d(this,I).get(t)}has(t){return this._validateKey(t),d(this,I).has(t)}delete(t){return this._validateKey(t),d(this,I).delete(t)}deleteWhere(t){let e=!1,i=0;for(let[s,r]of this)t(s,r,i++,this)&&(this.delete(s),e=!0);return e}clear(){d(this,I).clear()}keys(){return d(this,I).keys()}_entryFromKey(t){return[t,d(this,I).get(t)]}*values(){for(let t of this.keys())yield this._entryFromKey(t)[1]}*entries(){for(let t of this.keys())yield this._entryFromKey(t)}[Symbol.iterator](){return this.entries()}forEach(t,e){for(let[i,s]of this)t.call(e,s,i,this)}map(t,e={},i){let s=new Z([],e),r=0;for(let[n,h]of this){let[o,a]=i===void 0?t(h,n,r++,this):t.call(i,h,n,r++,this);s.set(o,a)}return s}filter(t,e){let i=new Z([],{comparator:d(this,Y)}),s=0;for(let[r,n]of this)(e===void 0?t(n,r,s++,this):t.call(e,n,r,s++,this))&&i.set(r,n);return i}reduce(t,e){let i=e,s=0;for(let[r,n]of this)i=t(i,n,r,s++,this);return i}every(t,e){let i=0;for(let[s,r]of this)if(!(e===void 0?t(r,s,i++,this):t.call(e,r,s,i++,this)))return!1;return!0}some(t,e){let i=0;for(let[s,r]of this)if(e===void 0?t(r,s,i++,this):t.call(e,r,s,i++,this))return!0;return!1}find(t,e){let i=0;for(let[s,r]of this)if(e===void 0?t(r,s,i++,this):t.call(e,r,s,i++,this))return[s,r]}toArray(){return[...this]}print(){d(this,I).print()}first(){let t=d(this,I).getLeftMost();return t===void 0?void 0:this._entryFromKey(t)}last(){let t=d(this,I).getRightMost();return t===void 0?void 0:this._entryFromKey(t)}pollFirst(){let t=this.first();if(t)return this.delete(t[0]),t}pollLast(){let t=this.last();if(t)return this.delete(t[0]),t}ceiling(t){this._validateKey(t);let e=d(this,I).ceiling(t);return e===void 0?void 0:this._entryFromKey(e)}floor(t){this._validateKey(t);let e=d(this,I).floor(t);return e===void 0?void 0:this._entryFromKey(e)}higher(t){this._validateKey(t);let e=d(this,I).higher(t);return e===void 0?void 0:this._entryFromKey(e)}lower(t){this._validateKey(t);let e=d(this,I).lower(t);return e===void 0?void 0:this._entryFromKey(e)}rangeSearch(t,e={}){let{lowInclusive:i=!0,highInclusive:s=!0}=e,[r,n]=t;this._validateKey(r),this._validateKey(n);let h=d(this,I).rangeSearch([r,n]),o=[],a=d(this,I).comparator;for(let l of h)l!==void 0&&(!i&&a(l,r)===0||!s&&a(l,n)===0||o.push(this._entryFromKey(l)));return o}getByRank(t){let e=d(this,I).getByRank(t);if(e!==void 0)return[e,d(this,I).get(e)]}getRank(t){return d(this,I).getRank(t)}rangeByRank(t,e){return d(this,I).rangeByRank(t,e).filter(s=>s!==void 0).map(s=>[s,d(this,I).get(s)])}clone(){return new Z(this,{comparator:d(this,J)?void 0:d(this,Y),isMapMode:d(this,I).isMapMode})}};I=new WeakMap;J=new WeakMap;Y=new WeakMap;u(di,"TreeMap");var S,G,gi=class ot{constructor(t=[],e={}){K(this,S),K(this,G),c(this,"_size",0);var i;let s=e.toElementFn,r=(i=e.comparator)!=null?i:Ne.createDefaultComparator();j(this,G,e.comparator===void 0),j(this,S,new ct([],{comparator:r,isMapMode:e.isMapMode,enableOrderStatistic:e.enableOrderStatistic}));for(let n of t){let h=s?s(n):n;this.add(h)}}_validateKey(t){if(d(this,G)){if(typeof t=="number"){Number.isNaN(t)&&w(TypeError,R.invalidNaN("TreeMultiSet"));return}if(typeof t!="string"){if(t instanceof Date){Number.isNaN(t.getTime())&&w(TypeError,R.invalidDate("TreeMultiSet"));return}w(TypeError,R.comparatorRequired("TreeMultiSet"))}}}_validateCount(t){(!Number.isSafeInteger(t)||t<0)&&w(RangeError,R.invalidArgument("count must be a safe integer >= 0.","TreeMultiSet"))}get size(){return this._size}get distinctSize(){return d(this,S).size}isEmpty(){return this.size===0}has(t){return this._validateKey(t),this.count(t)>0}count(t){var e;return this._validateKey(t),(e=d(this,S).get(t))!=null?e:0}add(t,e=1){var i;if(this._validateKey(t),this._validateCount(e),e===0)return!1;let r=((i=d(this,S).get(t))!=null?i:0)+e;return d(this,S).set(t,r),this._size+=e,!0}setCount(t,e){var i;this._validateKey(t),this._validateCount(e);let s=(i=d(this,S).get(t))!=null?i:0;return s===e?!1:(e===0?s!==0&&d(this,S).delete(t):d(this,S).set(t,e),this._size+=e-s,!0)}delete(t,e=1){var i;if(this._validateKey(t),this._validateCount(e),e===0)return!1;let s=(i=d(this,S).get(t))!=null?i:0;if(s===0)return!1;let r=Math.min(s,e),n=s-r;return n===0?d(this,S).delete(t):d(this,S).set(t,n),this._size-=r,!0}deleteAll(t){var e;this._validateKey(t);let i=(e=d(this,S).get(t))!=null?e:0;return i===0?!1:(d(this,S).delete(t),this._size-=i,!0)}*keysDistinct(){yield*d(this,S).keys()}*entries(){for(let[t,e]of d(this,S))yield[t,e!=null?e:0]}*[Symbol.iterator](){for(let[t,e]of this.entries())for(let i=0;i<e;i++)yield t}*keys(){yield*this}*values(){yield*this}toArray(){return[...this]}toDistinctArray(){return[...this.keysDistinct()]}toEntries(){return[...this.entries()]}get comparator(){return d(this,S).comparator}clear(){d(this,S).clear(),this._size=0}first(){return d(this,S).getLeftMost()}last(){return d(this,S).getRightMost()}pollFirst(){let t=this.first();if(t!==void 0)return this.deleteAll(t),t}pollLast(){let t=this.last();if(t!==void 0)return this.deleteAll(t),t}ceiling(t){return this._validateKey(t),d(this,S).ceiling(t)}floor(t){return this._validateKey(t),d(this,S).floor(t)}higher(t){return this._validateKey(t),d(this,S).higher(t)}lower(t){return this._validateKey(t),d(this,S).lower(t)}forEach(t){for(let[e,i]of this.entries())t(e,i)}filter(t){let e=new ot([],{comparator:d(this,G)?void 0:this.comparator,isMapMode:d(this,S).isMapMode});for(let[i,s]of this.entries())t(i,s)&&e.add(i,s);return e}reduce(t,e){let i=e;for(let[s,r]of this.entries())i=t(i,s,r);return i}map(t,e){let i=new ot([],{comparator:e==null?void 0:e.comparator,isMapMode:d(this,S).isMapMode});for(let[s,r]of this.entries()){let[n,h]=t(s,r);i.add(n,h)}return i}getByRank(t){return d(this,S).getByRank(t)}getRank(t){return d(this,S).getRank(t)}rangeByRank(t,e){return d(this,S).rangeByRank(t,e).filter(i=>i!==void 0)}clone(){let t=new ot([],{comparator:d(this,G)?void 0:this.comparator,isMapMode:d(this,S).isMapMode});for(let[e,i]of this.entries())t.add(e,i);return t}rangeSearch(t,e){let i=e!=null?e:(s=>s);return d(this,S).rangeSearch(t,s=>i(s.key))}print(){d(this,S).print()}};S=new WeakMap;G=new WeakMap;u(gi,"TreeMultiSet");var Se=class extends ft{constructor(t=[],e){super(t,e)}};u(Se,"PriorityQueue");var Fe=Se,pi=class extends Fe{constructor(t=[],e){super(t,e)}};u(pi,"MinPriorityQueue");var vi=class extends Fe{constructor(t=[],e){super(t,{comparator:u((i,s)=>((typeof i=="object"||typeof s=="object")&&w(TypeError,R.comparatorRequired("MaxPriorityQueue")),i<s?1:i>s?-1:0),"comparator"),...e})}};u(vi,"MaxPriorityQueue");var mi=class z{constructor(t,e){c(this,"_rows",0),c(this,"_cols",0),c(this,"_data");var i,s,r;if(e){let{rows:n,cols:h,addFn:o,subtractFn:a,multiplyFn:l}=e;typeof n=="number"&&n>0?this._rows=n:this._rows=t.length,typeof h=="number"&&h>0?this._cols=h:this._cols=((i=t[0])==null?void 0:i.length)||0,o&&(this._addFn=o),a&&(this._subtractFn=a),l&&(this._multiplyFn=l)}else this._rows=t.length,this._cols=(r=(s=t[0])==null?void 0:s.length)!=null?r:0;if(t.length>0)this._data=t;else{this._data=[];for(let n=0;n<this.rows;n++)this._data[n]=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(t,e){if(this.isValidIndex(t,e))return this.data[t][e]}set(t,e,i){return this.isValidIndex(t,e)?(this.data[t][e]=i,!0):!1}isMatchForCalculate(t){return this.rows===t.rows&&this.cols===t.cols}add(t){var e;this.isMatchForCalculate(t)||w(Error,R.matrixDimensionMismatch("addition"));let i=[];for(let s=0;s<this.rows;s++){i[s]=[];for(let r=0;r<this.cols;r++){let n=this.get(s,r),h=t.get(s,r);n!==void 0&&h!==void 0&&(i[s][r]=(e=this._addFn(n,h))!=null?e:0)}}return new z(i,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(t){var e;this.isMatchForCalculate(t)||w(Error,R.matrixDimensionMismatch("subtraction"));let i=[];for(let s=0;s<this.rows;s++){i[s]=[];for(let r=0;r<this.cols;r++){let n=this.get(s,r),h=t.get(s,r);n!==void 0&&h!==void 0&&(i[s][r]=(e=this._subtractFn(n,h))!=null?e:0)}}return new z(i,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(t){this.cols!==t.rows&&w(Error,R.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));let e=[];for(let i=0;i<this.rows;i++){e[i]=[];for(let s=0;s<t.cols;s++){let r;for(let n=0;n<this.cols;n++){let h=this.get(i,n),o=t.get(n,s);if(h!==void 0&&o!==void 0){let a=this.multiplyFn(h,o);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[i][s]=r)}}return new z(e,{rows:this.rows,cols:t.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){this.data.some(e=>e.length!==this.cols)&&w(Error,R.matrixNotRectangular());let t=[];for(let e=0;e<this.cols;e++){t[e]=[];for(let i=0;i<this.rows;i++){let s=this.get(i,e);s!==void 0&&(t[e][i]=s)}}return new z(t,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var t;this.rows!==this.cols&&w(Error,R.matrixNotSquare());let e=[];for(let r=0;r<this.rows;r++){e[r]=this.data[r].slice();for(let n=0;n<this.cols;n++)e[r][this.cols+n]=r===n?1:0}let i=new z(e,{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 n=r;for(;n<this.rows&&i.get(n,r)===0;)n++;n===this.rows&&w(Error,R.matrixSingular()),i._swapRows(r,n);let h=(t=i.get(r,r))!=null?t:1;h===0&&w(Error,R.matrixSingular()),i._scaleRow(r,1/h);for(let o=0;o<this.rows;o++)if(o!==r){let a=i.get(o,r);a===void 0&&(a=0),i._addScaledRow(o,r,-a)}}let s=[];for(let r=0;r<this.rows;r++)s[r]=i.data[r].slice(this.cols);return new z(s,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(t){this.cols!==t.rows&&w(Error,R.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));let e=[];for(let i=0;i<this.rows;i++){e[i]=[];for(let s=0;s<t.cols;s++){let r;for(let n=0;n<this.cols;n++){let h=this.get(i,n),o=t.get(n,s);if(h!==void 0&&o!==void 0){let a=this.multiplyFn(h,o);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[i][s]=r)}}return new z(e,{rows:this.rows,cols:t.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(t,e){return t>=0&&t<this.rows&&e>=0&&e<this.cols}clone(){return new z(this._data.map(t=>[...t]),{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}get size(){return[this._rows,this._cols]}isEmpty(){return this._rows===0||this._cols===0}toArray(){return this._data.map(t=>[...t])}flatten(){let t=[];for(let e of this._data)for(let i of e)t.push(i);return t}[Symbol.iterator](){let t=this._data,e=0;return{[Symbol.iterator](){return this},next(){return e<t.length?{value:[...t[e++]],done:!1}:{value:void 0,done:!0}}}}forEach(t){for(let e=0;e<this._rows;e++)for(let i=0;i<this._cols;i++)t(this._data[e][i],e,i)}map(t){let e=[];for(let i=0;i<this._rows;i++){e[i]=[];for(let s=0;s<this._cols;s++)e[i][s]=t(this._data[i][s],i,s)}return new z(e,{rows:this._rows,cols:this._cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}print(){for(let t of this._data)console.log(t.join(" "))}static zeros(t,e){let i=Array.from({length:t},()=>new Array(e).fill(0));return new z(i)}static identity(t){let e=Array.from({length:t},(i,s)=>Array.from({length:t},(r,n)=>s===n?1:0));return new z(e)}static from(t){return new z(t.map(e=>[...e]))}_addFn(t,e){return t===void 0?e:t+e}_subtractFn(t,e){return t-e}_multiplyFn(t,e){return t*e}_swapRows(t,e){let i=this.data[t];this.data[t]=this.data[e],this.data[e]=i}_scaleRow(t,e){for(let i=0;i<this.cols;i++){let s=this.multiplyFn(this.data[t][i],e);s===void 0&&(s=0),this.data[t][i]=s}}_addScaledRow(t,e,i){for(let s=0;s<this.cols;s++){let r=this.multiplyFn(this.data[e][s],i);r===void 0&&(r=0);let n=r,h=this.addFn(this.data[t][s],n);h===void 0&&(h=0),this.data[t][s]=h}}};u(mi,"Matrix");var Ie=class Ce{constructor(t,e){c(this,"direction"),c(this,"turn"),this.direction=t,this.turn=()=>new Ce(e[t],e)}};u(Ie,"Character");var yi=Ie,Mi=class{constructor({matrix:t,turning:e,onMove:i,init:{cur:s,charDir:r,VISITED:n}}){c(this,"onMove"),c(this,"_matrix"),c(this,"_cur"),c(this,"_character"),c(this,"_VISITED"),this._matrix=t,this._cur=s,this._character=new yi(r,e),this.onMove=i,this.onMove&&this.onMove(this._cur),this._VISITED=n,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:t}=this._character;this.check(t)?this.move(t):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(t){let e,i,s=this._matrix,[r,n]=this._cur;switch(t){case"up":if(i=s[r-1],!i)return!1;e=i[n];break;case"right":e=s[r][n+1];break;case"down":if(i=s[r+1],!i)return!1;e=i[n];break;case"left":e=s[r][n-1];break}return e!==void 0&&e!==this._VISITED}move(t){switch(t){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,i]=this._cur;this._matrix[e][i]=this._VISITED,this.onMove&&this.onMove(this._cur)}};u(Mi,"Navigator");var Te=class{constructor(t){c(this,"_key"),c(this,"_children"),c(this,"_isEnd"),this._key=t,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(t){this._key=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}};u(Te,"TrieNode");var mt=Te,ki=class extends ut{constructor(t=[],e){if(super(e),c(this,"_size",0),c(this,"_caseSensitive",!0),c(this,"_root",new mt("")),e){let{caseSensitive:i}=e;i!==void 0&&(this._caseSensitive=i)}t&&this.addMany(t)}get size(){return this._size}get caseSensitive(){return this._caseSensitive}get root(){return this._root}get _total(){return this._size}add(t){t=this._caseProcess(t);let e=this.root,i=!1;for(let s of t){let r=e.children.get(s);r||(r=new mt(s),e.children.set(s,r)),e=r}return e.isEnd||(i=!0,e.isEnd=!0,this._size++),i}addMany(t){let e=[];for(let i of t)this.toElementFn?e.push(this.add(this.toElementFn(i))):e.push(this.add(i));return e}has(t){t=this._caseProcess(t);let e=this.root;for(let i of t){let s=e.children.get(i);if(!s)return!1;e=s}return e.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new mt("")}delete(t){t=this._caseProcess(t);let e=!1,i=u((s,r)=>{let n=t[r],h=s.children.get(n);return h?r===t.length-1?h.isEnd?(h.children.size>0?h.isEnd=!1:s.children.delete(n),e=!0,!0):!1:i(h,r+1)&&!s.isEnd&&h.children.size===0?(s.children.delete(n),!0):!1:!1},"dfs");return i(this.root,0),e&&this._size--,e}getHeight(){let t=this.root,e=0;if(t){let i=u((s,r)=>{r>e&&(e=r);let{children:n}=s;if(n)for(let h of n.entries())i(h[1],r+1)},"bfs");i(t,0)}return e}hasPurePrefix(t){t=this._caseProcess(t);let e=this.root;for(let i of t){let s=e.children.get(i);if(!s)return!1;e=s}return!e.isEnd}hasPrefix(t){t=this._caseProcess(t);let e=this.root;for(let i of t){let s=e.children.get(i);if(!s)return!1;e=s}return!0}hasCommonPrefix(t){t=this._caseProcess(t);let e="",i=u(s=>{if(e+=s.key,e!==t&&!s.isEnd)if(s&&s.children&&s.children.size===1)i(Array.from(s.children.values())[0]);else return},"dfs");return i(this.root),e===t}getLongestCommonPrefix(){let t="",e=u(i=>{if(t+=i.key,!i.isEnd)if(i&&i.children&&i.children.size===1)e(Array.from(i.children.values())[0]);else return},"dfs");return e(this.root),t}getWords(t="",e=Number.MAX_SAFE_INTEGER,i=!1){t=this._caseProcess(t);let s=[],r=0,n=u((o,a)=>{for(let[l,_]of o.children){if(r>=e)return;n(_,a+l)}if(o.isEnd){if(r>=e)return;s.push(a),r++}},"dfs"),h=this.root;if(t)for(let o of t){let a=h.children.get(o);if(a)h=a;else return[]}return(i||h!==this.root)&&n(h,t),s}clone(){let t=this._createInstance();for(let e of this)t.add(e);return t}filter(t,e){let i=this._createInstance(),s=0;for(let r of this)t.call(e,r,s,this)&&i.add(r),s++;return i}map(t,e,i){let s=this._createLike([],e),r=0;for(let n of this){let h=i===void 0?t(n,r++,this):t.call(i,n,r++,this);typeof h!="string"&&w(TypeError,R.callbackReturnType("string",typeof h,"Trie.map")),s.add(h)}return s}mapSame(t,e){let i=this._createInstance(),s=0;for(let r of this){let n=e===void 0?t(r,s++,this):t.call(e,r,s++,this);i.add(n)}return i}_createInstance(t){let e=this.constructor;return new e([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive,...t!=null?t:{}})}_createLike(t=[],e){let i=this.constructor;return new i(t,e)}_spawnLike(t){return this._createLike([],t)}*_getIterator(){function*t(e,i){e.isEnd&&(yield i);for(let[s,r]of e.children)yield*t(r,i+s)}u(t,"_dfs"),yield*t(this.root,"")}_caseProcess(t){return this._caseSensitive||(t=t.toLowerCase()),t}};u(ki,"Trie");var bi=class Ae{constructor(t,e,i){c(this,"_key"),c(this,"_value"),c(this,"_children"),this._key=t,this._value=e||void 0,i&&(this._children=i)}get key(){return this._key}set key(t){this._key=t}get value(){return this._value}set value(t){this._value=t}get children(){return this._children}set children(t){this._children=t}addChildren(t){this._children||(this._children=[]),t instanceof Ae?this._children.push(t):this._children=this._children.concat(t)}getHeight(){let t=0;if(this){let e=u((i,s)=>{s>t&&(t=s);let{_children:r}=i;if(r)for(let n=0,h=r.length;n<h;n++)e(r[n],s+1)},"bfs");e(this,0)}return t}};u(bi,"TreeNode");return je(wi);})();
8
8
  /*! Bundled license information:
9
9
 
10
10
  data-structure-typed/dist/esm-legacy/index.mjs: