data-structure-typed 1.33.10 → 1.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/umd/bundle.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see bundle.min.js.LICENSE.txt */
2
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.dataStructureTyped=e():t.dataStructureTyped=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AVLTree:()=>it,AVLTreeNode:()=>st,AaTree:()=>lt,AbstractBinaryTree:()=>W,AbstractBinaryTreeNode:()=>Q,AbstractEdge:()=>z,AbstractGraph:()=>I,AbstractVertex:()=>A,ArrayDeque:()=>E,BST:()=>Z,BSTNode:()=>X,BTree:()=>rt,BinaryIndexedTree:()=>$,BinaryTree:()=>J,BinaryTreeNode:()=>Y,CP:()=>H,Character:()=>wt,CoordinateMap:()=>r,CoordinateSet:()=>n,Deque:()=>y,DirectedEdge:()=>C,DirectedGraph:()=>L,DirectedVertex:()=>O,DoublyLinkedList:()=>f,DoublyLinkedListNode:()=>d,FamilyPosition:()=>U,HashMap:()=>a,HashTable:()=>i,HashTableNode:()=>s,Heap:()=>gt,HeapItem:()=>ft,LinkedListQueue:()=>v,LoopType:()=>q,MapEdge:()=>D,MapGraph:()=>j,MapVertex:()=>B,Matrix2D:()=>bt,MatrixNTI2D:()=>yt,MaxHeap:()=>pt,MaxPriorityQueue:()=>mt,MinHeap:()=>_t,MinPriorityQueue:()=>vt,Navigator:()=>Tt,ObjectDeque:()=>x,Pair:()=>h,PriorityQueue:()=>N,Queue:()=>m,RBColor:()=>G,RBTree:()=>ht,RBTreeNode:()=>nt,SegmentTree:()=>et,SegmentTreeNode:()=>tt,SinglyLinkedList:()=>c,SinglyLinkedListNode:()=>u,SkipList:()=>p,SkipListNode:()=>g,SplayTree:()=>ot,Stack:()=>_,THUNK_SYMBOL:()=>T,TopologicalProperty:()=>K,TreeMap:()=>o,TreeMultiset:()=>ut,TreeMultisetNode:()=>at,TreeNode:()=>dt,TreeSet:()=>l,Trie:()=>St,TrieNode:()=>Mt,TwoThreeTree:()=>ct,UndirectedEdge:()=>P,UndirectedGraph:()=>F,UndirectedVertex:()=>k,Vector2D:()=>xt,arrayRemove:()=>w,isThunk:()=>M,toThunk:()=>S,trampoline:()=>R,trampolineAsync:()=>V,uuidV4:()=>b});class s{constructor(t,e){this.key=t,this.val=e,this.next=null}}class i{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get buckets(){return this._buckets}set buckets(t){this._buckets=t}get capacity(){return this._capacity}set capacity(t){this._capacity=t}constructor(t=i.DEFAULT_CAPACITY,e){this._hashFn=e||this._defaultHashFn,this._capacity=Math.max(t,i.DEFAULT_CAPACITY),this._size=0,this._buckets=new Array(this._capacity).fill(null)}_defaultHashFn(t){return("string"==typeof t?this._murmurStringHashFn(t):this._objectHash(t))%this._capacity}_multiplicativeStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=(.618033988749895*s+e.charCodeAt(t))%(1<<30);return Math.abs(s)}_murmurStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=1540483477*(s^e.charCodeAt(t)),s=668265261*(s^s>>>15),s^=s>>>15;return Math.abs(s)}_hash(t){return this.hashFn(t)}_stringHash(t){let e=0;for(let s=0;s<t.length;s++)e=31*e+t.charCodeAt(s)&4294967295;return e}_objectHash(t){return this._stringHash(JSON.stringify(t))}set(t,e){const r=this._hash(t),n=new s(t,e);if(this._buckets[r]){let s=this._buckets[r];for(;s;){if(s.key===t)return void(s.val=e);if(!s.next)break;s=s.next}s.next=n}else this._buckets[r]=n;this._size++,this._size/this._capacity>=i.LOAD_FACTOR&&this._expand()}get(t){const e=this._hash(t);let s=this._buckets[e];for(;s;){if(s.key===t)return s.val;s=s.next}}remove(t){const e=this._hash(t);let s=this._buckets[e],i=null;for(;s;){if(s.key===t)return i?i.next=s.next:this._buckets[e]=s.next,this._size--,void(s.next=null);i=s,s=s.next}}_expand(){const t=2*this._capacity,e=new Array(t).fill(null);for(const t of this._buckets){let i=t;for(;i;){const t=this._hash(i.key),r=new s(i.key,i.val);if(e[t]){let s=e[t];for(;s.next;)s=s.next;s.next=r}else e[t]=r;i=i.next}}this._buckets=e,this._capacity=t}get size(){return this._size}}i.DEFAULT_CAPACITY=16,i.LOAD_FACTOR=.75;class r extends Map{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}set(t,e){return super.set(t.join(this._joint),e)}get(t){return super.get(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class n extends Set{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}add(t){return super.add(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class h{}class o{}class l{}class a{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get table(){return this._table}set table(t){this._table=t}get capacityMultiplier(){return this._capacityMultiplier}set capacityMultiplier(t){this._capacityMultiplier=t}get loadFactor(){return this._loadFactor}set loadFactor(t){this._loadFactor=t}get initialCapacity(){return this._initialCapacity}set initialCapacity(t){this._initialCapacity=t}get size(){return this._size}set size(t){this._size=t}constructor(t=16,e=.75,s){this._initialCapacity=t,this._loadFactor=e,this._capacityMultiplier=2,this._size=0,this._table=new Array(t),this._hashFn=s||(t=>{const e=String(t);let s=0;for(let t=0;t<e.length;t++)s+=e.charCodeAt(t);return s%this.table.length})}_hash(t){return this._hashFn(t)}resizeTable(t){const e=new Array(t);for(const s of this._table)if(s)for(const[i,r]of s){const s=this._hash(i)%t;e[s]||(e[s]=[]),e[s].push([i,r])}this._table=e}set(t,e){this.size/this.table.length>=this.loadFactor&&this.resizeTable(this.table.length*this.capacityMultiplier);const s=this._hash(t);this.table[s]||(this.table[s]=[]);for(let i=0;i<this.table[s].length;i++)if(this.table[s][i][0]===t)return void(this.table[s][i][1]=e);this.table[s].push([t,e]),this.size++}get(t){const e=this._hash(t);if(this.table[e])for(const[s,i]of this.table[e])if(s===t)return i}remove(t){const e=this._hash(t);if(this.table[e])for(let s=0;s<this.table[e].length;s++)if(this.table[e][s][0]===t)return this.table[e].splice(s,1),this.size--,void(this.size/this.table.length<this.loadFactor/this.capacityMultiplier&&this.resizeTable(this.table.length/this.capacityMultiplier))}*entries(){for(const t of this.table)if(t)for(const[e,s]of t)yield[e,s]}[Symbol.iterator](){return this.entries()}clear(){this.size=0,this.table=new Array(this.initialCapacity)}isEmpty(){return 0===this.size}}class u{constructor(t){this._val=t,this._next=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}}class c{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new c;for(const s of t)e.push(s);return e}getLength(){return this._length}push(t){const e=new u(t);this.head?(this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}pop(){if(!this.head)return;if(this.head===this.tail){const t=this.head.val;return this.head=null,this.tail=null,this._length--,t}let t=this.head;for(;t.next!==this.tail;)t=t.next;const e=this.tail.val;return t.next=null,this.tail=t,this._length--,e}shift(){if(!this.head)return;const t=this.head;return this.head=this.head.next,this._length--,t.val}unshift(t){const e=new u(t);this.head?(e.next=this.head,this.head=e):(this.head=e,this.tail=e),this._length++}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t-1),s=e.next;return e.next=s.next,this._length--,s.val}delete(t){let e;e=t instanceof u?t.val:t;let s=this.head,i=null;for(;s;){if(s.val===e)return null===i?(this.head=s.next,s===this.tail&&(this.tail=null)):(i.next=s.next,s===this.tail&&(this.tail=i)),this._length--,!0;i=s,s=s.next}return!1}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new u(e),i=this.getNodeAt(t-1);return s.next=i.next,i.next=s,this._length++,!0}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}reverse(){if(!this.head||this.head===this.tail)return;let t=null,e=this.head,s=null;for(;e;)s=e.next,e.next=t,t=e,e=s;[this.head,this.tail]=[this.tail,this.head]}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertBefore(t,e){if(!this.head)return!1;let s;if(s=t instanceof u?t.val:t,this.head.val===s)return this.unshift(e),!0;let i=this.head;for(;i.next;){if(i.next.val===s){const t=new u(e);return t.next=i.next,i.next=t,this._length++,!0}i=i.next}return!1}insertAfter(t,e){let s;if(s=t instanceof u?t:this.findNode(t),s){const t=new u(e);return t.next=s.next,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}countOccurrences(t){let e=0,s=this.head;for(;s;)s.val===t&&e++,s=s.next;return e}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.val,t=t.next}}class d{constructor(t){this._val=t,this._next=null,this._prev=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}get prev(){return this._prev}set prev(t){this._prev=t}}class f{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new f;for(const s of t)e.push(s);return e}push(t){const e=new d(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}addLast(t){this.push(t)}pop(){if(!this.tail)return;const t=this.tail;return this.head===this.tail?(this.head=null,this.tail=null):(this.tail=t.prev,this.tail.next=null),this._length--,t.val}pollLast(){return this.pop()}shift(){if(!this.head)return;const t=this.head;return this.head===this.tail?(this.head=null,this.tail=null):(this.head=t.next,this.head.prev=null),this._length--,t.val}pollFirst(){return this.shift()}unshift(t){const e=new d(t);this.head?(e.next=this.head,this.head.prev=e,this.head=e):(this.head=e,this.tail=e),this._length++}addFirst(t){this.unshift(t)}peekFirst(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}peekLast(){var t;return null===(t=this.tail)||void 0===t?void 0:t.val}get size(){return this.length}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new d(e),i=this.getNodeAt(t-1),r=i.next;return s.prev=i,s.next=r,i.next=s,r.prev=s,this._length++,!0}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t),s=e.prev,i=e.next;return s.next=i,i.prev=s,this._length--,e.val}delete(t){let e;if(e=t instanceof d?t:this.findNode(t),e){if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{const t=e.prev,s=e.next;t.next=s,s.prev=t,this._length--}return!0}return!1}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findLast(t){let e=this.tail;for(;e;){if(t(e.val))return e.val;e=e.prev}return null}toArrayReverse(){const t=[];let e=this.tail;for(;e;)t.push(e.val),e=e.prev;return t}reverse(){let t=this.head;for([this.head,this.tail]=[this.tail,this.head];t;){const e=t.next;[t.prev,t.next]=[t.next,t.prev],t=e}}forEach(t){let e=this.head,s=0;for(;e;)t(e.val,s),e=e.next,s++}map(t){const e=new f;let s=this.head;for(;s;)e.push(t(s.val)),s=s.next;return e}filter(t){const e=new f;let s=this.head;for(;s;)t(s.val)&&e.push(s.val),s=s.next;return e}reduce(t,e){let s=e,i=this.head;for(;i;)s=t(s,i.val),i=i.next;return s}insertAfter(t,e){let s;if(s=t instanceof d?t:this.findNode(t),s){const t=new d(e);return t.next=s.next,s.next&&(s.next.prev=t),t.prev=s,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}insertBefore(t,e){let s;if(s=t instanceof d?t:this.findNode(t),s){const t=new d(e);return t.prev=s.prev,s.prev&&(s.prev.next=t),t.next=s,s.prev=t,s===this.head&&(this.head=t),this._length++,!0}return!1}}class g{constructor(t,e,s){this.key=t,this.value=e,this.forward=new Array(s)}}class p{get probability(){return this._probability}set probability(t){this._probability=t}get maxLevel(){return this._maxLevel}set maxLevel(t){this._maxLevel=t}get level(){return this._level}set level(t){this._level=t}get head(){return this._head}set head(t){this._head=t}constructor(t=16,e=.5){this._head=new g(null,null,t),this._level=0,this._maxLevel=t,this._probability=e}randomLevel(){let t=1;for(;Math.random()<this.probability&&t<this.maxLevel;)t++;return t}add(t,e){const s=new g(t,e,this.randomLevel()),i=new Array(this.maxLevel).fill(this.head);let r=this.head;for(let e=this.level-1;e>=0;e--){for(;r.forward[e]&&r.forward[e].key<t;)r=r.forward[e];i[e]=r}for(let t=0;t<s.forward.length;t++)s.forward[t]=i[t].forward[t],i[t].forward[t]=s;null!==s.forward[0]&&(this.level=Math.max(this.level,s.forward.length))}get(t){let e=this.head;for(let s=this.level-1;s>=0;s--)for(;e.forward[s]&&e.forward[s].key<t;)e=e.forward[s];if(e=e.forward[0],e&&e.key===t)return e.value}remove(t){const e=new Array(this.maxLevel).fill(this.head);let s=this.head;for(let i=this.level-1;i>=0;i--){for(;s.forward[i]&&s.forward[i].key<t;)s=s.forward[i];e[i]=s}if(s=s.forward[0],s&&s.key===t){for(let t=0;t<this.level&&e[t].forward[t]===s;t++)e[t].forward[t]=s.forward[t];for(;this.level>0&&null===this.head.forward[this.level-1];)this.level--;return!0}return!1}}class _{constructor(t){this._elements=Array.isArray(t)?t:[]}static fromArray(t){return new _(t)}isEmpty(){return 0===this._elements.length}size(){return this._elements.length}peek(){return this.isEmpty()?null:this._elements[this._elements.length-1]}push(t){return this._elements.push(t),this}pop(){return this.isEmpty()?null:this._elements.pop()||null}toArray(){return this._elements.slice()}clear(){this._elements=[]}clone(){return new _(this._elements.slice())}}class v extends c{enqueue(t){this.push(t)}dequeue(){return this.shift()}peek(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}}class m{constructor(t){this._nodes=t||[],this._offset=0}get nodes(){return this._nodes}set nodes(t){this._nodes=t}get offset(){return this._offset}set offset(t){this._offset=t}get size(){return this.nodes.length-this.offset}static fromArray(t){return new m(t)}push(t){return this.nodes.push(t),this}shift(){if(0===this.size)return;const t=this.peek();return this.offset+=1,2*this.offset<this.nodes.length||(this.nodes=this.nodes.slice(this.offset),this.offset=0),t}peek(){return this.size>0?this.nodes[this.offset]:void 0}peekLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}enqueue(t){this.push(t)}dequeue(){return this.shift()}getAt(t){return this.nodes[t]}isEmpty(){return 0===this.size}toArray(){return this.nodes.slice(this.offset)}clear(){this.nodes=[],this.offset=0}clone(){return new m(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(const t of this.nodes)yield t}}class y extends f{}class x{constructor(t){this._nodes={},this._capacity=Number.MAX_SAFE_INTEGER,this._first=-1,this._last=-1,this._size=0,void 0!==t&&(this._capacity=t)}get nodes(){return this._nodes}get capacity(){return this._capacity}set capacity(t){this._capacity=t}get first(){return this._first}set first(t){this._first=t}get last(){return this._last}set last(t){this._last=t}get size(){return this._size}addFirst(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._first--;this._nodes[this._first]=t,this._size++}addLast(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._last++;this._nodes[this._last]=t,this._size++}pollFirst(){if(!this._size)return;const t=this.peekFirst();return delete this._nodes[this._first],this._first++,this._size--,t}peekFirst(){if(this._size)return this._nodes[this._first]}pollLast(){if(!this._size)return;const t=this.peekLast();return delete this._nodes[this._last],this._last--,this._size--,t}peekLast(){if(this._size)return this._nodes[this._last]}get(t){return this._nodes[this._first+t]||null}isEmpty(){return this._size<=0}_seNodes(t){this._nodes=t}_setSize(t){this._size=t}}class E{constructor(){this._nodes=[]}get size(){return this._nodes.length}addLast(t){return this._nodes.push(t)}pollLast(){var t;return null!==(t=this._nodes.pop())&&void 0!==t?t:null}pollFirst(){var t;return null!==(t=this._nodes.shift())&&void 0!==t?t:null}addFirst(t){return this._nodes.unshift(t)}peekFirst(){var t;return null!==(t=this._nodes[0])&&void 0!==t?t:null}peekLast(){var t;return null!==(t=this._nodes[this._nodes.length-1])&&void 0!==t?t:null}get(t){var e;return null!==(e=this._nodes[t])&&void 0!==e?e:null}set(t,e){return this._nodes[t]=e}insert(t,e){return this._nodes.splice(t,0,e)}remove(t){return this._nodes.splice(t,1)}isEmpty(){return 0===this._nodes.length}}const b=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,(function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))},w=function(t,e){let s=-1,i=t?t.length:0;const r=[];for(;++s<i;){const n=t[s];e(n,s,t)&&(r.push(n),Array.prototype.splice.call(t,s--,1),i--)}return r},T=Symbol("thunk"),M=t=>"function"==typeof t&&t.__THUNK__===T,S=t=>{const e=()=>t();return e.__THUNK__=T,e},R=t=>Object.assign(((...e)=>{let s=t(...e);for(;M(s)&&"function"==typeof s;)s=s();return s}),{cont:(...e)=>S((()=>t(...e)))}),V=t=>Object.assign(((...e)=>{return s=void 0,i=void 0,n=function*(){let s=yield t(...e);for(;M(s)&&"function"==typeof s;)s=yield s();return s},new((r=void 0)||(r=Promise))((function(t,e){function h(t){try{l(n.next(t))}catch(t){e(t)}}function o(t){try{l(n.throw(t))}catch(t){e(t)}}function l(e){var s;e.done?t(e.value):(s=e.value,s instanceof r?s:new r((function(t){t(s)}))).then(h,o)}l((n=n.apply(s,i||[])).next())}));var s,i,r,n}),{cont:(...e)=>S((()=>t(...e)))});class N{constructor(t){this._nodes=[],this._comparator=(t,e)=>t-e;const{nodes:e,comparator:s,isFix:i=!0}=t;this._comparator=s,e&&Array.isArray(e)&&e.length>0&&(this._nodes=[...e],i&&this._fix())}get nodes(){return this._nodes}get size(){return this.nodes.length}static heapify(t){const e=new N(t);return e._fix(),e}static isPriorityQueueified(t){return new N(Object.assign(Object.assign({},t),{isFix:!1})).isValid()}getNodes(){return this._nodes}add(t){this.nodes.push(t),this._heapifyUp(this.size-1)}has(t){return this.nodes.includes(t)}peek(){return this.size?this.nodes[0]:null}poll(){var t,e;let s=null;return this.size>1?(this._swap(0,this.nodes.length-1),s=null!==(t=this.nodes.pop())&&void 0!==t?t:null,this._heapifyDown(0)):1===this.size&&(s=null!==(e=this.nodes.pop())&&void 0!==e?e:null),s}leaf(){var t;return null!==(t=this.nodes[this.size-1])&&void 0!==t?t:null}isEmpty(){return 0===this.size}clear(){this._setNodes([])}toArray(){return[...this.nodes]}clone(){return new N({nodes:this.nodes,comparator:this._comparator})}isValid(){for(let t=0;t<this.nodes.length;t++){const e=this._getLeft(t),s=this._getRight(t);if(this._isValidIndex(e)&&!this._compare(e,t))return!1;if(this._isValidIndex(s)&&!this._compare(s,t))return!1}return!0}sort(){const t=[];for(;0!==this.size;){const e=this.poll();e&&t.push(e)}return t}DFS(t){const e=[],s=i=>{var r,n,h;const o=this._getLeft(i),l=this._getRight(i);switch(t){case"in":this._isValidIndex(o)&&s(o),e.push(null!==(r=this.nodes[i])&&void 0!==r?r:null),this._isValidIndex(l)&&s(l);break;case"pre":e.push(null!==(n=this.nodes[i])&&void 0!==n?n:null),this._isValidIndex(o)&&s(o),this._isValidIndex(l)&&s(l);break;case"post":this._isValidIndex(o)&&s(o),this._isValidIndex(l)&&s(l),e.push(null!==(h=this.nodes[i])&&void 0!==h?h:null)}};return this._isValidIndex(0)&&s(0),e}_setNodes(t){this._nodes=t}_compare(t,e){return this._comparator(this.nodes[t],this.nodes[e])>0}_swap(t,e){const s=this.nodes[t];this.nodes[t]=this.nodes[e],this.nodes[e]=s}_isValidIndex(t){return t>-1&&t<this.nodes.length}_getParent(t){return Math.floor((t-1)/2)}_getLeft(t){return 2*t+1}_getRight(t){return 2*t+2}_getComparedChild(t){let e=t;const s=this._getLeft(t),i=this._getRight(t);return s<this.size&&this._compare(e,s)&&(e=s),i<this.size&&this._compare(e,i)&&(e=i),e}_heapifyUp(t){for(;t>0&&this._compare(this._getParent(t),t);){const e=this._getParent(t);this._swap(t,e),t=e}}_heapifyDown(t){let e=this._getComparedChild(t);for(;this._compare(t,e);)this._swap(e,t),t=e,e=this._getComparedChild(t)}_fix(){for(let t=Math.floor(this.size/2);t>-1;t--)this._heapifyDown(t)}}class A{constructor(t,e){this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}}class z{constructor(t,e){this._weight=void 0!==t?t:1,this._val=e,this._hashCode=b()}get val(){return this._val}set val(t){this._val=t}get weight(){return this._weight}set weight(t){this._weight=t}get hashCode(){return this._hashCode}_setHashCode(t){this._hashCode=t}}class I{constructor(){this._vertices=new Map}get vertices(){return this._vertices}getVertex(t){return this._vertices.get(t)||null}hasVertex(t){return this._vertices.has(this._getVertexId(t))}addVertex(t,e){if(t instanceof A)return this._addVertexOnly(t);{const s=this.createVertex(t,e);return this._addVertexOnly(s)}}removeVertex(t){const e=this._getVertexId(t);return this._vertices.delete(e)}removeAllVertices(t){const e=[];for(const s of t)e.push(this.removeVertex(s));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,s,i){if(t instanceof z)return this._addEdgeOnly(t);if(e instanceof A||"string"==typeof e||"number"==typeof e){if(!this.hasVertex(t)||!this.hasVertex(e))return!1;t instanceof A&&(t=t.id),e instanceof A&&(e=e.id);const r=this.createEdge(t,e,s,i);return this._addEdgeOnly(r)}throw new Error("dest must be a Vertex or vertex id while srcOrEdge is an Edge")}setEdgeWeight(t,e,s){const i=this.getEdge(t,e);return!!i&&(i.weight=s,!0)}getAllPathsBetween(t,e){const s=[],i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{r.set(t,!0),t===e&&s.push([i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),w(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}getPathSumWeight(t){var e;let s=0;for(let i=0;i<t.length;i++)s+=(null===(e=this.getEdge(t[i],t[i+1]))||void 0===e?void 0:e.weight)||0;return s}getMinCostBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0;for(const t of s)i=Math.min(this.getPathSumWeight(t),i);return i}{const s=this._getVertex(e),i=this._getVertex(t);if(!i||!s)return null;const r=new Map,n=[i];r.set(i,!0);let h=0;for(;n.length>0;){for(let t=0;t<n.length;t++){const t=n.shift();if(t===s)return h;if(void 0!==t){const e=this.getNeighbors(t);for(const t of e)r.has(t)||(r.set(t,!0),n.push(t))}}h++}return null}}getMinPathBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0,r=-1,n=0;for(const t of s){const e=this.getPathSumWeight(t);e<i&&(i=e,r=n),n++}return s[r]||null}{let s=[];const i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{if(r.set(t,!0),t===e)return void(s=[i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),w(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}}dijkstraWithoutHeap(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let r=1/0,n=null,h=[];const o=[],l=this._vertices,a=new Map,u=new Set,c=new Map,d=this._getVertex(t),f=e?this._getVertex(e):null;if(!d)return null;for(const t of l){const e=t[1];e instanceof A&&a.set(e,1/0)}a.set(d,0),c.set(d,null);const g=()=>{let t=1/0,e=null;for(const[s,i]of a)u.has(s)||i<t&&(t=i,e=s);return e},p=t=>{for(const e of l){const s=e[1];if(s instanceof A){const i=[s];let r=c.get(s);for(;r;)i.push(r),r=c.get(r);const n=i.reverse();e[1]===t&&(h=n),o.push(n)}}};for(let t=1;t<l.size;t++){const t=g();if(t){if(u.add(t),f&&f===t)return s&&(r=a.get(f)||1/0),i&&p(f),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h};const e=this.getNeighbors(t);for(const s of e)if(!u.has(s)){const e=this.getEdge(t,s);if(e){const i=a.get(t),r=a.get(s);void 0!==i&&void 0!==r&&e.weight+i<r&&(a.set(s,e.weight+i),c.set(s,t))}}}}return s&&a.forEach(((t,e)=>{e!==d&&t<r&&(r=t,i&&(n=e))})),i&&p(n),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h}}dijkstra(t,e,s,i){var r;void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let n=1/0,h=null,o=[];const l=[],a=this._vertices,u=new Map,c=new Set,d=new Map,f=this._getVertex(t),g=e?this._getVertex(e):null;if(!f)return null;for(const t of a){const e=t[1];e instanceof A&&u.set(e,1/0)}const p=new N({comparator:(t,e)=>t.id-e.id});p.add({id:0,val:f}),u.set(f,0),d.set(f,null);const _=t=>{for(const e of a){const s=e[1];if(s instanceof A){const i=[s];let r=d.get(s);for(;r;)i.push(r),r=d.get(r);const n=i.reverse();e[1]===t&&(o=n),l.push(n)}}};for(;p.size>0;){const t=p.poll(),e=null==t?void 0:t.id,h=null==t?void 0:t.val;if(void 0!==e&&h){if(c.add(h),g&&g===h)return s&&(n=u.get(g)||1/0),i&&_(g),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o};const t=this.getNeighbors(h);for(const s of t)if(!c.has(s)){const t=null===(r=this.getEdge(h,s))||void 0===r?void 0:r.weight;if("number"==typeof t){const i=u.get(s);i&&e+t<i&&(p.add({id:e+t,val:s}),d.set(s,h),u.set(s,e+t))}}}}return s&&u.forEach(((t,e)=>{e!==f&&t<n&&(n=t,i&&(h=e))})),i&&_(h),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o}}bellmanFord(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1);const r=this._getVertex(t),n=[],h=new Map,o=new Map;let l,a=1/0,u=[];if(e&&(l=!1),!r)return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u};const c=this._vertices,d=c.size,f=this.edgeSet(),g=f.length;this._vertices.forEach((t=>{h.set(t,1/0)})),h.set(r,0);for(let t=1;t<d;++t)for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s,r]=e,n=f[t].weight,l=h.get(s),a=h.get(r);void 0!==l&&void 0!==a&&h.get(s)!==1/0&&l+n<a&&(h.set(r,l+n),i&&o.set(r,s))}}let p=null;if(s&&h.forEach(((t,e)=>{e!==r&&t<a&&(a=t,i&&(p=e))})),i)for(const t of c){const e=t[1];if(e instanceof A){const s=[e];let i=o.get(e);for(;void 0!==i;)s.push(i),i=o.get(i);const r=s.reverse();t[1]===p&&(u=r),n.push(r)}}for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s]=e,i=f[t].weight,r=h.get(s);r&&r!==1/0&&r+i<r&&(l=!0)}}return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u}}floyd(){var t;const e=[...this._vertices],s=e.length,i=[],r=[];for(let t=0;t<s;t++){i[t]=[],r[t]=[];for(let e=0;e<s;e++)r[t][e]=null}for(let r=0;r<s;r++)for(let n=0;n<s;n++)i[r][n]=(null===(t=this.getEdge(e[r][1],e[n][1]))||void 0===t?void 0:t.weight)||1/0;for(let t=0;t<s;t++)for(let n=0;n<s;n++)for(let h=0;h<s;h++)i[n][h]>i[n][t]+i[t][h]&&(i[n][h]=i[n][t]+i[t][h],r[n][h]=e[t][1]);return{costs:i,predecessor:r}}tarjan(t,e,s,i){const r=!1;void 0===t&&(t=r),void 0===e&&(e=r),void 0===s&&(s=r),void 0===i&&(i=r);const n=new Map,h=new Map,o=this._vertices;o.forEach((t=>{n.set(t,-1),h.set(t,1/0)}));const[l]=o.values(),a=[],u=[];let c=0;const d=(s,i)=>{c++,n.set(s,c),h.set(s,c);const r=this.getNeighbors(s);let o=0;for(const c of r)if(c!==i){-1===n.get(c)&&(o++,d(c,s));const i=h.get(c),r=h.get(s);void 0!==r&&void 0!==i&&h.set(s,Math.min(r,i));const f=n.get(s);if(void 0!==i&&void 0!==f&&(t&&(s===l&&o>=2||s!==l&&i>=f)&&a.push(s),e&&i>f)){const t=this.getEdge(s,c);t&&u.push(t)}}};d(l,null);let f=new Map;const g=()=>{const t=new Map;return h.forEach(((e,s)=>{var i;t.has(e)?null===(i=t.get(e))||void 0===i||i.push(s):t.set(e,[s])})),t};s&&(f=g());const p=new Map;if(i){let t=new Map;t.size<1&&(t=g()),t.forEach(((t,e)=>{t.length>1&&p.set(e,t)}))}return{dfnMap:n,lowMap:h,bridges:u,articulationPoints:a,SCCs:f,cycles:p}}_addVertexOnly(t){return!this.hasVertex(t)&&(this._vertices.set(t.id,t),!0)}_getVertex(t){const e=this._getVertexId(t);return this._vertices.get(e)||null}_getVertexId(t){return t instanceof A?t.id:t}_setVertices(t){this._vertices=t}}class O extends A{constructor(t,e){super(t,e)}}class C extends z{constructor(t,e,s,i){super(s,i),this._src=t,this._dest=e}get src(){return this._src}set src(t){this._src=t}get dest(){return this._dest}set dest(t){this._dest=t}}class L extends I{constructor(){super(),this._outEdgeMap=new Map,this._inEdgeMap=new Map}get outEdgeMap(){return this._outEdgeMap}get inEdgeMap(){return this._inEdgeMap}createVertex(t,e){return new O(t,null!=e?e:t)}createEdge(t,e,s,i){return new C(t,e,null!=s?s:1,i)}getEdge(t,e){let s=[];if(null!==t&&null!==e){const i=this._getVertex(t),r=this._getVertex(e);if(i&&r){const t=this._outEdgeMap.get(i);t&&(s=t.filter((t=>t.dest===r.id)))}}return s[0]||null}removeEdgeSrcToDest(t,e){const s=this._getVertex(t),i=this._getVertex(e);let r=null;if(!s||!i)return null;const n=this._outEdgeMap.get(s);n&&w(n,(t=>t.dest===i.id));const h=this._inEdgeMap.get(i);return h&&(r=w(h,(t=>t.src===s.id))[0]||null),r}removeEdge(t){let e=null;const s=this._getVertex(t.src),i=this._getVertex(t.dest);if(s&&i){const t=this._outEdgeMap.get(s);t&&t.length>0&&w(t,(t=>t.src===s.id));const r=this._inEdgeMap.get(i);r&&r.length>0&&(e=w(r,(t=>t.dest===i.id))[0])}return e}removeEdgesBetween(t,e){const s=[];if(t&&e){const i=this.removeEdgeSrcToDest(t,e),r=this.removeEdgeSrcToDest(e,t);i&&s.push(i),r&&s.push(r)}return s}incomingEdgesOf(t){const e=this._getVertex(t);return e&&this.inEdgeMap.get(e)||[]}outgoingEdgesOf(t){const 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(null===t)return[];const e=[],s=this.outgoingEdgesOf(t);for(const t of s){const s=this.getEdgeDest(t);s&&e.push(s)}return e}topologicalSort(t){t=null!=t?t:"id";const e=new Map;for(const t of this.vertices)e.set(t[1],0);let s=[],i=!1;const r=t=>{e.set(t,1);const n=this.getDestinations(t);for(const t of n){const s=e.get(t);0===s?r(t):1===s&&(i=!0)}e.set(t,2),s.push(t)};for(const t of this.vertices)0===e.get(t[1])&&r(t[1]);return i?null:("id"===t&&(s=s.map((t=>t instanceof O?t.id:t))),s.reverse())}edgeSet(){let t=[];return this._outEdgeMap.forEach((e=>{t=[...t,...e]})),t}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.outgoingEdgesOf(s);for(const s of t){const t=this._getVertex(s.dest);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return null;const e=this._getVertex(t.src),s=this._getVertex(t.dest);return e&&s?[e,s]:null}_addEdgeOnly(t){if(!this.hasVertex(t.src)||!this.hasVertex(t.dest))return!1;const e=this._getVertex(t.src),s=this._getVertex(t.dest);if(e&&s){const i=this._outEdgeMap.get(e);i?i.push(t):this._outEdgeMap.set(e,[t]);const r=this._inEdgeMap.get(s);return r?r.push(t):this._inEdgeMap.set(s,[t]),!0}return!1}_setOutEdgeMap(t){this._outEdgeMap=t}_setInEdgeMap(t){this._inEdgeMap=t}}class k extends A{constructor(t,e){super(t,e)}}class P extends z{constructor(t,e,s,i){super(s,i),this._vertices=[t,e]}get vertices(){return this._vertices}set vertices(t){this._vertices=t}}class F extends I{constructor(){super(),this._edges=new Map}get edges(){return this._edges}createVertex(t,e){return new k(t,null!=e?e:t)}createEdge(t,e,s,i){return new P(t,e,null!=s?s:1,i)}getEdge(t,e){var s;let i=[];if(null!==t&&null!==e){const r=this._getVertex(t),n=this._getVertex(e);r&&n&&(i=null===(s=this._edges.get(r))||void 0===s?void 0:s.filter((t=>t.vertices.includes(n.id))))}return i&&i[0]||null}removeEdgeBetween(t,e){const s=this._getVertex(t),i=this._getVertex(e);if(!s||!i)return null;const r=this._edges.get(s);let n=null;r&&(n=w(r,(t=>t.vertices.includes(i.id)))[0]||null);const h=this._edges.get(i);return h&&w(h,(t=>t.vertices.includes(s.id))),n}removeEdge(t){return this.removeEdgeBetween(t.vertices[0],t.vertices[1])}degreeOf(t){var e;const s=this._getVertex(t);return s&&(null===(e=this._edges.get(s))||void 0===e?void 0:e.length)||0}edgesOf(t){const e=this._getVertex(t);return e&&this._edges.get(e)||[]}edgeSet(){const t=new Set;return this._edges.forEach((e=>{e.forEach((e=>{t.add(e)}))})),[...t]}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.edgesOf(s);for(const i of t){const t=this._getVertex(i.vertices.filter((t=>t!==s.id))[0]);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.vertices[0],t.vertices[1]))return null;const e=this._getVertex(t.vertices[0]),s=this._getVertex(t.vertices[1]);return e&&s?[e,s]:null}_addEdgeOnly(t){for(const e of t.vertices){const s=this._getVertex(e);if(null===s)return!1;if(s){const e=this._edges.get(s);e?e.push(t):this._edges.set(s,[t])}}return!0}_setEdges(t){this._edges=t}}class B extends O{constructor(t,e,s,i){super(t,i),this._lat=e,this._long=s}get lat(){return this._lat}set lat(t){this._lat=t}get long(){return this._long}set long(t){this._long=t}}class D extends C{constructor(t,e,s,i){super(t,e,s,i)}}class j extends L{constructor(t,e){super(),this._origin=[0,0],this._origin=t,this._bottomRight=e}get origin(){return this._origin}set origin(t){this._origin=t}get bottomRight(){return this._bottomRight}set bottomRight(t){this._bottomRight=t}createVertex(t,e,s=this.origin[0],i=this.origin[1]){return new B(t,s,i,e)}createEdge(t,e,s,i){return new D(t,e,s,i)}}var H,q,U,G,K;!function(t){t.lt="lt",t.eq="eq",t.gt="gt"}(H||(H={})),function(t){t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE"}(q||(q={})),function(t){t.ROOT="ROOT",t.LEFT="LEFT",t.RIGHT="RIGHT",t.ROOT_LEFT="ROOT_LEFT",t.ROOT_RIGHT="ROOT_RIGHT",t.ISOLATED="ISOLATED",t.MAL_NODE="MAL_NODE"}(U||(U={})),function(t){t.RED="RED",t.BLACK="BLACK"}(G||(G={})),function(t){t.VAL="VAL",t.NODE="NODE",t.ID="ID"}(K||(K={}));class Q{constructor(t,e){this._height=0,this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}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 parent(){return this._parent}set parent(t){this._parent=t}get height(){return this._height}set height(t){this._height=t}get familyPosition(){const t=this;return t.parent?t.parent.left===t?t.left||t.right?U.ROOT_LEFT:U.LEFT:t.parent.right===t?t.left||t.right?U.ROOT_RIGHT:U.RIGHT:U.MAL_NODE:t.left||t.right?U.ROOT:U.ISOLATED}}class W{constructor(t){if(this._root=null,this._size=0,this._loopType=q.ITERATIVE,this._visitedId=[],this._visitedVal=[],this._visitedNode=[],void 0!==t){const{loopType:e=q.ITERATIVE}=t;this._loopType=e}this.clear()}get root(){return this._root}get size(){return this._size}get loopType(){return this._loopType}get visitedId(){return this._visitedId}get visitedVal(){return this._visitedVal}get visitedNode(){return this._visitedNode}swapLocation(t,e){const{id:s,val:i,height:r}=e,n=this.createNode(s,i);return n&&(n.height=r,e.id=t.id,e.val=t.val,e.height=t.height,t.id=n.id,t.val=n.val,t.height=n.height),e}clear(){this._root=null,this._size=0,this._clearResults()}isEmpty(){return 0===this.size}add(t,e){let s,i;if(null===t)i=null;else if("number"==typeof t)i=this.createNode(t,e);else{if(!(t instanceof Q))return;i=t}const r=t?this.get(t,"id"):void 0;return this.root?r?(r.val=e,s=r):s=((t,e)=>{const s=[t];for(;s.length>0;){const t=s.shift();if(!t)return;{if(e&&t.id===e.id)return;const i=this._addTo(e,t);if(void 0!==i)return i;t.left&&s.push(t.left),t.right&&s.push(t.right)}}})(this.root,i):(this._setRoot(i),null!==i?this._setSize(1):this._setSize(0),s=this.root),s}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];if(r instanceof Q){s.push(this.add(r.id,r.val));continue}if(null===r){s.push(this.add(null));continue}const n=null==e?void 0:e[i];s.push(this.add(r,n))}return s}fill(t,e){return this.clear(),t.length===this.addMany(t,e).length}remove(t){const e=[];if(!this.root)return e;const s="number"==typeof t?this.get(t):t;if(!s)return e;const i=(null==s?void 0:s.parent)?s.parent:null;let r=null,n=s;if(s.left){const t=s.left?this.getRightMost(s.left):null;if(t){const e=t.parent;n=this.swapLocation(s,t),e&&(e.right===t?e.right=t.left:e.left=t.left,r=e)}}else if(i){const{familyPosition:t}=s;t===U.LEFT||t===U.ROOT_LEFT?i.left=s.right:t!==U.RIGHT&&t!==U.ROOT_RIGHT||(i.right=s.right),r=i}else void 0!==s.right&&this._setRoot(s.right);return this._setSize(this.size-1),e.push({deleted:n,needBalanced:r}),e}getDepth(t){"number"==typeof t&&(t=this.get(t,"id"));let e=0;for(;null==t?void 0:t.parent;)e++,t=t.parent;return e}getHeight(t){if("number"==typeof(t=null!=t?t:this.root)&&(t=this.get(t,"id")),!t)return-1;if(this._loopType===q.RECURSIVE){const e=t=>{if(!t)return-1;const s=e(t.left),i=e(t.right);return Math.max(s,i)+1};return e(t)}{if(!t)return-1;const e=[{node:t,depth:0}];let s=0;for(;e.length>0;){const{node:t,depth:i}=e.pop();t.left&&e.push({node:t.left,depth:i+1}),t.right&&e.push({node:t.right,depth:i+1}),s=Math.max(s,i)}return s}}getMinHeight(t){var e,s,i;if(!(t=t||this.root))return-1;if(this._loopType===q.RECURSIVE){const e=t=>{if(!t)return 0;if(!t.left&&!t.right)return 0;const s=e(t.left),i=e(t.right);return Math.min(s,i)+1};return e(t)}{const r=[];let n=t,h=null;const o=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],n.right&&h!==n.right)n=n.right;else if(n=r.pop(),n){const t=n.left&&null!==(e=o.get(n.left))&&void 0!==e?e:-1,i=n.right&&null!==(s=o.get(n.right))&&void 0!==s?s:-1;o.set(n,1+Math.min(t,i)),h=n,n=null}return null!==(i=o.get(t))&&void 0!==i?i:-1}}isPerfectlyBalanced(t){return this.getMinHeight(t)+1>=this.getHeight(t)}getNodes(t,e,s){if(!this.root)return[];e=null!=e?e:"id";const i=[];if(this.loopType===q.RECURSIVE){const r=n=>{this._pushByPropertyNameStopOrNot(n,i,t,e,s)||(n.left||n.right)&&(n.left&&r(n.left),n.right&&r(n.right))};r(this.root)}else{const r=[this.root];for(;r.length>0;){const n=r.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,i,t,e,s))return i;n.left&&r.push(n.left),n.right&&r.push(n.right)}}}return i}has(t,e){return e=null!=e?e:"id",this.getNodes(t,e).length>0}get(t,e){var s;return e=null!=e?e:"id",null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}getPathToRoot(t,e=!0){const s=[];for(;t.parent;)s.push(t),t=t.parent;return s.push(t),e?s.reverse():s}getLeftMost(t){if("number"==typeof t&&(t=this.get(t,"id")),!(t=null!=t?t:this.root))return t;if(this._loopType===q.RECURSIVE){const e=t=>t.left?e(t.left):t;return e(t)}{const e=R((t=>t.left?e.cont(t.left):t));return e(t)}}getRightMost(t){if(!(t=null!=t?t:this.root))return t;if(this._loopType===q.RECURSIVE){const e=t=>t.right?e(t.right):t;return e(t)}{const e=R((t=>t.right?e.cont(t.right):t));return e(t)}}isSubtreeBST(t){if(!t)return!0;if(this._loopType===q.RECURSIVE){const e=(t,s,i)=>!t||!(t.id<=s||t.id>=i)&&e(t.left,s,t.id)&&e(t.right,t.id,i);return e(t,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}{const e=[];let s=Number.MIN_SAFE_INTEGER,i=t;for(;i||e.length>0;){for(;i;)e.push(i),i=i.left;if(i=e.pop(),!i||s>=i.id)return!1;s=i.id,i=i.right}return!0}}isBST(){return this.isSubtreeBST(this.root)}getSubTreeSize(t){let e=0;if(!t)return e;if(this._loopType===q.RECURSIVE){const s=t=>{e++,t.left&&s(t.left),t.right&&s(t.right)};return s(t),e}{const s=[t];for(;s.length>0;){const t=s.pop();e++,t.right&&s.push(t.right),t.left&&s.push(t.left)}return e}}subTreeSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let s=0;const i=t=>{let s;switch(e){case"id":default:s=t.id;break;case"val":s="number"==typeof t.val?t.val:0}return s};if(this._loopType===q.RECURSIVE){const e=t=>{s+=i(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();s+=i(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return s}subTreeAdd(t,e,s){if(s=null!=s?s:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t=>{t.id+=e};if(this._loopType===q.RECURSIVE){const e=t=>{i(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();i(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}BFS(t){t=null!=t?t:"id",this._clearResults();const e=[this.root];for(;0!==e.length;){const s=e.shift();s&&(this._accumulatedByPropertyName(s,t),null!==(null==s?void 0:s.left)&&e.push(s.left),null!==(null==s?void 0:s.right)&&e.push(s.right))}return this._getResultByPropertyName(t)}DFS(t,e){t=null!=t?t:"in",e=null!=e?e:"id",this._clearResults();const s=i=>{switch(t){case"in":i.left&&s(i.left),this._accumulatedByPropertyName(i,e),i.right&&s(i.right);break;case"pre":this._accumulatedByPropertyName(i,e),i.left&&s(i.left),i.right&&s(i.right);break;case"post":i.left&&s(i.left),i.right&&s(i.right),this._accumulatedByPropertyName(i,e)}};return this.root&&s(this.root),this._getResultByPropertyName(e)}DFSIterative(t,e){if(t=t||"in",e=e||"id",this._clearResults(),!this.root)return this._getResultByPropertyName(e);const s=[{opt:0,node:this.root}];for(;s.length>0;){const i=s.pop();if(i&&i.node)if(1===i.opt)this._accumulatedByPropertyName(i.node,e);else switch(t){case"in":default:s.push({opt:0,node:i.node.right}),s.push({opt:1,node:i.node}),s.push({opt:0,node:i.node.left});break;case"pre":s.push({opt:0,node:i.node.right}),s.push({opt:0,node:i.node.left}),s.push({opt:1,node:i.node});break;case"post":s.push({opt:1,node:i.node}),s.push({opt:0,node:i.node.right}),s.push({opt:0,node:i.node.left})}}return this._getResultByPropertyName(e)}levelIterative(t,e){if(e=e||"id",!(t=t||this.root))return[];this._clearResults();const s=[t];for(;s.length>0;){const t=s.shift();t&&(this._accumulatedByPropertyName(t,e),t.left&&s.push(t.left),t.right&&s.push(t.right))}return this._getResultByPropertyName(e)}listLevels(t,e){if(e=e||"id",!(t=t||this.root))return[];const s=[],i=(t,i)=>{switch(e){case"id":default:s[i].push(t.id);break;case"val":s[i].push(t.val);break;case"node":s[i].push(t)}};if(this.loopType===q.RECURSIVE){const e=(t,r)=>{s[r]||(s[r]=[]),i(t,r),t.left&&e(t.left,r+1),t.right&&e(t.right,r+1)};e(t,0)}else{const e=[[t,0]];for(;e.length>0;){const t=e.pop(),[r,n]=t;s[n]||(s[n]=[]),i(r,n),r.right&&e.push([r.right,n+1]),r.left&&e.push([r.left,n+1])}}return s}getPredecessor(t){if(t.left){let e=t.left;for(;!e||e.right&&e.right!==t;)e&&(e=e.right);return e}return t}morris(t,e){if(null===this.root)return[];t=t||"in",e=e||"id",this._clearResults();let s=this.root;const i=t=>{let e=null,s=null;for(;t;)s=t.right,t.right=e,e=t,t=s;return e},r=t=>{const s=i(t);let r=s;for(;r;)this._accumulatedByPropertyName(r,e),r=r.right;i(s)};switch(t){case"in":for(;s;){if(s.left){const t=this.getPredecessor(s);if(!t.right){t.right=s,s=s.left;continue}t.right=null}this._accumulatedByPropertyName(s,e),s=s.right}break;case"pre":for(;s;){if(s.left){const t=this.getPredecessor(s);if(!t.right){t.right=s,this._accumulatedByPropertyName(s,e),s=s.left;continue}t.right=null}else this._accumulatedByPropertyName(s,e);s=s.right}break;case"post":for(;s;){if(s.left){const t=this.getPredecessor(s);if(null===t.right){t.right=s,s=s.left;continue}t.right=null,r(s.left)}s=s.right}r(this.root)}return this._getResultByPropertyName(e)}_addTo(t,e){return e?void 0===e.left?(e.left=t,t&&this._setSize(this.size+1),e.left):void 0===e.right?(e.right=t,t&&this._setSize(this.size+1),e.right):void 0:void 0}_setLoopType(t){this._loopType=t}_setVisitedId(t){this._visitedId=t}_setVisitedVal(t){this._visitedVal=t}_setVisitedNode(t){this._visitedNode=t}_setRoot(t){t&&(t.parent=void 0),this._root=t}_setSize(t){this._size=t}_clearResults(){this._visitedId=[],this._visitedVal=[],this._visitedNode=[]}_pushByPropertyNameStopOrNot(t,e,s,i,r){switch(i){case"id":default:if(t.id===s)return e.push(t),!!r;break;case"val":if(t.val===s)return e.push(t),!!r}}_accumulatedByPropertyName(t,e){switch(e=null!=e?e:"id"){case"id":default:this._visitedId.push(t.id);break;case"val":this._visitedVal.push(t.val);break;case"node":this._visitedNode.push(t)}}_getResultByPropertyName(t){switch(t=null!=t?t:"id"){case"id":default:return this._visitedId;case"val":return this._visitedVal;case"node":return this._visitedNode}}}class Y extends Q{constructor(t,e){super(t,e)}}class J extends W{constructor(t){super(t)}createNode(t,e){return new Y(t,e)}}class X extends Y{constructor(t,e){super(t,e)}}class Z extends J{constructor(t){if(super(t),this._comparator=(t,e)=>t-e,void 0!==t){const{comparator:e}=t;void 0!==e&&(this._comparator=e)}}createNode(t,e){return new X(t,e)}add(t,e){let s=null,i=null;if(t instanceof X?i=t:"number"==typeof t?i=this.createNode(t,e):null===t&&(i=null),null===this.root)this._setRoot(i),this._setSize(this.size+1),s=this.root;else{let t=this.root,e=!0;for(;e;)null!==t&&null!==i?this._compare(t.id,i.id)===H.eq?(i&&(t.val=i.val),e=!1,s=t):this._compare(t.id,i.id)===H.gt?void 0===t.left?(i&&(i.parent=t),t.left=i,this._setSize(this.size+1),e=!1,s=t.left):t.left&&(t=t.left):this._compare(t.id,i.id)===H.lt&&(void 0===t.right?(i&&(i.parent=t),t.right=i,this._setSize(this.size+1),e=!1,s=t.right):t.right&&(t=t.right)):e=!1}return s}addMany(t,e,s=!1){if(!s||-1!==t.indexOf(null))return super.addMany(t,e);const i=[],r=t.map(((t,s)=>[t,null==e?void 0:e[s]]));let n=[],h=[],o=[];if(function(t){for(const[e]of t)if(e instanceof X)return!0;return!1}(r))n=r.sort(((t,e)=>t[0].id-e[0].id));else{if(!function(t){for(const[e]of t)if("number"==typeof e)return!0;return!1}(r))throw new Error("Invalid input idsOrNodes");n=r.sort(((t,e)=>t[0]-e[0]))}h=n.map((([t])=>t)),o=n.map((([,t])=>t));const l=(t,e)=>{if(0===t.length)return;const s=Math.floor((t.length-1)/2),r=this.add(t[s],null==e?void 0:e[s]);i.push(r),l(t.slice(0,s),null==e?void 0:e.slice(0,s)),l(t.slice(s+1),null==e?void 0:e.slice(s+1))};return this.loopType===q.RECURSIVE?l(h,o):(()=>{const t=[[0,n.length-1]];for(;t.length>0;){const e=t.pop();if(e){const[s,r]=e;if(s<=r){const e=s+Math.floor((r-s)/2),n=this.add(h[e],null==o?void 0:o[e]);i.push(n),t.push([e+1,r]),t.push([s,e-1])}}}})(),i}get(t,e){var s;return e=null!=e?e:"id",null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}lastKey(){var t,e,s,i,r,n;return this._compare(0,1)===H.lt?null!==(e=null===(t=this.getRightMost())||void 0===t?void 0:t.id)&&void 0!==e?e:0:this._compare(0,1)===H.gt?null!==(i=null===(s=this.getLeftMost())||void 0===s?void 0:s.id)&&void 0!==i?i:0:null!==(n=null===(r=this.getRightMost())||void 0===r?void 0:r.id)&&void 0!==n?n:0}getNodes(t,e="id",s){if(!this.root)return[];const i=[];if(this.loopType===q.RECURSIVE){const r=n=>{this._pushByPropertyNameStopOrNot(n,i,t,e,s)||(n.left||n.right)&&("id"===e?(this._compare(n.id,t)===H.gt&&n.left&&r(n.left),this._compare(n.id,t)===H.lt&&n.right&&r(n.right)):(n.left&&r(n.left),n.right&&r(n.right)))};r(this.root)}else{const r=[this.root];for(;r.length>0;){const n=r.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,i,t,e,s))return i;"id"===e?(this._compare(n.id,t)===H.gt&&n.left&&r.push(n.left),this._compare(n.id,t)===H.lt&&n.right&&r.push(n.right)):(n.left&&r.push(n.left),n.right&&r.push(n.right))}}}return i}lesserSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const s=t.id,i=t=>{let e;return e=t.id,e};let r=0;if(this.loopType===q.RECURSIVE){const t=n=>{const h=this._compare(n.id,s);if(h!==H.eq)if(h===H.lt){if(n.left&&(r+=this.subTreeSum(n.left,e)),r+=i(n),!n.right)return;t(n.right)}else{if(!n.left)return;t(n.left)}else n.right&&(r+=this.subTreeSum(n.right,e))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const n=t.shift();if(n){const h=this._compare(n.id,s);if(h===H.eq)return n.right&&(r+=this.subTreeSum(n.right,e)),r;if(h===H.lt){if(n.left&&(r+=this.subTreeSum(n.left,e)),r+=i(n),!n.right)return r;t.push(n.right)}else{if(!n.left)return r;t.push(n.left)}}}}return r}allGreaterNodesAdd(t,e,s){if(s=null!=s?s:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t.id;if(!this.root)return!1;const r=t=>{t.id+=e};if(this.loopType===q.RECURSIVE){const t=e=>{this._compare(e.id,i)===H.gt&&r(e),(e.left||e.right)&&(e.left&&this._compare(e.left.id,i)===H.gt&&t(e.left),e.right&&this._compare(e.right.id,i)===H.gt&&t(e.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const e=t.shift();e&&(this._compare(e.id,i)===H.gt&&r(e),e.left&&this._compare(e.left.id,i)===H.gt&&t.push(e.left),e.right&&this._compare(e.right.id,i)===H.gt&&t.push(e.right))}return!0}}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(this.clear(),t.length<1)return!1;if(this.loopType===q.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.id,n.val),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.id,n.val),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}isAVLBalanced(){var t,e;if(!this.root)return!0;let s=!0;if(this.loopType===q.RECURSIVE){const t=e=>{if(!e)return 0;const i=t(e.left),r=t(e.right);return Math.abs(i-r)>1&&(s=!1),Math.max(i,r)+1};t(this.root)}else{const s=[];let i=this.root,r=null;const n=new Map;for(;s.length>0||i;)if(i)s.push(i),i=i.left;else if(i=s[s.length-1],i.right&&r!==i.right)i=i.right;else if(i=s.pop(),i){const s=i.left&&null!==(t=n.get(i.left))&&void 0!==t?t:-1,h=i.right&&null!==(e=n.get(i.right))&&void 0!==e?e:-1;if(Math.abs(s-h)>1)return!1;n.set(i,1+Math.max(s,h)),r=i,i=null}}return s}_compare(t,e){const s=this._comparator(t,e);return s>0?H.gt:s<0?H.lt:H.eq}}class ${constructor(t){this._sumTree=new Array(t+1).fill(0)}get sumTree(){return this._sumTree}static lowBit(t){return t&-t}update(t,e){for(;t<this._sumTree.length;)this._sumTree[t]+=e,t+=$.lowBit(t)}getPrefixSum(t){let e=0;for(;t>0;)e+=this._sumTree[t],t-=$.lowBit(t);return e}getRangeSum(t,e){if(!(0<=t&&t<=e&&e<=this._sumTree.length))throw"Index out of bounds";return this.getPrefixSum(e)-this.getPrefixSum(t)}_setSumTree(t){this._sumTree=t}}class tt{constructor(t,e,s,i){this._start=0,this._end=0,this._val=null,this._sum=0,this._left=null,this._right=null,this._start=t,this._end=e,this._sum=s,this._val=i||null}get start(){return this._start}set start(t){this._start=t}get end(){return this._end}set end(t){this._end=t}get val(){return this._val}set val(t){this._val=t}get sum(){return this._sum}set sum(t){this._sum=t}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}}class et{constructor(t,e,s){this._values=[],this._start=0,console.log("values.length:",t.length),e=e||0,s=s||t.length-1,this._values=t,this._start=e,this._end=s,t.length>0?(console.log("Initializing with non-empty array"),this._root=this.build(e,s)):(console.log("Initializing with empty array"),this._root=null,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(t,e){if(t>e)return new tt(t,e,0);if(t===e)return new tt(t,e,this._values[t]);const s=t+Math.floor((e-t)/2),i=this.build(t,s),r=this.build(s+1,e),n=new tt(t,e,i.sum+r.sum);return n.left=i,n.right=r,n}updateNode(t,e,s){const i=this.root||null;if(!i)return;const r=(t,e,s,i)=>{if(t.start===t.end&&t.start===e)return t.sum=s,void(void 0!==i&&(t.val=i));e<=t.start+Math.floor((t.end-t.start)/2)?t.left&&r(t.left,e,s,i):t.right&&r(t.right,e,s,i),t.left&&t.right&&(t.sum=t.left.sum+t.right.sum)};r(i,t,e,s)}querySumByRange(t,e){const s=this.root||null;if(!s)return 0;if(t<0||e>=this.values.length||t>e)return NaN;const i=(t,e,s)=>{if(e<=t.start&&s>=t.end)return t.sum;const r=t.start+Math.floor((t.end-t.start)/2);if(s<=r)return t.left?i(t.left,e,s):NaN;if(e>r)return t.right?i(t.right,e,s):NaN;{let n=0,h=0;return t.left&&(n=i(t.left,e,r)),t.right&&(h=i(t.right,r+1,s)),n+h}};return i(s,t,e)}_setValues(t){this._values=t}_setStart(t){this._start=t}_setEnd(t){this._end=t}_setRoot(t){this._root=t}}class st extends X{constructor(t,e){super(t,e)}}class it extends Z{constructor(t){super(t)}createNode(t,e){return new st(t,e)}add(t,e){const s=super.add(t,e);return s&&this._balancePath(s),s}remove(t){const e=super.remove(t);for(const{needBalanced:t}of e)t&&this._balancePath(t);return e}_balanceFactor(t){return t.right?t.left?t.right.height-t.left.height:+t.height:-t.height}_updateHeight(t){if(t.left||t.right)if(t.left)t.right?t.height=1+Math.max(t.right.height,t.left.height):t.height=1+t.left.height;else{const e=t.right?t.right.height:0;t.height=1+e}else t.height=0}_balancePath(t){const e=this.getPathToRoot(t,!1);for(let t=0;t<e.length;t++){const s=e[t];switch(this._updateHeight(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))}}}_balanceLL(t){const e=t.parent,s=t.left;t.parent=s,s&&s.right&&(s.right.parent=t),s&&(s.parent=e),t===this.root?s&&this._setRoot(s):(null==e?void 0:e.left)===t?e.left=s:e&&(e.right=s),s&&(t.left=s.right,s.right=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceLR(t){const e=t.parent,s=t.left;let i=null;s&&(i=s.right),t&&(t.parent=i),s&&(s.parent=i),i&&(i.left&&(i.left.parent=s),i.right&&(i.right.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.left=i.right,s&&(s.right=i.left),i.left=s,i.right=t),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}_balanceRR(t){const e=t.parent,s=t.right;t.parent=s,s&&(s.left&&(s.left.parent=t),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,s.left=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceRL(t){const e=t.parent,s=t.right;let i=null;s&&(i=s.left),t.parent=i,s&&(s.parent=i),i&&(i.left&&(i.left.parent=t),i.right&&(i.right.parent=s),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),s&&i&&(s.left=i.right),i&&(i.left=t),i&&(i.right=s),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}}class rt{}class nt extends X{constructor(t,e){super(t,e),this._color=G.RED}get color(){return this._color}set color(t){this._color=t}}class ht extends Z{constructor(t){super(t)}createNode(t,e){return new nt(t,e)}}class ot{}class lt{}class at extends st{constructor(t,e,s=1){super(t,e),this._count=s}get count(){return this._count}set count(t){this._count=t}}class ut extends it{constructor(t){super(Object.assign({},t)),this._count=0}get count(){return this._count}createNode(t,e,s){return new at(t,e,s)}swapLocation(t,e){const{id:s,val:i,count:r,height:n}=e,h=this.createNode(s,i,r);return h&&(h.height=n,e.id=t.id,e.val=t.val,e.count=t.count,e.height=t.height,t.id=h.id,t.val=h.val,t.count=h.count,t.height=h.height),e}add(t,e,s){let i,r;if(s=null!=s?s:1,r=t instanceof at?this.createNode(t.id,t.val,t.count):null===t?null:this.createNode(t,e,s),this.root){let t=this.root,e=!0;for(;e;)t?r&&(this._compare(t.id,r.id)===H.eq?(t.val=r.val,t.count+=r.count,this._setCount(this.count+r.count),e=!1,i=t):this._compare(t.id,r.id)===H.gt?void 0===t.left?(t.left=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.left):t.left&&(t=t.left):this._compare(t.id,r.id)===H.lt&&(void 0===t.right?(t.right=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.right):t.right&&(t=t.right))):e=!1}else this._setRoot(r),this._setSize(this.size+1),r&&this._setCount(this.count+r.count),i=this.root;return i&&this._balancePath(i),i}_addTo(t,e){return e?void 0===e.left?(e.left=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.left):void 0===e.right?(e.right=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.right):void 0:void 0}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];r instanceof at?s.push(this.add(r.id,r.val,r.count)):null!==r?s.push(this.add(r,null==e?void 0:e[i],1)):s.push(this.add(NaN,null,0))}return s}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(t.length<1)return!1;if(this.clear(),this.loopType===q.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.id,n.val,n.count),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.id,n.val,n.count),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}remove(t,e){const s=[];if(!this.root)return s;const i=this.get(t);if(!i)return s;const r=(null==i?void 0:i.parent)?i.parent:null;let n=null,h=i;if(i.count>1&&!e)i.count--,this._setCount(this.count-1);else{if(i.left){const t=i.left?this.getRightMost(i.left):null;if(t){const e=t.parent;h=this.swapLocation(i,t),e&&(e.right===t?e.right=t.left:e.left=t.left,n=e)}}else if(r){const{familyPosition:t}=i;t===U.LEFT||t===U.ROOT_LEFT?r.left=i.right:t!==U.RIGHT&&t!==U.ROOT_RIGHT||(r.right=i.right),n=r}else void 0!==i.right&&this._setRoot(i.right);this._setSize(this.size-1),this._setCount(this.count-h.count)}return s.push({deleted:h,needBalanced:n}),n&&this._balancePath(n),s}getSubTreeCount(t){const e=[0,0];if(!t)return e;if(this.loopType===q.RECURSIVE){const s=t=>{e[0]++,e[1]+=t.count,t.left&&s(t.left),t.right&&s(t.right)};return s(t),e}{const s=[t];for(;s.length>0;){const t=s.pop();e[0]++,e[1]+=t.count,t.right&&s.push(t.right),t.left&&s.push(t.left)}return e}}subTreeSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let e=0;if(this.loopType===q.RECURSIVE){const s=t=>{e+=t.count,t.left&&s(t.left),t.right&&s(t.right)};s(t)}else{const s=[t];for(;s.length>0;){const t=s.pop();e+=t.count,t.right&&s.push(t.right),t.left&&s.push(t.left)}}return e}subTreeAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const s=t=>{t.count+=e,this._setCount(this.count+e)};if(this.loopType===q.RECURSIVE){const e=t=>{s(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();s(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}getNodesByCount(t,e){if(!this.root)return[];const s=[];if(this.loopType===q.RECURSIVE){const i=r=>{r.count===t&&(s.push(r),e)||(r.left||r.right)&&(r.left&&i(r.left),r.right&&i(r.right))};i(this.root)}else{const i=[this.root];for(;i.length>0;){const r=i.shift();if(r){if(r.count===t&&(s.push(r),e))return s;r.left&&i.push(r.left),r.right&&i.push(r.right)}}}return s}BFSCount(){return super.BFS("node").map((t=>t.count))}listLevelsCount(t){return super.listLevels(t,"node").map((t=>t.map((t=>t.count))))}morrisCount(t){return t=t||"in",super.morris(t,"node").map((t=>t.count))}DFSIterativeCount(t){return t=null!=t?t:"in",super.DFSIterative(t,"node").map((t=>t.count))}DFSCount(t){return t=null!=t?t:"in",super.DFS(t,"node").map((t=>t.count))}lesserSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const e=t.id;let s=0;if(this.loopType===q.RECURSIVE){const t=i=>{const r=this._compare(i.id,e);if(r!==H.eq)if(r===H.lt){if(i.left&&(s+=this.subTreeSumCount(i.left)),s+=i.count,!i.right)return;t(i.right)}else{if(!i.left)return;t(i.left)}else i.right&&(s+=this.subTreeSumCount(i.right))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const i=t.shift();if(i){const r=this._compare(i.id,e);if(r===H.eq)return i.right&&(s+=this.subTreeSumCount(i.right)),s;if(r===H.lt){if(i.left&&(s+=this.subTreeSumCount(i.left)),s+=i.count,!i.right)return s;t.push(i.right)}else{if(!i.left)return s;t.push(i.left)}}}}return s}allGreaterNodesAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const s=t.id;if(!this.root)return!1;if(this.loopType===q.RECURSIVE){const t=i=>{this._compare(i.id,s)===H.gt&&(i.count+=e),(i.left||i.right)&&(i.left&&this._compare(i.left.id,s)===H.gt&&t(i.left),i.right&&this._compare(i.right.id,s)===H.gt&&t(i.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const i=t.shift();i&&(this._compare(i.id,s)===H.gt&&(i.count+=e),i.left&&this._compare(i.left.id,s)===H.gt&&t.push(i.left),i.right&&this._compare(i.right.id,s)===H.gt&&t.push(i.right))}return!0}}clear(){super.clear(),this._setCount(0)}_setCount(t){this._count=t}}class ct{}class dt{constructor(t,e,s){this._id=t,this._value=e||void 0,this._children=s||[]}get id(){return this._id}set id(t){this._id=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 dt?this.children.push(t):this.children=this.children.concat(t)}getHeight(){const t=this;let e=1;if(t){const s=(t,i)=>{i>e&&(e=i);const{children:r}=t;if(r)for(let t=0,e=r.length;t<e;t++)s(r[t],i+1)};s(t,1)}return e}}class ft{constructor(t=Number.MAX_SAFE_INTEGER,e=null){this._val=e,this._priority=t}get priority(){return this._priority}set priority(t){this._priority=t}get val(){return this._val}set val(t){this._val=t}}class gt{constructor(t){if(t){const{priorityExtractor:e}=t;if(void 0!==e&&"function"!=typeof e)throw new Error(".constructor expects a valid priority function");this._priorityExtractor=e||(t=>+t)}else this._priorityExtractor=t=>+t}get pq(){return this._pq}get priorityExtractor(){return this._priorityExtractor}get size(){return this._pq.size}isEmpty(){return this._pq.size<1}peek(t){t=null!=t&&t;const e=this._pq.peek();return t?e:null==e?void 0:e.val}peekLast(t){t=null!=t&&t;const e=this._pq.leaf();return t?e:null==e?void 0:e.val}add(t,e){return e=void 0===e?t:e,this._pq.add(new ft(t,e)),this}poll(t){t=null!=t&&t;const e=this._pq.poll();return e?t?e:e.val:null}has(t){return t instanceof ft?this.pq.getNodes().includes(t):-1!==this.pq.getNodes().findIndex((e=>e.val===t))}toArray(t){t=null!=t&&t;const e=this._pq.toArray();return t?e:e.map((t=>t.val))}sort(t){t=null!=t&&t;const e=this._pq.sort();return t?e:e.map((t=>t.val))}clear(){this._pq.clear()}}class pt extends gt{constructor(t){super(t),this._pq=new N({comparator:(t,e)=>e.priority-t.priority})}}class _t extends gt{constructor(t){super(t),this._pq=new N({comparator:(t,e)=>t.priority-e.priority})}}class vt extends N{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}))}static heapify(t){const e=new vt(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}));return e._fix(),e}}class mt extends N{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}))}static heapify(t){const e=new mt(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}));return e._fix(),e}}class yt{constructor(t){const{row:e,col:s,initialVal:i}=t;this._matrix=new Array(e).fill(void 0).map((()=>new Array(s).fill(i||0)))}toArray(){return this._matrix}}class xt{constructor(t=0,e=0,s=1){this.x=t,this.y=e,this.w=s}get isZero(){return 0===this.x&&0===this.y}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get lengthSq(){return this.x*this.x+this.y*this.y}get rounded(){return new xt(Math.round(this.x),Math.round(this.y))}static add(t,e){return new xt(t.x+e.x,t.y+e.y)}static subtract(t,e){return new xt(t.x-e.x,t.y-e.y)}static subtractValue(t,e){return new xt(t.x-e,t.y-e)}static multiply(t,e){return new xt(t.x*e,t.y*e)}static divide(t,e){return new xt(t.x/e,t.y/e)}static equals(t,e){return t.x===e.x&&t.y===e.y}static equalsRounded(t,e,s=12){const i=xt.abs(xt.subtract(t,e));return i.x<s&&i.y<s}static normalize(t){const e=t.length;return e>2220446049250313e-31?xt.divide(t,e):t}static truncate(t,e){return t.length>e?xt.multiply(xt.normalize(t),e):t}static perp(t){return new xt(-t.y,t.x)}static reverse(t){return new xt(-t.x,-t.y)}static abs(t){return new xt(Math.abs(t.x),Math.abs(t.y))}static dot(t,e){return t.x*e.x+t.y*e.y}static distance(t,e){const s=e.y-t.y,i=e.x-t.x;return Math.sqrt(s*s+i*i)}static distanceSq(t,e){const s=e.y-t.y,i=e.x-t.x;return s*s+i*i}static sign(t,e){return t.y*e.x>t.x*e.y?-1:1}static angle(t){const e=new xt(0,-1),s=Math.acos(xt.dot(t,e)/(t.length*e.length));return 1===xt.sign(t,e)?2*Math.PI-s:s}static random(t,e){const s=Math.floor(Math.random()*t-t/2),i=Math.floor(Math.random()*e-e/2);return new xt(s,i)}zero(){this.x=0,this.y=0}}const Et=xt;class bt{constructor(t){void 0===t?this._matrix=bt.identity:t instanceof Et?(this._matrix=bt.identity,this._matrix[0][0]=t.x,this._matrix[1][0]=t.y,this._matrix[2][0]=t.w):this._matrix=t}static get empty(){return[[],[],[]]}static get identity(){return[[1,0,0],[0,1,0],[0,0,1]]}get m(){return this._matrix}toVector(){return new Et(this._matrix[0][0],this._matrix[1][0])}static add(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]+e.m[i][r];return new bt(s)}static subtract(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]-e.m[i][r];return new bt(s)}static multiply(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++){s[i][r]=0;for(let n=0;n<3;n++)s[i][r]+=t.m[i][n]*e.m[n][r]}return new bt(s)}static multiplyByValue(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]*e;return new bt(s)}static multiplyByVector(t,e){return bt.multiply(t,new bt(e)).toVector()}static view(t,e){const s=t/2,i=e/2,r=Math.cos(Math.PI);return new bt([[1,0,s],[0,1*r,i],[0,0,1]])}static scale(t){return bt.multiplyByValue(new bt,t)}static rotate(t){const e=Math.cos(t),s=Math.sin(t);return new bt([[e,-s,0],[s,e,0],[0,0,1]])}static translate(t){return new bt([[1,0,t.x],[0,1,t.y],[0,0,t.w]])}}class wt{constructor(t,e){this.direction=t,this.turn=()=>new wt(e[t],e)}}class Tt{constructor({matrix:t,turning:e,onMove:s,init:{cur:i,charDir:r,VISITED:n}}){this._matrix=t,this._cur=i,this._character=new wt(r,e),this.onMove=s,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);){const{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,s;const i=this._matrix,[r,n]=this._cur;switch(t){case"up":if(s=i[r-1],!s)return!1;e=s[n];break;case"right":e=i[r][n+1];break;case"down":if(s=i[r+1],!s)return!1;e=s[n];break;case"left":e=i[r][n-1]}return void 0!==e&&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]--}const[e,s]=this._cur;this._matrix[e][s]=this._VISITED,this.onMove&&this.onMove(this._cur)}}class Mt{constructor(t){this._val=t,this._isEnd=!1,this._children=new Map}get val(){return this._val}set val(t){this._val=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}}class St{constructor(t){if(this._root=new Mt(""),t)for(const e of t)this.add(e)}get root(){return this._root}set root(t){this._root=t}add(t){let e=this._root;for(const s of t){let t=e.children.get(s);t||(t=new Mt(s),e.children.set(s,t)),e=t}return e.isEnd=!0,!0}has(t){let e=this._root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return e.isEnd}remove(t){let e=!1;const s=(i,r)=>{const n=t[r],h=i.children.get(n);return!!h&&(r===t.length-1?!!h.isEnd&&(h.children.size>0?h.isEnd=!1:i.children.delete(n),e=!0,!0):!(!s(h,r+1)||i.isEnd||0!==h.children.size||(i.children.delete(n),0)))};return s(this.root,0),e}isAbsPrefix(t){let e=this._root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!e.isEnd}isPrefix(t){let e=this._root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!0}isCommonPrefix(t){let e="";const s=i=>{e+=i.val,e!==t&&(i.isEnd||i&&i.children&&1===i.children.size&&s(Array.from(i.children.values())[0]))};return s(this._root),e===t}getLongestCommonPrefix(){let t="";const e=s=>{t+=s.val,s.isEnd||s&&s.children&&1===s.children.size&&e(Array.from(s.children.values())[0])};return e(this._root),t}getAll(t=""){const e=[];let s=this._root;if(t)for(const e of t){const t=s.children.get(e);t&&(s=t)}return function t(s,i){for(const e of s.children.keys()){const r=s.children.get(e);void 0!==r&&t(r,i.concat(e))}s.isEnd&&e.push(i)}(s,t),e}}return e})()));
2
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.dataStructureTyped=e():t.dataStructureTyped=e()}(self,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AVLTree:()=>it,AVLTreeNode:()=>st,AaTree:()=>lt,AbstractBinaryTree:()=>W,AbstractBinaryTreeNode:()=>Q,AbstractEdge:()=>z,AbstractGraph:()=>I,AbstractVertex:()=>A,ArrayDeque:()=>E,BST:()=>Z,BSTNode:()=>X,BTree:()=>rt,BinaryIndexedTree:()=>$,BinaryTree:()=>J,BinaryTreeNode:()=>Y,CP:()=>H,Character:()=>wt,CoordinateMap:()=>r,CoordinateSet:()=>n,Deque:()=>y,DirectedEdge:()=>C,DirectedGraph:()=>L,DirectedVertex:()=>O,DoublyLinkedList:()=>f,DoublyLinkedListNode:()=>d,FamilyPosition:()=>U,HashMap:()=>a,HashTable:()=>i,HashTableNode:()=>s,Heap:()=>gt,HeapItem:()=>ft,LinkedListQueue:()=>v,LoopType:()=>q,MapEdge:()=>D,MapGraph:()=>j,MapVertex:()=>B,Matrix2D:()=>bt,MatrixNTI2D:()=>yt,MaxHeap:()=>pt,MaxPriorityQueue:()=>mt,MinHeap:()=>_t,MinPriorityQueue:()=>vt,Navigator:()=>Tt,ObjectDeque:()=>x,Pair:()=>h,PriorityQueue:()=>N,Queue:()=>m,RBColor:()=>G,RBTree:()=>ht,RBTreeNode:()=>nt,SegmentTree:()=>et,SegmentTreeNode:()=>tt,SinglyLinkedList:()=>c,SinglyLinkedListNode:()=>u,SkipList:()=>p,SkipListNode:()=>g,SplayTree:()=>ot,Stack:()=>_,THUNK_SYMBOL:()=>T,TopologicalProperty:()=>K,TreeMap:()=>o,TreeMultiset:()=>ut,TreeMultisetNode:()=>at,TreeNode:()=>dt,TreeSet:()=>l,Trie:()=>St,TrieNode:()=>Mt,TwoThreeTree:()=>ct,UndirectedEdge:()=>P,UndirectedGraph:()=>F,UndirectedVertex:()=>k,Vector2D:()=>xt,arrayRemove:()=>w,isThunk:()=>M,toThunk:()=>S,trampoline:()=>R,trampolineAsync:()=>V,uuidV4:()=>b});class s{constructor(t,e){this.key=t,this.val=e,this.next=null}}class i{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get buckets(){return this._buckets}set buckets(t){this._buckets=t}get capacity(){return this._capacity}set capacity(t){this._capacity=t}constructor(t=i.DEFAULT_CAPACITY,e){this._hashFn=e||this._defaultHashFn,this._capacity=Math.max(t,i.DEFAULT_CAPACITY),this._size=0,this._buckets=new Array(this._capacity).fill(null)}_defaultHashFn(t){return("string"==typeof t?this._murmurStringHashFn(t):this._objectHash(t))%this._capacity}_multiplicativeStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=(.618033988749895*s+e.charCodeAt(t))%(1<<30);return Math.abs(s)}_murmurStringHashFn(t){const e=String(t);let s=0;for(let t=0;t<e.length;t++)s=1540483477*(s^e.charCodeAt(t)),s=668265261*(s^s>>>15),s^=s>>>15;return Math.abs(s)}_hash(t){return this.hashFn(t)}_stringHash(t){let e=0;for(let s=0;s<t.length;s++)e=31*e+t.charCodeAt(s)&4294967295;return e}_objectHash(t){return this._stringHash(JSON.stringify(t))}set(t,e){const r=this._hash(t),n=new s(t,e);if(this._buckets[r]){let s=this._buckets[r];for(;s;){if(s.key===t)return void(s.val=e);if(!s.next)break;s=s.next}s.next=n}else this._buckets[r]=n;this._size++,this._size/this._capacity>=i.LOAD_FACTOR&&this._expand()}get(t){const e=this._hash(t);let s=this._buckets[e];for(;s;){if(s.key===t)return s.val;s=s.next}}remove(t){const e=this._hash(t);let s=this._buckets[e],i=null;for(;s;){if(s.key===t)return i?i.next=s.next:this._buckets[e]=s.next,this._size--,void(s.next=null);i=s,s=s.next}}_expand(){const t=2*this._capacity,e=new Array(t).fill(null);for(const t of this._buckets){let i=t;for(;i;){const t=this._hash(i.key),r=new s(i.key,i.val);if(e[t]){let s=e[t];for(;s.next;)s=s.next;s.next=r}else e[t]=r;i=i.next}}this._buckets=e,this._capacity=t}get size(){return this._size}}i.DEFAULT_CAPACITY=16,i.LOAD_FACTOR=.75;class r extends Map{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}set(t,e){return super.set(t.join(this._joint),e)}get(t){return super.get(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class n extends Set{constructor(t){super(),this._joint="_",void 0!==t&&(this._joint=t)}get joint(){return this._joint}has(t){return super.has(t.join(this._joint))}add(t){return super.add(t.join(this._joint))}delete(t){return super.delete(t.join(this._joint))}_setJoint(t){this._joint=t}}class h{}class o{}class l{}class a{get hashFn(){return this._hashFn}set hashFn(t){this._hashFn=t}get table(){return this._table}set table(t){this._table=t}get capacityMultiplier(){return this._capacityMultiplier}set capacityMultiplier(t){this._capacityMultiplier=t}get loadFactor(){return this._loadFactor}set loadFactor(t){this._loadFactor=t}get initialCapacity(){return this._initialCapacity}set initialCapacity(t){this._initialCapacity=t}get size(){return this._size}set size(t){this._size=t}constructor(t=16,e=.75,s){this._initialCapacity=t,this._loadFactor=e,this._capacityMultiplier=2,this._size=0,this._table=new Array(t),this._hashFn=s||(t=>{const e=String(t);let s=0;for(let t=0;t<e.length;t++)s+=e.charCodeAt(t);return s%this.table.length})}_hash(t){return this._hashFn(t)}resizeTable(t){const e=new Array(t);for(const s of this._table)if(s)for(const[i,r]of s){const s=this._hash(i)%t;e[s]||(e[s]=[]),e[s].push([i,r])}this._table=e}set(t,e){this.size/this.table.length>=this.loadFactor&&this.resizeTable(this.table.length*this.capacityMultiplier);const s=this._hash(t);this.table[s]||(this.table[s]=[]);for(let i=0;i<this.table[s].length;i++)if(this.table[s][i][0]===t)return void(this.table[s][i][1]=e);this.table[s].push([t,e]),this.size++}get(t){const e=this._hash(t);if(this.table[e])for(const[s,i]of this.table[e])if(s===t)return i}remove(t){const e=this._hash(t);if(this.table[e])for(let s=0;s<this.table[e].length;s++)if(this.table[e][s][0]===t)return this.table[e].splice(s,1),this.size--,void(this.size/this.table.length<this.loadFactor/this.capacityMultiplier&&this.resizeTable(this.table.length/this.capacityMultiplier))}*entries(){for(const t of this.table)if(t)for(const[e,s]of t)yield[e,s]}[Symbol.iterator](){return this.entries()}clear(){this.size=0,this.table=new Array(this.initialCapacity)}isEmpty(){return 0===this.size}}class u{constructor(t){this._val=t,this._next=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}}class c{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new c;for(const s of t)e.push(s);return e}getLength(){return this._length}push(t){const e=new u(t);this.head?(this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}pop(){if(!this.head)return;if(this.head===this.tail){const t=this.head.val;return this.head=null,this.tail=null,this._length--,t}let t=this.head;for(;t.next!==this.tail;)t=t.next;const e=this.tail.val;return t.next=null,this.tail=t,this._length--,e}shift(){if(!this.head)return;const t=this.head;return this.head=this.head.next,this._length--,t.val}unshift(t){const e=new u(t);this.head?(e.next=this.head,this.head=e):(this.head=e,this.tail=e),this._length++}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t-1),s=e.next;return e.next=s.next,this._length--,s.val}delete(t){let e;e=t instanceof u?t.val:t;let s=this.head,i=null;for(;s;){if(s.val===e)return null===i?(this.head=s.next,s===this.tail&&(this.tail=null)):(i.next=s.next,s===this.tail&&(this.tail=i)),this._length--,!0;i=s,s=s.next}return!1}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new u(e),i=this.getNodeAt(t-1);return s.next=i.next,i.next=s,this._length++,!0}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}reverse(){if(!this.head||this.head===this.tail)return;let t=null,e=this.head,s=null;for(;e;)s=e.next,e.next=t,t=e,e=s;[this.head,this.tail]=[this.tail,this.head]}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertBefore(t,e){if(!this.head)return!1;let s;if(s=t instanceof u?t.val:t,this.head.val===s)return this.unshift(e),!0;let i=this.head;for(;i.next;){if(i.next.val===s){const t=new u(e);return t.next=i.next,i.next=t,this._length++,!0}i=i.next}return!1}insertAfter(t,e){let s;if(s=t instanceof u?t:this.findNode(t),s){const t=new u(e);return t.next=s.next,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}countOccurrences(t){let e=0,s=this.head;for(;s;)s.val===t&&e++,s=s.next;return e}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.val,t=t.next}}class d{constructor(t){this._val=t,this._next=null,this._prev=null}get val(){return this._val}set val(t){this._val=t}get next(){return this._next}set next(t){this._next=t}get prev(){return this._prev}set prev(t){this._prev=t}}class f{constructor(){this._head=null,this._tail=null,this._length=0}get head(){return this._head}set head(t){this._head=t}get tail(){return this._tail}set tail(t){this._tail=t}get length(){return this._length}static fromArray(t){const e=new f;for(const s of t)e.push(s);return e}push(t){const e=new d(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):(this.head=e,this.tail=e),this._length++}addLast(t){this.push(t)}pop(){if(!this.tail)return;const t=this.tail;return this.head===this.tail?(this.head=null,this.tail=null):(this.tail=t.prev,this.tail.next=null),this._length--,t.val}pollLast(){return this.pop()}shift(){if(!this.head)return;const t=this.head;return this.head===this.tail?(this.head=null,this.tail=null):(this.head=t.next,this.head.prev=null),this._length--,t.val}pollFirst(){return this.shift()}unshift(t){const e=new d(t);this.head?(e.next=this.head,this.head.prev=e,this.head=e):(this.head=e,this.tail=e),this._length++}addFirst(t){this.unshift(t)}peekFirst(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}peekLast(){var t;return null===(t=this.tail)||void 0===t?void 0:t.val}get size(){return this.length}getAt(t){if(t<0||t>=this.length)return;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e.val}getNodeAt(t){if(t<0||t>=this.length)return null;let e=this.head;for(let s=0;s<t;s++)e=e.next;return e}findNode(t){let e=this.head;for(;e;){if(e.val===t)return e;e=e.next}return null}insertAt(t,e){if(t<0||t>this.length)return!1;if(0===t)return this.unshift(e),!0;if(t===this.length)return this.push(e),!0;const s=new d(e),i=this.getNodeAt(t-1),r=i.next;return s.prev=i,s.next=r,i.next=s,r.prev=s,this._length++,!0}deleteAt(t){if(t<0||t>=this.length)return;if(0===t)return this.shift();if(t===this.length-1)return this.pop();const e=this.getNodeAt(t),s=e.prev,i=e.next;return s.next=i,i.prev=s,this._length--,e.val}delete(t){let e;if(e=t instanceof d?t:this.findNode(t),e){if(e===this.head)this.shift();else if(e===this.tail)this.pop();else{const t=e.prev,s=e.next;t.next=s,s.prev=t,this._length--}return!0}return!1}toArray(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}isEmpty(){return 0===this.length}clear(){this._head=null,this._tail=null,this._length=0}find(t){let e=this.head;for(;e;){if(t(e.val))return e.val;e=e.next}return null}indexOf(t){let e=0,s=this.head;for(;s;){if(s.val===t)return e;e++,s=s.next}return-1}findLast(t){let e=this.tail;for(;e;){if(t(e.val))return e.val;e=e.prev}return null}toArrayReverse(){const t=[];let e=this.tail;for(;e;)t.push(e.val),e=e.prev;return t}reverse(){let t=this.head;for([this.head,this.tail]=[this.tail,this.head];t;){const e=t.next;[t.prev,t.next]=[t.next,t.prev],t=e}}forEach(t){let e=this.head,s=0;for(;e;)t(e.val,s),e=e.next,s++}map(t){const e=new f;let s=this.head;for(;s;)e.push(t(s.val)),s=s.next;return e}filter(t){const e=new f;let s=this.head;for(;s;)t(s.val)&&e.push(s.val),s=s.next;return e}reduce(t,e){let s=e,i=this.head;for(;i;)s=t(s,i.val),i=i.next;return s}insertAfter(t,e){let s;if(s=t instanceof d?t:this.findNode(t),s){const t=new d(e);return t.next=s.next,s.next&&(s.next.prev=t),t.prev=s,s.next=t,s===this.tail&&(this.tail=t),this._length++,!0}return!1}insertBefore(t,e){let s;if(s=t instanceof d?t:this.findNode(t),s){const t=new d(e);return t.prev=s.prev,s.prev&&(s.prev.next=t),t.next=s,s.prev=t,s===this.head&&(this.head=t),this._length++,!0}return!1}}class g{constructor(t,e,s){this.key=t,this.value=e,this.forward=new Array(s)}}class p{get probability(){return this._probability}set probability(t){this._probability=t}get maxLevel(){return this._maxLevel}set maxLevel(t){this._maxLevel=t}get level(){return this._level}set level(t){this._level=t}get head(){return this._head}set head(t){this._head=t}constructor(t=16,e=.5){this._head=new g(null,null,t),this._level=0,this._maxLevel=t,this._probability=e}randomLevel(){let t=1;for(;Math.random()<this.probability&&t<this.maxLevel;)t++;return t}add(t,e){const s=new g(t,e,this.randomLevel()),i=new Array(this.maxLevel).fill(this.head);let r=this.head;for(let e=this.level-1;e>=0;e--){for(;r.forward[e]&&r.forward[e].key<t;)r=r.forward[e];i[e]=r}for(let t=0;t<s.forward.length;t++)s.forward[t]=i[t].forward[t],i[t].forward[t]=s;null!==s.forward[0]&&(this.level=Math.max(this.level,s.forward.length))}get(t){let e=this.head;for(let s=this.level-1;s>=0;s--)for(;e.forward[s]&&e.forward[s].key<t;)e=e.forward[s];if(e=e.forward[0],e&&e.key===t)return e.value}remove(t){const e=new Array(this.maxLevel).fill(this.head);let s=this.head;for(let i=this.level-1;i>=0;i--){for(;s.forward[i]&&s.forward[i].key<t;)s=s.forward[i];e[i]=s}if(s=s.forward[0],s&&s.key===t){for(let t=0;t<this.level&&e[t].forward[t]===s;t++)e[t].forward[t]=s.forward[t];for(;this.level>0&&null===this.head.forward[this.level-1];)this.level--;return!0}return!1}}class _{constructor(t){this._elements=Array.isArray(t)?t:[]}static fromArray(t){return new _(t)}isEmpty(){return 0===this._elements.length}size(){return this._elements.length}peek(){return this.isEmpty()?null:this._elements[this._elements.length-1]}push(t){return this._elements.push(t),this}pop(){return this.isEmpty()?null:this._elements.pop()||null}toArray(){return this._elements.slice()}clear(){this._elements=[]}clone(){return new _(this._elements.slice())}}class v extends c{enqueue(t){this.push(t)}dequeue(){return this.shift()}peek(){var t;return null===(t=this.head)||void 0===t?void 0:t.val}}class m{constructor(t){this._nodes=t||[],this._offset=0}get nodes(){return this._nodes}set nodes(t){this._nodes=t}get offset(){return this._offset}set offset(t){this._offset=t}get size(){return this.nodes.length-this.offset}static fromArray(t){return new m(t)}push(t){return this.nodes.push(t),this}shift(){if(0===this.size)return;const t=this.peek();return this.offset+=1,2*this.offset<this.nodes.length||(this.nodes=this.nodes.slice(this.offset),this.offset=0),t}peek(){return this.size>0?this.nodes[this.offset]:void 0}peekLast(){return this.size>0?this.nodes[this.nodes.length-1]:void 0}enqueue(t){this.push(t)}dequeue(){return this.shift()}getAt(t){return this.nodes[t]}isEmpty(){return 0===this.size}toArray(){return this.nodes.slice(this.offset)}clear(){this.nodes=[],this.offset=0}clone(){return new m(this.nodes.slice(this.offset))}*[Symbol.iterator](){for(const t of this.nodes)yield t}}class y extends f{}class x{constructor(t){this._nodes={},this._capacity=Number.MAX_SAFE_INTEGER,this._first=-1,this._last=-1,this._size=0,void 0!==t&&(this._capacity=t)}get nodes(){return this._nodes}get capacity(){return this._capacity}set capacity(t){this._capacity=t}get first(){return this._first}set first(t){this._first=t}get last(){return this._last}set last(t){this._last=t}get size(){return this._size}addFirst(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._first--;this._nodes[this._first]=t,this._size++}addLast(t){if(0===this._size){const t=Math.floor(this._capacity/2);this._first=t,this._last=t}else this._last++;this._nodes[this._last]=t,this._size++}pollFirst(){if(!this._size)return;const t=this.peekFirst();return delete this._nodes[this._first],this._first++,this._size--,t}peekFirst(){if(this._size)return this._nodes[this._first]}pollLast(){if(!this._size)return;const t=this.peekLast();return delete this._nodes[this._last],this._last--,this._size--,t}peekLast(){if(this._size)return this._nodes[this._last]}get(t){return this._nodes[this._first+t]||null}isEmpty(){return this._size<=0}_seNodes(t){this._nodes=t}_setSize(t){this._size=t}}class E{constructor(){this._nodes=[]}get size(){return this._nodes.length}addLast(t){return this._nodes.push(t)}pollLast(){var t;return null!==(t=this._nodes.pop())&&void 0!==t?t:null}pollFirst(){var t;return null!==(t=this._nodes.shift())&&void 0!==t?t:null}addFirst(t){return this._nodes.unshift(t)}peekFirst(){var t;return null!==(t=this._nodes[0])&&void 0!==t?t:null}peekLast(){var t;return null!==(t=this._nodes[this._nodes.length-1])&&void 0!==t?t:null}get(t){var e;return null!==(e=this._nodes[t])&&void 0!==e?e:null}set(t,e){return this._nodes[t]=e}insert(t,e){return this._nodes.splice(t,0,e)}remove(t){return this._nodes.splice(t,1)}isEmpty(){return 0===this._nodes.length}}const b=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,(function(t){const e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)}))},w=function(t,e){let s=-1,i=t?t.length:0;const r=[];for(;++s<i;){const n=t[s];e(n,s,t)&&(r.push(n),Array.prototype.splice.call(t,s--,1),i--)}return r},T=Symbol("thunk"),M=t=>"function"==typeof t&&t.__THUNK__===T,S=t=>{const e=()=>t();return e.__THUNK__=T,e},R=t=>Object.assign(((...e)=>{let s=t(...e);for(;M(s)&&"function"==typeof s;)s=s();return s}),{cont:(...e)=>S((()=>t(...e)))}),V=t=>Object.assign(((...e)=>{return s=void 0,i=void 0,n=function*(){let s=yield t(...e);for(;M(s)&&"function"==typeof s;)s=yield s();return s},new((r=void 0)||(r=Promise))((function(t,e){function h(t){try{l(n.next(t))}catch(t){e(t)}}function o(t){try{l(n.throw(t))}catch(t){e(t)}}function l(e){var s;e.done?t(e.value):(s=e.value,s instanceof r?s:new r((function(t){t(s)}))).then(h,o)}l((n=n.apply(s,i||[])).next())}));var s,i,r,n}),{cont:(...e)=>S((()=>t(...e)))});class N{constructor(t){this._nodes=[],this._comparator=(t,e)=>t-e;const{nodes:e,comparator:s,isFix:i=!0}=t;this._comparator=s,e&&Array.isArray(e)&&e.length>0&&(this._nodes=[...e],i&&this._fix())}get nodes(){return this._nodes}get size(){return this.nodes.length}static heapify(t){const e=new N(t);return e._fix(),e}static isPriorityQueueified(t){return new N(Object.assign(Object.assign({},t),{isFix:!1})).isValid()}getNodes(){return this._nodes}add(t){this.nodes.push(t),this._heapifyUp(this.size-1)}has(t){return this.nodes.includes(t)}peek(){return this.size?this.nodes[0]:null}poll(){var t,e;let s=null;return this.size>1?(this._swap(0,this.nodes.length-1),s=null!==(t=this.nodes.pop())&&void 0!==t?t:null,this._heapifyDown(0)):1===this.size&&(s=null!==(e=this.nodes.pop())&&void 0!==e?e:null),s}leaf(){var t;return null!==(t=this.nodes[this.size-1])&&void 0!==t?t:null}isEmpty(){return 0===this.size}clear(){this._setNodes([])}toArray(){return[...this.nodes]}clone(){return new N({nodes:this.nodes,comparator:this._comparator})}isValid(){for(let t=0;t<this.nodes.length;t++){const e=this._getLeft(t),s=this._getRight(t);if(this._isValidIndex(e)&&!this._compare(e,t))return!1;if(this._isValidIndex(s)&&!this._compare(s,t))return!1}return!0}sort(){const t=[];for(;0!==this.size;){const e=this.poll();e&&t.push(e)}return t}DFS(t){const e=[],s=i=>{var r,n,h;const o=this._getLeft(i),l=this._getRight(i);switch(t){case"in":this._isValidIndex(o)&&s(o),e.push(null!==(r=this.nodes[i])&&void 0!==r?r:null),this._isValidIndex(l)&&s(l);break;case"pre":e.push(null!==(n=this.nodes[i])&&void 0!==n?n:null),this._isValidIndex(o)&&s(o),this._isValidIndex(l)&&s(l);break;case"post":this._isValidIndex(o)&&s(o),this._isValidIndex(l)&&s(l),e.push(null!==(h=this.nodes[i])&&void 0!==h?h:null)}};return this._isValidIndex(0)&&s(0),e}_setNodes(t){this._nodes=t}_compare(t,e){return this._comparator(this.nodes[t],this.nodes[e])>0}_swap(t,e){const s=this.nodes[t];this.nodes[t]=this.nodes[e],this.nodes[e]=s}_isValidIndex(t){return t>-1&&t<this.nodes.length}_getParent(t){return Math.floor((t-1)/2)}_getLeft(t){return 2*t+1}_getRight(t){return 2*t+2}_getComparedChild(t){let e=t;const s=this._getLeft(t),i=this._getRight(t);return s<this.size&&this._compare(e,s)&&(e=s),i<this.size&&this._compare(e,i)&&(e=i),e}_heapifyUp(t){for(;t>0&&this._compare(this._getParent(t),t);){const e=this._getParent(t);this._swap(t,e),t=e}}_heapifyDown(t){let e=this._getComparedChild(t);for(;this._compare(t,e);)this._swap(e,t),t=e,e=this._getComparedChild(t)}_fix(){for(let t=Math.floor(this.size/2);t>-1;t--)this._heapifyDown(t)}}class A{constructor(t,e){this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}}class z{constructor(t,e){this._weight=void 0!==t?t:1,this._val=e,this._hashCode=b()}get val(){return this._val}set val(t){this._val=t}get weight(){return this._weight}set weight(t){this._weight=t}get hashCode(){return this._hashCode}_setHashCode(t){this._hashCode=t}}class I{constructor(){this._vertices=new Map}get vertices(){return this._vertices}getVertex(t){return this._vertices.get(t)||null}hasVertex(t){return this._vertices.has(this._getVertexId(t))}addVertex(t,e){if(t instanceof A)return this._addVertexOnly(t);{const s=this.createVertex(t,e);return this._addVertexOnly(s)}}removeVertex(t){const e=this._getVertexId(t);return this._vertices.delete(e)}removeAllVertices(t){const e=[];for(const s of t)e.push(this.removeVertex(s));return e.length>0}hasEdge(t,e){return!!this.getEdge(t,e)}addEdge(t,e,s,i){if(t instanceof z)return this._addEdgeOnly(t);if(e instanceof A||"string"==typeof e||"number"==typeof e){if(!this.hasVertex(t)||!this.hasVertex(e))return!1;t instanceof A&&(t=t.id),e instanceof A&&(e=e.id);const r=this.createEdge(t,e,s,i);return this._addEdgeOnly(r)}throw new Error("dest must be a Vertex or vertex id while srcOrEdge is an Edge")}setEdgeWeight(t,e,s){const i=this.getEdge(t,e);return!!i&&(i.weight=s,!0)}getAllPathsBetween(t,e){const s=[],i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{r.set(t,!0),t===e&&s.push([i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),w(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}getPathSumWeight(t){var e;let s=0;for(let i=0;i<t.length;i++)s+=(null===(e=this.getEdge(t[i],t[i+1]))||void 0===e?void 0:e.weight)||0;return s}getMinCostBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0;for(const t of s)i=Math.min(this.getPathSumWeight(t),i);return i}{const s=this._getVertex(e),i=this._getVertex(t);if(!i||!s)return null;const r=new Map,n=[i];r.set(i,!0);let h=0;for(;n.length>0;){for(let t=0;t<n.length;t++){const t=n.shift();if(t===s)return h;if(void 0!==t){const e=this.getNeighbors(t);for(const t of e)r.has(t)||(r.set(t,!0),n.push(t))}}h++}return null}}getMinPathBetween(t,e,s){if(void 0===s&&(s=!1),s){const s=this.getAllPathsBetween(t,e);let i=1/0,r=-1,n=0;for(const t of s){const e=this.getPathSumWeight(t);e<i&&(i=e,r=n),n++}return s[r]||null}{let s=[];const i=this._getVertex(t),r=this._getVertex(e);if(!i||!r)return[];const n=(t,e,r,h)=>{if(r.set(t,!0),t===e)return void(s=[i,...h]);const o=this.getNeighbors(t);for(const t of o)r.get(t)||(h.push(t),n(t,e,r,h),w(h,(e=>e===t)));r.set(t,!1)};return n(i,r,new Map,[]),s}}dijkstraWithoutHeap(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let r=1/0,n=null,h=[];const o=[],l=this._vertices,a=new Map,u=new Set,c=new Map,d=this._getVertex(t),f=e?this._getVertex(e):null;if(!d)return null;for(const t of l){const e=t[1];e instanceof A&&a.set(e,1/0)}a.set(d,0),c.set(d,null);const g=()=>{let t=1/0,e=null;for(const[s,i]of a)u.has(s)||i<t&&(t=i,e=s);return e},p=t=>{for(const e of l){const s=e[1];if(s instanceof A){const i=[s];let r=c.get(s);for(;r;)i.push(r),r=c.get(r);const n=i.reverse();e[1]===t&&(h=n),o.push(n)}}};for(let t=1;t<l.size;t++){const t=g();if(t){if(u.add(t),f&&f===t)return s&&(r=a.get(f)||1/0),i&&p(f),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h};const e=this.getNeighbors(t);for(const s of e)if(!u.has(s)){const e=this.getEdge(t,s);if(e){const i=a.get(t),r=a.get(s);void 0!==i&&void 0!==r&&e.weight+i<r&&(a.set(s,e.weight+i),c.set(s,t))}}}}return s&&a.forEach(((t,e)=>{e!==d&&t<r&&(r=t,i&&(n=e))})),i&&p(n),{distMap:a,preMap:c,seen:u,paths:o,minDist:r,minPath:h}}dijkstra(t,e,s,i){var r;void 0===s&&(s=!1),void 0===i&&(i=!1),void 0===e&&(e=null);let n=1/0,h=null,o=[];const l=[],a=this._vertices,u=new Map,c=new Set,d=new Map,f=this._getVertex(t),g=e?this._getVertex(e):null;if(!f)return null;for(const t of a){const e=t[1];e instanceof A&&u.set(e,1/0)}const p=new N({comparator:(t,e)=>t.id-e.id});p.add({id:0,val:f}),u.set(f,0),d.set(f,null);const _=t=>{for(const e of a){const s=e[1];if(s instanceof A){const i=[s];let r=d.get(s);for(;r;)i.push(r),r=d.get(r);const n=i.reverse();e[1]===t&&(o=n),l.push(n)}}};for(;p.size>0;){const t=p.poll(),e=null==t?void 0:t.id,h=null==t?void 0:t.val;if(void 0!==e&&h){if(c.add(h),g&&g===h)return s&&(n=u.get(g)||1/0),i&&_(g),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o};const t=this.getNeighbors(h);for(const s of t)if(!c.has(s)){const t=null===(r=this.getEdge(h,s))||void 0===r?void 0:r.weight;if("number"==typeof t){const i=u.get(s);i&&e+t<i&&(p.add({id:e+t,val:s}),d.set(s,h),u.set(s,e+t))}}}}return s&&u.forEach(((t,e)=>{e!==f&&t<n&&(n=t,i&&(h=e))})),i&&_(h),{distMap:u,preMap:d,seen:c,paths:l,minDist:n,minPath:o}}bellmanFord(t,e,s,i){void 0===s&&(s=!1),void 0===i&&(i=!1);const r=this._getVertex(t),n=[],h=new Map,o=new Map;let l,a=1/0,u=[];if(e&&(l=!1),!r)return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u};const c=this._vertices,d=c.size,f=this.edgeSet(),g=f.length;this._vertices.forEach((t=>{h.set(t,1/0)})),h.set(r,0);for(let t=1;t<d;++t)for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s,r]=e,n=f[t].weight,l=h.get(s),a=h.get(r);void 0!==l&&void 0!==a&&h.get(s)!==1/0&&l+n<a&&(h.set(r,l+n),i&&o.set(r,s))}}let p=null;if(s&&h.forEach(((t,e)=>{e!==r&&t<a&&(a=t,i&&(p=e))})),i)for(const t of c){const e=t[1];if(e instanceof A){const s=[e];let i=o.get(e);for(;void 0!==i;)s.push(i),i=o.get(i);const r=s.reverse();t[1]===p&&(u=r),n.push(r)}}for(let t=0;t<g;++t){const e=this.getEndsOfEdge(f[t]);if(e){const[s]=e,i=f[t].weight,r=h.get(s);r&&r!==1/0&&r+i<r&&(l=!0)}}return{hasNegativeCycle:l,distMap:h,preMap:o,paths:n,min:a,minPath:u}}floyd(){var t;const e=[...this._vertices],s=e.length,i=[],r=[];for(let t=0;t<s;t++){i[t]=[],r[t]=[];for(let e=0;e<s;e++)r[t][e]=null}for(let r=0;r<s;r++)for(let n=0;n<s;n++)i[r][n]=(null===(t=this.getEdge(e[r][1],e[n][1]))||void 0===t?void 0:t.weight)||1/0;for(let t=0;t<s;t++)for(let n=0;n<s;n++)for(let h=0;h<s;h++)i[n][h]>i[n][t]+i[t][h]&&(i[n][h]=i[n][t]+i[t][h],r[n][h]=e[t][1]);return{costs:i,predecessor:r}}tarjan(t,e,s,i){const r=!1;void 0===t&&(t=r),void 0===e&&(e=r),void 0===s&&(s=r),void 0===i&&(i=r);const n=new Map,h=new Map,o=this._vertices;o.forEach((t=>{n.set(t,-1),h.set(t,1/0)}));const[l]=o.values(),a=[],u=[];let c=0;const d=(s,i)=>{c++,n.set(s,c),h.set(s,c);const r=this.getNeighbors(s);let o=0;for(const c of r)if(c!==i){-1===n.get(c)&&(o++,d(c,s));const i=h.get(c),r=h.get(s);void 0!==r&&void 0!==i&&h.set(s,Math.min(r,i));const f=n.get(s);if(void 0!==i&&void 0!==f&&(t&&(s===l&&o>=2||s!==l&&i>=f)&&a.push(s),e&&i>f)){const t=this.getEdge(s,c);t&&u.push(t)}}};d(l,null);let f=new Map;const g=()=>{const t=new Map;return h.forEach(((e,s)=>{var i;t.has(e)?null===(i=t.get(e))||void 0===i||i.push(s):t.set(e,[s])})),t};s&&(f=g());const p=new Map;if(i){let t=new Map;t.size<1&&(t=g()),t.forEach(((t,e)=>{t.length>1&&p.set(e,t)}))}return{dfnMap:n,lowMap:h,bridges:u,articulationPoints:a,SCCs:f,cycles:p}}_addVertexOnly(t){return!this.hasVertex(t)&&(this._vertices.set(t.id,t),!0)}_getVertex(t){const e=this._getVertexId(t);return this._vertices.get(e)||null}_getVertexId(t){return t instanceof A?t.id:t}_setVertices(t){this._vertices=t}}class O extends A{constructor(t,e){super(t,e)}}class C extends z{constructor(t,e,s,i){super(s,i),this._src=t,this._dest=e}get src(){return this._src}set src(t){this._src=t}get dest(){return this._dest}set dest(t){this._dest=t}}class L extends I{constructor(){super(),this._outEdgeMap=new Map,this._inEdgeMap=new Map}get outEdgeMap(){return this._outEdgeMap}get inEdgeMap(){return this._inEdgeMap}createVertex(t,e){return new O(t,null!=e?e:t)}createEdge(t,e,s,i){return new C(t,e,null!=s?s:1,i)}getEdge(t,e){let s=[];if(null!==t&&null!==e){const i=this._getVertex(t),r=this._getVertex(e);if(i&&r){const t=this._outEdgeMap.get(i);t&&(s=t.filter((t=>t.dest===r.id)))}}return s[0]||null}removeEdgeSrcToDest(t,e){const s=this._getVertex(t),i=this._getVertex(e);let r=null;if(!s||!i)return null;const n=this._outEdgeMap.get(s);n&&w(n,(t=>t.dest===i.id));const h=this._inEdgeMap.get(i);return h&&(r=w(h,(t=>t.src===s.id))[0]||null),r}removeEdge(t){let e=null;const s=this._getVertex(t.src),i=this._getVertex(t.dest);if(s&&i){const t=this._outEdgeMap.get(s);t&&t.length>0&&w(t,(t=>t.src===s.id));const r=this._inEdgeMap.get(i);r&&r.length>0&&(e=w(r,(t=>t.dest===i.id))[0])}return e}removeEdgesBetween(t,e){const s=[];if(t&&e){const i=this.removeEdgeSrcToDest(t,e),r=this.removeEdgeSrcToDest(e,t);i&&s.push(i),r&&s.push(r)}return s}incomingEdgesOf(t){const e=this._getVertex(t);return e&&this.inEdgeMap.get(e)||[]}outgoingEdgesOf(t){const 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(null===t)return[];const e=[],s=this.outgoingEdgesOf(t);for(const t of s){const s=this.getEdgeDest(t);s&&e.push(s)}return e}topologicalSort(t){t=null!=t?t:"id";const e=new Map;for(const t of this.vertices)e.set(t[1],0);let s=[],i=!1;const r=t=>{e.set(t,1);const n=this.getDestinations(t);for(const t of n){const s=e.get(t);0===s?r(t):1===s&&(i=!0)}e.set(t,2),s.push(t)};for(const t of this.vertices)0===e.get(t[1])&&r(t[1]);return i?null:("id"===t&&(s=s.map((t=>t instanceof O?t.id:t))),s.reverse())}edgeSet(){let t=[];return this._outEdgeMap.forEach((e=>{t=[...t,...e]})),t}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.outgoingEdgesOf(s);for(const s of t){const t=this._getVertex(s.dest);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.src,t.dest))return null;const e=this._getVertex(t.src),s=this._getVertex(t.dest);return e&&s?[e,s]:null}_addEdgeOnly(t){if(!this.hasVertex(t.src)||!this.hasVertex(t.dest))return!1;const e=this._getVertex(t.src),s=this._getVertex(t.dest);if(e&&s){const i=this._outEdgeMap.get(e);i?i.push(t):this._outEdgeMap.set(e,[t]);const r=this._inEdgeMap.get(s);return r?r.push(t):this._inEdgeMap.set(s,[t]),!0}return!1}_setOutEdgeMap(t){this._outEdgeMap=t}_setInEdgeMap(t){this._inEdgeMap=t}}class k extends A{constructor(t,e){super(t,e)}}class P extends z{constructor(t,e,s,i){super(s,i),this._vertices=[t,e]}get vertices(){return this._vertices}set vertices(t){this._vertices=t}}class F extends I{constructor(){super(),this._edges=new Map}get edges(){return this._edges}createVertex(t,e){return new k(t,null!=e?e:t)}createEdge(t,e,s,i){return new P(t,e,null!=s?s:1,i)}getEdge(t,e){var s;let i=[];if(null!==t&&null!==e){const r=this._getVertex(t),n=this._getVertex(e);r&&n&&(i=null===(s=this._edges.get(r))||void 0===s?void 0:s.filter((t=>t.vertices.includes(n.id))))}return i&&i[0]||null}removeEdgeBetween(t,e){const s=this._getVertex(t),i=this._getVertex(e);if(!s||!i)return null;const r=this._edges.get(s);let n=null;r&&(n=w(r,(t=>t.vertices.includes(i.id)))[0]||null);const h=this._edges.get(i);return h&&w(h,(t=>t.vertices.includes(s.id))),n}removeEdge(t){return this.removeEdgeBetween(t.vertices[0],t.vertices[1])}degreeOf(t){var e;const s=this._getVertex(t);return s&&(null===(e=this._edges.get(s))||void 0===e?void 0:e.length)||0}edgesOf(t){const e=this._getVertex(t);return e&&this._edges.get(e)||[]}edgeSet(){const t=new Set;return this._edges.forEach((e=>{e.forEach((e=>{t.add(e)}))})),[...t]}getNeighbors(t){const e=[],s=this._getVertex(t);if(s){const t=this.edgesOf(s);for(const i of t){const t=this._getVertex(i.vertices.filter((t=>t!==s.id))[0]);t&&e.push(t)}}return e}getEndsOfEdge(t){if(!this.hasEdge(t.vertices[0],t.vertices[1]))return null;const e=this._getVertex(t.vertices[0]),s=this._getVertex(t.vertices[1]);return e&&s?[e,s]:null}_addEdgeOnly(t){for(const e of t.vertices){const s=this._getVertex(e);if(null===s)return!1;if(s){const e=this._edges.get(s);e?e.push(t):this._edges.set(s,[t])}}return!0}_setEdges(t){this._edges=t}}class B extends O{constructor(t,e,s,i){super(t,i),this._lat=e,this._long=s}get lat(){return this._lat}set lat(t){this._lat=t}get long(){return this._long}set long(t){this._long=t}}class D extends C{constructor(t,e,s,i){super(t,e,s,i)}}class j extends L{constructor(t,e){super(),this._origin=[0,0],this._origin=t,this._bottomRight=e}get origin(){return this._origin}set origin(t){this._origin=t}get bottomRight(){return this._bottomRight}set bottomRight(t){this._bottomRight=t}createVertex(t,e,s=this.origin[0],i=this.origin[1]){return new B(t,s,i,e)}createEdge(t,e,s,i){return new D(t,e,s,i)}}var H,q,U,G,K;!function(t){t.lt="lt",t.eq="eq",t.gt="gt"}(H||(H={})),function(t){t.ITERATIVE="ITERATIVE",t.RECURSIVE="RECURSIVE"}(q||(q={})),function(t){t.ROOT="ROOT",t.LEFT="LEFT",t.RIGHT="RIGHT",t.ROOT_LEFT="ROOT_LEFT",t.ROOT_RIGHT="ROOT_RIGHT",t.ISOLATED="ISOLATED",t.MAL_NODE="MAL_NODE"}(U||(U={})),function(t){t.RED="RED",t.BLACK="BLACK"}(G||(G={})),function(t){t.VAL="VAL",t.NODE="NODE",t.ID="ID"}(K||(K={}));class Q{constructor(t,e){this._height=0,this._id=t,this._val=e}get id(){return this._id}set id(t){this._id=t}get val(){return this._val}set val(t){this._val=t}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 parent(){return this._parent}set parent(t){this._parent=t}get height(){return this._height}set height(t){this._height=t}get familyPosition(){const t=this;return t.parent?t.parent.left===t?t.left||t.right?U.ROOT_LEFT:U.LEFT:t.parent.right===t?t.left||t.right?U.ROOT_RIGHT:U.RIGHT:U.MAL_NODE:t.left||t.right?U.ROOT:U.ISOLATED}}class W{constructor(t){if(this._root=null,this._size=0,this._loopType=q.ITERATIVE,this._visitedId=[],this._visitedVal=[],this._visitedNode=[],void 0!==t){const{loopType:e=q.ITERATIVE}=t;this._loopType=e}this.clear()}get root(){return this._root}get size(){return this._size}get loopType(){return this._loopType}get visitedId(){return this._visitedId}get visitedVal(){return this._visitedVal}get visitedNode(){return this._visitedNode}swapLocation(t,e){const{id:s,val:i,height:r}=e,n=this.createNode(s,i);return n&&(n.height=r,e.id=t.id,e.val=t.val,e.height=t.height,t.id=n.id,t.val=n.val,t.height=n.height),e}clear(){this._root=null,this._size=0,this._clearResults()}isEmpty(){return 0===this.size}add(t,e){let s,i;if(null===t)i=null;else if("number"==typeof t)i=this.createNode(t,e);else{if(!(t instanceof Q))return;i=t}const r=t?this.get(t,"id"):void 0;return this.root?r?(r.val=e,s=r):s=((t,e)=>{const s=[t];for(;s.length>0;){const t=s.shift();if(!t)return;{if(e&&t.id===e.id)return;const i=this._addTo(e,t);if(void 0!==i)return i;t.left&&s.push(t.left),t.right&&s.push(t.right)}}})(this.root,i):(this._setRoot(i),null!==i?this._setSize(1):this._setSize(0),s=this.root),s}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];if(r instanceof Q){s.push(this.add(r.id,r.val));continue}if(null===r){s.push(this.add(null));continue}const n=null==e?void 0:e[i];s.push(this.add(r,n))}return s}fill(t,e){return this.clear(),t.length===this.addMany(t,e).length}remove(t){const e=[];if(!this.root)return e;const s="number"==typeof t?this.get(t):t;if(!s)return e;const i=(null==s?void 0:s.parent)?s.parent:null;let r=null,n=s;if(s.left){const t=s.left?this.getRightMost(s.left):null;if(t){const e=t.parent;n=this.swapLocation(s,t),e&&(e.right===t?e.right=t.left:e.left=t.left,r=e)}}else if(i){const{familyPosition:t}=s;t===U.LEFT||t===U.ROOT_LEFT?i.left=s.right:t!==U.RIGHT&&t!==U.ROOT_RIGHT||(i.right=s.right),r=i}else void 0!==s.right&&this._setRoot(s.right);return this._setSize(this.size-1),e.push({deleted:n,needBalanced:r}),e}getDepth(t){"number"==typeof t&&(t=this.get(t,"id"));let e=0;for(;null==t?void 0:t.parent;)e++,t=t.parent;return e}getHeight(t){if("number"==typeof(t=null!=t?t:this.root)&&(t=this.get(t,"id")),!t)return-1;if(this._loopType===q.RECURSIVE){const e=t=>{if(!t)return-1;const s=e(t.left),i=e(t.right);return Math.max(s,i)+1};return e(t)}{if(!t)return-1;const e=[{node:t,depth:0}];let s=0;for(;e.length>0;){const{node:t,depth:i}=e.pop();t.left&&e.push({node:t.left,depth:i+1}),t.right&&e.push({node:t.right,depth:i+1}),s=Math.max(s,i)}return s}}getMinHeight(t){var e,s,i;if(!(t=t||this.root))return-1;if(this._loopType===q.RECURSIVE){const e=t=>{if(!t)return 0;if(!t.left&&!t.right)return 0;const s=e(t.left),i=e(t.right);return Math.min(s,i)+1};return e(t)}{const r=[];let n=t,h=null;const o=new Map;for(;r.length>0||n;)if(n)r.push(n),n=n.left;else if(n=r[r.length-1],n.right&&h!==n.right)n=n.right;else if(n=r.pop(),n){const t=n.left&&null!==(e=o.get(n.left))&&void 0!==e?e:-1,i=n.right&&null!==(s=o.get(n.right))&&void 0!==s?s:-1;o.set(n,1+Math.min(t,i)),h=n,n=null}return null!==(i=o.get(t))&&void 0!==i?i:-1}}isPerfectlyBalanced(t){return this.getMinHeight(t)+1>=this.getHeight(t)}getNodes(t,e,s){if(!this.root)return[];e=null!=e?e:"id";const i=[];if(this.loopType===q.RECURSIVE){const r=n=>{this._pushByPropertyNameStopOrNot(n,i,t,e,s)||(n.left||n.right)&&(n.left&&r(n.left),n.right&&r(n.right))};r(this.root)}else{const r=[this.root];for(;r.length>0;){const n=r.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,i,t,e,s))return i;n.left&&r.push(n.left),n.right&&r.push(n.right)}}}return i}has(t,e){return e=null!=e?e:"id",this.getNodes(t,e).length>0}get(t,e){var s;return e=null!=e?e:"id",null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}getPathToRoot(t,e=!0){const s=[];for(;t.parent;)s.push(t),t=t.parent;return s.push(t),e?s.reverse():s}getLeftMost(t){if("number"==typeof t&&(t=this.get(t,"id")),!(t=null!=t?t:this.root))return t;if(this._loopType===q.RECURSIVE){const e=t=>t.left?e(t.left):t;return e(t)}{const e=R((t=>t.left?e.cont(t.left):t));return e(t)}}getRightMost(t){if(!(t=null!=t?t:this.root))return t;if(this._loopType===q.RECURSIVE){const e=t=>t.right?e(t.right):t;return e(t)}{const e=R((t=>t.right?e.cont(t.right):t));return e(t)}}isSubtreeBST(t){if(!t)return!0;if(this._loopType===q.RECURSIVE){const e=(t,s,i)=>!t||!(t.id<=s||t.id>=i)&&e(t.left,s,t.id)&&e(t.right,t.id,i);return e(t,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER)}{const e=[];let s=Number.MIN_SAFE_INTEGER,i=t;for(;i||e.length>0;){for(;i;)e.push(i),i=i.left;if(i=e.pop(),!i||s>=i.id)return!1;s=i.id,i=i.right}return!0}}isBST(){return this.isSubtreeBST(this.root)}getSubTreeSize(t){let e=0;if(!t)return e;if(this._loopType===q.RECURSIVE){const s=t=>{e++,t.left&&s(t.left),t.right&&s(t.right)};return s(t),e}{const s=[t];for(;s.length>0;){const t=s.pop();e++,t.right&&s.push(t.right),t.left&&s.push(t.left)}return e}}subTreeSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let s=0;const i=t=>{let s;switch(e){case"id":default:s=t.id;break;case"val":s="number"==typeof t.val?t.val:0}return s};if(this._loopType===q.RECURSIVE){const e=t=>{s+=i(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();s+=i(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return s}subTreeAdd(t,e,s){if(s=null!=s?s:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t=>{t.id+=e};if(this._loopType===q.RECURSIVE){const e=t=>{i(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();i(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}BFS(t){t=null!=t?t:"id",this._clearResults();const e=[this.root];for(;0!==e.length;){const s=e.shift();s&&(this._accumulatedByPropertyName(s,t),null!==(null==s?void 0:s.left)&&e.push(s.left),null!==(null==s?void 0:s.right)&&e.push(s.right))}return this._getResultByPropertyName(t)}DFS(t,e){t=null!=t?t:"in",e=null!=e?e:"id",this._clearResults();const s=i=>{switch(t){case"in":i.left&&s(i.left),this._accumulatedByPropertyName(i,e),i.right&&s(i.right);break;case"pre":this._accumulatedByPropertyName(i,e),i.left&&s(i.left),i.right&&s(i.right);break;case"post":i.left&&s(i.left),i.right&&s(i.right),this._accumulatedByPropertyName(i,e)}};return this.root&&s(this.root),this._getResultByPropertyName(e)}DFSIterative(t,e){if(t=t||"in",e=e||"id",this._clearResults(),!this.root)return this._getResultByPropertyName(e);const s=[{opt:0,node:this.root}];for(;s.length>0;){const i=s.pop();if(i&&i.node)if(1===i.opt)this._accumulatedByPropertyName(i.node,e);else switch(t){case"in":default:s.push({opt:0,node:i.node.right}),s.push({opt:1,node:i.node}),s.push({opt:0,node:i.node.left});break;case"pre":s.push({opt:0,node:i.node.right}),s.push({opt:0,node:i.node.left}),s.push({opt:1,node:i.node});break;case"post":s.push({opt:1,node:i.node}),s.push({opt:0,node:i.node.right}),s.push({opt:0,node:i.node.left})}}return this._getResultByPropertyName(e)}levelIterative(t,e){if(e=e||"id",!(t=t||this.root))return[];this._clearResults();const s=[t];for(;s.length>0;){const t=s.shift();t&&(this._accumulatedByPropertyName(t,e),t.left&&s.push(t.left),t.right&&s.push(t.right))}return this._getResultByPropertyName(e)}listLevels(t,e){if(e=e||"id",!(t=t||this.root))return[];const s=[],i=(t,i)=>{switch(e){case"id":default:s[i].push(t.id);break;case"val":s[i].push(t.val);break;case"node":s[i].push(t)}};if(this.loopType===q.RECURSIVE){const e=(t,r)=>{s[r]||(s[r]=[]),i(t,r),t.left&&e(t.left,r+1),t.right&&e(t.right,r+1)};e(t,0)}else{const e=[[t,0]];for(;e.length>0;){const t=e.pop(),[r,n]=t;s[n]||(s[n]=[]),i(r,n),r.right&&e.push([r.right,n+1]),r.left&&e.push([r.left,n+1])}}return s}getPredecessor(t){if(t.left){let e=t.left;for(;!e||e.right&&e.right!==t;)e&&(e=e.right);return e}return t}morris(t,e){if(null===this.root)return[];t=t||"in",e=e||"id",this._clearResults();let s=this.root;const i=t=>{let e=null,s=null;for(;t;)s=t.right,t.right=e,e=t,t=s;return e},r=t=>{const s=i(t);let r=s;for(;r;)this._accumulatedByPropertyName(r,e),r=r.right;i(s)};switch(t){case"in":for(;s;){if(s.left){const t=this.getPredecessor(s);if(!t.right){t.right=s,s=s.left;continue}t.right=null}this._accumulatedByPropertyName(s,e),s=s.right}break;case"pre":for(;s;){if(s.left){const t=this.getPredecessor(s);if(!t.right){t.right=s,this._accumulatedByPropertyName(s,e),s=s.left;continue}t.right=null}else this._accumulatedByPropertyName(s,e);s=s.right}break;case"post":for(;s;){if(s.left){const t=this.getPredecessor(s);if(null===t.right){t.right=s,s=s.left;continue}t.right=null,r(s.left)}s=s.right}r(this.root)}return this._getResultByPropertyName(e)}_addTo(t,e){return e?void 0===e.left?(e.left=t,t&&this._setSize(this.size+1),e.left):void 0===e.right?(e.right=t,t&&this._setSize(this.size+1),e.right):void 0:void 0}_setLoopType(t){this._loopType=t}_setVisitedId(t){this._visitedId=t}_setVisitedVal(t){this._visitedVal=t}_setVisitedNode(t){this._visitedNode=t}_setRoot(t){t&&(t.parent=void 0),this._root=t}_setSize(t){this._size=t}_clearResults(){this._visitedId=[],this._visitedVal=[],this._visitedNode=[]}_pushByPropertyNameStopOrNot(t,e,s,i,r){switch(i){case"id":default:if(t.id===s)return e.push(t),!!r;break;case"val":if(t.val===s)return e.push(t),!!r}}_accumulatedByPropertyName(t,e){switch(e=null!=e?e:"id"){case"id":default:this._visitedId.push(t.id);break;case"val":this._visitedVal.push(t.val);break;case"node":this._visitedNode.push(t)}}_getResultByPropertyName(t){switch(t=null!=t?t:"id"){case"id":default:return this._visitedId;case"val":return this._visitedVal;case"node":return this._visitedNode}}}class Y extends Q{constructor(t,e){super(t,e)}}class J extends W{constructor(t){super(t)}createNode(t,e){return new Y(t,e)}}class X extends Y{constructor(t,e){super(t,e)}}class Z extends J{constructor(t){if(super(t),this._comparator=(t,e)=>t-e,void 0!==t){const{comparator:e}=t;void 0!==e&&(this._comparator=e)}}createNode(t,e){return new X(t,e)}add(t,e){let s=null,i=null;if(t instanceof X?i=t:"number"==typeof t?i=this.createNode(t,e):null===t&&(i=null),null===this.root)this._setRoot(i),this._setSize(this.size+1),s=this.root;else{let t=this.root,e=!0;for(;e;)null!==t&&null!==i?this._compare(t.id,i.id)===H.eq?(i&&(t.val=i.val),e=!1,s=t):this._compare(t.id,i.id)===H.gt?void 0===t.left?(i&&(i.parent=t),t.left=i,this._setSize(this.size+1),e=!1,s=t.left):t.left&&(t=t.left):this._compare(t.id,i.id)===H.lt&&(void 0===t.right?(i&&(i.parent=t),t.right=i,this._setSize(this.size+1),e=!1,s=t.right):t.right&&(t=t.right)):e=!1}return s}addMany(t,e,s=!1){if(!s||-1!==t.indexOf(null))return super.addMany(t,e);const i=[],r=t.map(((t,s)=>[t,null==e?void 0:e[s]]));let n=[],h=[],o=[];if(function(t){for(const[e]of t)if(e instanceof X)return!0;return!1}(r))n=r.sort(((t,e)=>t[0].id-e[0].id));else{if(!function(t){for(const[e]of t)if("number"==typeof e)return!0;return!1}(r))throw new Error("Invalid input idsOrNodes");n=r.sort(((t,e)=>t[0]-e[0]))}h=n.map((([t])=>t)),o=n.map((([,t])=>t));const l=(t,e)=>{if(0===t.length)return;const s=Math.floor((t.length-1)/2),r=this.add(t[s],null==e?void 0:e[s]);i.push(r),l(t.slice(0,s),null==e?void 0:e.slice(0,s)),l(t.slice(s+1),null==e?void 0:e.slice(s+1))};return this.loopType===q.RECURSIVE?l(h,o):(()=>{const t=[[0,n.length-1]];for(;t.length>0;){const e=t.pop();if(e){const[s,r]=e;if(s<=r){const e=s+Math.floor((r-s)/2),n=this.add(h[e],null==o?void 0:o[e]);i.push(n),t.push([e+1,r]),t.push([s,e-1])}}}})(),i}get(t,e){var s;return e=null!=e?e:"id",null!==(s=this.getNodes(t,e,!0)[0])&&void 0!==s?s:null}lastKey(){var t,e,s,i,r,n;return this._compare(0,1)===H.lt?null!==(e=null===(t=this.getRightMost())||void 0===t?void 0:t.id)&&void 0!==e?e:0:this._compare(0,1)===H.gt?null!==(i=null===(s=this.getLeftMost())||void 0===s?void 0:s.id)&&void 0!==i?i:0:null!==(n=null===(r=this.getRightMost())||void 0===r?void 0:r.id)&&void 0!==n?n:0}getNodes(t,e="id",s){if(!this.root)return[];const i=[];if(this.loopType===q.RECURSIVE){const r=n=>{this._pushByPropertyNameStopOrNot(n,i,t,e,s)||(n.left||n.right)&&("id"===e?(this._compare(n.id,t)===H.gt&&n.left&&r(n.left),this._compare(n.id,t)===H.lt&&n.right&&r(n.right)):(n.left&&r(n.left),n.right&&r(n.right)))};r(this.root)}else{const r=[this.root];for(;r.length>0;){const n=r.shift();if(n){if(this._pushByPropertyNameStopOrNot(n,i,t,e,s))return i;"id"===e?(this._compare(n.id,t)===H.gt&&n.left&&r.push(n.left),this._compare(n.id,t)===H.lt&&n.right&&r.push(n.right)):(n.left&&r.push(n.left),n.right&&r.push(n.right))}}}return i}lesserSum(t,e){if(e=null!=e?e:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const s=t.id,i=t=>{let e;return e=t.id,e};let r=0;if(this.loopType===q.RECURSIVE){const t=n=>{const h=this._compare(n.id,s);if(h!==H.eq)if(h===H.lt){if(n.left&&(r+=this.subTreeSum(n.left,e)),r+=i(n),!n.right)return;t(n.right)}else{if(!n.left)return;t(n.left)}else n.right&&(r+=this.subTreeSum(n.right,e))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const n=t.shift();if(n){const h=this._compare(n.id,s);if(h===H.eq)return n.right&&(r+=this.subTreeSum(n.right,e)),r;if(h===H.lt){if(n.left&&(r+=this.subTreeSum(n.left,e)),r+=i(n),!n.right)return r;t.push(n.right)}else{if(!n.left)return r;t.push(n.left)}}}}return r}allGreaterNodesAdd(t,e,s){if(s=null!=s?s:"id","number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const i=t.id;if(!this.root)return!1;const r=t=>{t.id+=e};if(this.loopType===q.RECURSIVE){const t=e=>{this._compare(e.id,i)===H.gt&&r(e),(e.left||e.right)&&(e.left&&this._compare(e.left.id,i)===H.gt&&t(e.left),e.right&&this._compare(e.right.id,i)===H.gt&&t(e.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const e=t.shift();e&&(this._compare(e.id,i)===H.gt&&r(e),e.left&&this._compare(e.left.id,i)===H.gt&&t.push(e.left),e.right&&this._compare(e.right.id,i)===H.gt&&t.push(e.right))}return!0}}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(this.clear(),t.length<1)return!1;if(this.loopType===q.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.id,n.val),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.id,n.val),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}isAVLBalanced(){var t,e;if(!this.root)return!0;let s=!0;if(this.loopType===q.RECURSIVE){const t=e=>{if(!e)return 0;const i=t(e.left),r=t(e.right);return Math.abs(i-r)>1&&(s=!1),Math.max(i,r)+1};t(this.root)}else{const s=[];let i=this.root,r=null;const n=new Map;for(;s.length>0||i;)if(i)s.push(i),i=i.left;else if(i=s[s.length-1],i.right&&r!==i.right)i=i.right;else if(i=s.pop(),i){const s=i.left&&null!==(t=n.get(i.left))&&void 0!==t?t:-1,h=i.right&&null!==(e=n.get(i.right))&&void 0!==e?e:-1;if(Math.abs(s-h)>1)return!1;n.set(i,1+Math.max(s,h)),r=i,i=null}}return s}_compare(t,e){const s=this._comparator(t,e);return s>0?H.gt:s<0?H.lt:H.eq}}class ${constructor(t){this._sumTree=new Array(t+1).fill(0)}get sumTree(){return this._sumTree}static lowBit(t){return t&-t}update(t,e){for(;t<this._sumTree.length;)this._sumTree[t]+=e,t+=$.lowBit(t)}getPrefixSum(t){let e=0;for(;t>0;)e+=this._sumTree[t],t-=$.lowBit(t);return e}getRangeSum(t,e){if(!(0<=t&&t<=e&&e<=this._sumTree.length))throw"Index out of bounds";return this.getPrefixSum(e)-this.getPrefixSum(t)}_setSumTree(t){this._sumTree=t}}class tt{constructor(t,e,s,i){this._start=0,this._end=0,this._val=null,this._sum=0,this._left=null,this._right=null,this._start=t,this._end=e,this._sum=s,this._val=i||null}get start(){return this._start}set start(t){this._start=t}get end(){return this._end}set end(t){this._end=t}get val(){return this._val}set val(t){this._val=t}get sum(){return this._sum}set sum(t){this._sum=t}get left(){return this._left}set left(t){this._left=t}get right(){return this._right}set right(t){this._right=t}}class et{constructor(t,e,s){this._values=[],this._start=0,e=e||0,s=s||t.length-1,this._values=t,this._start=e,this._end=s,t.length>0?this._root=this.build(e,s):(this._root=null,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(t,e){if(t>e)return new tt(t,e,0);if(t===e)return new tt(t,e,this._values[t]);const s=t+Math.floor((e-t)/2),i=this.build(t,s),r=this.build(s+1,e),n=new tt(t,e,i.sum+r.sum);return n.left=i,n.right=r,n}updateNode(t,e,s){const i=this.root||null;if(!i)return;const r=(t,e,s,i)=>{if(t.start===t.end&&t.start===e)return t.sum=s,void(void 0!==i&&(t.val=i));e<=t.start+Math.floor((t.end-t.start)/2)?t.left&&r(t.left,e,s,i):t.right&&r(t.right,e,s,i),t.left&&t.right&&(t.sum=t.left.sum+t.right.sum)};r(i,t,e,s)}querySumByRange(t,e){const s=this.root||null;if(!s)return 0;if(t<0||e>=this.values.length||t>e)return NaN;const i=(t,e,s)=>{if(e<=t.start&&s>=t.end)return t.sum;const r=t.start+Math.floor((t.end-t.start)/2);if(s<=r)return t.left?i(t.left,e,s):NaN;if(e>r)return t.right?i(t.right,e,s):NaN;{let n=0,h=0;return t.left&&(n=i(t.left,e,r)),t.right&&(h=i(t.right,r+1,s)),n+h}};return i(s,t,e)}_setValues(t){this._values=t}_setStart(t){this._start=t}_setEnd(t){this._end=t}_setRoot(t){this._root=t}}class st extends X{constructor(t,e){super(t,e)}}class it extends Z{constructor(t){super(t)}createNode(t,e){return new st(t,e)}add(t,e){const s=super.add(t,e);return s&&this._balancePath(s),s}remove(t){const e=super.remove(t);for(const{needBalanced:t}of e)t&&this._balancePath(t);return e}_balanceFactor(t){return t.right?t.left?t.right.height-t.left.height:+t.height:-t.height}_updateHeight(t){if(t.left||t.right)if(t.left)t.right?t.height=1+Math.max(t.right.height,t.left.height):t.height=1+t.left.height;else{const e=t.right?t.right.height:0;t.height=1+e}else t.height=0}_balancePath(t){const e=this.getPathToRoot(t,!1);for(let t=0;t<e.length;t++){const s=e[t];switch(this._updateHeight(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))}}}_balanceLL(t){const e=t.parent,s=t.left;t.parent=s,s&&s.right&&(s.right.parent=t),s&&(s.parent=e),t===this.root?s&&this._setRoot(s):(null==e?void 0:e.left)===t?e.left=s:e&&(e.right=s),s&&(t.left=s.right,s.right=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceLR(t){const e=t.parent,s=t.left;let i=null;s&&(i=s.right),t&&(t.parent=i),s&&(s.parent=i),i&&(i.left&&(i.left.parent=s),i.right&&(i.right.parent=t),i.parent=e),t===this.root?i&&this._setRoot(i):e&&(e.left===t?e.left=i:e.right=i),i&&(t.left=i.right,s&&(s.right=i.left),i.left=s,i.right=t),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}_balanceRR(t){const e=t.parent,s=t.right;t.parent=s,s&&(s.left&&(s.left.parent=t),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,s.left=t),this._updateHeight(t),s&&this._updateHeight(s)}_balanceRL(t){const e=t.parent,s=t.right;let i=null;s&&(i=s.left),t.parent=i,s&&(s.parent=i),i&&(i.left&&(i.left.parent=t),i.right&&(i.right.parent=s),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),s&&i&&(s.left=i.right),i&&(i.left=t),i&&(i.right=s),this._updateHeight(t),s&&this._updateHeight(s),i&&this._updateHeight(i)}}class rt{}class nt extends X{constructor(t,e){super(t,e),this._color=G.RED}get color(){return this._color}set color(t){this._color=t}}class ht extends Z{constructor(t){super(t)}createNode(t,e){return new nt(t,e)}}class ot{}class lt{}class at extends st{constructor(t,e,s=1){super(t,e),this._count=s}get count(){return this._count}set count(t){this._count=t}}class ut extends it{constructor(t){super(Object.assign({},t)),this._count=0}get count(){return this._count}createNode(t,e,s){return new at(t,e,s)}swapLocation(t,e){const{id:s,val:i,count:r,height:n}=e,h=this.createNode(s,i,r);return h&&(h.height=n,e.id=t.id,e.val=t.val,e.count=t.count,e.height=t.height,t.id=h.id,t.val=h.val,t.count=h.count,t.height=h.height),e}add(t,e,s){let i,r;if(s=null!=s?s:1,r=t instanceof at?this.createNode(t.id,t.val,t.count):null===t?null:this.createNode(t,e,s),this.root){let t=this.root,e=!0;for(;e;)t?r&&(this._compare(t.id,r.id)===H.eq?(t.val=r.val,t.count+=r.count,this._setCount(this.count+r.count),e=!1,i=t):this._compare(t.id,r.id)===H.gt?void 0===t.left?(t.left=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.left):t.left&&(t=t.left):this._compare(t.id,r.id)===H.lt&&(void 0===t.right?(t.right=r,this._setSize(this.size+1),this._setCount(this.count+r.count),e=!1,i=t.right):t.right&&(t=t.right))):e=!1}else this._setRoot(r),this._setSize(this.size+1),r&&this._setCount(this.count+r.count),i=this.root;return i&&this._balancePath(i),i}_addTo(t,e){return e?void 0===e.left?(e.left=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.left):void 0===e.right?(e.right=t,null!==t&&(this._setSize(this.size+1),this._setCount(this.count+t.count)),e.right):void 0:void 0}addMany(t,e){const s=[];for(let i=0;i<t.length;i++){const r=t[i];r instanceof at?s.push(this.add(r.id,r.val,r.count)):null!==r?s.push(this.add(r,null==e?void 0:e[i],1)):s.push(this.add(NaN,null,0))}return s}perfectlyBalance(){const t=this.DFS("in","node"),e=t.length;if(t.length<1)return!1;if(this.clear(),this.loopType===q.RECURSIVE){const s=(e,i)=>{if(e>i)return;const r=e+Math.floor((i-e)/2),n=t[r];this.add(n.id,n.val,n.count),s(e,r-1),s(r+1,i)};return s(0,e-1),!0}{const s=[[0,e-1]];for(;s.length>0;){const e=s.pop();if(e){const[i,r]=e;if(i<=r){const e=i+Math.floor((r-i)/2),n=t[e];this.add(n.id,n.val,n.count),s.push([e+1,r]),s.push([i,e-1])}}}return!0}}remove(t,e){const s=[];if(!this.root)return s;const i=this.get(t);if(!i)return s;const r=(null==i?void 0:i.parent)?i.parent:null;let n=null,h=i;if(i.count>1&&!e)i.count--,this._setCount(this.count-1);else{if(i.left){const t=i.left?this.getRightMost(i.left):null;if(t){const e=t.parent;h=this.swapLocation(i,t),e&&(e.right===t?e.right=t.left:e.left=t.left,n=e)}}else if(r){const{familyPosition:t}=i;t===U.LEFT||t===U.ROOT_LEFT?r.left=i.right:t!==U.RIGHT&&t!==U.ROOT_RIGHT||(r.right=i.right),n=r}else void 0!==i.right&&this._setRoot(i.right);this._setSize(this.size-1),this._setCount(this.count-h.count)}return s.push({deleted:h,needBalanced:n}),n&&this._balancePath(n),s}getSubTreeCount(t){const e=[0,0];if(!t)return e;if(this.loopType===q.RECURSIVE){const s=t=>{e[0]++,e[1]+=t.count,t.left&&s(t.left),t.right&&s(t.right)};return s(t),e}{const s=[t];for(;s.length>0;){const t=s.pop();e[0]++,e[1]+=t.count,t.right&&s.push(t.right),t.left&&s.push(t.left)}return e}}subTreeSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;let e=0;if(this.loopType===q.RECURSIVE){const s=t=>{e+=t.count,t.left&&s(t.left),t.right&&s(t.right)};s(t)}else{const s=[t];for(;s.length>0;){const t=s.pop();e+=t.count,t.right&&s.push(t.right),t.left&&s.push(t.left)}}return e}subTreeAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const s=t=>{t.count+=e,this._setCount(this.count+e)};if(this.loopType===q.RECURSIVE){const e=t=>{s(t),t.left&&e(t.left),t.right&&e(t.right)};e(t)}else{const e=[t];for(;e.length>0;){const t=e.pop();s(t),t.right&&e.push(t.right),t.left&&e.push(t.left)}}return!0}getNodesByCount(t,e){if(!this.root)return[];const s=[];if(this.loopType===q.RECURSIVE){const i=r=>{r.count===t&&(s.push(r),e)||(r.left||r.right)&&(r.left&&i(r.left),r.right&&i(r.right))};i(this.root)}else{const i=[this.root];for(;i.length>0;){const r=i.shift();if(r){if(r.count===t&&(s.push(r),e))return s;r.left&&i.push(r.left),r.right&&i.push(r.right)}}}return s}BFSCount(){return super.BFS("node").map((t=>t.count))}listLevelsCount(t){return super.listLevels(t,"node").map((t=>t.map((t=>t.count))))}morrisCount(t){return t=t||"in",super.morris(t,"node").map((t=>t.count))}DFSIterativeCount(t){return t=null!=t?t:"in",super.DFSIterative(t,"node").map((t=>t.count))}DFSCount(t){return t=null!=t?t:"in",super.DFS(t,"node").map((t=>t.count))}lesserSumCount(t){if("number"==typeof t&&(t=this.get(t,"id")),!t)return 0;if(!this.root)return 0;const e=t.id;let s=0;if(this.loopType===q.RECURSIVE){const t=i=>{const r=this._compare(i.id,e);if(r!==H.eq)if(r===H.lt){if(i.left&&(s+=this.subTreeSumCount(i.left)),s+=i.count,!i.right)return;t(i.right)}else{if(!i.left)return;t(i.left)}else i.right&&(s+=this.subTreeSumCount(i.right))};t(this.root)}else{const t=[this.root];for(;t.length>0;){const i=t.shift();if(i){const r=this._compare(i.id,e);if(r===H.eq)return i.right&&(s+=this.subTreeSumCount(i.right)),s;if(r===H.lt){if(i.left&&(s+=this.subTreeSumCount(i.left)),s+=i.count,!i.right)return s;t.push(i.right)}else{if(!i.left)return s;t.push(i.left)}}}}return s}allGreaterNodesAddCount(t,e){if("number"==typeof t&&(t=this.get(t,"id")),!t)return!1;const s=t.id;if(!this.root)return!1;if(this.loopType===q.RECURSIVE){const t=i=>{this._compare(i.id,s)===H.gt&&(i.count+=e),(i.left||i.right)&&(i.left&&this._compare(i.left.id,s)===H.gt&&t(i.left),i.right&&this._compare(i.right.id,s)===H.gt&&t(i.right))};return t(this.root),!0}{const t=[this.root];for(;t.length>0;){const i=t.shift();i&&(this._compare(i.id,s)===H.gt&&(i.count+=e),i.left&&this._compare(i.left.id,s)===H.gt&&t.push(i.left),i.right&&this._compare(i.right.id,s)===H.gt&&t.push(i.right))}return!0}}clear(){super.clear(),this._setCount(0)}_setCount(t){this._count=t}}class ct{}class dt{constructor(t,e,s){this._id=t,this._value=e||void 0,this._children=s||[]}get id(){return this._id}set id(t){this._id=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 dt?this.children.push(t):this.children=this.children.concat(t)}getHeight(){const t=this;let e=1;if(t){const s=(t,i)=>{i>e&&(e=i);const{children:r}=t;if(r)for(let t=0,e=r.length;t<e;t++)s(r[t],i+1)};s(t,1)}return e}}class ft{constructor(t=Number.MAX_SAFE_INTEGER,e=null){this._val=e,this._priority=t}get priority(){return this._priority}set priority(t){this._priority=t}get val(){return this._val}set val(t){this._val=t}}class gt{constructor(t){if(t){const{priorityExtractor:e}=t;if(void 0!==e&&"function"!=typeof e)throw new Error(".constructor expects a valid priority function");this._priorityExtractor=e||(t=>+t)}else this._priorityExtractor=t=>+t}get pq(){return this._pq}get priorityExtractor(){return this._priorityExtractor}get size(){return this._pq.size}isEmpty(){return this._pq.size<1}peek(t){t=null!=t&&t;const e=this._pq.peek();return t?e:null==e?void 0:e.val}peekLast(t){t=null!=t&&t;const e=this._pq.leaf();return t?e:null==e?void 0:e.val}add(t,e){return e=void 0===e?t:e,this._pq.add(new ft(t,e)),this}poll(t){t=null!=t&&t;const e=this._pq.poll();return e?t?e:e.val:null}has(t){return t instanceof ft?this.pq.getNodes().includes(t):-1!==this.pq.getNodes().findIndex((e=>e.val===t))}toArray(t){t=null!=t&&t;const e=this._pq.toArray();return t?e:e.map((t=>t.val))}sort(t){t=null!=t&&t;const e=this._pq.sort();return t?e:e.map((t=>t.val))}clear(){this._pq.clear()}}class pt extends gt{constructor(t){super(t),this._pq=new N({comparator:(t,e)=>e.priority-t.priority})}}class _t extends gt{constructor(t){super(t),this._pq=new N({comparator:(t,e)=>t.priority-e.priority})}}class vt extends N{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}))}static heapify(t){const e=new vt(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>t-e}));return e._fix(),e}}class mt extends N{constructor(t){super(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}))}static heapify(t){const e=new mt(Object.assign(Object.assign({},t),{comparator:(null==t?void 0:t.comparator)?t.comparator:(t,e)=>e-t}));return e._fix(),e}}class yt{constructor(t){const{row:e,col:s,initialVal:i}=t;this._matrix=new Array(e).fill(void 0).map((()=>new Array(s).fill(i||0)))}toArray(){return this._matrix}}class xt{constructor(t=0,e=0,s=1){this.x=t,this.y=e,this.w=s}get isZero(){return 0===this.x&&0===this.y}get length(){return Math.sqrt(this.x*this.x+this.y*this.y)}get lengthSq(){return this.x*this.x+this.y*this.y}get rounded(){return new xt(Math.round(this.x),Math.round(this.y))}static add(t,e){return new xt(t.x+e.x,t.y+e.y)}static subtract(t,e){return new xt(t.x-e.x,t.y-e.y)}static subtractValue(t,e){return new xt(t.x-e,t.y-e)}static multiply(t,e){return new xt(t.x*e,t.y*e)}static divide(t,e){return new xt(t.x/e,t.y/e)}static equals(t,e){return t.x===e.x&&t.y===e.y}static equalsRounded(t,e,s=12){const i=xt.abs(xt.subtract(t,e));return i.x<s&&i.y<s}static normalize(t){const e=t.length;return e>2220446049250313e-31?xt.divide(t,e):t}static truncate(t,e){return t.length>e?xt.multiply(xt.normalize(t),e):t}static perp(t){return new xt(-t.y,t.x)}static reverse(t){return new xt(-t.x,-t.y)}static abs(t){return new xt(Math.abs(t.x),Math.abs(t.y))}static dot(t,e){return t.x*e.x+t.y*e.y}static distance(t,e){const s=e.y-t.y,i=e.x-t.x;return Math.sqrt(s*s+i*i)}static distanceSq(t,e){const s=e.y-t.y,i=e.x-t.x;return s*s+i*i}static sign(t,e){return t.y*e.x>t.x*e.y?-1:1}static angle(t){const e=new xt(0,-1),s=Math.acos(xt.dot(t,e)/(t.length*e.length));return 1===xt.sign(t,e)?2*Math.PI-s:s}static random(t,e){const s=Math.floor(Math.random()*t-t/2),i=Math.floor(Math.random()*e-e/2);return new xt(s,i)}zero(){this.x=0,this.y=0}}const Et=xt;class bt{constructor(t){void 0===t?this._matrix=bt.identity:t instanceof Et?(this._matrix=bt.identity,this._matrix[0][0]=t.x,this._matrix[1][0]=t.y,this._matrix[2][0]=t.w):this._matrix=t}static get empty(){return[[],[],[]]}static get identity(){return[[1,0,0],[0,1,0],[0,0,1]]}get m(){return this._matrix}toVector(){return new Et(this._matrix[0][0],this._matrix[1][0])}static add(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]+e.m[i][r];return new bt(s)}static subtract(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]-e.m[i][r];return new bt(s)}static multiply(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++){s[i][r]=0;for(let n=0;n<3;n++)s[i][r]+=t.m[i][n]*e.m[n][r]}return new bt(s)}static multiplyByValue(t,e){const s=bt.empty;for(let i=0;i<3;i++)for(let r=0;r<3;r++)s[i][r]=t.m[i][r]*e;return new bt(s)}static multiplyByVector(t,e){return bt.multiply(t,new bt(e)).toVector()}static view(t,e){const s=t/2,i=e/2,r=Math.cos(Math.PI);return new bt([[1,0,s],[0,1*r,i],[0,0,1]])}static scale(t){return bt.multiplyByValue(new bt,t)}static rotate(t){const e=Math.cos(t),s=Math.sin(t);return new bt([[e,-s,0],[s,e,0],[0,0,1]])}static translate(t){return new bt([[1,0,t.x],[0,1,t.y],[0,0,t.w]])}}class wt{constructor(t,e){this.direction=t,this.turn=()=>new wt(e[t],e)}}class Tt{constructor({matrix:t,turning:e,onMove:s,init:{cur:i,charDir:r,VISITED:n}}){this._matrix=t,this._cur=i,this._character=new wt(r,e),this.onMove=s,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);){const{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,s;const i=this._matrix,[r,n]=this._cur;switch(t){case"up":if(s=i[r-1],!s)return!1;e=s[n];break;case"right":e=i[r][n+1];break;case"down":if(s=i[r+1],!s)return!1;e=s[n];break;case"left":e=i[r][n-1]}return void 0!==e&&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]--}const[e,s]=this._cur;this._matrix[e][s]=this._VISITED,this.onMove&&this.onMove(this._cur)}}class Mt{constructor(t){this._val=t,this._isEnd=!1,this._children=new Map}get val(){return this._val}set val(t){this._val=t}get children(){return this._children}set children(t){this._children=t}get isEnd(){return this._isEnd}set isEnd(t){this._isEnd=t}}class St{constructor(t){if(this._root=new Mt(""),t)for(const e of t)this.add(e)}get root(){return this._root}set root(t){this._root=t}add(t){let e=this._root;for(const s of t){let t=e.children.get(s);t||(t=new Mt(s),e.children.set(s,t)),e=t}return e.isEnd=!0,!0}has(t){let e=this._root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return e.isEnd}remove(t){let e=!1;const s=(i,r)=>{const n=t[r],h=i.children.get(n);return!!h&&(r===t.length-1?!!h.isEnd&&(h.children.size>0?h.isEnd=!1:i.children.delete(n),e=!0,!0):!(!s(h,r+1)||i.isEnd||0!==h.children.size||(i.children.delete(n),0)))};return s(this.root,0),e}isAbsPrefix(t){let e=this._root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!e.isEnd}isPrefix(t){let e=this._root;for(const s of t){const t=e.children.get(s);if(!t)return!1;e=t}return!0}isCommonPrefix(t){let e="";const s=i=>{e+=i.val,e!==t&&(i.isEnd||i&&i.children&&1===i.children.size&&s(Array.from(i.children.values())[0]))};return s(this._root),e===t}getLongestCommonPrefix(){let t="";const e=s=>{t+=s.val,s.isEnd||s&&s.children&&1===s.children.size&&e(Array.from(s.children.values())[0])};return e(this._root),t}getAll(t=""){const e=[];let s=this._root;if(t)for(const e of t){const t=s.children.get(e);t&&(s=t)}return function t(s,i){for(const e of s.children.keys()){const r=s.children.get(e);void 0!==r&&t(r,i.concat(e))}s.isEnd&&e.push(i)}(s,t),e}}return e})()));
3
3
  //# sourceMappingURL=bundle.min.js.map